Bug 1342057 - Part 2: Add a test that the MIME type is set correctly for image data, r=baku
☠☠ backed out by 26ee17ce7b5b ☠ ☠
authorMichael Layzell <michael@thelayzells.com>
Fri, 24 Feb 2017 16:37:12 -0500
changeset 394492 5a1e069911faeeaf1f3d3a6047251464a17b3e31
parent 394491 6758f6e0b836e38e21e2ca4a346f9b205d8b72f1
child 394493 4c3e4f77ea2fc477936ba06fc4488a6e4468a6d2
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1342057
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1342057 - Part 2: Add a test that the MIME type is set correctly for image data, r=baku Unfortunately drag and drop / clipboard data is not super easy to test with our current testing infrastructure, so we can't do too much better than this. Additional testing will have to be done manually through our QA process once this has landed. MozReview-Commit-ID: 1etmIxjjiBd
dom/tests/mochitest/general/test_clipboard_events.html
--- a/dom/tests/mochitest/general/test_clipboard_events.html
+++ b/dom/tests/mochitest/general/test_clipboard_events.html
@@ -5,16 +5,17 @@
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="border: 3px solid black; padding: 3em;">CONTENT TEXT<input id="content-input" value="INPUT TEXT"></div>
+<img id="image" src="image_50.png">
 <button id="button">Button</button>
 
 <div id="syntheticSpot" oncut="compareSynthetic(event, 'cut')"
                         oncopy="compareSynthetic(event, 'copy')"
                         onpaste="compareSynthetic(event, 'paste')">Spot</div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
@@ -51,16 +52,17 @@ var testFunctions = [
   test_input_cut_abort_dataTransfer,
   test_input_copy_dataTransfer,
   test_input_paste_dataTransfer,
   test_input_paste_abort_dataTransfer,
   test_input_copypaste_dataTransfer_multiple,
   test_input_copy_button_dataTransfer,
   test_eventspref_disabled,
   test_input_cut_disallowed_types_dataTransfer,
+  test_image_dataTransfer,
   ];
 
 function doTests()
 {
   // Init clipboard
   setClipboardText(clipboardInitialValue);
 
   // Reset value of contentInput.
@@ -703,14 +705,48 @@ function test_input_cut_disallowed_types
   try {
     synthesizeKey("x", {accelKey: 1});
     ok(oncutExecuted, "The oncut handler should have been executed");
   } finally {
     contentInput.oncut = null;
   }
 }
 
+// Try copying an image to the clipboard and make sure that it looks correct when pasting it.
+function test_image_dataTransfer() {
+  // Copy the image's data to the clipboard
+  SpecialPowers.setCommandNode(window, document.getElementById("image"));
+  SpecialPowers.doCommand(window, "cmd_copyImageContents");
+
+  let onpasteCalled = false;
+  document.onpaste = function(event) {
+    ok(event instanceof ClipboardEvent, "paste event is an ClipboardEvent");
+    ok(event.clipboardData instanceof DataTransfer, "paste event dataTransfer is a DataTransfer");
+    let items = event.clipboardData.items;
+    let foundData = false;
+    for (let i = 0; i < items.length; ++i)  {
+      if (items[i].kind == "file") {
+        foundData = true;
+        is(items[i].type, "image/png", "The type of the data must be image/png");
+        is(items[i].getAsFile().type, "image/png", "The attached file must be image/png");
+      }
+    }
+    ok(foundData, "Should have found a file entry in the DataTransferItemList");
+    let files = event.clipboardData.files;
+    is(files.length, 1, "There should only be one file on the DataTransfer");
+    is(files[0].type, "image/png", "The only file should be an image/png");
+    onpasteCalled = true;
+  }
+
+  try {
+    synthesizeKey("v", {accelKey: 1});
+    ok(onpasteCalled, "The paste event listener must have been called");
+  } finally {
+    document.onpaste = null;
+  }
+}
+
 SimpleTest.waitForFocus(doTests);
 
 </script>
 </pre>
 </body>
 </html>