-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[presentation-api] Refine getAvailability() test (#4257)
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
1 parent
3137d1d
commit 5be497b
Showing
1 changed file
with
29 additions
and
50 deletions.
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 |
---|---|---|
@@ -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> |