OLD | NEW |
---|---|
(Empty) | |
1 // getLocked(). if true then fail. | |
2 // setLocked(true) | |
3 // wait for onChanged. if timeout then fail. | |
4 // getLocked(). if false then fail. | |
5 // setLocked(false) | |
6 // wait for onChanged. if timeout then fail. | |
7 // getLocked(). if true then fail. | |
8 // succeed | |
9 | |
10 var stage = 0; | |
11 | |
12 function now() { | |
13 return (new Date()).getTime(); | |
14 } | |
15 | |
16 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.
| |
17 return function() { | |
18 watchdog.clear(); | |
19 var result = wrapped.apply(this, arguments); | |
20 watchdog.clear(); | |
21 if (result) { | |
22 watchdog.timer = window.setTimeout(function() { | |
23 chrome.test.fail('timeout after ' + (now() - watchdog.started) + | |
24 'ms at stage ' + stage); | |
25 }, watchdog.timeoutMs); | |
26 watchdog.started = now(); | |
27 console.debug('watchdog started at ' + watchdog.started + | |
28 ' at stage ' + stage); | |
29 } | |
30 return result; | |
31 } | |
32 } | |
33 watchdog.timer = null; | |
34 watchdog.timeoutMs = 2000; | |
35 watchdog.started = 0; | |
36 watchdog.clear = function() { | |
37 if (!watchdog.timer) { | |
38 return; | |
39 } | |
40 console.debug('watchdog cleared after ' + (now() - watchdog.started) + 'ms'); | |
41 window.clearTimeout(watchdog.timer); | |
42 watchdog.timer = null; | |
43 watchdog.started = 0; | |
44 }; | |
45 | |
46 function gotLocked(locked) { | |
47 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.
| |
48 if (stage === 0) { | |
49 if (locked) { | |
50 chrome.test.fail('locked at stage ' + stage); | |
51 } else { | |
52 chrome.screenlockPrivate.setLocked(true); | |
53 ++stage; | |
54 return true; | |
55 } | |
56 } else if (stage === 1) { | |
57 if (!locked) { | |
58 chrome.test.fail('unlocked at stage ' + stage); | |
59 } else { | |
60 chrome.screenlockPrivate.setLocked(false); | |
61 ++stage; | |
62 return true; | |
63 } | |
64 } else if (stage === 2) { | |
65 if (locked) { | |
66 chrome.test.fail('locked at stage ' + stage); | |
67 } else { | |
68 chrome.test.succeed(); | |
69 } | |
70 } | |
71 } | |
72 | |
73 var step = watchdog(function() { | |
74 chrome.screenlockPrivate.getLocked(watchdog(gotLocked)); | |
75 }); | |
76 | |
77 chrome.screenlockPrivate.onChanged.addListener(watchdog(function(locked) { | |
78 console.log('onChanged stage=' + stage + ' locked=' + locked); | |
79 if (locked != (1 == (stage % 2))) { | |
80 chrome.test.fail((locked ? '' : 'un') + 'locked at stage ' + stage + | |
81 ' onChanged'); | |
82 } else { | |
83 return step(); | |
84 } | |
85 })); | |
86 | |
87 step(); | |
OLD | NEW |