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

Unified Diff: LayoutTests/fast/dom/DeviceMotion/page-visibility.html

Issue 23705010: Add page visibility observer support for Device Motion (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | LayoutTests/fast/dom/DeviceMotion/page-visibility-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/dom/DeviceMotion/page-visibility.html
diff --git a/LayoutTests/fast/dom/DeviceMotion/page-visibility.html b/LayoutTests/fast/dom/DeviceMotion/page-visibility.html
new file mode 100644
index 0000000000000000000000000000000000000000..ac929ad168a95b42c42595864da64e2f67f34f8a
--- /dev/null
+++ b/LayoutTests/fast/dom/DeviceMotion/page-visibility.html
@@ -0,0 +1,68 @@
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+
+description('Tests to check that devicemotion events are not fired when the page is not visible.');
+window.jsTestIsAsync = true;
+
+var eventCount = 0;
+
+function generateDeviceMotionEvent()
+{
+ if (!window.testRunner)
+ return;
+
+ debug("Sending mock device motion event");
+ testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0,
+ true, 0, true, 0, true, 0,
+ true, 0, true, 0, true, 0,
+ 0);
+}
+
+function deviceMotionListener(event) {
+ debug("Received a device motion event");
+ ++eventCount;
timvolodine 2013/09/18 13:03:16 if (++eventCount == 1) setTimeout(function(){c
+}
+
+function checkGotEventAndFinish()
+{
timvolodine 2013/09/18 13:03:16 debug("Received a device motion event"); ++eventCo
+ shouldBe('eventCount', '2');
+ finishJSTest();
+}
+
+function checkNoEventAndShowPage()
+{
+ shouldBe('eventCount', '1');
+ window.removeEventListener('devicemotion', deviceMotionListener);
+ if (window.testRunner)
+ testRunner.setPageVisibility("visible");
+ debug("* Page is visible");
+ generateDeviceMotionEvent();
timvolodine 2013/09/18 13:03:16 remove
+ window.addEventListener('devicemotion', deviceMotionListener);
timvolodine 2013/09/18 13:03:16 I would put checkGotEventAndFinish here as callbac
+ setTimeout(checkGotEventAndFinish, 100);
+}
+
+function checkGotEventAndHidePage()
+{
+ shouldBe('eventCount', '1');
+ window.removeEventListener('devicemotion', deviceMotionListener);
+ if (window.testRunner)
+ testRunner.setPageVisibility("hidden");
+ debug("* Page is hidden");
+ generateDeviceMotionEvent();
timvolodine 2013/09/18 13:03:16 pls remove this line, not necessary to call genera
+ window.addEventListener('devicemotion', deviceMotionListener);
+
+ setTimeout(checkNoEventAndShowPage, 100);
+}
+
+debug("* Page is visible");
+generateDeviceMotionEvent();
timvolodine 2013/09/18 13:03:16 the name is somewhat misleading, it is actually mo
+window.addEventListener('devicemotion', deviceMotionListener);
+setTimeout(checkGotEventAndHidePage, 100);
timvolodine 2013/09/18 13:03:16 instead of using a timeout of 100ms you could use
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/fast/dom/DeviceMotion/page-visibility-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698