Bug 1168300 - notify clear-cookiejar-data. r=sicking

This commit is contained in:
Yoshi Huang 2015-05-27 16:10:42 +08:00
Родитель 6f70fe8661
Коммит 94fb90e9cf
4 изменённых файлов: 144 добавлений и 0 удалений

Просмотреть файл

@ -4862,7 +4862,22 @@ this.DOMApplicationRegistry = {
browserOnly: browserOnly,
QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams])
};
this._clearCookieJarData(appId, browserOnly);
this._notifyCategoryAndObservers(subject, "webapps-clear-data", null, msg);
},
_clearCookieJarData: function(appId, browserOnly) {
let browserCookieJar =
ChromeUtils.originAttributesToCookieJar({appId: appId,
inBrowser: true});
this._notifyCategoryAndObservers(null, "clear-cookiejar-data", browserCookieJar);
if (!browserOnly) {
let appCookieJar =
ChromeUtils.originAttributesToCookieJar({appId: appId,
inBrowser: false});
this._notifyCategoryAndObservers(null, "clear-cookiejar-data", appCookieJar);
}
}
};

Просмотреть файл

@ -41,6 +41,8 @@ skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in moch
[test_app_update.html]
skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
[test_bug_795164.html]
[test_bug_1168300.html]
skip-if = toolkit == "gonk" # see bug 1175784
[test_import_export.html]
[test_install_dev_mode.html]
[test_install_multiple_apps_origin.html]

Просмотреть файл

@ -0,0 +1,126 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1168300
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1168300</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript;version=1.7">
/** Test for Bug 1168300 **/
SimpleTest.waitForExplicitFinish();
var url = "http://test/tests/dom/apps/tests/file_manifest.json";
var gGenerator = runTest();
function go() {
SpecialPowers.pushPermissions(
[{ "type": "webapps-manage", "allow": 1, "context": document }],
function() { gGenerator.next() });
}
function continueTest() {
try {
gGenerator.next();
} catch (e if e instanceof StopIteration) {
SimpleTest.finish();
}
}
function mozAppsError() {
ok(false, "mozApps error: " + this.error.name);
SimpleTest.finish();
}
function runTest() {
// Set up.
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.autoConfirmAppInstall(continueTest);
yield undefined;
SpecialPowers.autoConfirmAppUninstall(continueTest);
yield undefined;
let request = navigator.mozApps.install(url);
request.onerror = mozAppsError;
request.onsuccess = continueTest;
yield undefined;
let app = request.result;
let _topic = "clear-cookiejar-data";
let observer = new Observer(_topic);
observer.onobserve = function(subject, topic, data, count) {
ok(topic == _topic, "unknown topic " + topic);
let cookieJar = data;
ok(cookieJar, "params.cookieJar should have value for an app.");
// should receive 2 notifications when an app is uninstalled.
if (count == 2) {
ok(true);
observer.shutdown();
continueTest();
}
};
request = navigator.mozApps.mgmt.uninstall(app);
request.onerror = mozAppsError;
navigator.mozApps.mgmt.onuninstall = function(evt) {
if (evt.application.manifestURL != url) {
return;
}
ok(true, "got onuninstall event");
continueTest();
};
// we now wait for "clear-cookiejar-data" notifications and onuninstall
// callback.
yield undefined;
yield undefined;
navigator.mozApps.mgmt.onuninstall = null;
}
function Observer(topic) {
this.topic = topic;
SpecialPowers.addObserver(this, topic, false);
}
Observer.prototype = {
topic: null,
count: 1,
callback: null,
observe: function(subject, topic, data) {
if (this.callback) this.callback(subject, topic, data, this.count++);
},
shutdown: function() {
SpecialPowers.removeObserver(this, this.topic);
},
set onobserve (callback) {
this.callback = callback;
}
};
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body onload="go()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1168300">Mozilla Bug 1168300</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

Просмотреть файл

@ -16,4 +16,5 @@ interface mozIApplicationClearPrivateDataParams : nsISupports
%{C++
#define TOPIC_WEB_APP_CLEAR_DATA "webapps-clear-data"
#define TOPIC_CLEAR_COOKIEJAR_DATA "clear-cookiejar-data"
%}