Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: LayoutTests/batterystatus/script-tests/add-listener-from-callback.js

Issue 16298005: Remove Battery Status API support code from Blink (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 description('Tests that adding a new event listener from a callback works as exp ected.');
2
3 var charging = false;
4 var chargingTime = Number.POSITIVE_INFINITY;
5 var dischargingTime = 6000;
6 var level = 0.7;
7
8 var battery = navigator.webkitBattery;
9
10 function checkBatteryStatus() {
11 shouldBe("battery.charging", "false");
12 shouldBe("battery.chargingTime", "Infinity");
13 shouldBe("battery.dischargingTime", "6000");
14 shouldBe("battery.level", "0.7");
15 }
16
17 var firstListenerEvents = 0;
18 function firstListener() {
19 checkBatteryStatus();
20 if (++firstListenerEvents == 1) {
21 battery.addEventListener('chargingchange', secondListener);
22 internals.setBatteryStatus(document, 'chargingchange', charging, chargin gTime, dischargingTime, level);
23 }
24 else if (firstListenerEvents > 2)
25 testFailed('Too many events for first listener.');
26 maybeFinishTest();
27 }
28
29 var secondListenerEvents = 0;
30 function secondListener() {
31 checkBatteryStatus();
32 if (++secondListenerEvents > 1)
33 testFailed('Too many events for second listener.');
34 maybeFinishTest();
35 }
36
37 function maybeFinishTest() {
38 if (firstListenerEvents == 2 && secondListenerEvents == 1)
39 finishJSTest();
40 }
41
42 battery.addEventListener('chargingchange', firstListener);
43 internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, d ischargingTime, level);
44 window.jsTestIsAsync = true;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698