Chromium Code Reviews| Index: LayoutTests/fast/dom/DeviceLight/multiple-event-listeners.html |
| diff --git a/LayoutTests/fast/dom/DeviceLight/multiple-event-listeners.html b/LayoutTests/fast/dom/DeviceLight/multiple-event-listeners.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b7a554b9dd46413d1cc36aaf896b440c123b0685 |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/DeviceLight/multiple-event-listeners.html |
| @@ -0,0 +1,85 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<body> |
| +<script src="../../../resources/js-test.js"></script> |
| +<script> |
| + |
| +description('Tests using multiple event handlers for the Device Light API.'); |
| + |
| +var mockEvent; |
| +var expectedEvent; |
| +function setMockLight(value) { |
| + |
| + mockEvent = {value: value}; |
| + |
| + if (window.testRunner) |
| + testRunner.setMockDeviceLight(mockEvent.value); |
| + else |
| + debug('This test can not be run without the TestRunner'); |
| +} |
| + |
| +var deviceLightEvent; |
| +function checkLight(event) { |
| + deviceLightEvent = event; |
| + shouldBe('deviceLightEvent.value', 'expectedEvent.value'); |
| +} |
| + |
| +var counter = 0; |
| +function firstListener(event) { |
| + checkLight(event); |
| + counter++; |
|
timvolodine
2015/03/30 13:00:54
technically the same counter is used for secondLis
riju_
2015/03/31 11:03:41
Done. i checked a few times, firstListener and sec
|
| + proceedIfNecessary(); |
| +} |
| + |
| +function secondListener(event) { |
| + checkLight(event); |
| + counter++; |
| + proceedIfNecessary(); |
| +} |
| + |
| +function proceedIfNecessary() { |
| + if (counter == 2) { |
| + setMockLight(20); |
| + // Note: this should not stop Device Light updates, |
| + // because there is still one listener active. |
| + window.removeEventListener('devicelight', secondListener); |
| + initThirdListener(); |
| + } |
| +} |
| + |
| +var childFrame; |
| +function initThirdListener() { |
| + childFrame = document.createElement('iframe'); |
| + document.body.appendChild(childFrame); |
| + childFrame.contentWindow.addEventListener('devicelight', thirdListener); |
| +} |
| + |
| +function thirdListener(event) { |
| + // Expect the cached event because Device Light was already active |
| + // when third listener was added. |
| + checkLight(event); |
| + window.removeEventListener('devicelight', firstListener); |
| + childFrame.contentWindow.removeEventListener('devicelight', thirdListener); |
| + initFourthListener(); |
| +} |
| + |
| +function initFourthListener() { |
| + expectedEvent = mockEvent; |
| + window.addEventListener('devicelight', fourthListener); |
| +} |
| + |
| +function fourthListener(event) { |
| + checkLight(event); |
| + finishJSTest(); |
| +} |
| + |
| +setMockLight(10); |
| +expectedEvent = mockEvent; |
| +window.addEventListener('devicelight', firstListener); |
| +window.addEventListener('devicelight', secondListener); |
| + |
| +window.jsTestIsAsync = true; |
| + |
| +</script> |
| +</body> |
| +</html> |