Skip to content

Commit

Permalink
Basic tests for Presentation API (web-platform-tests#3063)
Browse files Browse the repository at this point in the history
* PresentationRequest constructor  test with incorrect url
* PresentationRequest test with correct url
* reconnect() test with wrong Presentation ID
  • Loading branch information
taff-franck authored and ivanzr committed Jun 29, 2016
1 parent 30fc10b commit d3b639f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
32 changes: 32 additions & 0 deletions presentation-api/controlling-ua/PresentationRequest_error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Presentation API PresentationRequest for Controlling User Agent (Error)</title>
<link rel="author" title="Franck William Taffo" href="http://www.fokus.fraunhofer.de">
<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

var wrong_presentation_url = null;

/**
* Test if PresentationRequest constructor returns a TypeError() by missing presentation URL
*/

test(function() {
assert_throws(new TypeError(), function() {
new PresentationRequest();
});
}, 'Call PresentationRequest() constructor without presentation URL. TypeError Exception expected.');

/**
* Test if PresentationRequest constructor returns a TypeError() by wrong presentation URL
*/

test(function() {
assert_throws(new TypeError(), function() {
new PresentationRequest(wrong_presentation_url);
});
}, 'Call PresentationRequest() constructor with null presentation URL. TypeError Exception expected.');

</script>
29 changes: 29 additions & 0 deletions presentation-api/controlling-ua/PresentationRequest_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Presentation API PresentationRequest for Controlling User Agent (Success)</title>
<link rel="author" title="Franck William Taffo" href="http://www.fokus.fraunhofer.de">
<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>

var client_id = String(new Date().getTime()) + String(Math.floor(Math.random() * 1e5));
//relative presentation URL
var presentation_url = "../receiving-ua/idlharness.html#__castAppId__=2334D33A/__castClientId__="+ client_id;

/**
* Test if PresentationRequest constructor returns a SyntaxError() by missing presentation URL
*/

test(function() {
try{
var request = new PresentationRequest(presentation_url);
assert_true(request instanceof PresentationRequest);
}
catch (ex){
assert_unreached("Call PresentationRequest() constructor with valid presentation URL....????");
}
}, 'Call PresentationRequest() constructor with valid presentation URL. No Exception expected.');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<meta charset="utf-8">
<title>Presentation API reconnect a presentation for Controlling User Agent (Error - manual test)</title>
<link rel="author" title="Franck William Taffo" href="http://www.fokus.fraunhofer.de">
<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

/**
*
* Test if reconnect returns a NotFoundError() by wrong presentation ID
*/

var client_id = String(new Date().getTime()) + String(Math.floor(Math.random() * 1e5));
//relative presentation URL
var presentation_url = "../receiving-ua/idlharness.html#__castAppId__=2334D33A/__castClientId__="+ client_id;
var request = new PresentationRequest(presentation_url);
var wrong_presentationId = null;

var reconnect = function () {
promise_test(function () {

var presId = "presId";
// presId is mandatory when reconnecting to a presentation.
return request.reconnect(presId)
.then(function (setConnection) {
assert_unreached("reconnect should not return a Promise resolve by wrong presentation ID");
})
}, "Check that the promise is rejected by wrong presentation Id");
};

setup({explicit_timeout: true})
</script>
<p>click on the button to the perfom the test</p>
<button id="reconnectBtn" onclick="reconnect()">Reconnect</button>

0 comments on commit d3b639f

Please sign in to comment.