OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 <script src="../resources/mojo-helpers.js"></script> | |
6 <script src="resources/mock-battery-monitor.js"></script> | |
5 <script> | 7 <script> |
6 description("Test basic API definitions."); | 8 description("Test basic API definitions."); |
7 | 9 |
8 if (!window.testRunner) | 10 if (!window.testRunner) |
9 debug('This test cannot be run without the TestRunner'); | 11 debug('This test cannot be run without the TestRunner'); |
10 if (!window.internals) | 12 if (!window.internals) |
Yuki
2016/03/30 02:39:45
Because of your great work, we no longer need wind
Sam McNally
2016/03/30 03:15:32
Done.
| |
11 debug('This test cannot be run without the window.internals'); | 13 debug('This test cannot be run without the window.internals'); |
12 | 14 |
13 // Clean-up any unused battery manager objects from previous tests. | 15 // Clean-up any unused battery manager objects from previous tests. |
14 gc(); | 16 gc(); |
15 jsTestIsAsync = true; | 17 jsTestIsAsync = true; |
16 testRunner.waitUntilDone(); | 18 testRunner.waitUntilDone(); |
17 | 19 |
18 var mockBatteryInfo; | |
19 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) { | |
20 mockBatteryInfo = { charging: charging, | |
21 chargingTime: chargingTime, | |
22 dischargingTime: dischargingTime, | |
23 level: level }; | |
24 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime , level); | |
25 } | |
26 | |
27 var battery; | 20 var battery; |
Yuki
2016/03/30 02:39:45
We don't need this variable.
Let's add |let| on li
Sam McNally
2016/03/30 03:15:32
Unfortunately, we do need this. The test assertion
| |
21 var promise; | |
Yuki
2016/03/30 02:39:45
nit: Better to declare this variable just before l
Sam McNally
2016/03/30 03:15:32
Done.
| |
28 function batteryStatusSuccess(batteryManager) { | 22 function batteryStatusSuccess(batteryManager) { |
29 debug('batteryStatusSuccess invoked'); | 23 debug('batteryStatusSuccess invoked'); |
30 battery = batteryManager; | 24 battery = batteryManager; |
31 | 25 |
32 shouldBeDefined("battery"); | 26 shouldBeDefined("battery"); |
33 shouldBeNonNull("battery"); | 27 shouldBeNonNull("battery"); |
34 shouldBeDefined("battery.charging"); | 28 shouldBeDefined("battery.charging"); |
35 shouldBeDefined("battery.chargingTime"); | 29 shouldBeDefined("battery.chargingTime"); |
36 shouldBeDefined("battery.dischargingTime"); | 30 shouldBeDefined("battery.dischargingTime"); |
37 shouldBeDefined("battery.level"); | 31 shouldBeDefined("battery.level"); |
38 | 32 |
39 shouldBe('battery.charging', 'mockBatteryInfo.charging'); | 33 shouldBe('battery.charging', 'mockBatteryInfo.charging'); |
Yuki
2016/03/30 02:39:45
Let's use |checkBatteryInfo| defined in mock-batte
Sam McNally
2016/03/30 03:15:32
Done.
| |
40 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime'); | 34 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime'); |
41 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime'); | 35 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
42 shouldBe('battery.level', 'mockBatteryInfo.level'); | 36 shouldBe('battery.level', 'mockBatteryInfo.level'); |
43 | 37 |
44 shouldBeTrue("typeof battery.onchargingchange == 'object'"); | 38 shouldBeTrue("typeof battery.onchargingchange == 'object'"); |
45 shouldBeTrue("typeof battery.onchargingtimechange == 'object'"); | 39 shouldBeTrue("typeof battery.onchargingtimechange == 'object'"); |
46 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'"); | 40 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'"); |
47 shouldBeTrue("typeof battery.onlevelchange == 'object'"); | 41 shouldBeTrue("typeof battery.onlevelchange == 'object'"); |
48 | 42 |
49 shouldBeTrue("'onchargingchange' in battery"); | 43 shouldBeTrue("'onchargingchange' in battery"); |
50 shouldBeTrue("'onchargingtimechange' in battery"); | 44 shouldBeTrue("'onchargingtimechange' in battery"); |
51 shouldBeTrue("'ondischargingtimechange' in battery"); | 45 shouldBeTrue("'ondischargingtimechange' in battery"); |
52 shouldBeTrue("'onlevelchange' in battery"); | 46 shouldBeTrue("'onlevelchange' in battery"); |
53 | 47 |
54 setTimeout(finishJSTest, 0); | 48 setTimeout(finishJSTest, 0); |
55 } | 49 } |
56 | 50 |
57 function batteryStatusFailure() { | 51 ready.then(() => { |
58 testFailed('failed to successfully resolve the promise'); | 52 promise = navigator.getBattery(); |
59 setTimeout(finishJSTest, 0); | 53 shouldBeDefined("promise"); |
60 } | 54 shouldBeDefined("promise.then"); |
61 | 55 promise.then(batteryStatusSuccess, batteryStatusFailure); |
62 promise = navigator.getBattery(); | 56 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
63 shouldBeDefined("promise"); | 57 }); |
64 shouldBeDefined("promise.then"); | |
65 promise.then(batteryStatusSuccess, batteryStatusFailure); | |
66 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | |
67 </script> | 58 </script> |
68 </body> | 59 </body> |
69 </html> | 60 </html> |
OLD | NEW |