-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AmbientLightSensor: Update tests to be compliance with latest ED #4203
Changes from all commits
34f902b
d69335d
867043a
5245912
f96b506
84ad754
8bba338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: insecure context</title> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<link rel="help" href="https://www.w3.org/TR/ambient-light/"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<h2>Precondition</h2> | ||
<ol> | ||
<li> | ||
Run test in an insecure context, e.g. http://example.com/. | ||
</li> | ||
</ol> | ||
<div id="log"></div> | ||
<script> | ||
|
||
test(() => { | ||
assert_throws('SecurityError', () => { | ||
let sensor = new AmbientLightSensor(); | ||
}); | ||
}, "throw a 'SecurityError' when construct AmbientLightSensor in an insecure context"); | ||
|
||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: onerror</title> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<link rel="help" href="https://www.w3.org/TR/ambient-light/"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<h2>Precondition</h2> | ||
<ol> | ||
<li> | ||
Disable the Ambient Light Sensor or run test on a device without Amibent Light Sensor. | ||
</li> | ||
</ol> | ||
<div id="log"></div> | ||
<script> | ||
let sensor; | ||
setup(() => { | ||
sensor = new AmbientLightSensor(); | ||
}); | ||
|
||
async_test(t => { | ||
sensor.onactivate = t.step_func_done(assert_unreached); | ||
|
||
sensor.onerror = t.step_func_done(event => { | ||
assert_equals(sensor.state, 'errored'); | ||
assert_equals(event.error.name, 'NotFoundError'); | ||
}); | ||
|
||
sensor.start(); | ||
}, "Test that 'onerror' event is fired when sensor is not supported"); | ||
|
||
</script> |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: reading</title> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<link rel="help" href="https://www.w3.org/TR/ambient-light/"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="log"></div> | ||
<script> | ||
|
||
let sensor, sensor1, sensor2, cachedReading1, cachedReading2; | ||
|
||
setup(() => { | ||
sensor = new AmbientLightSensor(); | ||
sensor1 = new AmbientLightSensor(); | ||
sensor2 = new AmbientLightSensor(); | ||
sensor1.start(); | ||
sensor2.start(); | ||
}); | ||
|
||
async_test(t => { | ||
let sensor = new AmbientLightSensor(); | ||
sensor.start(); | ||
sensor.onactivate = t.step_func_done(() => { | ||
let cachedReading = sensor.reading; | ||
let cachedIlluminance = cachedReading.illuminance; | ||
sensor.stop(); | ||
assert_equals(cachedReading.illuminance, cachedIlluminance); | ||
}); | ||
sensor.onerror = t.step_func_done(event => { | ||
assert_unreached(event.error.name + ":" + event.error.message); | ||
}); | ||
}, "Test that sensor reading must be immutable."); | ||
|
||
async_test(t => { | ||
sensor1.onactivate = t.step_func_done(() => { | ||
cachedReading1 = sensor1.reading; | ||
cachedReading2 = sensor2.reading; | ||
//both sensors share the same reading instance | ||
assert_equals(cachedReading1, cachedReading2); | ||
//after first sensor stops its reading is null, second sensor remains | ||
sensor1.stop(); | ||
assert_equals(sensor1.reading, null); | ||
assert_equals(String(sensor2.reading), "[object AmbientLightSensorReading]"); | ||
}); | ||
sensor1.onerror = t.step_func_done(event => { | ||
assert_unreached(event.error.name + ":" + event.error.message); | ||
}); | ||
}, "Test that sensor reading is correct."); | ||
|
||
async_test(t => { | ||
t.step_timeout(() => { | ||
sensor2.onchange = t.step_func_done(() => { | ||
let cachedReading3 = sensor2.reading; | ||
assert_not_equals(cachedReading2, cachedReading3); | ||
sensor2.stop(); | ||
}); | ||
sensor2.onerror = t.step_func_done(event => { | ||
assert_unreached(event.error.name + ":" + event.error.message); | ||
}); | ||
}, 1000); | ||
}, "Test that the sensor reading is updated when time passes."); | ||
|
||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,22 +8,27 @@ | |
<div id="log"></div> | ||
<script> | ||
|
||
var sensor, stop_return; | ||
setup(function() { | ||
let sensor, stop_return; | ||
|
||
setup(() => { | ||
sensor = new AmbientLightSensor(); | ||
sensor.start(); | ||
stop_return = sensor.stop(); | ||
}); | ||
|
||
test(function() { | ||
assert_equals(String(sensor.reading), "null"); | ||
test(() => { | ||
assert_equals(sensor.state, "idle"); | ||
}, "The sensor.state changes to 'idle' after sensor.stop()"); | ||
|
||
test(() => { | ||
assert_equals(sensor.reading, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might change. We might want to keep the latest reading around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spec dependence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tobie, I would like to leave it as is until we make the final conclusion. |
||
}, "the sensor.reading is null after executing stop() method"); | ||
|
||
test(function() { | ||
assert_throws("InvalidStateError", function() { sensor.stop(); }, "stop() twice"); | ||
test(() => { | ||
assert_throws("InvalidStateError", () => { sensor.stop(); }, "stop() twice"); | ||
}, "throw an InvalidStateError exception when state is either idle or errored"); | ||
|
||
test(function() { | ||
test(() => { | ||
assert_equals(stop_return, undefined); | ||
}, "the sensor.stop() returns undefined"); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is flaky. You should instead rely on a new
onchange
event.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed in new commit.