Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/screenlockPrivate/test.js |
| diff --git a/chrome/test/data/extensions/api_test/screenlockPrivate/test.js b/chrome/test/data/extensions/api_test/screenlockPrivate/test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bc0eda8c901e18eb9009c59611ca7eb035485067 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/screenlockPrivate/test.js |
| @@ -0,0 +1,87 @@ |
| +// getLocked(). if true then fail. |
| +// setLocked(true) |
| +// wait for onChanged. if timeout then fail. |
| +// getLocked(). if false then fail. |
| +// setLocked(false) |
| +// wait for onChanged. if timeout then fail. |
| +// getLocked(). if true then fail. |
| +// succeed |
| + |
| +var stage = 0; |
| + |
| +function now() { |
| + return (new Date()).getTime(); |
| +} |
| + |
| +function watchdog(wrapped) { |
|
Matt Perry
2013/11/13 01:01:14
Cool addition, but the test fixture has a built in
benjhayden
2013/11/13 17:17:51
Done.
|
| + return function() { |
| + watchdog.clear(); |
| + var result = wrapped.apply(this, arguments); |
| + watchdog.clear(); |
| + if (result) { |
| + watchdog.timer = window.setTimeout(function() { |
| + chrome.test.fail('timeout after ' + (now() - watchdog.started) + |
| + 'ms at stage ' + stage); |
| + }, watchdog.timeoutMs); |
| + watchdog.started = now(); |
| + console.debug('watchdog started at ' + watchdog.started + |
| + ' at stage ' + stage); |
| + } |
| + return result; |
| + } |
| +} |
| +watchdog.timer = null; |
| +watchdog.timeoutMs = 2000; |
| +watchdog.started = 0; |
| +watchdog.clear = function() { |
| + if (!watchdog.timer) { |
| + return; |
| + } |
| + console.debug('watchdog cleared after ' + (now() - watchdog.started) + 'ms'); |
| + window.clearTimeout(watchdog.timer); |
| + watchdog.timer = null; |
| + watchdog.started = 0; |
| +}; |
| + |
| +function gotLocked(locked) { |
| + console.log('step stage=' + stage + ' locked=' + locked); |
|
Matt Perry
2013/11/13 01:01:14
remove the logs before checking in to reduce log s
benjhayden
2013/11/13 17:17:51
Done.
|
| + if (stage === 0) { |
| + if (locked) { |
| + chrome.test.fail('locked at stage ' + stage); |
| + } else { |
| + chrome.screenlockPrivate.setLocked(true); |
| + ++stage; |
| + return true; |
| + } |
| + } else if (stage === 1) { |
| + if (!locked) { |
| + chrome.test.fail('unlocked at stage ' + stage); |
| + } else { |
| + chrome.screenlockPrivate.setLocked(false); |
| + ++stage; |
| + return true; |
| + } |
| + } else if (stage === 2) { |
| + if (locked) { |
| + chrome.test.fail('locked at stage ' + stage); |
| + } else { |
| + chrome.test.succeed(); |
| + } |
| + } |
| +} |
| + |
| +var step = watchdog(function() { |
| + chrome.screenlockPrivate.getLocked(watchdog(gotLocked)); |
| +}); |
| + |
| +chrome.screenlockPrivate.onChanged.addListener(watchdog(function(locked) { |
| + console.log('onChanged stage=' + stage + ' locked=' + locked); |
| + if (locked != (1 == (stage % 2))) { |
| + chrome.test.fail((locked ? '' : 'un') + 'locked at stage ' + stage + |
| + ' onChanged'); |
| + } else { |
| + return step(); |
| + } |
| +})); |
| + |
| +step(); |