Skip to content

Commit

Permalink
[presentation-api] Refine getAvailability() test (#4257)
Browse files Browse the repository at this point in the history
Completes test on getAvailability to match recent updates made to the spec.

The test assesses that the same Promise gets returned as long as it is unsettled, and that a new one is afterwards. It also checks that the algorithm returns a `true` availability (assuming that the current context features an available presentation display).
  • Loading branch information
tomoyukilabs authored and tidoust committed Dec 29, 2016
1 parent 3137d1d commit 5be497b
Showing 1 changed file with 29 additions and 50 deletions.
79 changes: 29 additions & 50 deletions presentation-api/controlling-ua/getAvailability.html
Original file line number Diff line number Diff line change
@@ -1,69 +1,48 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Presentation API - monitor screen availability tests for Controlling User Agent</title>
<title>Getting the presentation displays availability information.</title>
<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-presentation-display-availability">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>

<p>The test passes if a "PASS" result appears.</p>

<script>
// ---------------------------------
// Helper Function
// ---------------------------------
var createRequestObject = function () {
var request = new PresentationRequest(presentationUrls);
return request;
}

// ---------------------------------
// Screen Availability Tests - begin
// ---------------------------------
// ---------------------------------------
// Presentation Availability Tests - begin
// ---------------------------------------

// Instance of Promise Test
test(function () {
var request = createRequestObject();
assert_true(request.getAvailability() instanceof Promise);
}, 'The request is an Promise.')
promise_test(function(t) {
var availability;

// Instance of PresentationRequest Test
test(function () {
var request = createRequestObject();
assert_true(request instanceof PresentationRequest);
}, 'The request is an instance of PresentationRequest.')
var request = new PresentationRequest(presentationUrls);
assert_true(request instanceof PresentationRequest, 'The request is an instance of PresentationRequest.');

// Instance of PresentationAvailability Test
promise_test(function () {
var request = createRequestObject();
var promise = request.getAvailability();
assert_equals(promise, request.getAvailability(), 'If the PresentationRequest object has an unsettled Promise, getAvailability returns that Promise.');

return request.getAvailability()
.then(function (availability) {
assert_true(availability instanceof PresentationAvailability);
});
}, "The promise is an instance of PresentationAvailability");
function catchNotSupported(err) {
assert_equals(err.name, 'NotSupportedError', 'getAvailability() rejects a Promise with a NotSupportedError exception, if the browser can find presentation displays only when starting a connection.')
}

// Availability.value is set Test
promise_test(function () {
var request = createRequestObject();
return promise.then(function (a) {
availability = a;

return request.getAvailability()
.then(function (availability) {
assert_true(typeof availability.value == 'boolean');
});
}, "The availability has an boolean value.");
assert_true(availability instanceof PresentationAvailability, 'The promise is resolved with an instance of PresentationAvailability.');
assert_equals(typeof availability.value, 'boolean', 'The availability has an boolean value.');
assert_true(availability.value, 'The availability value is true when any presentation display is available.');

var newPromise = request.getAvailability();
assert_not_equals(promise, newPromise, 'If the Promise from a previous call to getAvailability has already been settled, getAvailability returns a new Promise.');

// Best Case Scenario Test
// -----------------------
promise_test(function () {
var request = createRequestObject();
return newPromise.then(function (newAvailability) {
assert_equals(availability, newAvailability, 'Promises from a PresentationRequest\'s getAvailability are resolved with the same PresentationAvailability object.');
}, catchNotSupported);
}, catchNotSupported);
});

return request.getAvailability()
.then(function (availability) {
assert_true(availability.value);
});
}, "There is an availability.");
// -------------------------------
// Screen Availability Tests - end
// -------------------------------
</script>

0 comments on commit 5be497b

Please sign in to comment.