commit dc9533fe8ec258aff8bf7c99c9d20586e6f58e5a Author: Neil Deakin neil@mozilla.com Date: Wed May 11 10:04:19 2016 -0400
Bug 1270277, HasDataMatchingFlavors should only return true for text/unicode, r=snorp --- dom/base/test/test_bug116083.html | 23 +++++++++++++++-------- widget/android/nsClipboard.cpp | 9 ++++++++- 2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/dom/base/test/test_bug116083.html b/dom/base/test/test_bug116083.html index dfdef8d..0d37242 100644 --- a/dom/base/test/test_bug116083.html +++ b/dom/base/test/test_bug116083.html @@ -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() { diff --git a/widget/android/nsClipboard.cpp b/widget/android/nsClipboard.cpp index cf8675b..9a49bb0 100644 --- a/widget/android/nsClipboard.cpp +++ b/widget/android/nsClipboard.cpp @@ -97,7 +97,14 @@ nsClipboard::HasDataMatchingFlavors(const char **aFlavorList, *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; }