-
Notifications
You must be signed in to change notification settings - Fork 3k
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: add some basic functionality tests #3696
Merged
zqzhang
merged 2 commits into
web-platform-tests:master
from
Honry:ambient-light/add-basic-tests
Sep 18, 2016
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: Sensor readings must only be available in the top-level browsing 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> | ||
<div id="log"></div> | ||
<iframe src="support-iframe.html" id="frame" style="display:none"> | ||
</iframe> | ||
<script> | ||
|
||
async_test(function (t) { | ||
document.getElementById('frame').onload = t.step_func_done(function(event) { | ||
var iframe = document.getElementById('frame').contentWindow; | ||
let reading = iframe.document.getElementById('reading').value; | ||
assert_equals(reading, "null"); | ||
}); | ||
}, "sensor readings can not be fired within iframes"); | ||
|
||
test(function() { | ||
let sensor = new AmbientLightSensor(); | ||
sensor.start(); | ||
var win = window.open('', '_blank'); | ||
let reading = String(sensor.reading); | ||
win.close(); | ||
sensor.stop(); | ||
assert_equals(reading, "null"); | ||
}, "sensor readings can not be fired on the background tab"); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: onchange</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>Description</h2> | ||
<p> | ||
This test validates that the "onchange" event can be invoked when changing the ambient light illuminance of the device. | ||
</p> | ||
|
||
<h2>Precondition</h2> | ||
<ol> | ||
<li> | ||
Change the ambient light illuminance of the device. | ||
</li> | ||
</ol> | ||
|
||
<script> | ||
|
||
async_test(function(t) { | ||
let sensor = new AmbientLightSensor(); | ||
sensor.start(); | ||
|
||
sensor.onchange = t.step_func_done(function(event) { | ||
sensor.stop(); | ||
}); | ||
|
||
sensor.onerror = t.step_func_done(function(event) { | ||
assert_unreached(event.error.name + ":" + event.error.message); | ||
}); | ||
}, "event change fired"); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: onstatechange</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> | ||
var sensor; | ||
setup(function() { | ||
sensor = new AmbientLightSensor(); | ||
}); | ||
|
||
test(function() { | ||
assert_equals(sensor.state, "idle"); | ||
}, "The default sensor.state is 'idle'."); | ||
|
||
async_test(function(t) { | ||
sensor.onstatechange = t.step_func_done(function(event) { | ||
assert_equals(sensor.state, "activating"); | ||
}); | ||
sensor.onerror = t.step_func_done(function(event) { | ||
assert_unreached(event.error.name + ":" + event.error.message); | ||
}); | ||
sensor.start(); | ||
}, "The sensor.state changes to 'activating' after sensor.start()."); | ||
|
||
async_test(function(t) { | ||
sensor.onstatechange = t.step_func_done(function(event) { | ||
assert_equals(sensor.state, "idle"); | ||
}); | ||
sensor.onerror = t.step_func_done(function(event) { | ||
assert_unreached(event.error.name + ":" + event.error.message); | ||
}); | ||
sensor.stop(); | ||
}, "The sensor.state changes to 'idle' after sensor.stop()."); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: start()</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> | ||
var sensor, start_return; | ||
|
||
setup(function() { | ||
sensor = new AmbientLightSensor(); | ||
start_return = sensor.start(); | ||
}); | ||
|
||
test(function() { | ||
assert_equals(sensor.state, "activating"); | ||
}, "the sensor.state is activating after executing start() method"); | ||
|
||
test(function() { | ||
assert_equals(String(sensor.reading), "[object AmbientLightSensorReading]"); | ||
}, "the sensor.reading is AmbientLightSensorReading after executing start() method"); | ||
|
||
test(function() { | ||
assert_throws("InvalidStateError", function() { sensor.start(); }, "start() twice"); | ||
}, "throw an InvalidStateError exception when state is neither idle nor errored"); | ||
|
||
//TODO: The permission is not ready. | ||
|
||
test(function() { | ||
assert_equals(start_return, undefined); | ||
}, "the sensor.start() return undefined"); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>AmbientLightSensor Test: stop()</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> | ||
|
||
var sensor, stop_return; | ||
setup(function() { | ||
sensor = new AmbientLightSensor(); | ||
sensor.start(); | ||
stop_return = sensor.stop(); | ||
}); | ||
|
||
test(function() { | ||
assert_equals(sensor.state, "idle"); | ||
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. I think it is better to put all these assertions in this test file together within |
||
}, "the sensor.state is idle after executing stop() method"); | ||
|
||
test(function() { | ||
assert_equals(String(sensor.reading), "null"); | ||
}, "the sensor.reading is null after executing stop() method"); | ||
|
||
test(function() { | ||
assert_throws("InvalidStateError", function() { sensor.stop(); }, "stop() twice"); | ||
}, "throw an InvalidStateError exception when state is either idle or errored"); | ||
|
||
test(function() { | ||
assert_equals(stop_return, undefined); | ||
}, "the sensor.stop() returns undefined"); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE HTML> | ||
<meta charset="utf-8"> | ||
<input type="text" id="reading" /> | ||
<script> | ||
|
||
let sensor = new AmbientLightSensor(); | ||
sensor.start(); | ||
document.getElementById("reading").value = String(sensor.reading); | ||
sensor.stop(); | ||
|
||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think it is better to put all these assertions in this test file together within
ambient-light/AmbientLightSensor_onstatechange.html
.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.
@zqzhang, thanks for your comments! Agree!