Bug 417606: See all search results always number 10. r=gavin.sharp, r=robstrong

This commit is contained in:
dtownsend@oxymoronical.com 2008-03-07 03:16:48 -08:00
parent 69b1dc1564
commit 15d0b60dfe
7 changed files with 773 additions and 17 deletions

View File

@ -61,7 +61,9 @@ nsURLFormatterService.prototype = {
_defaults: {
get appInfo() {
if (!this._appInfo)
this._appInfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
this._appInfo = Cc["@mozilla.org/xre/app-info;1"].
getService(Ci.nsIXULAppInfo).
QueryInterface(Ci.nsIXULRuntime);
return this._appInfo;
},
@ -74,7 +76,9 @@ nsURLFormatterService.prototype = {
APPBUILDID: function() this.appInfo.appBuildID,
PLATFORMVERSION: function() this.appInfo.platformVersion,
PLATFORMBUILDID: function() this.appInfo.platformBuildID,
APP: function() this.appInfo.name.toLowerCase().replace(/ /, "")
APP: function() this.appInfo.name.toLowerCase().replace(/ /, ""),
OS: function() this.appInfo.OS,
XPCOMABI: function() this.appInfo.XPCOMABI
},
formatURL: function uf_formatURL(aFormat) {

View File

@ -42,10 +42,10 @@ function run_test() {
var prefs = Cc['@mozilla.org/preferences-service;1'].
getService(Ci.nsIPrefBranch);
var upperUrlRaw = "http://%LOCALE%.%VENDOR%.foo/?name=%NAME%&id=%ID%&version=%VERSION%&platversion=%PLATFORMVERSION%&abid=%APPBUILDID%&pbid=%PLATFORMBUILDID%&app=%APP%";
var lowerUrlRaw = "http://%locale%.%vendor%.foo/?name=%name%&id=%id%&version=%version%&platversion=%platformversion%&abid=%appbuildid%&pbid=%platformbuildid%&app=%app%";
var upperUrlRaw = "http://%LOCALE%.%VENDOR%.foo/?name=%NAME%&id=%ID%&version=%VERSION%&platversion=%PLATFORMVERSION%&abid=%APPBUILDID%&pbid=%PLATFORMBUILDID%&app=%APP%&os=%OS%&abi=%XPCOMABI%";
var lowerUrlRaw = "http://%locale%.%vendor%.foo/?name=%name%&id=%id%&version=%version%&platversion=%platformversion%&abid=%appbuildid%&pbid=%platformbuildid%&app=%app%&os=%os%&abi=%xpcomabi%";
//XXX %APP%'s RegExp is not global, so it only replaces the first space
var ulUrlRef = "http://" + locale + ".Mozilla.foo/?name=Url Formatter Test&id=urlformattertest@test.mozilla.org&version=1&platversion=2.0&abid=2007122405&pbid=2007122406&app=urlformatter test";
var ulUrlRef = "http://" + locale + ".Mozilla.foo/?name=Url Formatter Test&id=urlformattertest@test.mozilla.org&version=1&platversion=2.0&abid=2007122405&pbid=2007122406&app=urlformatter test&os=XPCShell&abi=noarch-spidermonkey";
var multiUrl = "http://%VENDOR%.%VENDOR%.%NAME%.%VENDOR%.%NAME%";
var multiUrlRef = "http://Mozilla.Mozilla.Url Formatter Test.Mozilla.Url Formatter Test";

View File

@ -51,6 +51,8 @@ const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml";
const API_VERSION = "1";
function AddonSearchResult() {
}
@ -140,10 +142,14 @@ AddonRepository.prototype = {
this._recommended = true;
this._maxResults = aMaxResults;
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var urlf = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
.getService(Components.interfaces.nsIURLFormatter);
var uri = urlf.formatURLPref(PREF_GETADDONS_GETRECOMMENDED);
var uri = prefs.getCharPref(PREF_GETADDONS_GETRECOMMENDED);
uri = uri.replace(/%API_VERSION%/g, API_VERSION);
uri = urlf.formatURL(uri);
this._loadList(uri);
},
@ -163,6 +169,7 @@ AddonRepository.prototype = {
.getService(Components.interfaces.nsIURLFormatter);
var uri = prefs.getCharPref(PREF_GETADDONS_GETSEARCHRESULTS);
uri = uri.replace(/%API_VERSION%/g, API_VERSION);
uri = uri.replace(/%TERMS%/g, encodeURIComponent(aSearchTerms));
uri = urlf.formatURL(uri);
this._loadList(uri);
@ -211,18 +218,22 @@ AddonRepository.prototype = {
return;
// Ignore add-ons not compatible with this OS
var compatible = false;
var os = element.getElementsByTagName("compatible_os");
var i = 0;
while (i < os.length && !compatible) {
if (os[i].textContent == "ALL" || os[i].textContent == app.OS) {
compatible = true;
break;
// Only the version 0 schema included compatible_os if it isn't there then
// we will see os compatibility on the install elements.
if (os.length > 0) {
var compatible = false;
var i = 0;
while (i < os.length && !compatible) {
if (os[i].textContent == "ALL" || os[i].textContent == app.OS) {
compatible = true;
break;
}
i++;
}
i++;
if (!compatible)
return;
}
if (!compatible)
return;
// Ignore add-ons not compatible with this Application
compatible = false;
@ -284,6 +295,13 @@ AddonRepository.prototype = {
addon.type = Ci.nsIUpdateItem.TYPE_EXTENSION;
break;
case "install":
// No os attribute means the xpi is compatible with any os
if (node.hasAttribute("os")) {
var os = node.getAttribute("os").toLowerCase();
// If the os is not ALL and not the current OS then ignore this xpi
if (os != "all" && os != app.OS.toLowerCase())
break;
}
addon.xpiURL = node.textContent;
if (node.hasAttribute("hash"))
addon.xpiHash = node.getAttribute("hash");
@ -293,7 +311,9 @@ AddonRepository.prototype = {
node = node.nextSibling;
}
this._addons.push(addon);
// Add only if there was an xpi compatible with this os
if (addon.xpiURL)
this._addons.push(addon);
},
// Called when a single request has completed, parses out any add-ons and
@ -318,7 +338,11 @@ AddonRepository.prototype = {
return;
}
}
this._reportSuccess(elements.length);
if (responseXML.documentElement.hasAttribute("total_results"))
this._reportSuccess(responseXML.documentElement.getAttribute("total_results"));
else
this._reportSuccess(elements.length);
},
// Performs a new request for results

View File

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="utf-8" ?>
<searchresults>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test1@tests.mozilla.org</guid>
<version>1.0</version>
<status id='2'>Sandbox</status>
<summary>Should not return sandboxed add-on</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test2@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return an incompatible add-on</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>2</min_version>
<max_version>2</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test3@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return an incompatible add-on</summary>
<compatible_applications>
<application>
<name>Firefox</name>
<application_id>1</application_id>
<min_version>2</min_version>
<max_version>2</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test4@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return an add-on for a different OS</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<compatible_os>Windows</compatible_os>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>PASS</name>
<type id='1'>Extension</type>
<guid>test5@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>This should work fine</summary>
<description>Test description</description>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>bug397778@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return items that are already installed</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test5@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not include the same result twice</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>PASS</name>
<type id='2'>Theme</type>
<guid>test6@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<rating>4</rating>
<summary>Specific OS should work fine</summary>
<eula>EULA should be confirmed</eula>
<thumbnail>http://localhost:4444/test_bug404024/thumbnail.png</thumbnail>
<icon>http://localhost:4444/test_bug404024/icon.png</icon>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<compatible_os>XPCShell</compatible_os>
<install>http://localhost:4444/test.xpi</install>
</addon>
</searchresults>

View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="utf-8" ?>
<searchresults total_results="100">
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test1@tests.mozilla.org</guid>
<version>1.0</version>
<status id='2'>Sandbox</status>
<summary>Should not return sandboxed add-on</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install os="ALL" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test2@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return an incompatible add-on</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>2</min_version>
<max_version>2</max_version>
</application>
</compatible_applications>
<install os="ALL" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test3@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return an incompatible add-on</summary>
<compatible_applications>
<application>
<name>Firefox</name>
<application_id>1</application_id>
<min_version>2</min_version>
<max_version>2</max_version>
</application>
</compatible_applications>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install os="ALL" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test4@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return an add-on for a different OS</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install os="Windows" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>PASS</name>
<type id='1'>Extension</type>
<guid>test5@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>This should work fine</summary>
<description>Test description</description>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install os="ALL" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>bug397778@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not return items that are already installed</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<install os="ALL" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>FAIL</name>
<type id='1'>Extension</type>
<guid>test5@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<summary>Should not include the same result twice</summary>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
<install os="ALL" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
</addon>
<addon>
<name>PASS</name>
<type id='2'>Theme</type>
<guid>test6@tests.mozilla.org</guid>
<version>1.0</version>
<status id='4'>Public</status>
<rating>4</rating>
<summary>Specific OS should work fine</summary>
<eula>EULA should be confirmed</eula>
<thumbnail>http://localhost:4444/test_bug404024/thumbnail.png</thumbnail>
<icon>http://localhost:4444/test_bug404024/icon.png</icon>
<compatible_applications>
<application>
<name>XPCShell</name>
<application_id>1</application_id>
<min_version>1</min_version>
<max_version>1</max_version>
</application>
</compatible_applications>
<install os="Windows">http://localhost:4444/test.xpi</install>
<install os="XPCShell">http://localhost:4444/XPCShell.xpi</install>
<install os="Darwin">http://localhost:4444/test.xpi</install>
</addon>
</searchresults>

View File

@ -0,0 +1,209 @@
/* ***** 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) 2007
* 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 *****
*/
const PREF_GETADDONS_BROWSEADDONS = "extensions.getAddons.browseAddons";
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url";
const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
const BROWSE = "http://localhost:4444/";
const RECOMMENDED = "http://localhost:4444/recommended.html";
const SEARCH = "http://localhost:4444/search.html?q=";
var BROWSE_SEARCH_URLS = [
["test", SEARCH + "test" ],
["SEARCH", SEARCH + "SEARCH" ],
["test search", SEARCH + "test%20search" ],
["odd=search:with&weird\"characters", SEARCH + "odd%3Dsearch%3Awith%26weird%22characters" ]
];
do_import_script("netwerk/test/httpserver/httpd.js");
var server;
var addonRepo;
var RESULTS = [
{
id: "test5@tests.mozilla.org",
name: "PASS",
version: "1.0",
summary: "This should work fine",
description: "Test description",
rating: -1,
iconURL: null,
thumbnailURL: null,
homepageURL: "https://addons.mozilla.org/addon/5992",
eula: null,
type: Ci.nsIUpdateItem.TYPE_EXTENSION,
xpiURL: "http://localhost:4444/test.xpi",
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
},
{
id: "test6@tests.mozilla.org",
name: "PASS",
version: "1.0",
summary: "Specific OS should work fine",
description: null,
rating: 4,
iconURL: "http://localhost:4444/test_bug404024/icon.png",
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
homepageURL: null,
eula: "EULA should be confirmed",
type: Ci.nsIUpdateItem.TYPE_THEME,
xpiURL: "http://localhost:4444/test.xpi",
xpiHash: null
}
];
function checkResults(addons, length) {
do_check_eq(addons.length, RESULTS.length);
do_check_eq(addons.length, length);
for (var i = 0; i < addons.length; i++) {
if (addons[i].name == "FAIL")
do_throw(addons[i].id + " - " + addons[i].summary);
if (addons[i].name != "PASS")
do_throw(addons[i].id + " - " + "invalid add-on name " + addons[i].name);
}
for (var i = 0; i < addons.length; i++) {
for (var p in RESULTS[i]) {
if (addons[i][p] != RESULTS[i][p])
do_throw("Failed on property " + p + " on add-on " + addons[i].id +
addons[i][p] + " == " + RESULTS[i][p]);
}
}
}
var RecommendedCallback = {
searchSucceeded: function(addons, length, total) {
// Search is complete
do_check_false(addonRepo.isSearching);
checkResults(addons, length);
// "search" for the same results
addonRepo.searchAddons("bug404024", 10, SearchCallback);
// Should be searching now and any attempt to retrieve again should be ignored
do_check_true(addonRepo.isSearching);
addonRepo.searchAddons("test search", 10, FailCallback);
},
searchFailed: function() {
do_test_finished();
server.stop();
do_throw("Recommended results failed");
}
};
var SearchCallback = {
searchSucceeded: function(addons, length, total) {
do_check_false(addonRepo.isSearching);
checkResults(addons, length);
do_test_finished();
server.stop();
},
searchFailed: function() {
do_test_finished();
server.stop();
do_throw("Search results failed");
}
};
var FailCallback = {
searchSucceeded: function(addons, length, total) {
do_test_finished();
server.stop();
do_throw("Should not be called");
},
searchFailed: function() {
do_test_finished();
server.stop();
do_throw("Should not be called");
}
};
function run_test()
{
// Setup for test
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
// Install an add-on so we can check the same add-on isn't returns in the results
startupEM();
gEM.installItemFromFile(do_get_addon("test_bug397778"), NS_INSTALL_LOCATION_APPPROFILE);
restartEM();
server = new nsHttpServer();
server.registerDirectory("/", do_get_file("toolkit/mozapps/extensions/test/unit/data"));
server.start(4444);
// Point the addons repository to the test server
gPrefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
gPrefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
gPrefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug404024.xml");
gPrefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
gPrefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
.getService(Components.interfaces.nsIAddonRepository);
do_check_neq(addonRepo, null);
// Check the homepage and recommended urls
do_check_eq(addonRepo.homepageURL, BROWSE);
do_check_eq(addonRepo.getRecommendedURL(), RECOMMENDED);
// Check that search urls are correct
for (var i = 0; i < BROWSE_SEARCH_URLS.length; i++) {
var url = addonRepo.getSearchURL(BROWSE_SEARCH_URLS[i][0]);
if (url != BROWSE_SEARCH_URLS[i][1])
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
}
do_test_pending();
// This should fail because we cancel it immediately.
addonRepo.retrieveRecommendedAddons(10, FailCallback);
addonRepo.cancelSearch();
// Pull some results.
addonRepo.retrieveRecommendedAddons(10, RecommendedCallback);
// Should be searching now and any attempt to retrieve again should be ignored
do_check_true(addonRepo.isSearching);
addonRepo.retrieveRecommendedAddons(10, FailCallback);
}

View File

@ -0,0 +1,209 @@
/* ***** 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) 2007
* 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 *****
*/
const PREF_GETADDONS_BROWSEADDONS = "extensions.getAddons.browseAddons";
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url";
const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
const BROWSE = "http://localhost:4444/";
const RECOMMENDED = "http://localhost:4444/recommended.html";
const SEARCH = "http://localhost:4444/search/";
var BROWSE_SEARCH_URLS = [
["test", SEARCH + "test" ],
["SEARCH", SEARCH + "SEARCH" ],
["test search", SEARCH + "test%20search" ],
["odd=search:with&weird\"characters", SEARCH + "odd%3Dsearch%3Awith%26weird%22characters" ]
];
do_import_script("netwerk/test/httpserver/httpd.js");
var server;
var addonRepo;
var RESULTS = [
{
id: "test5@tests.mozilla.org",
name: "PASS",
version: "1.0",
summary: "This should work fine",
description: "Test description",
rating: -1,
iconURL: null,
thumbnailURL: null,
homepageURL: "https://addons.mozilla.org/addon/5992",
eula: null,
type: Ci.nsIUpdateItem.TYPE_EXTENSION,
xpiURL: "http://localhost:4444/test.xpi",
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
},
{
id: "test6@tests.mozilla.org",
name: "PASS",
version: "1.0",
summary: "Specific OS should work fine",
description: null,
rating: 4,
iconURL: "http://localhost:4444/test_bug404024/icon.png",
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
homepageURL: null,
eula: "EULA should be confirmed",
type: Ci.nsIUpdateItem.TYPE_THEME,
xpiURL: "http://localhost:4444/XPCShell.xpi",
xpiHash: null
}
];
function checkResults(addons) {
do_check_eq(addons.length, RESULTS.length);
for (var i = 0; i < addons.length; i++) {
if (addons[i].name == "FAIL")
do_throw(addons[i].id + " - " + addons[i].summary);
if (addons[i].name != "PASS")
do_throw(addons[i].id + " - " + "invalid add-on name " + addons[i].name);
}
for (var i = 0; i < addons.length; i++) {
for (var p in RESULTS[i]) {
if (addons[i][p] != RESULTS[i][p])
do_throw("Failed on property " + p + " on add-on " + addons[i].id +
addons[i][p] + " == " + RESULTS[i][p]);
}
}
}
var RecommendedCallback = {
searchSucceeded: function(addons, length, total) {
// Search is complete
do_check_false(addonRepo.isSearching);
checkResults(addons);
// "search" for the same results
addonRepo.searchAddons("bug417606", 10, SearchCallback);
// Should be searching now and any attempt to retrieve again should be ignored
do_check_true(addonRepo.isSearching);
addonRepo.searchAddons("test search", 10, FailCallback);
},
searchFailed: function() {
do_test_finished();
server.stop();
do_throw("Recommended results failed");
}
};
var SearchCallback = {
searchSucceeded: function(addons, length, total) {
do_check_false(addonRepo.isSearching);
do_check_eq(total, 100);
checkResults(addons);
do_test_finished();
server.stop();
},
searchFailed: function() {
do_test_finished();
server.stop();
do_throw("Search results failed");
}
};
var FailCallback = {
searchSucceeded: function(addons, length, total) {
do_test_finished();
server.stop();
do_throw("Should not be called");
},
searchFailed: function() {
do_test_finished();
server.stop();
do_throw("Should not be called");
}
};
function run_test()
{
// Setup for test
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
// Install an add-on so we can check the same add-on isn't returns in the results
startupEM();
gEM.installItemFromFile(do_get_addon("test_bug397778"), NS_INSTALL_LOCATION_APPPROFILE);
restartEM();
server = new nsHttpServer();
server.registerDirectory("/", do_get_file("toolkit/mozapps/extensions/test/unit/data"));
server.start(4444);
// Point the addons repository to the test server
gPrefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
gPrefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
gPrefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug417606.xml");
gPrefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
gPrefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
.getService(Components.interfaces.nsIAddonRepository);
do_check_neq(addonRepo, null);
// Check the homepage and recommended urls
do_check_eq(addonRepo.homepageURL, BROWSE);
do_check_eq(addonRepo.getRecommendedURL(), RECOMMENDED);
// Check that search urls are correct
for (var i = 0; i < BROWSE_SEARCH_URLS.length; i++) {
var url = addonRepo.getSearchURL(BROWSE_SEARCH_URLS[i][0]);
if (url != BROWSE_SEARCH_URLS[i][1])
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
}
do_test_pending();
// This should fail because we cancel it immediately.
addonRepo.retrieveRecommendedAddons(10, FailCallback);
addonRepo.cancelSearch();
// Pull some results.
addonRepo.retrieveRecommendedAddons(10, RecommendedCallback);
// Should be searching now and any attempt to retrieve again should be ignored
do_check_true(addonRepo.isSearching);
addonRepo.retrieveRecommendedAddons(10, FailCallback);
}