Commit c33bf961 authored by Neil Deakin's avatar Neil Deakin Committed by Georg Koppen
Browse files

Bug 1270277, HasDataMatchingFlavors should only return true for text/unicode, r=snorp

parent 2a06f9c2
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -52,15 +52,22 @@ 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() {
@@ -77,7 +84,7 @@ function nextTest() {
    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() {
+8 −1
Original line number Diff line number Diff line
@@ -97,7 +97,14 @@ nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
  *aHasText = false;
  if (aWhichClipboard != kGlobalClipboard)
    return NS_ERROR_NOT_IMPLEMENTED;

  for (uint32_t k = 0; k < aLength; k++) {
    if (strcmp(aFlavorList[k], kUnicodeMime) == 0) {
      *aHasText = widget::Clipboard::HasText();
      break;
    }
  }

  return NS_OK;
}