Bug 1008044 - DataStoreServiceChild should check the name of the DataStore before resolving the promise callback, r=ehsan, f=kgrandon

--HG--
rename : dom/datastore/tests/test_oop.html => dom/datastore/tests/test_bug1008044.html
This commit is contained in:
Andrea Marchesini 2014-05-22 12:12:15 +01:00
parent bf7d1cfd9a
commit 7cf70f2edb
4 changed files with 181 additions and 0 deletions

View File

@ -489,6 +489,7 @@ DataStoreServiceChild.prototype = {
debug("DataStoreServiceChild init");
this._successCb = aSuccessCb;
this._errorCb = aErrorCb;
this._name = aName;
this.initDOMRequestHelper(aWindow, [ "DataStore:Get:Return:OK",
"DataStore:Get:Return:KO" ]);
@ -500,6 +501,10 @@ DataStoreServiceChild.prototype = {
receiveMessage: function(aMessage) {
debug("DataStoreServiceChild receiveMessage");
if (aMessage.data.name != this._name) {
return;
}
switch (aMessage.name) {
case 'DataStore:Get:Return:OK':
this.destroyDOMRequestHelper();

View File

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for DataStore - bug 1008044</title>
</head>
<body>
<div id="container"></div>
<script type="application/javascript;version=1.7">
function ok(a, msg) {
alert((!!a ? 'OK' : 'KO') + ' ' + msg)
}
function cbError() {
alert('KO error');
}
function finish() {
alert('DONE');
}
navigator.getDataStores('foo').then(function(stores) {
if (stores[0].name != 'foo') {
ok(false, "Wrong name is received! Expected 'foo'");
}
runTest();
});
navigator.getDataStores('bar').then(function(stores) {
if (stores[0].name != 'bar') {
ok(false, "Wrong name is received! Expected 'bar'");
}
runTest();
});
var pending = 2;
function runTest() {
if (--pending == 0) {
ok(true, "Test passed!");
finish();
}
}
</script>
</body>
</html>

View File

@ -28,6 +28,7 @@ support-files =
file_transactions.html
file_basic_common.js
file_sync_common.js
file_bug1008044.html
[test_app_install.html]
[test_readonly.html]
@ -52,3 +53,4 @@ skip-if = (toolkit == 'gonk' && debug) #debug-only failure; time out
[test_bug986056.html]
[test_oop_events.html]
[test_transactions.html]
[test_bug1008044.html]

View File

@ -0,0 +1,128 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for DataStore - bug 1008044</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="container"></div>
<script type="application/javascript;version=1.7">
var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug1008044.html';
var gApp;
function cbError() {
ok(false, "Error callback invoked");
finish();
}
function installApp() {
var request = navigator.mozApps.install(gHostedManifestURL);
request.onerror = cbError;
request.onsuccess = function() {
gApp = request.result;
runTest();
}
}
function uninstallApp() {
// Uninstall the app.
var request = navigator.mozApps.mgmt.uninstall(gApp);
request.onerror = cbError;
request.onsuccess = function() {
// All done.
info("All done");
runTest();
}
}
function testApp() {
var ifr = document.createElement('iframe');
ifr.setAttribute('mozbrowser', 'true');
ifr.setAttribute('mozapp', gApp.manifestURL);
ifr.setAttribute('src', gApp.manifest.launch_path);
var domParent = document.getElementById('container');
// Set us up to listen for messages from the app.
var listener = function(e) {
var message = e.detail.message;
if (/^OK/.exec(message)) {
ok(true, "Message from app: " + message);
} else if (/KO/.exec(message)) {
ok(false, "Message from app: " + message);
} else if (/DONE/.exec(message)) {
ok(true, "Messaging from app complete");
ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
domParent.removeChild(ifr);
runTest();
}
}
// This event is triggered when the app calls "alert".
ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
domParent.appendChild(ifr);
}
var tests = [
// Permissions
function() {
SpecialPowers.pushPermissions(
[{ "type": "browser", "allow": 1, "context": document },
{ "type": "embed-apps", "allow": 1, "context": document },
{ "type": "webapps-manage", "allow": 1, "context": document }], runTest);
},
// Preferences
function() {
SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
["dom.ipc.browser_frames.oop_by_default", true],
["dom.testing.ignore_ipc_principal", true],
["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
},
function() {
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
runTest();
},
// No confirmation needed when an app is installed
function() {
SpecialPowers.autoConfirmAppInstall(runTest);
},
// Installing the app
installApp,
// Run tests in app
testApp,
// Uninstall the app
uninstallApp
];
function runTest() {
if (!tests.length) {
finish();
return;
}
var test = tests.shift();
test();
}
function finish() {
SimpleTest.finish();
}
if (SpecialPowers.isMainProcess()) {
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
}
SimpleTest.waitForExplicitFinish();
runTest();
</script>
</body>
</html>