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

Unified Diff: LayoutTests/fast/dom/DeviceMotion/script-tests/add-during-dispatch.js

Issue 21256002: Fire null Device Motion events only once. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed comments Created 7 years, 5 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/DeviceMotion/script-tests/add-during-dispatch.js
diff --git a/LayoutTests/fast/dom/DeviceMotion/script-tests/add-during-dispatch.js b/LayoutTests/fast/dom/DeviceMotion/script-tests/add-during-dispatch.js
new file mode 100644
index 0000000000000000000000000000000000000000..df3d996f1e4ff3fd94c6f418d41ddcd4839aa58e
--- /dev/null
+++ b/LayoutTests/fast/dom/DeviceMotion/script-tests/add-during-dispatch.js
@@ -0,0 +1,71 @@
+description('Test no fire listeners added during event dispatch.');
+
+var mockEvent;
+function setMockMotion(accelerationX, accelerationY, accelerationZ,
+ accelerationIncludingGravityX, accelerationIncludingGravityY, accelerationIncludingGravityZ,
+ rotationRateAlpha, rotationRateBeta, rotationRateGamma,
+ interval) {
+
+ mockEvent = {accelerationX: accelerationX, accelerationY: accelerationY, accelerationZ: accelerationZ,
+ accelerationIncludingGravityX: accelerationIncludingGravityX, accelerationIncludingGravityY: accelerationIncludingGravityY, accelerationIncludingGravityZ: accelerationIncludingGravityZ,
+ rotationRateAlpha: rotationRateAlpha, rotationRateBeta: rotationRateBeta, rotationRateGamma: rotationRateGamma,
+ interval: interval};
+
+ if (window.testRunner)
+ testRunner.setMockDeviceMotion(null != mockEvent.accelerationX, null == mockEvent.accelerationX ? 0 : mockEvent.accelerationX,
+ null != mockEvent.accelerationY, null == mockEvent.accelerationY ? 0 : mockEvent.accelerationY,
+ null != mockEvent.accelerationZ, null == mockEvent.accelerationZ ? 0 : mockEvent.accelerationZ,
+ null != mockEvent.accelerationIncludingGravityX, null == mockEvent.accelerationIncludingGravityX ? 0 : mockEvent.accelerationIncludingGravityX,
+ null != mockEvent.accelerationIncludingGravityY, null == mockEvent.accelerationIncludingGravityY ? 0 : mockEvent.accelerationIncludingGravityY,
+ null != mockEvent.accelerationIncludingGravityZ, null == mockEvent.accelerationIncludingGravityZ ? 0 : mockEvent.accelerationIncludingGravityZ,
+ null != mockEvent.rotationRateAlpha, null == mockEvent.rotationRateAlpha ? 0 : mockEvent.rotationRateAlpha,
+ null != mockEvent.rotationRateBeta, null == mockEvent.rotationRateBeta ? 0 : mockEvent.rotationRateBeta,
+ null != mockEvent.rotationRateGamma, null == mockEvent.rotationRateGamma ? 0 : mockEvent.rotationRateGamma,
+ interval);
+ else
+ debug('This test can not be run without the TestRunner');
+}
+
+
+var deviceMotionEvent;
+function checkMotion(event) {
+ deviceMotionEvent = event;
+ shouldBe('deviceMotionEvent.acceleration.x', 'mockEvent.accelerationX');
+ shouldBe('deviceMotionEvent.acceleration.y', 'mockEvent.accelerationY');
+ shouldBe('deviceMotionEvent.acceleration.z', 'mockEvent.accelerationZ');
+
+ shouldBe('deviceMotionEvent.accelerationIncludingGravity.x', 'mockEvent.accelerationIncludingGravityX');
+ shouldBe('deviceMotionEvent.accelerationIncludingGravity.y', 'mockEvent.accelerationIncludingGravityY');
+ shouldBe('deviceMotionEvent.accelerationIncludingGravity.z', 'mockEvent.accelerationIncludingGravityZ');
+
+ shouldBe('deviceMotionEvent.rotationRate.alpha', 'mockEvent.rotationRateAlpha');
+ shouldBe('deviceMotionEvent.rotationRate.beta', 'mockEvent.rotationRateBeta');
+ shouldBe('deviceMotionEvent.rotationRate.gamma', 'mockEvent.rotationRateGamma');
+
+ shouldBe('deviceMotionEvent.interval', 'mockEvent.interval');
+}
+
+function firstListener(event) {
+ checkMotion(event);
+ window.removeEventListener('devicemotion', firstListener);
+ window.addEventListener('devicemotion', secondListener);
+ setTimeout(function(){finish();}, 100);
+}
+
+var numSecondListenerCalls = 0;
+function secondListener(event) {
+ ++numSecondListenerCalls;
+}
+
+function finish() {
+ shouldBe('numSecondListenerCalls', '1');
+ finishJSTest();
+}
+
+setMockMotion(1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9,
+ 10);
+window.addEventListener('devicemotion', firstListener);
+
+window.jsTestIsAsync = true;

Powered by Google App Engine
This is Rietveld 408576698