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

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: Fix tim's comments Created 5 years, 9 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..9092fc2b37b5a6d6e919f1ecbb87a26b727b2227
--- /dev/null
+++ b/LayoutTests/fast/dom/DeviceLight/multiple-event-listeners.html
@@ -0,0 +1,86 @@
+<!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 firstListenerCount = 0;
+function firstListener(event) {
+ checkLight(event);
+ firstListenerCount++;
+ proceedIfNecessary();
+}
+
+var secondListenerCount = 0;
+function secondListener(event) {
+ checkLight(event);
+ secondListenerCount++;
+ proceedIfNecessary();
+}
+
+function proceedIfNecessary() {
+ if (firstListenerCount == 1 && secondListenerCount == 1) {
+ 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>

Powered by Google App Engine
This is Rietveld 408576698