summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_copy_image_data.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/inspector/markup/test/browser_markup_copy_image_data.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/inspector/markup/test/browser_markup_copy_image_data.js')
-rw-r--r--devtools/client/inspector/markup/test/browser_markup_copy_image_data.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/devtools/client/inspector/markup/test/browser_markup_copy_image_data.js b/devtools/client/inspector/markup/test/browser_markup_copy_image_data.js
new file mode 100644
index 000000000..275bff0b7
--- /dev/null
+++ b/devtools/client/inspector/markup/test/browser_markup_copy_image_data.js
@@ -0,0 +1,67 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that image nodes have the "copy data-uri" contextual menu item enabled
+// and that clicking it puts the image data into the clipboard
+
+add_task(function* () {
+ yield addTab(URL_ROOT + "doc_markup_image_and_canvas.html");
+ let {inspector, testActor} = yield openInspector();
+
+ yield selectNode("div", inspector);
+ yield assertCopyImageDataNotAvailable(inspector);
+
+ yield selectNode("img", inspector);
+ yield assertCopyImageDataAvailable(inspector);
+ let expectedSrc = yield testActor.getAttribute("img", "src");
+ yield triggerCopyImageUrlAndWaitForClipboard(expectedSrc, inspector);
+
+ yield selectNode("canvas", inspector);
+ yield assertCopyImageDataAvailable(inspector);
+ let expectedURL = yield testActor.eval(`
+ content.document.querySelector(".canvas").toDataURL();`);
+ yield triggerCopyImageUrlAndWaitForClipboard(expectedURL, inspector);
+
+ // Check again that the menu isn't available on the DIV (to make sure our
+ // menu updating mechanism works)
+ yield selectNode("div", inspector);
+ yield assertCopyImageDataNotAvailable(inspector);
+});
+
+function* assertCopyImageDataNotAvailable(inspector) {
+ let allMenuItems = openContextMenuAndGetAllItems(inspector);
+ let item = allMenuItems.find(i => i.id === "node-menu-copyimagedatauri");
+
+ ok(item, "The menu item was found in the contextual menu");
+ ok(item.disabled, "The menu item is disabled");
+}
+
+function* assertCopyImageDataAvailable(inspector) {
+ let allMenuItems = openContextMenuAndGetAllItems(inspector);
+ let item = allMenuItems.find(i => i.id === "node-menu-copyimagedatauri");
+
+ ok(item, "The menu item was found in the contextual menu");
+ ok(!item.disabled, "The menu item is enabled");
+}
+
+function triggerCopyImageUrlAndWaitForClipboard(expected, inspector) {
+ let def = defer();
+
+ SimpleTest.waitForClipboard(expected, () => {
+ inspector.markup.getContainer(inspector.selection.nodeFront)
+ .copyImageDataUri();
+ }, () => {
+ ok(true, "The clipboard contains the expected value " +
+ expected.substring(0, 50) + "...");
+ def.resolve();
+ }, () => {
+ ok(false, "The clipboard doesn't contain the expected value " +
+ expected.substring(0, 50) + "...");
+ def.resolve();
+ });
+
+ return def.promise;
+}