Skip to content

Instantly share code, notes, and snippets.

@zpao
Created June 2, 2010 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zpao/423041 to your computer and use it in GitHub Desktop.
Save zpao/423041 to your computer and use it in GitHub Desktop.
/*
* 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) {
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