tenfourfox/b2g/components/test/mochitest/test_presentation_request_ui_glue.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

106 lines
3.7 KiB
HTML

<!DOCTYPE HTML>
<html>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<head>
<meta charset="utf-8">
<title>Test for Presentation UI Glue</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Test for Presentation UI Glue</a>
<script type="application/javascript;version=1.8">
'use strict';
SimpleTest.waitForExplicitFinish();
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('presentation_ui_glue_handler_chrome.js'));
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
var url = 'http://example.com';
var sessionId = 'sessionId';
function testLaunchReceiver() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('presentation-launch-receiver', function launchReceiverHandler(aDetail) {
gScript.removeMessageListener('presentation-launch-receiver', launchReceiverHandler);
ok(true, "A presentation-launch-receiver mozPresentationChromeEvent should be received.");
is(aDetail.url, url, "Url should be the same.");
is(aDetail.id, sessionId, "Session ID should be the same.");
aResolve();
});
gScript.sendAsyncMessage('trigger-ui-glue',
{ url: url,
sessionId : sessionId });
});
}
function testReceiverLaunched() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('iframe-resolved', function iframeResolvedHandler(aFrame) {
gScript.removeMessageListener('iframe-resolved', iframeResolvedHandler);
ok(true, "The promise should be resolved.");
aResolve();
});
var iframe = document.createElement('iframe');
iframe.setAttribute('remote', 'true');
iframe.setAttribute('mozbrowser', 'true');
iframe.setAttribute('src', 'http://example.com');
document.body.appendChild(iframe);
gScript.sendAsyncMessage('trigger-presentation-content-event',
{ type: 'presentation-receiver-launched',
id: sessionId,
frame: iframe });
});
}
function testLaunchError() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('presentation-launch-receiver', function launchReceiverHandler(aDetail) {
gScript.removeMessageListener('presentation-launch-receiver', launchReceiverHandler);
ok(true, "A presentation-launch-receiver mozPresentationChromeEvent should be received.");
is(aDetail.url, url, "Url should be the same.");
is(aDetail.id, sessionId, "Session ID should be the same.");
gScript.addMessageListener('iframe-rejected', function iframeRejectedHandler() {
gScript.removeMessageListener('iframe-rejected', iframeRejectedHandler);
ok(true, "The promise should be rejected.");
aResolve();
});
gScript.sendAsyncMessage('trigger-presentation-content-event',
{ type: 'presentation-receiver-permission-denied',
id: sessionId });
});
gScript.sendAsyncMessage('trigger-ui-glue',
{ url: url,
sessionId : sessionId });
});
}
function runTests() {
testLaunchReceiver()
.then(testReceiverLaunched)
.then(testLaunchError)
.then(function() {
info('test finished, teardown');
gScript.destroy();
SimpleTest.finish();
});
}
window.addEventListener('load', runTests);
</script>
</body>
</html>