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; }