Skip to content
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

Merged
merged 7 commits into from
Dec 1, 2016

Conversation

Honry
Copy link
Contributor

@Honry Honry commented Nov 14, 2016

  • 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

@wpt-pr-bot
Copy link
Collaborator

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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");
Copy link
Contributor

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec dependence.

Copy link
Contributor

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) {
Copy link
Contributor

@tobie tobie Nov 14, 2016

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec dependence.

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.");
Copy link
Contributor

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.

Copy link
Contributor Author

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.");
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onstatechange has been removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec dependence.

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onstatechange has been removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec dependence.

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec dependence.

Copy link
Contributor Author

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
Copy link
Contributor Author

Honry commented Nov 15, 2016

@tobie, many thanks for your comments, at present tests are compliance to latest WD in order to match what Chromium implementation follows. And I will update them once new WD published. WDYT?

@tobie
Copy link
Contributor

tobie commented Nov 15, 2016

@Honry please track the ED not the WD.

@Honry
Copy link
Contributor Author

Honry commented Nov 15, 2016

@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
@Honry
Copy link
Contributor Author

Honry commented Nov 15, 2016

@tobie, I have one concern about the condition to call onchange event.
Spec says, onchange event is called whenever a new reading is available. Meanwhile, according to the code snippet in your comment in issues#15, as my understanding, the sensor reading will change while time passing. But when I testing on Chromium, the onchange only can be called when the ambient light illuminance changes. Who is correct?

@tobie
Copy link
Contributor

tobie commented Nov 15, 2016

This is still in flux.

@Honry
Copy link
Contributor Author

Honry commented Nov 15, 2016

I think I should prioritize following the spec. :)

@Honry
Copy link
Contributor Author

Honry commented Nov 15, 2016

@tobie, Just update tests to latest ED, pls. help review. Thanks!

});

async_test(function(t) {
sensor.onactivate = t.step_func_done(function(event) {
Copy link
Contributor

@tobie tobie Nov 15, 2016

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, updated.

@Honry Honry changed the title AmbientLightSensor: Update tests to be compliance with latest WD AmbientLightSensor: Update tests to be compliance with latest ED Nov 16, 2016
 - 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
@dontcallmedom dontcallmedom merged commit 4c038b7 into web-platform-tests:master Dec 1, 2016
@dontcallmedom
Copy link
Contributor

Merging as discussed on DAS call

@Honry Honry deleted the ALS/refresh-tests branch December 19, 2016 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants