From a81636618b48b4f1361535a2da4a55676e9d52f2 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 12 Jul 2021 03:55:21 +0000 Subject: [PATCH] Bug 1719387 - Make `test_bug795418-2.html` request `text/unicode` flavor in the headless mode r=smaug Until fixing bug 1686012, clipboard in the headless mode does not support "text/html" flavor. Therefore, the `waitForClipboard` in the test does not get expected value as `aData` in the first callback. So, it should request `text/unicode` in the headless mode. Depends on D119483 Differential Revision: https://phabricator.services.mozilla.com/D119484 --- editor/libeditor/tests/test_bug795418-2.html | 27 +++++++++---------- .../content/SpecialPowersChild.jsm | 4 +++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/editor/libeditor/tests/test_bug795418-2.html b/editor/libeditor/tests/test_bug795418-2.html index 64a33398b451..1360b2e550c5 100644 --- a/editor/libeditor/tests/test_bug795418-2.html +++ b/editor/libeditor/tests/test_bug795418-2.html @@ -27,15 +27,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795418 /** Test for Bug 795418 **/ SimpleTest.waitForExplicitFinish(); SimpleTest.waitForFocus(function() { - var div = document.getElementById("copySource"); - var sel = window.getSelection(); - sel.removeAllRanges(); - - // Select the text from the text node in div. - var r = document.createRange(); - r.setStart(div.firstChild, 0); - r.setEnd(div.firstChild, 9); - sel.addRange(r); + const div = document.getElementById("copySource"); + getSelection().setBaseAndExtent(div.firstChild, 0, div.firstChild, "Copy this".length); + info(`Selected test: "${getSelection().getRangeAt(0).toString()}"`); function checkResult() { var iframe = document.querySelector("iframe"); @@ -66,20 +60,23 @@ SimpleTest.waitForFocus(function() { SimpleTest.waitForClipboard( aData => { - // XXX Oddly, specifying `r.toString()` causes timeout in headless mode. - info(`copied text: "${aData}"`); - return true; + if (aData.includes(`${getSelection().getRangeAt(0)?.toString()}`)) { + return true; + } + info(`Text in the clipboard: "${aData}"`); + return false; }, function setup() { - synthesizeKey("C", {accelKey: true}); + synthesizeKey("c", {accelKey: true}); }, function onSuccess() { - setTimeout(pasteQuote, 0); + SimpleTest.executeSoon(pasteQuote); }, function onFailure() { SimpleTest.finish(); }, - "text/html" + // TODO: bug 1686012 + SpecialPowers.isHeadless ? "text/unicode" : "text/html" ); }); diff --git a/testing/specialpowers/content/SpecialPowersChild.jsm b/testing/specialpowers/content/SpecialPowersChild.jsm index 0706ecaa5154..b5b906e3f777 100644 --- a/testing/specialpowers/content/SpecialPowersChild.jsm +++ b/testing/specialpowers/content/SpecialPowersChild.jsm @@ -712,6 +712,10 @@ class SpecialPowersChild extends JSWindowActorChild { return Cr; } + get isHeadless() { + return Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo).isHeadless; + } + get addProfilerMarker() { return ChromeUtils.addProfilerMarker; }