Commit 2f3bb77d authored by Wanming Lin's avatar Wanming Lin Committed by Commit Bot

[device-orientation] Upstream web tests to WPT

This CL upstreams most device orientation tests to WPT.

- Moves device orientation tests from
  web_tests/device_orientation/,
  web_tests/http/tests/security/powerfuFeatureRestrictions/,
  to web_tests/external/wpt/orientation-event with some necessary
  updates to adapt to WPT test framework.
- Retains two page-visibility.html tests as which could not be
  automated in WPT at present and adds two similar manual tests
  there to keep test coverage sufficient.
- Leaves existing tests as is, further improvement (e.g. remove duplicate
  tests, use EventWatcher, etc.) will be arranged in a follow-up.
- Updates test paths in some profiles.

Bug: 816462
Change-Id: I1b91168c5362fc6e059b2529dd4a1d8119f5dad6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135059
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758443}
parent 0411e2cd
...@@ -361,7 +361,7 @@ ...@@ -361,7 +361,7 @@
'filepath': 'content/browser/device_sensors/' \ 'filepath': 'content/browser/device_sensors/' \
'|content/test/data/device_sensors/' \ '|content/test/data/device_sensors/' \
'|third_party/blink/renderer/modules/device_orientation/' \ '|third_party/blink/renderer/modules/device_orientation/' \
'|third_party/blink/web_tests/device_orientation/' \ '|third_party/blink/web_tests/external/wpt/orientation-event/' \
'|third_party/blink/renderer/core/frame/platform_event_(controller|dispatcher)' \ '|third_party/blink/renderer/core/frame/platform_event_(controller|dispatcher)' \
'|third_party/blink/renderer/core/frame/device_single_window_event_controller' '|third_party/blink/renderer/core/frame/device_single_window_event_controller'
}, },
......
...@@ -1814,6 +1814,8 @@ external/wpt/offscreen-canvas/text/2d.text.draw.fill.maxWidth.large-manual.worke ...@@ -1814,6 +1814,8 @@ external/wpt/offscreen-canvas/text/2d.text.draw.fill.maxWidth.large-manual.worke
external/wpt/offscreen-canvas/text/2d.text.draw.fill.rtl-manual.worker.js [ Skip ] external/wpt/offscreen-canvas/text/2d.text.draw.fill.rtl-manual.worker.js [ Skip ]
external/wpt/offscreen-canvas/text/2d.text.draw.kern.consistent-manual.worker.js [ Skip ] external/wpt/offscreen-canvas/text/2d.text.draw.kern.consistent-manual.worker.js [ Skip ]
external/wpt/offscreen-canvas/text/2d.text.draw.stroke.basic-manual.worker.js [ Skip ] external/wpt/offscreen-canvas/text/2d.text.draw.stroke.basic-manual.worker.js [ Skip ]
external/wpt/orientation-event/motion/page-visibility-manual.https.html [ Skip ]
external/wpt/orientation-event/orientation/page-visibility-manual.https.html [ Skip ]
external/wpt/orientation-event/free-fall-manual.https.html [ Skip ] external/wpt/orientation-event/free-fall-manual.https.html [ Skip ]
external/wpt/orientation-event/screen-upmost-manual.https.html [ Skip ] external/wpt/orientation-event/screen-upmost-manual.https.html [ Skip ]
external/wpt/orientation-event/screen-upright-manual.https.html [ Skip ] external/wpt/orientation-event/screen-upright-manual.https.html [ Skip ]
......
...@@ -65,8 +65,6 @@ css-parser/font-size-adjust.html ...@@ -65,8 +65,6 @@ css-parser/font-size-adjust.html
custom-elements/array-squat-crash.html custom-elements/array-squat-crash.html
custom-elements/imports/upgrade-order.html custom-elements/imports/upgrade-order.html
custom-elements/spec/state-failed-create.html custom-elements/spec/state-failed-create.html
device_orientation/motion/add-listener-from-callback.html
device_orientation/orientation/create-event.html
dom/attr/parent-adopt-node.html dom/attr/parent-adopt-node.html
dom/comment/remove.html dom/comment/remove.html
dom/document_fragment/parent-node-interface.html dom/document_fragment/parent-node-interface.html
...@@ -271,7 +269,9 @@ external/wpt/mediasession/playbackstate.html ...@@ -271,7 +269,9 @@ external/wpt/mediasession/playbackstate.html
external/wpt/mediasession/setactionhandler.html external/wpt/mediasession/setactionhandler.html
external/wpt/navigation-timing/nav2_test_instance_accessible_from_the_start.html external/wpt/navigation-timing/nav2_test_instance_accessible_from_the_start.html
external/wpt/navigation-timing/test_navigation_redirectCount_none.html external/wpt/navigation-timing/test_navigation_redirectCount_none.html
external/wpt/orientation-event/devicemotionevent-init.html external/wpt/orientation-event/motion/add-listener-from-callback.https.html
external/wpt/orientation-event/orientation/create-event.https.html
external/wpt/orientation-event/devicemotionevent-init.https.html
external/wpt/pointerevents/pointerevent_touch-action-illegal.html external/wpt/pointerevents/pointerevent_touch-action-illegal.html
external/wpt/preload/avoid-delaying-onload-link-preload.html external/wpt/preload/avoid-delaying-onload-link-preload.html
external/wpt/referrer-policy/generic/subresource-test/attr-referrer-invalid-value.html external/wpt/referrer-policy/generic/subresource-test/attr-referrer-invalid-value.html
......
...@@ -5038,7 +5038,7 @@ crbug.com/1022816 virtual/omt-worker-fetch/external/wpt/resource-timing/crossori ...@@ -5038,7 +5038,7 @@ crbug.com/1022816 virtual/omt-worker-fetch/external/wpt/resource-timing/crossori
crbug.com/778467 [ Fuchsia ] mhtml/mhtml_in_iframe.html [ Failure ] crbug.com/778467 [ Fuchsia ] mhtml/mhtml_in_iframe.html [ Failure ]
# These tests load resources from file:///gen/... . # These tests load resources from file:///gen/... .
crbug.com/919639 [ Fuchsia ] device_orientation/motion/add-listener-from-callback.html [ Failure ] crbug.com/919639 [ Fuchsia ] external/wpt/orientation-event/motion/add-listener-from-callback.https.html [ Failure ]
crbug.com/919639 [ Fuchsia ] fast/speech/scripted/speechrecognition-re-restart.html [ Failure ] crbug.com/919639 [ Fuchsia ] fast/speech/scripted/speechrecognition-re-restart.html [ Failure ]
crbug.com/919639 [ Fuchsia ] presentation/presentationconnectionavailableevent-ctor-mock.html [ Failure ] crbug.com/919639 [ Fuchsia ] presentation/presentationconnectionavailableevent-ctor-mock.html [ Failure ]
crbug.com/919639 [ Fuchsia ] webmidi/permission.html [ Failure ] crbug.com/919639 [ Fuchsia ] webmidi/permission.html [ Failure ]
......
'use strict'; 'use strict';
const MOTION_ROTATION_EPSILON = 1e-8;
function assertTestRunner() {
assert_true(window.testRunner instanceof Object,
"This test can not be run without the window.testRunner.");
}
function generateMotionData(accelerationX, accelerationY, accelerationZ, function generateMotionData(accelerationX, accelerationY, accelerationZ,
accelerationIncludingGravityX, accelerationIncludingGravityX,
accelerationIncludingGravityY, accelerationIncludingGravityY,
...@@ -68,30 +61,6 @@ function setMockOrientationData(sensorProvider, orientationData) { ...@@ -68,30 +61,6 @@ function setMockOrientationData(sensorProvider, orientationData) {
]); ]);
} }
function checkMotion(event, expectedMotionData) {
assert_equals(event.acceleration.x, expectedMotionData.accelerationX, "acceleration.x");
assert_equals(event.acceleration.y, expectedMotionData.accelerationY, "acceleration.y");
assert_equals(event.acceleration.z, expectedMotionData.accelerationZ, "acceleration.z");
assert_equals(event.accelerationIncludingGravity.x, expectedMotionData.accelerationIncludingGravityX, "accelerationIncludingGravity.x");
assert_equals(event.accelerationIncludingGravity.y, expectedMotionData.accelerationIncludingGravityY, "accelerationIncludingGravity.y");
assert_equals(event.accelerationIncludingGravity.z, expectedMotionData.accelerationIncludingGravityZ, "accelerationIncludingGravity.z");
assert_approx_equals(event.rotationRate.alpha, expectedMotionData.rotationRateAlpha, MOTION_ROTATION_EPSILON, "rotationRate.alpha");
assert_approx_equals(event.rotationRate.beta, expectedMotionData.rotationRateBeta, MOTION_ROTATION_EPSILON, "rotationRate.beta");
assert_approx_equals(event.rotationRate.gamma, expectedMotionData.rotationRateGamma, MOTION_ROTATION_EPSILON, "rotationRate.gamma");
assert_equals(event.interval, expectedMotionData.interval, "interval");
}
function checkOrientation(event, expectedOrientationData) {
assert_equals(event.alpha, expectedOrientationData.alpha, "alpha");
assert_equals(event.beta, expectedOrientationData.beta, "beta");
assert_equals(event.gamma, expectedOrientationData.gamma, "gamma");
assert_equals(event.absolute, expectedOrientationData.absolute, "absolute");
}
function waitForOrientation(expectedOrientationData, targetWindow = window) { function waitForOrientation(expectedOrientationData, targetWindow = window) {
return waitForEvent( return waitForEvent(
new DeviceOrientationEvent('deviceorientation', { new DeviceOrientationEvent('deviceorientation', {
...@@ -103,17 +72,6 @@ function waitForOrientation(expectedOrientationData, targetWindow = window) { ...@@ -103,17 +72,6 @@ function waitForOrientation(expectedOrientationData, targetWindow = window) {
targetWindow); targetWindow);
} }
function waitForAbsoluteOrientation(expectedOrientationData, targetWindow = window) {
return waitForEvent(
new DeviceOrientationEvent('deviceorientationabsolute', {
alpha: expectedOrientationData.alpha,
beta: expectedOrientationData.beta,
gamma: expectedOrientationData.gamma,
absolute: expectedOrientationData.absolute,
}),
targetWindow);
}
function waitForMotion(expectedMotionData, targetWindow = window) { function waitForMotion(expectedMotionData, targetWindow = window) {
return waitForEvent( return waitForEvent(
new DeviceMotionEvent('devicemotion', { new DeviceMotionEvent('devicemotion', {
......
...@@ -100,29 +100,3 @@ function verifyGeoSensorReading(pattern, {latitude, longitude, altitude, ...@@ -100,29 +100,3 @@ function verifyGeoSensorReading(pattern, {latitude, longitude, altitude,
function verifyProximitySensorReading(pattern, {distance, max, near, timestamp}, isNull) { function verifyProximitySensorReading(pattern, {distance, max, near, timestamp}, isNull) {
return verifySensorReading(pattern, [distance, max, near], timestamp, isNull); return verifySensorReading(pattern, [distance, max, near], timestamp, isNull);
} }
// A "sliding window" that iterates over |data| and returns one item at a
// time, advancing and wrapping around as needed. |data| must be an array of
// arrays.
class RingBuffer {
constructor(data) {
this.bufferPosition_ = 0;
// Validate |data|'s format and deep-copy every element.
this.data_ = Array.from(data, element => {
if (!Array.isArray(element)) {
throw new TypeError('Every |data| element must be an array.');
}
return Array.from(element);
})
}
next() {
const value = this.data_[this.bufferPosition_];
this.bufferPosition_ = (this.bufferPosition_ + 1) % this.data_.length;
return { done: false, value: value };
}
[Symbol.iterator]() {
return this;
}
}
...@@ -300,6 +300,7 @@ SET TIMEOUT: html/cross-origin-embedder-policy/resources/navigate-require-corp.s ...@@ -300,6 +300,7 @@ SET TIMEOUT: html/cross-origin-embedder-policy/resources/navigate-require-corp.s
SET TIMEOUT: html/cross-origin-embedder-policy/resources/navigate-require-corp-same-site.sub.html SET TIMEOUT: html/cross-origin-embedder-policy/resources/navigate-require-corp-same-site.sub.html
SET TIMEOUT: html/dom/documents/dom-tree-accessors/Document.currentScript.html SET TIMEOUT: html/dom/documents/dom-tree-accessors/Document.currentScript.html
SET TIMEOUT: html/webappapis/timers/* SET TIMEOUT: html/webappapis/timers/*
SET TIMEOUT: orientation-event/resources/orientation-event-helpers.js
SET TIMEOUT: portals/history/resources/portal-harness.js SET TIMEOUT: portals/history/resources/portal-harness.js
SET TIMEOUT: resources/chromium/* SET TIMEOUT: resources/chromium/*
SET TIMEOUT: resources/test/tests/functional/add_cleanup.html SET TIMEOUT: resources/test/tests/functional/add_cleanup.html
...@@ -703,6 +704,7 @@ MISSING DEPENDENCY: shape-detection/resources/shapedetection-helpers.js ...@@ -703,6 +704,7 @@ MISSING DEPENDENCY: shape-detection/resources/shapedetection-helpers.js
MISSING DEPENDENCY: webxr/resources/webxr_util.js MISSING DEPENDENCY: webxr/resources/webxr_util.js
MISSING DEPENDENCY: contacts/resources/helpers.js MISSING DEPENDENCY: contacts/resources/helpers.js
MISSING DEPENDENCY: generic-sensor/resources/generic-sensor-helpers.js MISSING DEPENDENCY: generic-sensor/resources/generic-sensor-helpers.js
MISSING DEPENDENCY: orientation-event/resources/orientation-event-helpers.js
# Tests that are false positives for using Ahem as a system font # Tests that are false positives for using Ahem as a system font
AHEM SYSTEM FONT: acid/acid3/test.html AHEM SYSTEM FONT: acid/acid3/test.html
......
The `resources/orientation-event-helpers.js` tests depend on the implementation of
the `GenericSensorTest` interface which is defined in [README.md](../generic-sensor/README.md).
The Chromium implementation of the `GenericSensorTest` interface is located in
[generic_sensor_mocks.js](../resources/chromium/generic_sensor_mocks.js).
Other browser vendors should provide their own implementations of
the `GenericSensorTest` interface.
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
<title>Device sensor event listeners for `window` of detached documents.</title> <title>Device sensor event listeners for `window` of detached documents.</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<body></body> <script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/orientation-event-helpers.js"></script>
<script> <script>
promise_test(async t => { sensor_test(async t => {
const childFrame = document.createElement('iframe'); const childFrame = document.createElement('iframe');
childFrame.src = "/resources/dummy.html"; childFrame.src = "/common/blank.html";
setTimeout(() => document.body.append(childFrame)); document.body.append(childFrame);
const childLoadWatcher = new EventWatcher(t, childFrame, ["load"]); const childLoadWatcher = new EventWatcher(t, childFrame, ["load"]);
await childLoadWatcher.wait_for("load"); await childLoadWatcher.wait_for("load");
......
...@@ -2,22 +2,18 @@ ...@@ -2,22 +2,18 @@
<title>Device Sensor Events not exposed to insecure origins</title> <title>Device Sensor Events not exposed to insecure origins</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/resources/get-host-info.js"></script> <script src="/common/get-host-info.sub.js"></script>
<script src="/resources/sensor-helpers.js"></script> <script src="/resources/testdriver.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="/gen/services/device/public/mojom/sensor_provider.mojom.js"></script> <script src="resources/orientation-event-helpers.js"></script>
<script> <script>
// Cannot use `step_timeout()` because we need the `sensor_test` infrastructure below, function waitForLackOfEvent(t, eventName) {
// which, however, is using `promise_test` internally. Cannot use `promise_rejects` return new Promise(async (resolve, reject) => {
// either, as `sensor_test` does not expose the `test_object`.
function waitForLackOfEvent(eventName) {
return new Promise((resolve, reject) => {
window.addEventListener(eventName, reject); window.addEventListener(eventName, reject);
window.setTimeout(() => { await new Promise(r => t.step_timeout(r, 1000));
window.removeEventListener(eventName, reject); window.removeEventListener(eventName, reject);
resolve(); resolve();
}, 1000);
}); });
} }
...@@ -36,7 +32,7 @@ if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) { ...@@ -36,7 +32,7 @@ if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) {
assert_false('ondeviceorientationabsolute' in window); assert_false('ondeviceorientationabsolute' in window);
}, 'Event interfaces and event handlers are not exposed on `window`.'); }, 'Event interfaces and event handlers are not exposed on `window`.');
sensor_test((t, sensorProvider) => { sensor_test(async (t, sensorProvider) => {
const FAKE_ACCELERATION_DATA = [1, 2, 3]; const FAKE_ACCELERATION_DATA = [1, 2, 3];
const FAKE_LINEAR_ACCELERATION_DATA = [4, 5, 6]; const FAKE_LINEAR_ACCELERATION_DATA = [4, 5, 6];
const FAKE_GYROSCOPE_DATA = [7, 8, 9]; const FAKE_GYROSCOPE_DATA = [7, 8, 9];
...@@ -44,21 +40,21 @@ if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) { ...@@ -44,21 +40,21 @@ if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) {
setMockSensorDataForType(sensorProvider, 'LinearAccelerationSensor', FAKE_LINEAR_ACCELERATION_DATA); setMockSensorDataForType(sensorProvider, 'LinearAccelerationSensor', FAKE_LINEAR_ACCELERATION_DATA);
setMockSensorDataForType(sensorProvider, 'Gyroscope', FAKE_GYROSCOPE_DATA); setMockSensorDataForType(sensorProvider, 'Gyroscope', FAKE_GYROSCOPE_DATA);
return waitForLackOfEvent('devicemotion'); return waitForLackOfEvent(t, 'devicemotion');
}, 'addEventListener() for `devicemotion` does not crash but the handler never fires.'); }, 'addEventListener() for `devicemotion` does not crash but the handler never fires.');
sensor_test((t, sensorProvider) => { sensor_test(async (t, sensorProvider) => {
const FAKE_ORIENTATION_DATA = [1.1, 2.2, 3.3]; const FAKE_ORIENTATION_DATA = [1.1, 2.2, 3.3];
setMockSensorDataForType(sensorProvider, 'RelativeOrientationEulerAngles', FAKE_ORIENTATION_DATA); setMockSensorDataForType(sensorProvider, 'RelativeOrientationEulerAngles', FAKE_ORIENTATION_DATA);
return waitForLackOfEvent('deviceorientation'); return waitForLackOfEvent(t, 'deviceorientation');
}, 'addEventListener() for `deviceorientation` does not crash but the handler never fires.'); }, 'addEventListener() for `deviceorientation` does not crash but the handler never fires.');
sensor_test((t, sensorProvider) => { sensor_test(async (t, sensorProvider) => {
const FAKE_ORIENTATION_DATA = [1.1, 2.2, 3.3]; const FAKE_ORIENTATION_DATA = [1.1, 2.2, 3.3];
setMockSensorDataForType(sensorProvider, 'AbsoluteOrientationEulerAngles', FAKE_ORIENTATION_DATA); setMockSensorDataForType(sensorProvider, 'AbsoluteOrientationEulerAngles', FAKE_ORIENTATION_DATA);
return waitForLackOfEvent('deviceorientationabsolute'); return waitForLackOfEvent(t, 'deviceorientationabsolute');
}, 'addEventListener() for `deviceorientationabsolute` does not crash but the handler never fires.'); }, 'addEventListener() for `deviceorientationabsolute` does not crash but the handler never fires.');
} }
</script> </script>
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
<title>Device Sensor Events on Secure Origin</title> <title>Device Sensor Events on Secure Origin</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/resources/get-host-info.js"></script> <script src="/common/get-host-info.sub.js"></script>
<script src="/resources/sensor-helpers.js"></script> <script src="/resources/testdriver.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="/gen/services/device/public/mojom/sensor_provider.mojom.js"></script> <script src="resources/orientation-event-helpers.js"></script>
<script> <script>
test(() => { test(() => {
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
test(function() { test(() => {
var childFrame = document.createElement('iframe'); const childFrame = document.createElement('iframe');
document.body.appendChild(childFrame); document.body.appendChild(childFrame);
let childWindow = childFrame.contentWindow; const childWindow = childFrame.contentWindow;
document.body.removeChild(childFrame); document.body.removeChild(childFrame);
childWindow.addEventListener('devicemotion', function() {}); childWindow.addEventListener('devicemotion', () => {});
}, 'Tests that an event listener can be safely added to a child frame that has been detached from the parent.'); }, 'Tests that an event listener can be safely added to a child frame that has been detached from the parent.');
</script> </script>
</body> </body>
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -24,5 +21,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -24,5 +21,3 @@ sensor_test(async (t, sensorProvider) => {
}); });
}, 'Test no fire listeners added during event dispatch.'); }, 'Test no fire listeners added during event dispatch.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -47,5 +44,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -47,5 +44,3 @@ sensor_test(async (t, sensorProvider) => {
assert_equals(secondEventCount, 1, "Too many events fired for the second listener"); assert_equals(secondEventCount, 1, "Too many events fired for the second listener");
}, 'Tests that adding a new devicemotion event listener from a callback works as expected.'); }, 'Tests that adding a new devicemotion event listener from a callback works as expected.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
test(test => { test(test => {
var event = document.createEvent('DeviceMotionEvent'); const event = document.createEvent('DeviceMotionEvent');
var newEvent = new CustomEvent("devicemotion", { const newEvent = new CustomEvent("devicemotion", {
bubbles: false, cancelable: false, bubbles: false, cancelable: false,
acceleration: {x:1.5,y:2.5,z:3.5}, acceleration: {x:1.5,y:2.5,z:3.5},
accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5}, accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5},
...@@ -41,5 +39,3 @@ test(test => { ...@@ -41,5 +39,3 @@ test(test => {
assert_equals(typeof event.interval, 'number'); assert_equals(typeof event.interval, 'number');
}, 'Tests that document.createEvent() works with DeviceMotionEvent.'); }, 'Tests that document.createEvent() works with DeviceMotionEvent.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -38,5 +35,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -38,5 +35,3 @@ sensor_test(async (t, sensorProvider) => {
return waitForMotion(motionData2); return waitForMotion(motionData2);
}, 'Tests using multiple event handlers for the Device Motion API.'); }, 'Tests using multiple event handlers for the Device Motion API.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -40,5 +37,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -40,5 +37,3 @@ sensor_test(async (t, sensorProvider) => {
return waitForMotion(motionData4); return waitForMotion(motionData4);
}, 'Tests using null values for some or all of the event properties.'); }, 'Tests using null values for some or all of the event properties.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
function ObjectThrowingException() {}; function ObjectThrowingException() {};
ObjectThrowingException.prototype.valueOf = function() { throw new Error('valueOf threw exception'); } ObjectThrowingException.prototype.valueOf = () => { throw new Error('valueOf threw exception'); }
ObjectThrowingException.prototype.__defineGetter__("x", function() { throw new Error('x getter exception'); }); ObjectThrowingException.prototype.__defineGetter__("x", () => { throw new Error('x getter exception'); });
ObjectThrowingException.prototype.__defineGetter__("alpha", function() { throw new Error('alpha getter exception'); }); ObjectThrowingException.prototype.__defineGetter__("alpha", () => { throw new Error('alpha getter exception'); });
var objectThrowingException = new ObjectThrowingException(); const objectThrowingException = new ObjectThrowingException();
test(test => { test(test => {
event = document.createEvent('DeviceMotionEvent'); event = document.createEvent('DeviceMotionEvent');
assert_equals(event.type, "");
assert_equals(event.acceleration, null); assert_equals(event.acceleration, null);
assert_equals(event.accelerationIncludingGravity, null); assert_equals(event.accelerationIncludingGravity, null);
assert_equals(event.rotationRate, null); assert_equals(event.rotationRate, null);
...@@ -21,10 +20,11 @@ test(test => { ...@@ -21,10 +20,11 @@ test(test => {
}, 'Tests creating a DeviceMotionEvent.'); }, 'Tests creating a DeviceMotionEvent.');
test(test => { test(test => {
event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2}, event = new DeviceMotionEvent('foo', {acceleration: {x: 0, y: 1, z: 2},
accelerationIncludingGravity: {x: 3, y: 4, z: 5}, accelerationIncludingGravity: {x: 3, y: 4, z: 5},
rotationRate: {alpha: 6, beta: 7, gamma: 8}, rotationRate: {alpha: 6, beta: 7, gamma: 8},
interval: 9}); interval: 9});
assert_equals(event.type, "foo");
assert_equals(event.acceleration.x, 0); assert_equals(event.acceleration.x, 0);
assert_equals(event.acceleration.y, 1); assert_equals(event.acceleration.y, 1);
assert_equals(event.acceleration.z, 2); assert_equals(event.acceleration.z, 2);
...@@ -255,5 +255,3 @@ test(test => { ...@@ -255,5 +255,3 @@ test(test => {
assert_equals(event.interval, 0); assert_equals(event.interval, 0);
}, 'Tests some fields are undefined.'); }, 'Tests some fields are undefined.');
</script> </script>
</body>
</html>
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
promise_test(t => {
return new Promise((resolve, reject) => {
document.addEventListener("visibilitychange", () => {
assert_true(document.hidden, "document is hidden");
window.addEventListener(
'devicemotion',
event => {
if (document.hidden) {
reject();
} else {
resolve();
}
},
{ once: true });
}, { once: true });
});
}, 'Tests to check that devicemotion events are not fired when the page is not visible.');
</script>
<p>Switch the page to the background, then switch back to it.</p>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
function hasDeviceMotionEventProperty() function hasDeviceMotionEventProperty()
{ {
for (var property in window) { for (let property in window) {
if (property == "DeviceMotionEvent") if (property == "DeviceMotionEvent")
return true; return true;
} }
...@@ -17,7 +15,7 @@ function hasDeviceMotionEventProperty() ...@@ -17,7 +15,7 @@ function hasDeviceMotionEventProperty()
function hasOnDeviceMotionProperty() function hasOnDeviceMotionProperty()
{ {
for (var property in window) { for (let property in window) {
if (property == "ondevicemotion") if (property == "ondevicemotion")
return true; return true;
} }
...@@ -36,5 +34,3 @@ test(test => { ...@@ -36,5 +34,3 @@ test(test => {
assert_true(window.hasOwnProperty('ondevicemotion')); assert_true(window.hasOwnProperty('ondevicemotion'));
}, 'Tests that the window.DeviceMotionEvent and window.ondevicemotion properties are present.'); }, 'Tests that the window.DeviceMotionEvent and window.ondevicemotion properties are present.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -15,10 +12,8 @@ sensor_test(async (t, sensorProvider) => { ...@@ -15,10 +12,8 @@ sensor_test(async (t, sensorProvider) => {
// Make the relative orientation sensor unavailable and set mock data for // Make the relative orientation sensor unavailable and set mock data for
// the absolute one. // the absolute one.
sensorProvider.getSensorTypeSettings('RelativeOrientationEulerAngles').unavailable = true; sensorProvider.setGetSensorShouldFail('RelativeOrientationEulerAngles', true);
setMockOrientationData(sensorProvider, orientationData); setMockOrientationData(sensorProvider, orientationData);
return waitForOrientation(orientationData); return waitForOrientation(orientationData);
}, 'Tests that deviceorientation falls back to using absolute orientation data if relative is unavailable.'); }, 'Tests that deviceorientation falls back to using absolute orientation data if relative is unavailable.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -45,5 +42,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -45,5 +42,3 @@ sensor_test(async (t, sensorProvider) => {
assert_equals(secondEventCount, 1, "Too many events fired for the second listener"); assert_equals(secondEventCount, 1, "Too many events fired for the second listener");
}, 'Tests that adding a new deviceorientation event listener from a callback works as expected.'); }, 'Tests that adding a new deviceorientation event listener from a callback works as expected.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -17,5 +14,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -17,5 +14,3 @@ sensor_test(async (t, sensorProvider) => {
return waitForAbsoluteOrientation(orientationData); return waitForAbsoluteOrientation(orientationData);
}, 'Tests basic operation of deviceorientationabsolute event using mock data.'); }, 'Tests basic operation of deviceorientationabsolute event using mock data.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -17,5 +14,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -17,5 +14,3 @@ sensor_test(async (t, sensorProvider) => {
return waitForOrientation(orientationData); return waitForOrientation(orientationData);
}, 'Tests basic operation of deviceorientation event using mock data.'); }, 'Tests basic operation of deviceorientation event using mock data.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
test(test => { test(test => {
var event = document.createEvent('DeviceOrientationEvent'); const event = document.createEvent('DeviceOrientationEvent');
var newEvent = new CustomEvent("deviceorientation", { const newEvent = new CustomEvent("deviceorientation", {
bubbles: false, cancelable: false, bubbles: false, cancelable: false,
alpha: 1.0, alpha: 1.0,
beta: 2.0, beta: 2.0,
...@@ -40,5 +38,3 @@ test(test => { ...@@ -40,5 +38,3 @@ test(test => {
assert_false(newEvent.cancelable); assert_false(newEvent.cancelable);
}, 'Tests that document.createEvent() works with DeviceOrientationEvent.'); }, 'Tests that document.createEvent() works with DeviceOrientationEvent.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -33,5 +30,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -33,5 +30,3 @@ sensor_test(async (t, sensorProvider) => {
return waitForOrientation(orientationData2); return waitForOrientation(orientationData2);
}, 'Tests using multiple event handlers for the Device Orientation API.'); }, 'Tests using multiple event handlers for the Device Orientation API.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
sensor_test(async (t, sensorProvider) => { sensor_test(async (t, sensorProvider) => {
var orientationData = generateOrientationData(1.1, 2.2, 3.3, false); const orientationData = generateOrientationData(1.1, 2.2, 3.3, false);
let setMockDataPromise = setMockOrientationData(sensorProvider, orientationData); let setMockDataPromise = setMockOrientationData(sensorProvider, orientationData);
// Add an empty listener to make sure the event pump is running and the mock // Add an empty listener to make sure the event pump is running and the mock
...@@ -28,5 +25,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -28,5 +25,3 @@ sensor_test(async (t, sensorProvider) => {
}); });
}, 'Tests that events are never fired synchronously from a call to window.addEventListener().'); }, 'Tests that events are never fired synchronously from a call to window.addEventListener().');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <script src="/resources/testharness.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../resources/device-orientation-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -31,5 +29,4 @@ sensor_test(async (t, sensorProvider) => { ...@@ -31,5 +29,4 @@ sensor_test(async (t, sensorProvider) => {
return waitForOrientation(orientationData4); return waitForOrientation(orientationData4);
}, 'Tests using null values for some of the event properties.'); }, 'Tests using null values for some of the event properties.');
</script> </script>
</body>
</html> </html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
test(test => { test(test => {
event = document.createEvent('DeviceOrientationEvent'); event = document.createEvent('DeviceOrientationEvent');
assert_equals(event.type, "");
assert_equals(event.alpha, null); assert_equals(event.alpha, null);
assert_equals(event.beta, null); assert_equals(event.beta, null);
assert_equals(event.gamma, null); assert_equals(event.gamma, null);
...@@ -15,7 +14,8 @@ test(test => { ...@@ -15,7 +14,8 @@ test(test => {
}, 'Tests creating a DeviceOrientationEvent.'); }, 'Tests creating a DeviceOrientationEvent.');
test(test => { test(test => {
event = new DeviceOrientationEvent('', {alpha: 0, beta: 1, gamma: 2, absolute: false}); event = new DeviceOrientationEvent('foo', {alpha: 0, beta: 1, gamma: 2, absolute: false});
assert_equals(event.type, "foo");
assert_equals(event.alpha, 0); assert_equals(event.alpha, 0);
assert_equals(event.beta, 1); assert_equals(event.beta, 1);
assert_equals(event.gamma, 2); assert_equals(event.gamma, 2);
...@@ -71,5 +71,3 @@ test(test => { ...@@ -71,5 +71,3 @@ test(test => {
assert_false(event.absolute); assert_false(event.absolute);
}, 'Tests all values are null.'); }, 'Tests all values are null.');
</script> </script>
</body>
</html>
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
promise_test(t => {
return new Promise((resolve, reject) => {
document.addEventListener("visibilitychange", () => {
assert_true(document.hidden, "document is hidden");
window.addEventListener(
'deviceorientation',
event => {
if (document.hidden) {
reject();
} else {
resolve();
}
},
{ once: true });
}, { once: true });
});
}, 'Tests to check that deviceorientation events are not fired when the page is not visible.');
</script>
<p>Switch the page to the background, then switch back to it.</p>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script> <script src="/resources/testdriver.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="/resources/testdriver-vendor.js"></script>
<script src="../../http/tests/resources/sensor-helpers.js"></script> <script src="../resources/orientation-event-helpers.js"></script>
<script src="../resources/device-orientation-helpers.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/device/public/mojom/sensor_provider.mojom.js"></script>
<script> <script>
'use strict'; 'use strict';
...@@ -21,5 +18,3 @@ sensor_test(async (t, sensorProvider) => { ...@@ -21,5 +18,3 @@ sensor_test(async (t, sensorProvider) => {
return waitForOrientation(orientationData2); return waitForOrientation(orientationData2);
}, 'Tests that updates to the orientation causes new events to fire.'); }, 'Tests that updates to the orientation causes new events to fire.');
</script> </script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="/resources/testharness.js"></script>
<body> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
'use strict'; 'use strict';
function hasProperty(orientationProperty) function hasProperty(orientationProperty)
{ {
for (var property in window) { for (let property in window) {
if (property == orientationProperty) if (property == orientationProperty)
return true; return true;
} }
...@@ -31,5 +29,3 @@ test(test => { ...@@ -31,5 +29,3 @@ test(test => {
assert_true(window.hasOwnProperty('ondeviceorientationabsolute')); assert_true(window.hasOwnProperty('ondeviceorientationabsolute'));
}, 'Tests that the window.DeviceOrientationEvent and window.ondeviceorientation and window.ondeviceorientationabsolute properties are present.'); }, 'Tests that the window.DeviceOrientationEvent and window.ondeviceorientation and window.ondeviceorientationabsolute properties are present.');
</script> </script>
</body>
</html>
'use strict';
// These tests rely on the User Agent providing an implementation of
// platform sensor backends.
//
// In Chromium-based browsers this implementation is provided by a polyfill
// in order to reduce the amount of test-only code shipped to users. To enable
// these tests the browser must be run with these options:
//
// --enable-blink-features=MojoJS,MojoJSTest
const loadChromiumResources = async () => {
if (!('MojoInterfaceInterceptor' in self)) {
// Do nothing on non-Chromium-based browsers or when the Mojo bindings are
// not present in the global namespace.
return;
}
const resources = [
'/gen/layout_test_data/mojo/public/js/mojo_bindings.js',
'/gen/mojo/public/mojom/base/string16.mojom.js',
'/gen/services/device/public/mojom/sensor.mojom.js',
'/gen/services/device/public/mojom/sensor_provider.mojom.js',
'/resources/chromium/generic_sensor_mocks.js',
];
await Promise.all(resources.map(path => {
const script = document.createElement('script');
script.src = path;
script.async = false;
const promise = new Promise((resolve, reject) => {
script.onload = resolve;
script.onerror = reject;
});
document.head.appendChild(script);
return promise;
}));
};
async function initialize_generic_sensor_tests() {
if (typeof GenericSensorTest === 'undefined') {
await loadChromiumResources();
}
assert_true(
typeof GenericSensorTest !== 'undefined',
'Mojo testing interface is not available.'
);
let sensorTest = new GenericSensorTest();
await sensorTest.initialize();
return sensorTest;
}
function sensor_test(func, name, properties) {
promise_test(async (t) => {
let sensorTest = await initialize_generic_sensor_tests();
try {
await func(t, sensorTest.getSensorProvider());
} finally {
await sensorTest.reset();
};
}, name, properties);
}
const MOTION_ROTATION_EPSILON = 1e-8;
function generateMotionData(accelerationX, accelerationY, accelerationZ,
accelerationIncludingGravityX,
accelerationIncludingGravityY,
accelerationIncludingGravityZ,
rotationRateAlpha, rotationRateBeta, rotationRateGamma,
interval = 16) {
const motionData = {accelerationX: accelerationX,
accelerationY: accelerationY,
accelerationZ: accelerationZ,
accelerationIncludingGravityX: accelerationIncludingGravityX,
accelerationIncludingGravityY: accelerationIncludingGravityY,
accelerationIncludingGravityZ: accelerationIncludingGravityZ,
rotationRateAlpha: rotationRateAlpha,
rotationRateBeta: rotationRateBeta,
rotationRateGamma: rotationRateGamma,
interval: interval};
return motionData;
}
function generateOrientationData(alpha, beta, gamma, absolute) {
const orientationData = {alpha: alpha,
beta: beta,
gamma: gamma,
absolute: absolute};
return orientationData;
}
async function setMockSensorDataForType(sensorProvider, sensorType, mockDataArray) {
const createdSensor = await sensorProvider.getCreatedSensor(sensorType);
return createdSensor.setSensorReading([mockDataArray]);
}
// Device[Orientation|Motion]EventPump treat NaN as a missing value.
let nullToNan = x => (x === null ? NaN : x);
function setMockMotionData(sensorProvider, motionData) {
const degToRad = Math.PI / 180;
return Promise.all([
setMockSensorDataForType(sensorProvider, "Accelerometer", [
nullToNan(motionData.accelerationIncludingGravityX),
nullToNan(motionData.accelerationIncludingGravityY),
nullToNan(motionData.accelerationIncludingGravityZ),
]),
setMockSensorDataForType(sensorProvider, "LinearAccelerationSensor", [
nullToNan(motionData.accelerationX),
nullToNan(motionData.accelerationY),
nullToNan(motionData.accelerationZ),
]),
setMockSensorDataForType(sensorProvider, "Gyroscope", [
nullToNan(motionData.rotationRateAlpha) * degToRad,
nullToNan(motionData.rotationRateBeta) * degToRad,
nullToNan(motionData.rotationRateGamma) * degToRad,
]),
]);
}
function setMockOrientationData(sensorProvider, orientationData) {
let sensorType = orientationData.absolute
? "AbsoluteOrientationEulerAngles" : "RelativeOrientationEulerAngles";
return setMockSensorDataForType(sensorProvider, sensorType, [
nullToNan(orientationData.beta),
nullToNan(orientationData.gamma),
nullToNan(orientationData.alpha),
]);
}
function checkMotion(event, expectedMotionData) {
assert_equals(event.acceleration.x, expectedMotionData.accelerationX, "acceleration.x");
assert_equals(event.acceleration.y, expectedMotionData.accelerationY, "acceleration.y");
assert_equals(event.acceleration.z, expectedMotionData.accelerationZ, "acceleration.z");
assert_equals(event.accelerationIncludingGravity.x, expectedMotionData.accelerationIncludingGravityX, "accelerationIncludingGravity.x");
assert_equals(event.accelerationIncludingGravity.y, expectedMotionData.accelerationIncludingGravityY, "accelerationIncludingGravity.y");
assert_equals(event.accelerationIncludingGravity.z, expectedMotionData.accelerationIncludingGravityZ, "accelerationIncludingGravity.z");
assert_approx_equals(event.rotationRate.alpha, expectedMotionData.rotationRateAlpha, MOTION_ROTATION_EPSILON, "rotationRate.alpha");
assert_approx_equals(event.rotationRate.beta, expectedMotionData.rotationRateBeta, MOTION_ROTATION_EPSILON, "rotationRate.beta");
assert_approx_equals(event.rotationRate.gamma, expectedMotionData.rotationRateGamma, MOTION_ROTATION_EPSILON, "rotationRate.gamma");
assert_equals(event.interval, expectedMotionData.interval, "interval");
}
function checkOrientation(event, expectedOrientationData) {
assert_equals(event.alpha, expectedOrientationData.alpha, "alpha");
assert_equals(event.beta, expectedOrientationData.beta, "beta");
assert_equals(event.gamma, expectedOrientationData.gamma, "gamma");
assert_equals(event.absolute, expectedOrientationData.absolute, "absolute");
}
// Returns a promise that will be resolved when an event equal to the given
// event is fired.
function waitForEvent(expectedEvent, targetWindow = window) {
const stringify = (thing, targetWindow) => {
if (thing instanceof targetWindow.Object && thing.constructor !== targetWindow.Object) {
let str = '{';
for (let key of Object.keys(Object.getPrototypeOf(thing))) {
str += JSON.stringify(key) + ': ' + stringify(thing[key], targetWindow) + ', ';
}
return str + '}';
} else if (thing instanceof Number) {
return thing.toFixed(6);
}
return JSON.stringify(thing);
};
return new Promise((resolve, reject) => {
let events = [];
let timeoutId = null;
const expectedEventString = stringify(expectedEvent, window);
function listener(event) {
const eventString = stringify(event, targetWindow);
if (eventString === expectedEventString) {
targetWindow.clearTimeout(timeoutId);
targetWindow.removeEventListener(expectedEvent.type, listener);
resolve();
} else {
events.push(eventString);
}
}
targetWindow.addEventListener(expectedEvent.type, listener);
timeoutId = targetWindow.setTimeout(() => {
targetWindow.removeEventListener(expectedEvent.type, listener);
let errorMessage = 'Timeout waiting for expected event: ' + expectedEventString;
if (events.length == 0) {
errorMessage += ', no events were fired';
} else {
errorMessage += ', received events: '
for (let event of events) {
errorMessage += event + ', ';
}
}
reject(errorMessage);
}, 500);
});
}
function waitForOrientation(expectedOrientationData, targetWindow = window) {
return waitForEvent(
new DeviceOrientationEvent('deviceorientation', {
alpha: expectedOrientationData.alpha,
beta: expectedOrientationData.beta,
gamma: expectedOrientationData.gamma,
absolute: expectedOrientationData.absolute,
}),
targetWindow);
}
function waitForAbsoluteOrientation(expectedOrientationData, targetWindow = window) {
return waitForEvent(
new DeviceOrientationEvent('deviceorientationabsolute', {
alpha: expectedOrientationData.alpha,
beta: expectedOrientationData.beta,
gamma: expectedOrientationData.gamma,
absolute: expectedOrientationData.absolute,
}),
targetWindow);
}
function waitForMotion(expectedMotionData, targetWindow = window) {
return waitForEvent(
new DeviceMotionEvent('devicemotion', {
acceleration: {
x: expectedMotionData.accelerationX,
y: expectedMotionData.accelerationY,
z: expectedMotionData.accelerationZ,
},
accelerationIncludingGravity: {
x: expectedMotionData.accelerationIncludingGravityX,
y: expectedMotionData.accelerationIncludingGravityY,
z: expectedMotionData.accelerationIncludingGravityZ,
},
rotationRate: {
alpha: expectedMotionData.rotationRateAlpha,
beta: expectedMotionData.rotationRateBeta,
gamma: expectedMotionData.rotationRateGamma,
},
interval: expectedMotionData.interval,
}),
targetWindow);
}
'use strict'; 'use strict';
// A "sliding window" that iterates over |data| and returns one item at a
// time, advancing and wrapping around as needed. |data| must be an array of
// arrays.
class RingBuffer {
constructor(data) {
this.bufferPosition_ = 0;
// Validate |data|'s format and deep-copy every element.
this.data_ = Array.from(data, element => {
if (!Array.isArray(element)) {
throw new TypeError('Every |data| element must be an array.');
}
return Array.from(element);
})
}
next() {
const value = this.data_[this.bufferPosition_];
this.bufferPosition_ = (this.bufferPosition_ + 1) % this.data_.length;
return { done: false, value: value };
}
[Symbol.iterator]() {
return this;
}
}
var GenericSensorTest = (() => { var GenericSensorTest = (() => {
// Default sensor frequency in default configurations. // Default sensor frequency in default configurations.
const DEFAULT_FREQUENCY = 5; const DEFAULT_FREQUENCY = 5;
...@@ -10,6 +36,7 @@ var GenericSensorTest = (() => { ...@@ -10,6 +36,7 @@ var GenericSensorTest = (() => {
constructor(sensorRequest, handle, offset, size, reportingMode) { constructor(sensorRequest, handle, offset, size, reportingMode) {
this.client_ = null; this.client_ = null;
this.startShouldFail_ = false; this.startShouldFail_ = false;
this.notifyOnReadingChange_ = true;
this.reportingMode_ = reportingMode; this.reportingMode_ = reportingMode;
this.sensorReadingTimerId_ = null; this.sensorReadingTimerId_ = null;
this.readingData_ = null; this.readingData_ = null;
...@@ -59,6 +86,13 @@ var GenericSensorTest = (() => { ...@@ -59,6 +86,13 @@ var GenericSensorTest = (() => {
this.stopReading(); this.stopReading();
} }
// ConfigureReadingChangeNotifications(bool enabled)
// Configures whether to report a reading change when in ON_CHANGE
// reporting mode.
configureReadingChangeNotifications(notifyOnReadingChange) {
this.notifyOnReadingChange_ = notifyOnReadingChange;
}
// Mock functions // Mock functions
// Resets mock Sensor state. // Resets mock Sensor state.
...@@ -66,6 +100,7 @@ var GenericSensorTest = (() => { ...@@ -66,6 +100,7 @@ var GenericSensorTest = (() => {
this.stopReading(); this.stopReading();
this.startShouldFail_ = false; this.startShouldFail_ = false;
this.requestedFrequencies_ = []; this.requestedFrequencies_ = [];
this.notifyOnReadingChange_ = true;
this.readingData_ = null; this.readingData_ = null;
this.buffer_.fill(0); this.buffer_.fill(0);
this.binding_.close(); this.binding_.close();
...@@ -100,7 +135,8 @@ var GenericSensorTest = (() => { ...@@ -100,7 +135,8 @@ var GenericSensorTest = (() => {
// For all tests sensor reading should have monotonically // For all tests sensor reading should have monotonically
// increasing timestamp in seconds. // increasing timestamp in seconds.
this.buffer_[1] = window.performance.now() * 0.001; this.buffer_[1] = window.performance.now() * 0.001;
if (this.reportingMode_ === device.mojom.ReportingMode.ON_CHANGE) { if (this.reportingMode_ === device.mojom.ReportingMode.ON_CHANGE &&
this.notifyOnReadingChange_) {
this.client_.sensorReadingChanged(); this.client_.sensorReadingChanged();
} }
}, timeout); }, timeout);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment