Bug 428341: Wrong error message displayed when installing an extension that isn't compatible with the app. r=robstring, a=beltzner

This commit is contained in:
dtownsend@oxymoronical.com 2008-04-11 02:44:41 -07:00
Родитель 0d21648297
Коммит 544334ecb9
11 изменённых файлов: 385 добавлений и 5 удалений

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

@ -4530,11 +4530,14 @@ ExtensionManager.prototype = {
this._installListeners[i].onInstallStarted(addon); this._installListeners[i].onInstallStarted(addon);
shouldPhoneHomeIfNecessary = true; shouldPhoneHomeIfNecessary = true;
var installManifest = null;
var installManifestFile = extractRDFFileToTempDir(aXPIFile, var installManifestFile = extractRDFFileToTempDir(aXPIFile,
FILE_INSTALL_MANIFEST, FILE_INSTALL_MANIFEST,
true); true);
var installManifest = getInstallManifest(installManifestFile); if (installManifestFile.exists()) {
installManifest = getInstallManifest(installManifestFile);
installManifestFile.remove(false); installManifestFile.remove(false);
}
if (!installManifest) { if (!installManifest) {
LOG("The Install Manifest supplied by this item is not well-formed. " + LOG("The Install Manifest supplied by this item is not well-formed. " +
"Installation will not proceed."); "Installation will not proceed.");
@ -4550,8 +4553,8 @@ ExtensionManager.prototype = {
// Recreate the add-on item with the full detail from the install manifest // Recreate the add-on item with the full detail from the install manifest
addon = makeItem(installData.id, installData.version, addon = makeItem(installData.id, installData.version,
aInstallLocationKey, aInstallLocationKey,
installData.currentApp.minVersion, installData.currentApp ? installData.currentApp.minVersion : "",
installData.currentApp.maxVersion, installData.currentApp ? installData.currentApp.maxVersion : "",
installData.name, installData.name,
getURIFromFile(aXPIFile).spec, getURIFromFile(aXPIFile).spec,
"", /* XPI Update Hash */ "", /* XPI Update Hash */
@ -4559,7 +4562,7 @@ ExtensionManager.prototype = {
installData.updateURL || "", installData.updateURL || "",
installData.updateKey || "", installData.updateKey || "",
installData.type, installData.type,
installData.currentApp.id); installData.currentApp ? installData.currentApp.id : "");
switch (installData.error) { switch (installData.error) {
case INSTALLERROR_INCOMPATIBLE_VERSION: case INSTALLERROR_INCOMPATIBLE_VERSION:

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

@ -0,0 +1 @@
This is an add-on with no install.rdf that should fail to install.

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

@ -0,0 +1 @@
This install.rdf is malformed.

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

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!-- This rdf is valid, but no install manifest resource -->
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
</RDF>

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

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!-- Invalid guid -->
<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>{invalid-guid}</em:id>
<em:version>1</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
<em:name>Test for Bug 428341</em:name>
</Description>
</RDF>

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

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!-- Invalid platform -->
<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>bug428341_5@tests.mozilla.org</em:id>
<em:version>1</em:version>
<em:targetPlatform>Linux</em:targetPlatform>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
<em:name>Test for Bug 428341</em:name>
</Description>
</RDF>

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

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!-- Has an insecure update url -->
<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>bug428341_6@tests.mozilla.org</em:id>
<em:version>1</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
<em:updateURL>http://localhost</em:updateURL>
<em:name>Test for Bug 428341</em:name>
</Description>
</RDF>

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

@ -0,0 +1,17 @@
<?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>bug428341_7@tests.mozilla.org</em:id>
<em:version>1</em:version>
<em:targetApplication>
<Description>
<em:id>unknown@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
<em:name>Test for Bug 428341</em:name>
</Description>
</RDF>

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

@ -0,0 +1,17 @@
<?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>bug428341_8@tests.mozilla.org</em:id>
<em:version>1</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>2</em:minVersion>
<em:maxVersion>2</em:maxVersion>
</Description>
</em:targetApplication>
<em:name>Test for Bug 428341</em:name>
</Description>
</RDF>

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

@ -0,0 +1,17 @@
<?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>bug428341_9@tests.mozilla.org</em:id>
<em:version>1</em:version>
<em:targetApplication>
<Description>
<em:id>toolkit@mozilla.org</em:id>
<em:minVersion>2</em:minVersion>
<em:maxVersion>2</em:maxVersion>
</Description>
</em:targetApplication>
<em:name>Test for Bug 428341</em:name>
</Description>
</RDF>

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

@ -0,0 +1,258 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Dave Townsend <dtownsend@oxymoronical.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL
*
* ***** END LICENSE BLOCK *****
*/
// This allows the EM to attempt to display errors to the user without failing
var promptService = {
alert: function(aParent, aDialogTitle, aText) {
},
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState) {
},
confirm: function(aParent, aDialogTitle, aText) {
},
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState) {
},
confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title, aCheckMsg, aCheckState) {
},
prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState) {
},
promptUsernameAndPassword: function(aParent, aDialogTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState) {
},
promptPassword: function(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState) {
},
select: function(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection) {
},
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIPromptService)
|| iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
var PromptServiceFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return promptService.QueryInterface(iid);
}
};
var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
registrar.registerFactory(Components.ID("{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}"), "PromptService",
"@mozilla.org/embedcomp/prompt-service;1", PromptServiceFactory);
var gNextState = null;
var gIndex = null;
var ADDONS = [
{
id: null,
addon: "test_bug428341_1",
error: -8,
checksCompatibility: false
},
{
id: null,
addon: "test_bug428341_2",
error: -8,
checksCompatibility: false
},
{
id: null,
addon: "test_bug428341_3",
error: -8,
checksCompatibility: false
},
{
id: "{invalid-guid}",
addon: "test_bug428341_4",
error: -2,
checksCompatibility: false
},
{
id: "bug428341_5@tests.mozilla.org",
addon: "test_bug428341_5",
error: -5,
checksCompatibility: false
},
{
id: "bug428341_6@tests.mozilla.org",
addon: "test_bug428341_6",
error: -7,
checksCompatibility: false
},
{
id: "bug428341_7@tests.mozilla.org",
addon: "test_bug428341_7",
error: -3,
checksCompatibility: false
},
{
id: "bug428341_8@tests.mozilla.org",
addon: "test_bug428341_8",
error: -3,
checksCompatibility: true
},
{
id: "bug428341_9@tests.mozilla.org",
addon: "test_bug428341_9",
error: -3,
checksCompatibility: true
}
];
// nsIAddonInstallListener
var installListener = {
onDownloadStarted: function(aAddon) {
do_throw("onDownloadStarted should not be called for a direct install");
},
onDownloadEnded: function(aAddon) {
do_throw("onDownloadEnded should not be called for a direct install");
},
onInstallStarted: function(aAddon) {
var state = "onInstallStarted";
if (gNextState != state) {
do_throw("Encountered invalid state installing add-on " + ADDONS[gIndex].addon +
". Saw " + state + " but expected " + gNextState);
}
dump("Seen " + state + " for add-on " + ADDONS[gIndex].addon + "\n");
if (ADDONS[gIndex].checksCompatibility)
gNextState = "onCompatibilityCheckStarted";
else
gNextState = "onInstallEnded";
},
onCompatibilityCheckStarted: function(aAddon) {
var state = "onCompatibilityCheckStarted";
if (gNextState != state) {
do_throw("Encountered invalid state installing add-on " + ADDONS[gIndex].addon +
". Saw " + state + " but expected " + gNextState);
}
dump("Seen " + state + " for add-on " + ADDONS[gIndex].addon + "\n");
gNextState = "onCompatibilityCheckEnded";
},
onCompatibilityCheckEnded: function(aAddon, aStatus) {
var state = "onCompatibilityCheckEnded";
if (gNextState != state) {
do_throw("Encountered invalid state installing add-on " + ADDONS[gIndex].addon +
". Saw " + state + " but expected " + gNextState);
}
dump("Seen " + state + " for add-on " + ADDONS[gIndex].addon + "\n");
gNextState = "onInstallEnded";
},
onInstallEnded: function(aAddon, aStatus) {
var state = "onInstallEnded";
if (gNextState != state) {
do_throw("Encountered invalid state installing add-on " + ADDONS[gIndex].addon +
". Saw " + state + " but expected " + gNextState);
}
if (ADDONS[gIndex].id && ADDONS[gIndex].id != aAddon.id)
do_throw("Add-on " + ADDONS[gIndex].addon + " had an incorrect id " + aAddon.id);
if (aStatus != ADDONS[gIndex].error)
do_throw("Add-on " + ADDONS[gIndex].addon + " returned incorrect status " + aStatus + ".");
dump("Seen " + state + " for add-on " + ADDONS[gIndex].addon + "\n");
gNextState = "onInstallsCompleted";
},
onInstallsCompleted: function() {
var state = "onInstallsCompleted";
if (gNextState != state) {
do_throw("Encountered invalid state installing add-on " + ADDONS[gIndex].addon +
". Saw " + state + " but expected " + gNextState);
}
dump("Seen " + state + " for add-on " + ADDONS[gIndex].addon + "\n");
gNextState = null;
gIndex++;
installNextAddon();
},
onDownloadProgress: function onProgress(aAddon, aValue, aMaxValue) {
do_throw("onDownloadProgress should not be called for a direct install");
}
}
function installNextAddon() {
if (gIndex >= ADDONS.length) {
do_test_finished();
return;
}
gNextState = "onInstallStarted";
try {
dump("Installing add-on " + ADDONS[gIndex].addon + "\n");
gEM.installItemFromFile(do_get_addon(ADDONS[gIndex].addon),
NS_INSTALL_LOCATION_APPPROFILE);
}
catch (e) {
do_throw("Exception installing add-on " + ADDONS[gIndex].addon + " " + e);
}
}
function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
startupEM();
gEM.addInstallListener(installListener);
gIndex = 0;
do_test_pending();
installNextAddon();
}