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

Unified Diff: LayoutTests/fast/dom/DeviceLight/page-visibility.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/page-visibility.html
diff --git a/LayoutTests/fast/dom/DeviceLight/page-visibility.html b/LayoutTests/fast/dom/DeviceLight/page-visibility.html
new file mode 100644
index 0000000000000000000000000000000000000000..073ab4b35af8db7d212e17e6e4df1f0288605c0b
--- /dev/null
+++ b/LayoutTests/fast/dom/DeviceLight/page-visibility.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../../resources/js-test.js"></script>
+<script>
+
+description('Tests to check that devicelight events are not fired when the page is not visible.');
+window.jsTestIsAsync = true;
+
+function succeedAndFinish()
+{
+ testPassed("Received a devicelight event");
+ setTimeout(finishJSTest, 0);
+}
+
+function testWithPageVisible()
+{
+ testPassed("Did not receive a devicelight event");
+ window.removeEventListener('devicelight', failAndFinish);
+ testRunner.setPageVisibility("visible");
+ debug("* Page is visible");
+ window.addEventListener('devicelight', succeedAndFinish);
+}
+
+function failAndFinish()
+{
+ testFailed('Should not have received a devicelight event while the page was hidden');
+ setTimeout(finishJSTest, 0);
+}
+
+function deviceLightListener(event)
+{
+ testPassed("Received a devicelight event");
+ window.removeEventListener('devicelight', deviceLightListener);
+ testRunner.setPageVisibility("hidden");
+ debug("* Page is hidden");
+ window.addEventListener('devicelight', failAndFinish);
+
+ setTimeout(testWithPageVisible, 0);
+}
+
+if (window.testRunner)
+ testRunner.setMockDeviceLight(100);
+else
+ debug('This test can not be run without the TestRunner');
+
+debug("* Page is visible");
+window.addEventListener('devicelight', deviceLightListener);
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698