From db5194e591c37c55fa239f624b9ca97c81a24e9c Mon Sep 17 00:00:00 2001 From: Martin Stransky Date: Mon, 19 Aug 2013 08:49:42 -0400 Subject: [PATCH] Bug 815120 - xpinstall.enabled=false still allows to install xpi via. addon search. r=Unfocused --- .../mozapps/extensions/content/extensions.js | 7 ++++ .../test/browser/browser_searching.js | 39 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index bfebbe682b5..6860e5183d5 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -2085,6 +2085,9 @@ var gSearchView = { this._emptyNotice = document.getElementById("search-list-empty"); this._allResultsLink = document.getElementById("search-allresults-link"); + if (!AddonManager.isInstallEnabled("application/x-xpinstall")) + this._filter.hidden = true; + var self = this; this._listBox.addEventListener("keydown", function listbox_onKeydown(aEvent) { if (aEvent.keyCode == aEvent.DOM_VK_ENTER || @@ -2226,6 +2229,10 @@ var gSearchView = { updateView: function gSearchView_updateView() { var showLocal = this._filter.value == "local"; + + if (!showLocal && !AddonManager.isInstallEnabled("application/x-xpinstall")) + showLocal = true; + this._listBox.setAttribute("local", showLocal); this._listBox.setAttribute("remote", !showLocal); diff --git a/toolkit/mozapps/extensions/test/browser/browser_searching.js b/toolkit/mozapps/extensions/test/browser/browser_searching.js index 4de07f186a3..38d1b2fcc35 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_searching.js +++ b/toolkit/mozapps/extensions/test/browser/browser_searching.js @@ -335,8 +335,10 @@ function check_results(aQuery, aSortBy, aReverseOrder, aShowLocal) { * How the results are sorted (e.g. "name") * @param aReverseOrder * Boolean representing if the results are in reverse default order + * @param aLocalOnly + * Boolean representing if the results are local only, can be undefined */ -function check_filtered_results(aQuery, aSortBy, aReverseOrder) { +function check_filtered_results(aQuery, aSortBy, aReverseOrder, aLocalOnly) { var localFilter = gManagerWindow.document.getElementById("search-filter-local"); var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); @@ -348,8 +350,9 @@ function check_filtered_results(aQuery, aSortBy, aReverseOrder) { check_results(aQuery, aSortBy, aReverseOrder, true); // Check with showing remote add-ons + aLocalOnly = aLocalOnly || false; EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); - check_results(aQuery, aSortBy, aReverseOrder, false); + check_results(aQuery, aSortBy, aReverseOrder, aLocalOnly); } /* @@ -647,3 +650,35 @@ add_test(function() { }); }); +function bug_815120_test_search(aLocalOnly) { + restart_manager(gManagerWindow, "addons://list/extension", function(aWindow) { + gManagerWindow = aWindow; + gCategoryUtilities = new CategoryUtilities(gManagerWindow); + + // Installed add-on is considered local on new search + gAddonInstalled = true; + + // Check the search setup + if (aLocalOnly) { + var localFilterSelected = aWindow.document.getElementById("search-filter-local").selected; + ok(localFilterSelected, "Local filter should be selected if remote plugin installation is disabled"); + } + var remoteFilterButton = aWindow.document.getElementById("search-filter-remote"); + is(aLocalOnly, is_hidden(remoteFilterButton), "Remote filter button visibility does not match, aLocalOnly = " + aLocalOnly); + + search(QUERY, false, function() { + check_filtered_results(QUERY, "relevancescore", false, aLocalOnly); + run_next_test(); + }); + }); +} + +// Tests for Bug 815120 +add_test(function() { + Services.prefs.setBoolPref(PREF_XPI_ENABLED, false); + bug_815120_test_search(true); +}); +add_test(function() { + Services.prefs.setBoolPref(PREF_XPI_ENABLED, true); + bug_815120_test_search(false); +});