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

Unified 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: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
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..7311c9ae68b6f40448e7d911be2573db18dbc38c
--- /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++;
+ 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);
+ setTimeout(function(){initThirdListener();}, 0);
+ }
+}
+
+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);
+ setTimeout(function(){initFourthListener();}, 0);
+}
+
+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>

Powered by Google App Engine
This is Rietveld 408576698