mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
309b4049b4
We are white-listing the existing set of tests that use setTimeout like this. Hopefully these tests will be investigated and fixed in the future, so that we can narrow down the white-list. This check is only turned on for mochitest-plain for now.
344 lines
11 KiB
HTML
344 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id={900533}
|
|
-->
|
|
<head>
|
|
<title>Test for Bug {900533} Packaged app update tests</title>
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="text/javascript" src="test_packaged_app_common.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={900533}">Mozilla Bug {900533}</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
"use strict";
|
|
|
|
function debug(aMsg) {
|
|
//dump("== Tests debug == " + aMsg + "\n");
|
|
}
|
|
|
|
var miniManifestURL;
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
SimpleTest.requestFlakyTimeout("untriaged");
|
|
|
|
function checkForUpdate(aExpected, aOnSuccess, aOnApplied, aOnDownloadError,
|
|
aLaunchDownload, aOnRequestError) {
|
|
var lApp = PackagedTestHelper.gApp;
|
|
|
|
lApp.ondownloadsuccess = aOnSuccess || null;
|
|
lApp.ondownloadapplied = aOnApplied || null;
|
|
lApp.ondownloaderror = aOnDownloadError || null;
|
|
|
|
var request = lApp.checkForUpdate();
|
|
request.onerror = aOnRequestError ? aOnRequestError.bind(undefined, request) :
|
|
PackagedTestHelper.mozAppsError;
|
|
request.onsuccess = function(event) {
|
|
var expectingDownload = aExpected ? "": "not ";
|
|
ok(lApp.downloadAvailable === aExpected,
|
|
"Download should " + expectingDownload + "be available");
|
|
if (aLaunchDownload) {
|
|
lApp.download();
|
|
} else {
|
|
PackagedTestHelper.next();
|
|
}
|
|
};
|
|
}
|
|
|
|
function checkLastAppState(aMiniManifestURL, aExpectedReady, aExpectedDownload,
|
|
aExpectedVersion, aCb) {
|
|
info(aExpectedReady ? "App downloaded" : "App download applied");
|
|
var expected = {
|
|
name: PackagedTestHelper.gAppName,
|
|
manifestURL: aMiniManifestURL,
|
|
installOrigin: PackagedTestHelper.gInstallOrigin,
|
|
progress: 0,
|
|
installState: aExpectedReady ? "updating" : "installed",
|
|
downloadAvailable: aExpectedDownload,
|
|
downloading: false,
|
|
size: 0,
|
|
readyToApplyDownload: aExpectedReady
|
|
};
|
|
|
|
PackagedTestHelper.checkAppState(PackagedTestHelper.gApp, aExpectedVersion,
|
|
expected, true, false, aCb);
|
|
}
|
|
|
|
function updateApp(aExpectedReady, aPreviousVersion, aNextVersion, aFailOnError) {
|
|
var lApp = PackagedTestHelper.gApp;
|
|
|
|
var ondownloadappliedhandler =
|
|
checkLastAppState.bind(PackagedTestHelper, miniManifestURL, false, false,
|
|
aNextVersion,
|
|
setTimeout.bind(undefined, PackagedTestHelper.next, 500));
|
|
|
|
var ondownloadsuccesshandler =
|
|
checkLastAppState.bind(undefined, miniManifestURL,
|
|
aExpectedReady, false, aPreviousVersion,
|
|
function() {
|
|
navigator.mozApps.mgmt.applyDownload(lApp);
|
|
});
|
|
|
|
var ondownloaderrorhandler = aFailOnError ?
|
|
function() {
|
|
ok(false, "We should not get an error but got " +
|
|
lApp.downloadError.name);
|
|
PackagedTestHelper.finish();
|
|
} : null;
|
|
|
|
checkForUpdate(true, ondownloadsuccesshandler, ondownloadappliedhandler,
|
|
ondownloaderrorhandler, true);
|
|
|
|
}
|
|
|
|
var initialPermissionState = {
|
|
"geolocation": "prompt",
|
|
"audio-capture": "prompt",
|
|
"video-capture": "prompt",
|
|
"test-permission-read": "prompt",
|
|
"downloads": "deny"
|
|
}
|
|
|
|
var permissionsToSet = {
|
|
"geolocation": "allow",
|
|
"test-permission-read": "allow",
|
|
"audio-capture": "deny"
|
|
}
|
|
|
|
var permissionsToCheck = {
|
|
"geolocation": "allow",
|
|
"audio-capture": "deny",
|
|
"video-capture": "prompt",
|
|
"test-permission-read": "allow",
|
|
"downloads": "deny"
|
|
}
|
|
|
|
function validatePermissions(aList, aDontFail) {
|
|
var gApp = PackagedTestHelper.gApp;
|
|
var mozPermissions = window.navigator.mozPermissionSettings;
|
|
var permission;
|
|
for (permission in aList) {
|
|
var permValue = mozPermissions.get(permission, gApp.manifestURL,
|
|
gApp.origin, false);
|
|
var wouldFail = permValue != aList[permission];
|
|
var checkFun = (aDontFail && wouldFail) ? todo_is : is;
|
|
checkFun(permValue, aList[permission],
|
|
"Permission " + permission + " should be " + aList[permission]);
|
|
}
|
|
}
|
|
|
|
|
|
var steps = [
|
|
function() {
|
|
// Set up
|
|
SpecialPowers.setAllAppsLaunchable(true);
|
|
SpecialPowers.addPermission("webapps-manage", true, document);
|
|
info("Set up");
|
|
// Note that without useCurrentProfile the permissions just aren't added.
|
|
SpecialPowers.pushPermissions(
|
|
[{'type': 'permissions', 'allow': true, 'context': document}],
|
|
function() {
|
|
SpecialPowers.pushPrefEnv(
|
|
{"set": [["dom.mozPermissionSettings.enabled", true],
|
|
["dom.webapps.useCurrentProfile", true]]},
|
|
PackagedTestHelper.next);
|
|
}
|
|
);
|
|
},
|
|
function() {
|
|
info("autoConfirmAppInstall");
|
|
SpecialPowers.autoConfirmAppInstall(PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(2, PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
info("== TEST == Install packaged app");
|
|
navigator.mozApps.mgmt.oninstall = function(evt) {
|
|
info("Got oninstall event");
|
|
PackagedTestHelper.gApp = evt.application;
|
|
PackagedTestHelper.gApp.ondownloaderror = function() {
|
|
ok(false, "Download error " + PackagedTestHelper.gApp.downloadError.name);
|
|
PackagedTestHelper.finish();
|
|
};
|
|
PackagedTestHelper.gApp.ondownloadsuccess =
|
|
checkLastAppState.bind(undefined, miniManifestURL, false, false,
|
|
2, PackagedTestHelper.next);
|
|
};
|
|
|
|
var request = navigator.mozApps.installPackage(miniManifestURL);
|
|
request.onerror = PackagedTestHelper.mozAppsError;
|
|
request.onsuccess = function() {
|
|
info("Application installed");
|
|
};
|
|
},
|
|
function() {
|
|
info("== TEST == Permissions installed correctly");
|
|
validatePermissions(initialPermissionState);
|
|
PackagedTestHelper.next();
|
|
},
|
|
function() {
|
|
info("== TEST == Check for Update and try to download it without update available");
|
|
|
|
function onerror() {
|
|
is(PackagedTestHelper.gApp.downloadError.name, "NO_DOWNLOAD_AVAILABLE", "Download not available");
|
|
ok(!PackagedTestHelper.gApp.readyToApplyDownload, "Not ready to apply download");
|
|
PackagedTestHelper.next();
|
|
}
|
|
function onsuccess() {
|
|
ok(false, "ondownloadsuccess fired");
|
|
PackagedTestHelper.next();
|
|
}
|
|
|
|
checkForUpdate(false, onsuccess, null, onerror, true);
|
|
},
|
|
function() {
|
|
info("== TEST == Remember permissions");
|
|
var gApp = PackagedTestHelper.gApp;
|
|
var mozPermissions = window.navigator.mozPermissionSettings;
|
|
var permission;
|
|
for (permission in permissionsToSet) {
|
|
try {
|
|
window.navigator.mozPermissionSettings.set(permission,
|
|
permissionsToSet[permission],
|
|
gApp.manifestURL,
|
|
gApp.origin, false);
|
|
} catch (e) {
|
|
ok(false,
|
|
"mozPermissionSettings.set failed for " + permission + " - " + e);
|
|
}
|
|
}
|
|
PackagedTestHelper.next();
|
|
},
|
|
function() {
|
|
info("== TEST == Check that the permissions have been saved");
|
|
// Since the permission API isn't really synchronous, just log any errors
|
|
// here.
|
|
validatePermissions(permissionsToCheck, true /*dontFail*/);
|
|
PackagedTestHelper.next();
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(3, PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
info("== TEST == Update packaged app");
|
|
updateApp(true, 2, 3);
|
|
},
|
|
function() {
|
|
info("== TEST == Check that saved permissions were kept");
|
|
validatePermissions(permissionsToCheck);
|
|
PackagedTestHelper.next();
|
|
},
|
|
function() {
|
|
info("== TEST == Check for Update after getting a new package");
|
|
checkForUpdate(false);
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(4, PackagedTestHelper.next, true);
|
|
},
|
|
function() {
|
|
info("== TEST == Update packaged app - same package");
|
|
updateApp(false, 3, 3, true);
|
|
},
|
|
function() {
|
|
info("== TEST == Check for Update after getting the same package");
|
|
checkForUpdate(false);
|
|
},
|
|
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(5, PackagedTestHelper.next,
|
|
/* aDontUpdatePackage */ false,
|
|
/* aAllowCancel */ false,
|
|
/* aRole */ undefined,
|
|
/* aFailOnce */ true);
|
|
|
|
},
|
|
function() {
|
|
info("== TEST == Update packaged app - fail the update once");
|
|
|
|
var downloadSuccess = function() {
|
|
ok(false, "We got an unexpected downloadsuccess or downloadapplied");
|
|
PackagedTestHelper.finish();
|
|
};
|
|
var downloadError = function() {
|
|
info("We got an expected download error: " +
|
|
PackagedTestHelper.gApp.downloadError.name);
|
|
PackagedTestHelper.next();
|
|
};
|
|
checkForUpdate(true, downloadSuccess, downloadSuccess, downloadError,
|
|
/* aLaunchDownload */ true);
|
|
},
|
|
function() {
|
|
info("=== TEST == Update packaged app - apply the update after failing");
|
|
var lApp = PackagedTestHelper.gApp;
|
|
lApp.ondownloadsuccess = function() {
|
|
info("Download succeeded, applying it");
|
|
navigator.mozApps.mgmt.applyDownload(lApp);
|
|
};
|
|
lApp.ondownloadapplied = function() {
|
|
info("Download successfuly applied");
|
|
PackagedTestHelper.next();
|
|
};
|
|
lApp.ondownloaderror = function() {
|
|
ok(false, "Got an unexpected error: " + lApp.downloaderror.name);
|
|
PackagedTestHelper.finish();
|
|
};
|
|
lApp.download();
|
|
},
|
|
function() {
|
|
info("== TEST == Check for Update applying a previously failed package");
|
|
checkForUpdate(false);
|
|
},
|
|
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(1, PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
info("== TEST == Update packaged app - Updating a pending app");
|
|
miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&appName=arandomname" +
|
|
"&appToFail1";
|
|
PackagedTestHelper.checkAppDownloadError(miniManifestURL,
|
|
"MANIFEST_MISMATCH", 1, false, true,
|
|
"arandomname",
|
|
function () {
|
|
checkForUpdate(false, null, null, null, false,
|
|
function (request) {
|
|
if (request.error.name === "PENDING_APP_NOT_UPDATABLE") {
|
|
info("Got expected PENDING_APP_NOT_UPDATEABLE");
|
|
} else {
|
|
ok(false, "Got unexpected " + request.error.name);
|
|
}
|
|
PackagedTestHelper.next();
|
|
});
|
|
});
|
|
},
|
|
function() {
|
|
info("all done!\n");
|
|
PackagedTestHelper.finish();
|
|
}
|
|
];
|
|
|
|
PackagedTestHelper.setSteps(steps);
|
|
// appToUpdate added to the URL so we get a unique URL for this app.
|
|
// Unique in this case meaning different from the ones used on the
|
|
// install tests
|
|
miniManifestURL = PackagedTestHelper.gSJS + "?getManifest=true&appToUpdate";
|
|
|
|
addLoadEvent(PackagedTestHelper.start);
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|