Bug 1140275 - System messages shouldn't be sent to app pages not registered in manifests. r=fabrice

This commit is contained in:
Sean Lin 2015-08-03 01:05:00 +02:00
parent 1cdf15ede9
commit 80c08cfc26
12 changed files with 141 additions and 11 deletions

View File

@ -1,6 +1,7 @@
[DEFAULT]
support-files =
file_empty.html
system_message_chrome_script.js
[test_alarm_add_data.html]
skip-if = ((buildapp == 'mulet' || buildapp == 'b2g') && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage

View File

@ -0,0 +1,18 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const { classes: Cc, interfaces: Ci } = Components;
const systemMessenger = Cc["@mozilla.org/system-message-internal;1"]
.getService(Ci.nsISystemMessagesInternal);
const ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
addMessageListener("trigger-register-page", function(aData) {
systemMessenger.registerPage(aData.type,
ioService.newURI(aData.pageURL, null, null),
ioService.newURI(aData.manifestURL, null, null));
sendAsyncMessage("page-registered");
});

View File

@ -14,6 +14,20 @@
"use strict";
function registerPage() {
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('system_message_chrome_script.js'));
gScript.addMessageListener("page-registered", function pageRegisteredHandler() {
gScript.removeMessageListener("page-registered", pageRegisteredHandler);
gScript.destroy();
testFireTimeAlert();
});
gScript.sendAsyncMessage("trigger-register-page",
{ type: "alarm",
manifestURL: window.location.origin + "/manifest.webapp",
pageURL: window.location.href });
}
function testFireTimeAlert() {
var secondsLater = new Date();
secondsLater.setSeconds(secondsLater.getSeconds() + 10);
@ -27,7 +41,7 @@
});
domRequest = navigator.mozAlarms.add(secondsLater, "honorTimezone",
{type: "timer"});
{type: "timer"});
} catch (e) {
ok(false, "Unexpected exception trying to set time alert.");
@ -62,7 +76,7 @@
if (isAllowedToTest) {
ok(true, "Start to test...");
testFireTimeAlert();
registerPage();
} else {
// A sanity check to make sure we must run tests on Firefox OS (B2G).
if (navigator.userAgent.indexOf("Mobile") != -1 &&

View File

@ -14,6 +14,20 @@
"use strict";
function registerPage() {
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('system_message_chrome_script.js'));
gScript.addMessageListener("page-registered", function pageRegisteredHandler() {
gScript.removeMessageListener("page-registered", pageRegisteredHandler);
gScript.destroy();
testFireTimeAlertWithNoData();
});
gScript.sendAsyncMessage("trigger-register-page",
{ type: "alarm",
manifestURL: window.location.origin + "/manifest.webapp",
pageURL: window.location.href });
}
function testFireTimeAlertWithNoData() {
var secondsLater = new Date();
secondsLater.setSeconds(secondsLater.getSeconds() + 1);
@ -61,7 +75,7 @@
if (isAllowedToTest) {
ok(true, "Start to test...");
testFireTimeAlertWithNoData();
registerPage();
} else {
// A sanity check to make sure we must run tests on Firefox OS (B2G).
if (navigator.userAgent.indexOf("Mobile") != -1 &&

View File

@ -742,11 +742,9 @@ SystemMessageInternal.prototype = {
if (!page) {
debug("Message " + aType + " is not registered for " +
aPageURL + " @ " + aManifestURL);
// FIXME bug 1140275 should only send message to page registered in manifest
// return MSG_SENT_FAILURE_PERM_DENIED;
return MSG_SENT_FAILURE_PERM_DENIED;
}
if (page)
this._queueMessage(page, aMessage, aMessageID);
this._queueMessage(page, aMessage, aMessageID);
let appPageIsRunning = false;
let pageKey = this._createKeyForPage({ type: aType,
@ -801,8 +799,7 @@ SystemMessageInternal.prototype = {
result = MSG_SENT_FAILURE_APP_NOT_RUNNING;
this._acquireCpuWakeLock(pageKey);
}
if (page)
this._openAppPage(page, aMessage, aExtra, result);
this._openAppPage(page, aMessage, aExtra, result);
return result;
},

View File

@ -1,2 +1,6 @@
[DEFAULT]
support-files =
system_message_chrome_script.js
[test_bug_993732.html]
skip-if = buildapp == 'mulet' || (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage

View File

@ -0,0 +1,18 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const { classes: Cc, interfaces: Ci } = Components;
const systemMessenger = Cc["@mozilla.org/system-message-internal;1"]
.getService(Ci.nsISystemMessagesInternal);
const ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
addMessageListener("trigger-register-page", function(aData) {
systemMessenger.registerPage(aData.type,
ioService.newURI(aData.pageURL, null, null),
ioService.newURI(aData.manifestURL, null, null));
sendAsyncMessage("page-registered");
});

View File

@ -19,6 +19,20 @@
// listening system message is broadcast. So this test case uses the alarm message
// to test if a running app can receive the system message.
function registerPage() {
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('system_message_chrome_script.js'));
gScript.addMessageListener("page-registered", function pageRegisteredHandler() {
gScript.removeMessageListener("page-registered", pageRegisteredHandler);
gScript.destroy();
testAlarm(10000);
});
gScript.sendAsyncMessage("trigger-register-page",
{ type: "alarm",
manifestURL: window.location.origin + "/manifest.webapp",
pageURL: window.location.href });
}
function testAlarm(aMillisecondsFromNow) {
var at = new Date();
at.setTime(at.getTime() + aMillisecondsFromNow);
@ -40,7 +54,7 @@
// Waiting for alarm message.
};
domRequest.onerror = function(e) {
ok(false, "Unable to add alarm for tomorrow`.");
ok(false, "Unable to add alarm.");
SimpleTest.finish();
};
}
@ -52,7 +66,7 @@
if (navigator.userAgent.indexOf("Mobile") != -1 &&
navigator.appVersion.indexOf("Android") == -1)
{
testAlarm(10000);
registerPage();
} else {
ok(true, "mozAlarms on Firefox OS only.");
SimpleTest.finish();

View File

@ -6,6 +6,7 @@ support-files =
file_basic_app.html
common_app.js
common_basic.js
system_message_chrome_script.js
[test_webidl.html]
[test_minInterval.html]

View File

@ -0,0 +1,18 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const { classes: Cc, interfaces: Ci } = Components;
const systemMessenger = Cc["@mozilla.org/system-message-internal;1"]
.getService(Ci.nsISystemMessagesInternal);
const ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
addMessageListener("trigger-register-page", function(aData) {
systemMessenger.registerPage(aData.type,
ioService.newURI(aData.pageURL, null, null),
ioService.newURI(aData.manifestURL, null, null));
sendAsyncMessage("page-registered");
});

View File

@ -13,6 +13,20 @@
var taskExecuted = false;
function registerPage() {
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('system_message_chrome_script.js'));
gScript.addMessageListener("page-registered", function pageRegisteredHandler() {
gScript.removeMessageListener("page-registered", pageRegisteredHandler);
gScript.destroy();
runTests();
});
gScript.sendAsyncMessage("trigger-register-page",
{ type: "request-sync",
manifestURL: window.location.origin + "/manifest.webapp",
pageURL: window.location.href });
}
function setMessageHandler() {
navigator.mozSetMessageHandler('request-sync', function(e) {
ok(true, "One event has been received!");
@ -85,6 +99,8 @@
runTests();
},
registerPage,
setMessageHandler,
test_register_oneShot,

View File

@ -20,6 +20,20 @@
}
}
function registerPage() {
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('system_message_chrome_script.js'));
gScript.addMessageListener("page-registered", function pageRegisteredHandler() {
gScript.removeMessageListener("page-registered", pageRegisteredHandler);
gScript.destroy();
runTests();
});
gScript.sendAsyncMessage("trigger-register-page",
{ type: "request-sync",
manifestURL: window.location.origin + "/manifest.webapp",
pageURL: window.location.href });
}
function setMessageHandler() {
navigator.mozSetMessageHandler('request-sync', function(e) {
ok(true, "One event has been received!");
@ -146,6 +160,7 @@
runTests();
},
registerPage,
setMessageHandler,
test_register_oneShot,