diff --git a/browser/base/content/test/browser_bug321000.js b/browser/base/content/test/browser_bug321000.js index 2033831a9128..d73a926a1278 100644 --- a/browser/base/content/test/browser_bug321000.js +++ b/browser/base/content/test/browser_bug321000.js @@ -63,62 +63,21 @@ var gTests = [ function test() { waitForExplicitFinish(); - // Put a multi-line string in the clipboard. - info("About to put a string in clipboard"); - Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper) - .copyString(kTestString); + let cbHelper = Cc["@mozilla.org/widget/clipboardhelper;1"]. + getService(Ci.nsIClipboardHelper); + // Put a multi-line string in the clipboard. // Setting the clipboard value is an async OS operation, so we need to poll // the clipboard for valid data before going on. - setTimeout(poll_clipboard, 100); -} - -var runCount = 0; -function poll_clipboard() { - // Poll for a maximum of 5s (each run happens after 100ms). - if (++runCount > 50) { - // Log the failure. - ok(false, "Timed out while polling clipboard for pasted data"); - // Cleanup and interrupt the test. - finish_test(); - return; - } - - info("Polling clipboard cycle " + runCount); - var clip = Cc["@mozilla.org/widget/clipboard;1"]. - getService(Ci.nsIClipboard); - var trans = Cc["@mozilla.org/widget/transferable;1"]. - createInstance(Ci.nsITransferable); - trans.addDataFlavor("text/unicode"); - var str = new Object(); - try { - // This code could throw if the clipboard is not set yet. - clip.getData(trans, clip.kGlobalClipboard); - trans.getTransferData("text/unicode", str, {}); - str = str.value.QueryInterface(Ci.nsISupportsString); - } - catch(ex) {} - - if (kTestString == str) { - next_test(); - } - else - setTimeout(poll_clipboard, 100); + waitForClipboard(kTestString, function() { cbHelper.copyString(kTestString); }, + next_test, finish); } function next_test() { - if (gTests.length) { - var currentTest = gTests.shift(); - test_paste(currentTest); - } - else { - // No more tests to run. - // Clear the clipboard, emptyClipboard would not clear the native one, so - // we are setting it to an empty string. - Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper) - .copyString(""); + if (gTests.length) + test_paste(gTests.shift()); + else finish(); - } } function test_paste(aCurrentTest) { diff --git a/toolkit/components/passwordmgr/test/browser/browser_passwordmgrcopypwd.js b/toolkit/components/passwordmgr/test/browser/browser_passwordmgrcopypwd.js index 069e1552afb3..8bd1f6cff463 100644 --- a/toolkit/components/passwordmgr/test/browser/browser_passwordmgrcopypwd.js +++ b/toolkit/components/passwordmgr/test/browser/browser_passwordmgrcopypwd.js @@ -75,47 +75,10 @@ function test() { let data = ""; let polls = 0; - function step1() { - Cc["@mozilla.org/widget/clipboardhelper;1"]. - getService(Ci.nsIClipboardHelper).copyString("manatee"); - - waitForClipboard("manatee", step2); - } - - function step2() { + function copyPassword() { let doc = pwmgrdlg.document; doc.getElementById("signonsTree").currentIndex = 2; doc.getElementById("context-copypassword").doCommand(); - - polls = 0; - waitForClipboard("coded", cleanUp); - } - - function waitForClipboard(expectedValue, callback) { - if (++polls > 50) { - ok(false, "Timed out while polling clipboard"); - cleanUp(); - return; - } - - let data = null; - let trans = Cc["@mozilla.org/widget/transferable;1"]. - createInstance(Ci.nsITransferable); - trans.addDataFlavor("text/unicode"); - clip.getData(trans, clip.kGlobalClipboard); - - try { - let str = {}; - trans.getTransferData("text/unicode", str, {}); - data = str.value.QueryInterface(Ci.nsISupportsString).data; - } catch (e) {} - - if (data == expectedValue) { - is(data, expectedValue, "Clipboard should match expected value"); - callback(); - } - else - setTimeout(waitForClipboard, 100, expectedValue, callback); } function cleanUp() { @@ -127,6 +90,6 @@ function test() { pwmgrdlg.close(); } - step1(); + waitForClipboard("coded", copyPassword, cleanUp, cleanUp); } }