-
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
AmbientLightSensor: Update tests to be compliance with latest ED #4203
Conversation
Honry
commented
Nov 14, 2016
•
edited
Loading
edited
- Add https postfix as all interfaces must only be available within a secure context
- Add new tests for onerror event, errored state, sensor object contruction, sensor readings
- Update browsing context test
- Reorg some tests
Reviewers for this pull request are: @Volker-E, @dontcallmedom, @riju, @tobie, and @zqzhang. |
sensor.onchange = t.step_func_done(function() { | ||
assert_not_equals(sensor.reading, null); | ||
let win = window.open('', '_blank'); | ||
assert_equals(sensor.reading, null); |
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 might probably change to hold on to the latest reading.
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.
sensor.onchange = t.step_func_done(function(event) { | ||
sensor.onchange = t.step_func_done(function() { | ||
assert_greater_than_equal(sensor.reading.illuminance, 0); | ||
assert_equals(sensor.state, "active"); |
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.
The state should now be called "activated".
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.
Spec dependence.
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.
}); | ||
|
||
async_test(function(t) { | ||
sensor1.onstatechange = t.step_func_done(function(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.
We're removing onstatechange
this from the spec.
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.
Spec dependence.
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.
let cachedReading = sensor.reading; | ||
let cachedIlluminance = cachedReading.illuminance; | ||
sensor.stop(); | ||
assert_equals(cachedReading.illuminance, cachedIlluminance); |
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.
You probably want to test for this asynchronously.
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, you are right, fixed in new commit.
}, "Test that sensor reading must be immutable."); | ||
|
||
test(function() { | ||
assert_equals(cachedReading1, cachedReading2); |
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 should really be: assert(cachedReading1 === cachedReading2);
or something similar, imho.
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.
Actually assert_equals
can be use for objects comparison as well. Following note is picked from assert_equals
from testharness.js.
Test if two primitives are equal or two objects are the same object.
sensor1.stop(); | ||
assert_equals(sensor1.reading, null); | ||
assert_equals(String(sensor2.reading), "[object AmbientLightSensorReading]"); | ||
}, "Test that sensor is independent."); |
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 don't understand this test.
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.
The test purpose is checking sensors don't interfere each others. After first sensor stops its reading is null, second sensor remains.
assert_not_equals(cachedReading2, cachedReading3); | ||
sensor2.stop(); | ||
}, 2000); | ||
}, "Test that the sensor reading is updated when time passes."); |
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.
}, "The default sensor.state is 'idle'"); | ||
|
||
async_test(function(t) { | ||
sensor.onstatechange = t.step_func_done(function(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.
onstatechange
has been removed.
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.
Spec dependence.
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.
}); | ||
|
||
async_test(function(t) { | ||
sensor.onstatechange = t.step_func_done(function(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.
onstatechange
has been removed.
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.
Spec dependence.
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.
test(function() { | ||
assert_equals(String(sensor.reading), "null"); | ||
assert_equals(sensor.reading, null); |
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 might change. We might want to keep the latest reading around.
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.
Spec dependence.
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.
@tobie, I would like to leave it as is until we make the final conclusion.
@Honry please track the ED not the WD. |
@tobie, OK, I will update the tests later on. |
- Add https postfix as all interfaces must only be available within a secure context - Add new tests for onerror event, errored state, sensor object contruction, sensor readings - Update browsing context test - Reorg some tests
@tobie, I have one concern about the condition to call |
This is still in flux. |
I think I should prioritize following the spec. :) |
@tobie, Just update tests to latest ED, pls. help review. Thanks! |
}); | ||
|
||
async_test(function(t) { | ||
sensor.onactivate = t.step_func_done(function(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.
Can't you just rewrite this as:
sensor.onactivate = t.step_func_done(assert_unreached);
Not necessary, but clearer, imho.
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.
Of course, updated.
- Move reading stuff into onchange event - reading would hold on to the latest reading when the tab is inactive
- Remove onstatechange event tests - Update "active" state to "activated" - Add test for onactivate event
Merging as discussed on DAS call |