Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / battery-status / page-visibility.html
blob7f00ac7bd0f685e63971f0a75d74a075498ad883
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/js-test.js"></script>
5 <script>
6 description("Test with page visibility.");
8 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner');
11 // Clean-up any unused battery manager objects from previous tests.
12 gc();
13 jsTestIsAsync = true;
14 testRunner.waitUntilDone();
16 var mockBatteryInfo;
17 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, level) {
18 mockBatteryInfo = { charging: charging,
19 chargingTime: chargingTime,
20 dischargingTime: dischargingTime,
21 level: level };
22 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, level);
25 // compare obtained battery values with the mock values
26 function checkBatteryInfo(batteryManager) {
27 batteryInfo = batteryManager;
28 shouldBeDefined("batteryInfo");
29 shouldBeDefined("mockBatteryInfo");
30 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
31 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
32 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
33 shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
36 function batteryStatusFailure() {
37 testFailed('failed to successfully resolve the promise');
38 setTimeout(cleanupAndFinish, 0);
41 var battery;
42 function batteryStatusSuccess(batteryManager) {
43 battery = batteryManager;
44 checkBatteryInfo(battery);
45 battery.addEventListener('levelchange', failAndFinish);
46 testRunner.setPageVisibility("hidden");
47 debug("page is hidden");
48 setTimeout(fireNextMockBatteryInfo, 0);
51 function fireNextMockBatteryInfo() {
52 setAndFireMockBatteryInfo(false, 10, 20, 0.55);
53 testWithVisiblePage();
56 function testWithVisiblePage() {
57 battery.removeEventListener('levelchange', failAndFinish);
58 battery.addEventListener('levelchange', onLevelChange);
59 testRunner.setPageVisibility("visible");
60 debug("page is visible");
61 setAndFireMockBatteryInfo(false, 10, 20, 0.6);
64 function onLevelChange() {
65 checkBatteryInfo(battery);
66 battery.removeEventListener('levelchange', onLevelChange);
67 setTimeout(finishJSTest, 0);
70 function failAndFinish() {
71 testFailed('received event while the page was hidden');
72 setTimeout(finishJSTest, 0);
75 debug("page is visible");
76 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
77 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
78 </script>
79 </body>
80 </html>