2016-04-25 12:57:30 +03:00
|
|
|
<!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 B2G PresentationConnection API at receiver side (OOP)</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="application/javascript" src="PresentationSessionFrameScript.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1148307">Test B2G PresentationConnection API at receiver side (OOP)</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<pre id="test"></pre>
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
|
|
|
|
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_receiver.html');
|
|
|
|
var nonReceiverUrl = SimpleTest.getTestFileURL('file_presentation_non_receiver.html');
|
|
|
|
|
|
|
|
var isReceiverFinished = false;
|
|
|
|
var isNonReceiverFinished = false;
|
|
|
|
|
|
|
|
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(SpecialPowers.Ci.nsIObserverService);
|
|
|
|
var receiverIframe;
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
return new Promise(function(aResolve, aReject) {
|
|
|
|
gScript.sendAsyncMessage('trigger-device-add');
|
|
|
|
|
|
|
|
// Create a receiver OOP iframe.
|
|
|
|
receiverIframe = document.createElement('iframe');
|
|
|
|
receiverIframe.setAttribute('remote', 'true');
|
|
|
|
receiverIframe.setAttribute('mozbrowser', 'true');
|
|
|
|
receiverIframe.setAttribute('mozpresentation', receiverUrl);
|
|
|
|
receiverIframe.setAttribute('src', receiverUrl);
|
|
|
|
|
|
|
|
// This event is triggered when the iframe calls "alert".
|
|
|
|
receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(aEvent) {
|
|
|
|
var message = aEvent.detail.message;
|
|
|
|
if (/^OK /.exec(message)) {
|
|
|
|
ok(true, "Message from iframe: " + message);
|
|
|
|
} else if (/^KO /.exec(message)) {
|
|
|
|
ok(false, "Message from iframe: " + message);
|
|
|
|
} else if (/^INFO /.exec(message)) {
|
|
|
|
info("Message from iframe: " + message);
|
|
|
|
} else if (/^COMMAND /.exec(message)) {
|
|
|
|
var command = JSON.parse(message.replace(/^COMMAND /, ''));
|
|
|
|
if (command.name == "trigger-incoming-message") {
|
|
|
|
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
|
|
|
|
mm.sendAsyncMessage('trigger-incoming-message', {"data": command.data});
|
|
|
|
} else {
|
|
|
|
gScript.sendAsyncMessage(command.name, command.data);
|
|
|
|
}
|
|
|
|
} else if (/^DONE$/.exec(message)) {
|
|
|
|
ok(true, "Messaging from iframe complete.");
|
|
|
|
receiverIframe.removeEventListener('mozbrowsershowmodalprompt', receiverListener);
|
|
|
|
|
|
|
|
isReceiverFinished = true;
|
|
|
|
|
|
|
|
if (isNonReceiverFinished) {
|
|
|
|
teardown();
|
|
|
|
}
|
|
|
|
}
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2016-04-25 12:57:30 +03:00
|
|
|
|
|
|
|
var promise = new Promise(function(aResolve, aReject) {
|
|
|
|
document.body.appendChild(receiverIframe);
|
2017-01-25 09:01:52 +03:00
|
|
|
receiverIframe.addEventListener("mozbrowserloadstart", function() {
|
2016-04-25 12:57:30 +03:00
|
|
|
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
|
|
|
|
mm.loadFrameScript("data:,(" + loadPrivilegedScriptTest.toString() + ")();", false);
|
2017-01-25 09:01:52 +03:00
|
|
|
}, {once: true});
|
2016-04-25 12:57:30 +03:00
|
|
|
|
|
|
|
aResolve(receiverIframe);
|
|
|
|
});
|
2017-04-14 22:51:39 +03:00
|
|
|
obs.notifyObservers(promise, 'setup-request-promise');
|
2016-04-25 12:57:30 +03:00
|
|
|
|
|
|
|
// Create a non-receiver OOP iframe.
|
|
|
|
var nonReceiverIframe = document.createElement('iframe');
|
|
|
|
nonReceiverIframe.setAttribute('remote', 'true');
|
|
|
|
nonReceiverIframe.setAttribute('mozbrowser', 'true');
|
|
|
|
nonReceiverIframe.setAttribute('src', nonReceiverUrl);
|
|
|
|
|
|
|
|
// This event is triggered when the iframe calls "alert".
|
|
|
|
nonReceiverIframe.addEventListener('mozbrowsershowmodalprompt', function nonReceiverListener(aEvent) {
|
|
|
|
var message = aEvent.detail.message;
|
|
|
|
if (/^OK /.exec(message)) {
|
|
|
|
ok(true, "Message from iframe: " + message);
|
|
|
|
} else if (/^KO /.exec(message)) {
|
|
|
|
ok(false, "Message from iframe: " + message);
|
|
|
|
} else if (/^INFO /.exec(message)) {
|
|
|
|
info("Message from iframe: " + message);
|
|
|
|
} else if (/^COMMAND /.exec(message)) {
|
|
|
|
var command = JSON.parse(message.replace(/^COMMAND /, ''));
|
|
|
|
gScript.sendAsyncMessage(command.name, command.data);
|
|
|
|
} else if (/^DONE$/.exec(message)) {
|
|
|
|
ok(true, "Messaging from iframe complete.");
|
|
|
|
nonReceiverIframe.removeEventListener('mozbrowsershowmodalprompt', nonReceiverListener);
|
|
|
|
|
|
|
|
isNonReceiverFinished = true;
|
|
|
|
|
|
|
|
if (isReceiverFinished) {
|
|
|
|
teardown();
|
|
|
|
}
|
|
|
|
}
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2016-04-25 12:57:30 +03:00
|
|
|
|
|
|
|
document.body.appendChild(nonReceiverIframe);
|
|
|
|
|
|
|
|
gScript.addMessageListener('offer-received', function offerReceivedHandler() {
|
|
|
|
gScript.removeMessageListener('offer-received', offerReceivedHandler);
|
|
|
|
info("An offer is received.");
|
|
|
|
});
|
|
|
|
|
|
|
|
gScript.addMessageListener('answer-sent', function answerSentHandler(aIsValid) {
|
|
|
|
gScript.removeMessageListener('answer-sent', answerSentHandler);
|
|
|
|
ok(aIsValid, "A valid answer is sent.");
|
|
|
|
});
|
|
|
|
|
|
|
|
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
|
|
|
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
|
|
|
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
|
|
|
|
});
|
|
|
|
|
|
|
|
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
|
|
|
|
mm.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
|
|
|
|
mm.removeMessageListener('check-navigator', checknavigatorHandler);
|
|
|
|
ok(aSuccess.data.data, "buildDataChannel get correct window object");
|
|
|
|
});
|
|
|
|
|
|
|
|
mm.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
|
|
|
|
mm.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
|
|
|
|
info("Data notification is enabled for data transport channel.");
|
|
|
|
});
|
|
|
|
|
|
|
|
mm.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
|
|
|
mm.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
|
|
|
is(aReason.data.data, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
|
|
|
|
});
|
|
|
|
|
|
|
|
aResolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testIncomingSessionRequest() {
|
|
|
|
return new Promise(function(aResolve, aReject) {
|
|
|
|
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
|
|
|
|
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
|
|
|
|
info("Trying to launch receiver page.");
|
|
|
|
|
|
|
|
aResolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var mmTeardownComplete = false;
|
|
|
|
var gScriptTeardownComplete = false;
|
|
|
|
function teardown() {
|
|
|
|
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
|
|
|
|
mm.addMessageListener('teardown-complete', function teardownCompleteHandler() {
|
|
|
|
mm.removeMessageListener('teardown-complete', teardownCompleteHandler);
|
|
|
|
mmTeardownComplete = true;
|
|
|
|
if (gScriptTeardownComplete) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mm.sendAsyncMessage('teardown');
|
|
|
|
|
|
|
|
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
|
|
|
|
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
|
|
|
|
gScript.destroy();
|
|
|
|
gScriptTeardownComplete = true;
|
|
|
|
if (mmTeardownComplete) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
gScript.sendAsyncMessage('teardown');
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTests() {
|
|
|
|
setup().
|
|
|
|
then(testIncomingSessionRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SpecialPowers.pushPermissions([
|
|
|
|
{type: 'presentation-device-manage', allow: false, context: document},
|
|
|
|
{type: 'browser', allow: true, context: document},
|
|
|
|
], function() {
|
|
|
|
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
|
2016-11-02 12:53:31 +03:00
|
|
|
["dom.presentation.controller.enabled", false],
|
2016-06-03 14:50:30 +03:00
|
|
|
["dom.presentation.receiver.enabled", true],
|
2016-04-25 12:57:30 +03:00
|
|
|
["dom.presentation.session_transport.data_channel.enable", true],
|
|
|
|
["dom.mozBrowserFramesEnabled", true],
|
2016-11-17 16:53:30 +03:00
|
|
|
["network.disable.ipc.security", true],
|
2016-04-25 12:57:30 +03:00
|
|
|
["dom.ipc.browser_frames.oop_by_default", true],
|
|
|
|
["presentation.receiver.loading.timeout", 5000000]]},
|
|
|
|
runTests);
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|