Skip to content

Commit

Permalink
Add accelerometer screen tests in sensor-tester (#50)
Browse files Browse the repository at this point in the history
* Add accelerometer screen tests in sensor-tester
  • Loading branch information
xiuqijix authored and rakuco committed Sep 18, 2018
1 parent f23db7f commit 8ae7f07
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 18 deletions.
2 changes: 2 additions & 0 deletions sensor-tester/polymer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"fragments": [
"src/absoluteorientationsensor-page.html",
"src/accelerometer-page.html",
"src/accelerometer-screen-page.html",
"src/ambientlightsensor-page.html",
"src/gyroscope-page.html",
"src/linearaccelerationsensor-page.html",
"src/linearaccelerationsensor-screen-page.html",
"src/magnetometer-page.html",
"src/relativeorientationsensor-page.html",
"src/sensor-tests-page.html"
Expand Down
2 changes: 1 addition & 1 deletion sensor-tester/src/absoluteorientationsensor-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="absoluteorientationsensor-page">
<template>
<sensor-tests-page tests="src/tests/absoluteorientationsensor.json" sensortype="AbsoluteOrientationSensor" frequency=60></sensor-tests-page>
<sensor-tests-page tests="src/tests/absoluteorientationsensor.json" sensortype="AbsoluteOrientationSensor" frequency="60"></sensor-tests-page>
</template>

<script>
Expand Down
2 changes: 1 addition & 1 deletion sensor-tester/src/accelerometer-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="accelerometer-page">
<template>
<sensor-tests-page tests="src/tests/accelerometer.json" sensortype="Accelerometer" frequency=60></sensor-tests-page>
<sensor-tests-page tests="src/tests/accelerometer.json" sensortype="Accelerometer" frequency="60"></sensor-tests-page>
</template>

<script>
Expand Down
15 changes: 15 additions & 0 deletions sensor-tester/src/accelerometer-screen-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="sensor-tests-page.html">

<dom-module id="accelerometer-screen-page">
<template>
<sensor-tests-page tests="src/tests/accelerometer-screen.json" sensortype="Accelerometer" referenceframe="screen" frequency="60"></sensor-tests-page>
</template>

<script>
class AccelerometerScreenPage extends Polymer.Element {
static get is() { return 'accelerometer-screen-page'; }
}
window.customElements.define(AccelerometerScreenPage.is, AccelerometerScreenPage);
</script>
</dom-module>
4 changes: 2 additions & 2 deletions sensor-tester/src/ambientlightsensor-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="ambientlightsensor-page">
<template>
<sensor-tests-page tests="src/tests/ambientlightsensor.json" sensortype="AmbientLightSensor" frequency=10></sensor-tests-page>
<sensor-tests-page tests="src/tests/ambientlightsensor.json" sensortype="AmbientLightSensor" frequency="10"></sensor-tests-page>
</template>

<script>
Expand All @@ -12,4 +12,4 @@
}
window.customElements.define(AmbientLightSensorPage.is, AmbientLightSensorPage);
</script>
</dom-module>
</dom-module>
2 changes: 1 addition & 1 deletion sensor-tester/src/gyroscope-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="gyroscope-page">
<template>
<sensor-tests-page tests="src/tests/gyroscope.json" sensortype="Gyroscope" frequency=60></sensor-tests-page>
<sensor-tests-page tests="src/tests/gyroscope.json" sensortype="Gyroscope" frequency="60"></sensor-tests-page>
</template>

<script>
Expand Down
2 changes: 1 addition & 1 deletion sensor-tester/src/linearaccelerationsensor-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="linearaccelerationsensor-page">
<template>
<sensor-tests-page tests="src/tests/linearaccelerationsensor.json" sensortype="LinearAccelerationSensor" frequency=60></sensor-tests-page>
<sensor-tests-page tests="src/tests/linearaccelerationsensor.json" sensortype="LinearAccelerationSensor" frequency="60"></sensor-tests-page>
</template>

<script>
Expand Down
15 changes: 15 additions & 0 deletions sensor-tester/src/linearaccelerationsensor-screen-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="sensor-tests-page.html">

<dom-module id="linearaccelerationsensor-screen-page">
<template>
<sensor-tests-page tests="src/tests/linearaccelerationsensor-screen.json" sensortype="LinearAccelerationSensor" referenceframe="screen" frequency="60"></sensor-tests-page>
</template>

<script>
class LinearAccelerationSensorScreenPage extends Polymer.Element {
static get is() { return 'linearaccelerationsensor-screen-page'; }
}
window.customElements.define(LinearAccelerationSensorScreenPage.is, LinearAccelerationSensorScreenPage);
</script>
</dom-module>
2 changes: 1 addition & 1 deletion sensor-tester/src/magnetometer-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="magnetometer-page">
<template>
<sensor-tests-page tests="src/tests/magnetometer.json" sensortype="Magnetometer" frequency=10></sensor-tests-page>
<sensor-tests-page tests="src/tests/magnetometer.json" sensortype="Magnetometer" frequency="10"></sensor-tests-page>
</template>

<script>
Expand Down
2 changes: 1 addition & 1 deletion sensor-tester/src/relativeorientationsensor-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<dom-module id="relativeorientationsensor-page">
<template>
<sensor-tests-page tests="src/tests/relativeorientationsensor.json" sensortype="RelativeOrientationSensor" frequency=60></sensor-tests-page>
<sensor-tests-page tests="src/tests/relativeorientationsensor.json" sensortype="RelativeOrientationSensor" frequency="60"></sensor-tests-page>
</template>

<script>
Expand Down
24 changes: 17 additions & 7 deletions sensor-tester/src/sensor-tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">

<link rel="lazy-import" href="accelerometer-page.html">
<link rel="lazy-import" href="accelerometer-screen-page.html">
<link rel="lazy-import" href="linearaccelerationsensor-page.html">
<link rel="lazy-import" href="linearaccelerationsensor-screen-page.html">
<link rel="lazy-import" href="gyroscope-page.html">
<link rel="lazy-import" href="absoluteorientationsensor-page.html">
<link rel="lazy-import" href="relativeorientationsensor-page.html">
Expand Down Expand Up @@ -60,25 +62,31 @@
<app-toolbar>Choose sensor:</app-toolbar>
<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
<a name="accelerometer" href="[[rootPath]]accelerometer">
Accelerometer
Accelerometer with device coordinates
</a>
<a name="accelerometer-screen" href="[[rootPath]]accelerometer-screen">
Accelerometer with screen coordinates
</a>
<a name="linearaccelerationsensor" href="[[rootPath]]linearaccelerationsensor">
LinearAccelerationSensor
LinearAccelerationSensor with device coordinates
</a>
<a name="linearaccelerationsensor-screen" href="[[rootPath]]linearaccelerationsensor-screen">
LinearAccelerationSensor with screen coordinates
</a>
<a name="gyroscope" href="[[rootPath]]gyroscope">
Gyroscope
Gyroscope with device coordinates
</a>
<a name="absoluteorientationsensor" href="[[rootPath]]absoluteorientationsensor">
AbsoluteOrientationSensor
AbsoluteOrientationSensor with device coordinates
</a>
<a name="relativeorientationsensor" href="[[rootPath]]relativeorientationsensor">
RelativeOrientationSensor
RelativeOrientationSensor with device coordinates
</a>
<a name="ambientlightsensor" href="[[rootPath]]ambientlightsensor">
AmbientLightSensor
AmbientLightSensor with device coordinates
</a>
<a name="magnetometer" href="[[rootPath]]magnetometer">
Magnetometer
Magnetometer with device coordinates
</a>
</iron-selector>
</app-drawer>
Expand All @@ -94,7 +102,9 @@

<iron-pages id="ironPage" selected="[[page]]" attr-for-selected="name" fallback-selection="accelerometer" role="main">
<accelerometer-page name="accelerometer"></accelerometer-page>
<accelerometer-screen-page name="accelerometer-screen"></accelerometer-screen-page>
<linearaccelerationsensor-page name="linearaccelerationsensor"></linearaccelerationsensor-page>
<linearaccelerationsensor-screen-page name="linearaccelerationsensor-screen"></linearaccelerationsensor-screen-page>
<gyroscope-page name="gyroscope"></gyroscope-page>
<absoluteorientationsensor-page name="absoluteorientationsensor"></absoluteorientationsensor-page>
<relativeorientationsensor-page name="relativeorientationsensor"></relativeorientationsensor-page>
Expand Down
60 changes: 59 additions & 1 deletion sensor-tester/src/sensor-tests-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
display: none;
}

div.device {
display: none;
}

div.screen {
display: block;
}

iron-list.supported {
display: block;
}
Expand All @@ -39,6 +47,12 @@
background-color: var(--app-primary-color);
}

paper-button.LOCK {
margin-bottom: 10px;
float: none;
background-color: var(--app-primary-color);
}

paper-button.PASSED {
background-color: var(--paper-green-500);
}
Expand Down Expand Up @@ -97,6 +111,15 @@

<div class$="[[isSupported]]">Sensor is not supported by the browser or the device.</div>

<div class$="[[referenceframe]]">
<div>If device supports screen.orientation.lock(), rotate web page to different angles with the following buttons before running the tests.</div>
<paper-button on-click="lockOrientation" class="LOCK" data-args="portrait-primary"></paper-button>
<paper-button on-click="lockOrientation" class="LOCK" data-args="landscape-primary">90˚</paper-button>
<paper-button on-click="lockOrientation" class="LOCK" data-args="portrait-secondary">180˚</paper-button>
<paper-button on-click="lockOrientation" class="LOCK" data-args="landscape-secondary">270˚</paper-button>
<paper-button on-click="lockOrientation" class="LOCK" data-args="RESET">RESET</paper-button>
</div>

<iron-list class$="[[isSupported]]" id="list" items="[[items]]" as="item" scroll-target="document">
<template>
<div>
Expand Down Expand Up @@ -126,6 +149,10 @@
type: Number,
value: 10
},
referenceframe: {
type: String,
value: "device"
},
sensortype: {
type: String
},
Expand Down Expand Up @@ -198,7 +225,7 @@
ready() {
super.ready();
if (this.sensortype in window) {
this.sensor_ = new window[this.sensortype]({frequency: this.frequency});
this.sensor_ = new window[this.sensortype]({frequency: this.frequency, referenceFrame: this.referenceframe});
this.sensor_.onreading = () => {
this.sensor_.stop();
this.sensor_.onreading = null;
Expand All @@ -207,6 +234,7 @@
this.sensor_.onerror = e => {
if (e.error.name === 'NotReadableError') {
this.isSupported = "not-supported";
this.referenceframe = "device";
this.items = [];
this.notifyPath('items');
}
Expand All @@ -215,6 +243,7 @@
this.sensor_.start();
} else {
this.isSupported = "not-supported";
this.referenceframe = "device";
}
}

Expand Down Expand Up @@ -263,6 +292,35 @@
// start sensor
this.sensor.start();
}

lockOrientation(e) {
let index = e.target.getAttribute('data-args');

let doc = window.document;
let docEl = doc.documentElement;
let requestFullScreen = docEl.requestFullscreen ||
docEl.webkitRequestFullscreen ||
docEl.mozRequestFullScreen ||
docEl.msRequestFullscreen;
let cancelFullScreen = doc.exitFullscreen ||
doc.webkitExitFullscreen ||
doc.mozCancelFullScreen ||
doc.msExitFullscreen;

let orientation = screen.msOrientation || (screen.orientation || screen.mozOrientation || {});

if (index == "RESET") {
orientation.unlock();
cancelFullScreen.call(doc);
return;
}
requestFullScreen.call(docEl);
orientation.lock(index)
.catch(() => {
console.log("screen.orientation.lock() is not available on this device.");
cancelFullScreen.call(doc);
});
}
}

window.customElements.define(SensorTestsPage.is, SensorTestsPage);
Expand Down
66 changes: 66 additions & 0 deletions sensor-tester/src/tests/accelerometer-screen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"name": "Test web page +Z gravity",
"description": "Test that sensor reports +9.8 m/s^2 along the Z axis when device is at rest on a leveled surface and web page is facing towards the sky.",
"illustration": "src/tests/accel_+z_gravity.png",
"duration": 3,
"expected": { "x": 0, "y": 0, "z": 9.8 },
"epsilon": 1
},
{
"name": "Test web page -Z gravity",
"description": "Test that sensor reports -9.8 m/s^2 along the Z axis when device is at rest on a leveled surface and web page is facing towards the ground.",
"illustration": "src/tests/accel_-z_gravity.png",
"duration": 4,
"expected": { "x": 0, "y": 0, "z": -9.8 },
"epsilon": 1
},
{
"name": "Test web page +X gravity",
"description": "Test that sensor reports 9.8 m/s^2 along the X axis when device is at rest on a leveled surface and right edge of the web page points towards the ground.",
"illustration": "src/tests/accel_+x_gravity.png",
"duration": 3,
"expected": { "x": 9.8, "y": 0, "z": 0 },
"epsilon": 1
},
{
"name": "Test web page -X gravity",
"description": "Test that sensor reports -9.8 m/s^2 along the X axis when device is at rest on a leveled surface and left edge of the web page points towards the ground.",
"illustration": "src/tests/accel_-x_gravity.png",
"duration": 3,
"expected": { "x": -9.8, "y": 0, "z": 0 },
"epsilon": 1
},
{
"name": "Test web page +Y gravity",
"description": "Test that sensor reports 9.8 m/s^2 along the Y axis when device is at rest on a leveled surface and top edge of the web page points towards the sky.",
"illustration": "src/tests/accel_+y_gravity.png",
"duration": 4,
"expected": { "x": 0, "y": 9.8, "z": 0 },
"epsilon": 1
},
{
"name": "Test web page -Y gravity",
"description": "Test that sensor reports -9.8 m/s^2 along the Y axis when device is at rest on a leveled surface and top edge of the web page points towards the ground.",
"illustration": "src/tests/accel_-y_gravity.png",
"duration": 4,
"expected": { "x": 0, "y": -9.8, "z": 0 },
"epsilon": 1
},
{
"name": "Test web page +X acceleration",
"description": "Test that sensor reports positive acceleration along the X axis when device is pushed from the web page left edge to the right.",
"illustration": "src/tests/accel_+x_acceleration.gif",
"duration": 5,
"expected": { "x": 3.0 },
"epsilon": 1
},
{
"name": "Test web page -X acceleration",
"description": "Test that sensor reports negative acceleration along the X axis when device is pushed from the web page right edge to the left.",
"illustration": "src/tests/accel_-x_acceleration.gif",
"duration": 5,
"expected": { "x": -3.0 },
"epsilon": 1
}
]
4 changes: 2 additions & 2 deletions sensor-tester/src/tests/accelerometer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[
{
"name": "Test +Z gravity",
"description": "Test that sensor reports +9.8 m/s^2 along the Z axis when device is at rest on a leveled surface and screen is facing towards the sky.",
"description": "Test that sensor reports +9.8 m/s^2 along the Z axis when device is at rest on a leveled surface and web page is facing towards the sky.",
"illustration": "src/tests/accel_+z_gravity.png",
"duration": 3,
"expected": { "x": 0, "y": 0, "z": 9.8 },
"epsilon": 1
},
{
"name": "Test -Z gravity",
"description": "Test that sensor reports -9.8 m/s^2 along the Z axis when device is at rest on a leveled surface and screen is facing towards the ground.",
"description": "Test that sensor reports -9.8 m/s^2 along the Z axis when device is at rest on a leveled surface and web page is facing towards the ground.",
"illustration": "src/tests/accel_-z_gravity.png",
"duration": 4,
"expected": { "x": 0, "y": 0, "z": -9.8 },
Expand Down
Loading

0 comments on commit 8ae7f07

Please sign in to comment.