Bug 1338328 - Change error type for custom-clipdata mime type, and add test for correct exception type, r=baku
☠☠ backed out by 413a21e421db ☠ ☠
authorMichael Layzell <michael@thelayzells.com>
Wed, 01 Mar 2017 15:15:36 -0500
changeset 374545 bfc13d436dd486b917fb707f9648651efe5d35fb
parent 374544 f3ee1078d7099276195aed0603e12d26dfae1807
child 374546 39cba44c517d9a4060215449ddab6956c7abfe86
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1338328
milestone54.0a1
Bug 1338328 - Change error type for custom-clipdata mime type, and add test for correct exception type, r=baku MozReview-Commit-ID: 9qwwXxWgWrO
dom/events/DataTransfer.cpp
dom/tests/mochitest/general/test_clipboard_events.html
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -676,17 +676,17 @@ DataTransfer::SetDataAtInternal(const ns
   if (aIndex > 0 &&
       (mEventMessage == eCut || mEventMessage == eCopy ||
        mEventMessage == ePaste)) {
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   // Don't allow the custom type to be assigned.
   if (aFormat.EqualsLiteral(kCustomTypesMime)) {
-    return NS_ERROR_TYPE_ERR;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
   }
 
   if (!PrincipalMaySetData(aFormat, aData, aSubjectPrincipal)) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   return SetDataWithPrincipal(aFormat, aData, aIndex, aSubjectPrincipal);
 }
--- a/dom/tests/mochitest/general/test_clipboard_events.html
+++ b/dom/tests/mochitest/general/test_clipboard_events.html
@@ -49,17 +49,18 @@ var testFunctions = [
   test_input_onpaste_abort,
   test_input_cut_dataTransfer,
   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_eventspref_disabled,
+  test_input_cut_disallowed_types_dataTransfer,
   ];
 
 function doTests()
 {
   // Init clipboard
   setClipboardText(clipboardInitialValue);
 
   // Reset value of contentInput.
@@ -671,14 +672,45 @@ function checkCachedDataTransfer(cd, eve
 
   var exh = false;
   try { cd.mozClearDataAt("text/plain", 0); } catch (ex) { exh = true; }
   ok(eventtype == "paste" ? exh : !exh, "exception occured clearing " + testprefix);
 
   is(getClipboardText(), "Some Clipboard Text", "clipboard not changed using " + testprefix);
 }
 
+function test_input_cut_disallowed_types_dataTransfer() {
+  selectContentInput();
+  let oncutExecuted = false;
+  contentInput.oncut = function(event) {
+    // Setting an arbitrary type should be OK
+    try {
+      event.clipboardData.setData("apple/cider", "Anything your heart desires");
+      ok(true, "We should have successfully executed the setData call");
+    } catch(e) {
+      ok(false, "We should not have gotten an exception for trying to set that data");
+    }
+
+    // Unless that type happens to be application/x-moz-custom-clipdata
+    try {
+      event.clipboardData.setData("application/x-moz-custom-clipdata", "Anything your heart desires");
+      ok(false, "We should not have successfully executed the setData call");
+    } catch(e) {
+      is(e.name, "NotSupportedError",
+         "We should have gotten an NotSupportedError exception for trying to set that data");
+    }
+    oncutExecuted = true;
+  };
+
+  try {
+    synthesizeKey("x", {accelKey: 1});
+    ok(oncutExecuted, "The oncut handler should have been executed");
+  } finally {
+    contentInput.oncut = null;
+  }
+}
+
 SimpleTest.waitForFocus(doTests);
 
 </script>
 </pre>
 </body>
 </html>