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

Side by Side Diff: LayoutTests/fast/dom/DeviceLight/multiple-event-listeners.html

Issue 490773003: [DeviceLight] Add Layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix tim's comments Created 5 years, 8 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../../resources/js-test.js"></script>
5 <script>
6
7 description('Tests using multiple event handlers for the Device Light API.');
8
9 var mockEvent;
10 var expectedEvent;
11 function setMockLight(value) {
12
13 mockEvent = {value: value};
14
15 if (window.testRunner)
16 testRunner.setMockDeviceLight(mockEvent.value);
17 else
18 debug('This test can not be run without the TestRunner');
19 }
20
21 var deviceLightEvent;
22 function checkLight(event) {
23 deviceLightEvent = event;
24 shouldBe('deviceLightEvent.value', 'expectedEvent.value');
25 }
26
27 var firstListenerCount = 0;
28 function firstListener(event) {
29 checkLight(event);
30 firstListenerCount++;
31 proceedIfNecessary();
32 }
33
34 var secondListenerCount = 0;
35 function secondListener(event) {
36 checkLight(event);
37 secondListenerCount++;
38 proceedIfNecessary();
39 }
40
41 function proceedIfNecessary() {
42 if (firstListenerCount == 1 && secondListenerCount == 1) {
43 setMockLight(20);
44 // Note: this should not stop Device Light updates,
45 // because there is still one listener active.
46 window.removeEventListener('devicelight', secondListener);
47 initThirdListener();
48 }
49 }
50
51 var childFrame;
52 function initThirdListener() {
53 childFrame = document.createElement('iframe');
54 document.body.appendChild(childFrame);
55 childFrame.contentWindow.addEventListener('devicelight', thirdListener);
56 }
57
58 function thirdListener(event) {
59 // Expect the cached event because Device Light was already active
60 // when third listener was added.
61 checkLight(event);
62 window.removeEventListener('devicelight', firstListener);
63 childFrame.contentWindow.removeEventListener('devicelight', thirdListener);
64 initFourthListener();
65 }
66
67 function initFourthListener() {
68 expectedEvent = mockEvent;
69 window.addEventListener('devicelight', fourthListener);
70 }
71
72 function fourthListener(event) {
73 checkLight(event);
74 finishJSTest();
75 }
76
77 setMockLight(10);
78 expectedEvent = mockEvent;
79 window.addEventListener('devicelight', firstListener);
80 window.addEventListener('devicelight', secondListener);
81
82 window.jsTestIsAsync = true;
83
84 </script>
85 </body>
86 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698