Created
June 2, 2010 21:41
-
-
Save zpao/423041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Polls the clipboard waiting for the expected value. A known value different than | |
* the expected value is put on the clipboard first (and also polled for) so we | |
* can be sure the value we get isn't just the expected value because it was already | |
* on the clipboard. This only uses the global clipboard and only for text/unicode | |
* values. | |
* | |
* @param aExpectedVal | |
* The string value that is expected to be on the clipboard | |
* @param aSetupFn | |
* A function responsible for setting the clipboard to the expected value, | |
* called after the known value setting succeeds. | |
* @param aSuccessFn | |
* A function called when the expected value is found on the clipboard. | |
* @param aFailureFn | |
* A function called if the expected value isn't found on the clipboard | |
* within 5s. It can also be called if the known value can't be found. | |
*/ | |
SimpleTest.waitForClipboard = function(aExpectedVal, aSetupFn, aSuccessFn, aFailureFn) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
waitForExplicitFinish(); | |
// the value we expect to be on the clipboard | |
const EXPECTED_VAL = "foo"; | |
// function that will set up the clipboard | |
function setup() { | |
Cc["@mozilla.org/widget/clipboardhelper;1"]. | |
getService(Ci.nsIClipboardHelper). | |
copyString(EXPECTED_VAL); | |
} | |
// function that will be run after the clipboard has EXPECTED_VAL | |
function nextTest() { | |
// do some other testing here if you want | |
finish(); | |
} | |
waitForClipboard(EXPECTED_VAL, setup, nextTest, finish); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment