mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 13:48:23 +02:00
Bug 1447903: Part 10a - Refactor test_cacheflush.js to not be insane. r=aswan
MozReview-Commit-ID: EqMO3gwQILE --HG-- extra : rebase_source : 287bf6f810122199d58e3acedb058e0cc140da80
This commit is contained in:
parent
ef1e5e3c1b
commit
1529052a3e
3 changed files with 95 additions and 117 deletions
|
|
@ -1,22 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
|
|
||||||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
||||||
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
|
||||||
|
|
||||||
<Description about="urn:mozilla:install-manifest">
|
|
||||||
<em:id>addon1@tests.mozilla.org</em:id>
|
|
||||||
<em:version>2.0</em:version>
|
|
||||||
|
|
||||||
<!-- Front End MetaData -->
|
|
||||||
<em:name>File Pointer Test</em:name>
|
|
||||||
|
|
||||||
<em:targetApplication>
|
|
||||||
<Description>
|
|
||||||
<em:id>xpcshell@tests.mozilla.org</em:id>
|
|
||||||
<em:minVersion>1</em:minVersion>
|
|
||||||
<em:maxVersion>1</em:maxVersion>
|
|
||||||
</Description>
|
|
||||||
</em:targetApplication>
|
|
||||||
|
|
||||||
</Description>
|
|
||||||
</RDF>
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
|
|
||||||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
||||||
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
|
||||||
|
|
||||||
<Description about="urn:mozilla:install-manifest">
|
|
||||||
<em:id>addon2@tests.mozilla.org</em:id>
|
|
||||||
<em:version>2.0</em:version>
|
|
||||||
|
|
||||||
<!-- Front End MetaData -->
|
|
||||||
<em:name>File Pointer Test</em:name>
|
|
||||||
<em:bootstrap>true</em:bootstrap>
|
|
||||||
|
|
||||||
<em:targetApplication>
|
|
||||||
<Description>
|
|
||||||
<em:id>xpcshell@tests.mozilla.org</em:id>
|
|
||||||
<em:minVersion>1</em:minVersion>
|
|
||||||
<em:maxVersion>1</em:maxVersion>
|
|
||||||
</Description>
|
|
||||||
</em:targetApplication>
|
|
||||||
|
|
||||||
</Description>
|
|
||||||
</RDF>
|
|
||||||
|
|
@ -15,79 +15,103 @@ var CacheFlushObserver = {
|
||||||
if (aData == "cert-override")
|
if (aData == "cert-override")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Assert.ok(gExpectedFile != null);
|
ok(gExpectedFile != null);
|
||||||
Assert.ok(aSubject instanceof AM_Ci.nsIFile);
|
ok(aSubject instanceof AM_Ci.nsIFile);
|
||||||
Assert.equal(aSubject.path, gExpectedFile.path);
|
equal(aSubject.path, gExpectedFile.path);
|
||||||
gCacheFlushCount++;
|
gCacheFlushCount++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function run_test() {
|
const ADDONS = [
|
||||||
do_test_pending();
|
{
|
||||||
|
id: "addon1@tests.mozilla.org",
|
||||||
|
version: "2.0",
|
||||||
|
name: "Cache Flush Test",
|
||||||
|
|
||||||
|
targetApplications: [{
|
||||||
|
id: "xpcshell@tests.mozilla.org",
|
||||||
|
minVersion: "1",
|
||||||
|
maxVersion: "1" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "addon2@tests.mozilla.org",
|
||||||
|
version: "2.0",
|
||||||
|
|
||||||
|
name: "Cache Flush Test",
|
||||||
|
bootstrap: true,
|
||||||
|
|
||||||
|
targetApplications: [{
|
||||||
|
id: "xpcshell@tests.mozilla.org",
|
||||||
|
minVersion: "1",
|
||||||
|
maxVersion: "1" }],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const XPIS = ADDONS.map(addon => createTempXPIFile(addon));
|
||||||
|
|
||||||
|
add_task(async function setup() {
|
||||||
Services.obs.addObserver(CacheFlushObserver, "flush-cache-entry");
|
Services.obs.addObserver(CacheFlushObserver, "flush-cache-entry");
|
||||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2");
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2");
|
||||||
|
|
||||||
startupManager();
|
await promiseStartupManager();
|
||||||
|
});
|
||||||
run_test_1();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that the cache is flushed when cancelling a pending install
|
// Tests that the cache is flushed when cancelling a pending install
|
||||||
function run_test_1() {
|
add_task(async function test_flush_pending_install() {
|
||||||
AddonManager.getInstallForFile(do_get_addon("test_cacheflush1"), function(aInstall) {
|
let install = await AddonManager.getInstallForFile(XPIS[0]);
|
||||||
completeAllInstalls([aInstall], function() {
|
await promiseCompleteInstall(install);
|
||||||
|
|
||||||
// We should flush the staged XPI when cancelling the install
|
// We should flush the staged XPI when cancelling the install
|
||||||
gExpectedFile = gProfD.clone();
|
gExpectedFile = gProfD.clone();
|
||||||
gExpectedFile.append("extensions");
|
gExpectedFile.append("extensions");
|
||||||
gExpectedFile.append("staged");
|
gExpectedFile.append("staged");
|
||||||
gExpectedFile.append("addon1@tests.mozilla.org.xpi");
|
gExpectedFile.append("addon1@tests.mozilla.org.xpi");
|
||||||
aInstall.cancel();
|
install.cancel();
|
||||||
|
|
||||||
Assert.equal(gCacheFlushCount, 1);
|
equal(gCacheFlushCount, 1);
|
||||||
gExpectedFile = null;
|
gExpectedFile = null;
|
||||||
gCacheFlushCount = 0;
|
gCacheFlushCount = 0;
|
||||||
|
|
||||||
run_test_2();
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that the cache is flushed when uninstalling an add-on
|
// Tests that the cache is flushed when uninstalling an add-on
|
||||||
function run_test_2() {
|
add_task(async function test_flush_uninstall() {
|
||||||
installAllFiles([do_get_addon("test_cacheflush1")], function() {
|
await promiseInstallFile(XPIS[0]);
|
||||||
|
|
||||||
// Installing will flush the staged XPI during startup
|
// Installing will flush the staged XPI during startup
|
||||||
gExpectedFile = gProfD.clone();
|
gExpectedFile = gProfD.clone();
|
||||||
gExpectedFile.append("extensions");
|
gExpectedFile.append("extensions");
|
||||||
gExpectedFile.append("staged");
|
gExpectedFile.append("staged");
|
||||||
gExpectedFile.append("addon1@tests.mozilla.org.xpi");
|
gExpectedFile.append("addon1@tests.mozilla.org.xpi");
|
||||||
restartManager();
|
|
||||||
Assert.equal(gCacheFlushCount, 1);
|
await promiseRestartManager();
|
||||||
|
|
||||||
|
equal(gCacheFlushCount, 1);
|
||||||
gExpectedFile = null;
|
gExpectedFile = null;
|
||||||
gCacheFlushCount = 0;
|
gCacheFlushCount = 0;
|
||||||
|
|
||||||
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
|
let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
|
||||||
// We should flush the installed XPI when uninstalling
|
// We should flush the installed XPI when uninstalling
|
||||||
Assert.ok(a1 != null);
|
ok(addon != null);
|
||||||
a1.uninstall();
|
addon.uninstall();
|
||||||
Assert.equal(gCacheFlushCount, 0);
|
equal(gCacheFlushCount, 0);
|
||||||
|
|
||||||
gExpectedFile = gProfD.clone();
|
gExpectedFile = gProfD.clone();
|
||||||
gExpectedFile.append("extensions");
|
gExpectedFile.append("extensions");
|
||||||
gExpectedFile.append("addon1@tests.mozilla.org.xpi");
|
gExpectedFile.append("addon1@tests.mozilla.org.xpi");
|
||||||
restartManager();
|
|
||||||
Assert.equal(gCacheFlushCount, 1);
|
await promiseRestartManager();
|
||||||
|
|
||||||
|
equal(gCacheFlushCount, 1);
|
||||||
gExpectedFile = null;
|
gExpectedFile = null;
|
||||||
gCacheFlushCount = 0;
|
gCacheFlushCount = 0;
|
||||||
|
|
||||||
executeSoon(run_test_3);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that the cache is flushed when installing a restartless add-on
|
// Tests that the cache is flushed when installing a restartless add-on
|
||||||
function run_test_3() {
|
add_task(async function test_flush_restartless_install() {
|
||||||
AddonManager.getInstallForFile(do_get_addon("test_cacheflush2"), function(aInstall) {
|
let install = await AddonManager.getInstallForFile(XPIS[1]);
|
||||||
aInstall.addListener({
|
|
||||||
|
await new Promise(resolve => {
|
||||||
|
install.addListener({
|
||||||
onInstallStarted() {
|
onInstallStarted() {
|
||||||
// We should flush the staged XPI when completing the install
|
// We should flush the staged XPI when completing the install
|
||||||
gExpectedFile = gProfD.clone();
|
gExpectedFile = gProfD.clone();
|
||||||
|
|
@ -97,31 +121,30 @@ function run_test_3() {
|
||||||
},
|
},
|
||||||
|
|
||||||
onInstallEnded() {
|
onInstallEnded() {
|
||||||
Assert.equal(gCacheFlushCount, 1);
|
equal(gCacheFlushCount, 1);
|
||||||
gExpectedFile = null;
|
gExpectedFile = null;
|
||||||
gCacheFlushCount = 0;
|
gCacheFlushCount = 0;
|
||||||
|
|
||||||
executeSoon(run_test_4);
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
aInstall.install();
|
install.install();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that the cache is flushed when uninstalling a restartless add-on
|
// Tests that the cache is flushed when uninstalling a restartless add-on
|
||||||
function run_test_4() {
|
add_task(async function test_flush_uninstall() {
|
||||||
AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
|
let addon = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
|
||||||
|
|
||||||
// We should flush the installed XPI when uninstalling
|
// We should flush the installed XPI when uninstalling
|
||||||
gExpectedFile = gProfD.clone();
|
gExpectedFile = gProfD.clone();
|
||||||
gExpectedFile.append("extensions");
|
gExpectedFile.append("extensions");
|
||||||
gExpectedFile.append("addon2@tests.mozilla.org.xpi");
|
gExpectedFile.append("addon2@tests.mozilla.org.xpi");
|
||||||
|
|
||||||
a2.uninstall();
|
addon.uninstall();
|
||||||
Assert.equal(gCacheFlushCount, 1);
|
|
||||||
|
equal(gCacheFlushCount, 1);
|
||||||
gExpectedFile = null;
|
gExpectedFile = null;
|
||||||
gCacheFlushCount = 0;
|
gCacheFlushCount = 0;
|
||||||
|
|
||||||
executeSoon(do_test_finished);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue