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

Unified Diff: LayoutTests/fast/dom/DeviceMotion/script-tests/add-listener-from-callback.js

Issue 16020003: Blink-side Device Motion API testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed window-property layout test 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-listener-from-callback.js
diff --git a/LayoutTests/fast/dom/DeviceMotion/script-tests/add-listener-from-callback.js b/LayoutTests/fast/dom/DeviceMotion/script-tests/add-listener-from-callback.js
new file mode 100644
index 0000000000000000000000000000000000000000..60a334856b616f1c6689ed76fb6a178a72fba3e7
--- /dev/null
+++ b/LayoutTests/fast/dom/DeviceMotion/script-tests/add-listener-from-callback.js
@@ -0,0 +1,50 @@
+description('Tests that adding a new devicemotion event listener from a callback works as expected.');
+
+var mockAccelerationX = 1.1;
+var mockAccelerationY = 2.1;
+var mockAccelerationZ = 3.1;
+
+var mockAccelerationIncludingGravityX = 1.2;
+var mockAccelerationIncludingGravityY = 2.2;
+var mockAccelerationIncludingGravityZ = 3.2;
+
+var mockRotationRateAlpha = 1.3;
+var mockRotationRateBeta = 2.3;
+var mockRotationRateGamma = 3.3;
+
+var mockInterval = 100;
+
+if (window.testRunner) {
+ testRunner.setMockDeviceMotion(true, mockAccelerationX, true, mockAccelerationY, true, mockAccelerationZ,
+ true, mockAccelerationIncludingGravityX, true, mockAccelerationIncludingGravityY, true, mockAccelerationIncludingGravityZ,
+ true, mockRotationRateAlpha, true, mockRotationRateBeta, true, mockRotationRateGamma,
+ mockInterval);
+ debug('TEST MODE enabled');
+} else
+ debug('This test can not be run without the TestRunner');
+
+var deviceMotionEvent;
+function checkMotion(event) {
+ deviceMotionEvent = event;
+ shouldBe('deviceMotionEvent.acceleration.x', 'mockAccelerationX');
+ shouldBe('deviceMotionEvent.acceleration.y', 'mockAccelerationY');
+ shouldBe('deviceMotionEvent.acceleration.z', 'mockAccelerationZ');
+
+ shouldBe('deviceMotionEvent.accelerationIncludingGravity.x', 'mockAccelerationIncludingGravityX');
+ shouldBe('deviceMotionEvent.accelerationIncludingGravity.y', 'mockAccelerationIncludingGravityY');
+ shouldBe('deviceMotionEvent.accelerationIncludingGravity.z', 'mockAccelerationIncludingGravityZ');
+
+ shouldBe('deviceMotionEvent.rotationRate.alpha', 'mockRotationRateAlpha');
+ shouldBe('deviceMotionEvent.rotationRate.beta', 'mockRotationRateBeta');
+ shouldBe('deviceMotionEvent.rotationRate.gamma', 'mockRotationRateGamma');
+
+ shouldBe('deviceMotionEvent.interval', 'mockInterval');
+}
+
+function listener(event) {
+ checkMotion(event);
+ finishJSTest();
+}
+
+window.addEventListener('devicemotion', listener);
+window.jsTestIsAsync = true;

Powered by Google App Engine
This is Rietveld 408576698