Bug 1270277, HasDataMatchingFlavors should only return true for text/unicode, r=snorp
authorNeil Deakin <neil@mozilla.com>
Wed, 11 May 2016 10:04:19 -0400
changeset 296982 bb36d2769fe3689817a8b33f9a6c0eb6d63ad1d2
parent 296981 d4e621e02edccfff3eb4cb6b2a47655eca845280
child 296983 5b8f356e9556d9e8a7d86ffc39d63453956dd640
push id76544
push userneil@mozilla.com
push dateWed, 11 May 2016 14:05:20 +0000
treeherdermozilla-inbound@bb36d2769fe3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1270277
milestone49.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 1270277, HasDataMatchingFlavors should only return true for text/unicode, r=snorp
dom/base/test/test_bug116083.html
widget/android/nsClipboard.cpp
--- a/dom/base/test/test_bug116083.html
+++ b/dom/base/test/test_bug116083.html
@@ -47,42 +47,49 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div data-result="&#10;foo bar&#10;">foo  bar</div>
 </div>
 <script type="application/javascript">
 
 const Cc = SpecialPowers.Cc;
 const Ci = SpecialPowers.Ci;
 
 function hasExpectedFlavors() {
-  var flavors = [
-    "text/plain",
-    "text/html",
-    "application/x-moz-nativehtml",
-  ];
   var cb = Cc["@mozilla.org/widget/clipboard;1"].
            getService(Ci.nsIClipboard);
-  return cb.hasDataMatchingFlavors(flavors, flavors.length,
-                                   cb.kGlobalClipboard);
+
+  ok(cb.hasDataMatchingFlavors(["text/unicode"], 1, cb.kGlobalClipboard),
+     "The clipboard has text/unicode");
+
+  // Android only supports plain text
+  if (navigator.appVersion.indexOf("Android") == -1) {
+    ok(cb.hasDataMatchingFlavors(["text/html"], 1, cb.kGlobalClipboard),
+       "The clipboard has text/html");
+  }
+
+  if (navigator.appVersion.indexOf("Win") >= 0) {
+    ok(cb.hasDataMatchingFlavors(["application/x-moz-nativehtml"], 1, cb.kGlobalClipboard),
+       "The clipboard has application/x-moz-nativehtml");
+  }
 }
 
 function nextTest() {
   var div = document.querySelector("#content>div");
   if (!div) {
     SimpleTest.finish();
     return;
   }
   getSelection().selectAllChildren(div);
   var expected = div.hasAttribute("data-result") ?
                  div.getAttribute("data-result") :
                  div.textContent;
   SimpleTest.waitForClipboard(expected, function() {
     synthesizeKey("C", {accelKey: true});
   }, function() {
     ok(true, div.getAttribute("style") + " passed");
-    ok(hasExpectedFlavors(), "The clipboard has the expected flavors");
+    hasExpectedFlavors();
     div.parentNode.removeChild(div);
     nextTest();
   }, function() {
     ok(false, "failed to copy the expected content to the clipboard");
     SimpleTest.finish();
   });
 }
 
--- a/widget/android/nsClipboard.cpp
+++ b/widget/android/nsClipboard.cpp
@@ -92,17 +92,24 @@ nsClipboard::EmptyClipboard(int32_t aWhi
 NS_IMETHODIMP
 nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
                                     uint32_t aLength, int32_t aWhichClipboard,
                                     bool *aHasText)
 {
   *aHasText = false;
   if (aWhichClipboard != kGlobalClipboard)
     return NS_ERROR_NOT_IMPLEMENTED;
-  *aHasText = widget::Clipboard::HasText();
+
+  for (uint32_t k = 0; k < aLength; k++) {
+    if (strcmp(aFlavorList[k], kUnicodeMime) == 0) {
+      *aHasText = widget::Clipboard::HasText();
+      break;
+    }
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
 {
   *aIsSupported = false;
   return NS_OK;