Bug 1273719 - Allow chrome/resource icon URLs for built-in search engines. r=florian

This commit is contained in:
Michael Kaply 2016-06-09 11:02:05 -05:00
parent 170631fab0
commit 7b28bcdb63
7 changed files with 86 additions and 0 deletions

View File

@ -1777,6 +1777,13 @@ Engine.prototype = {
+ this.name + "\".");
// Only accept remote icons from http[s] or ftp
switch (uri.scheme) {
case "resource":
case "chrome":
// We only allow chrome and resource icon URLs for built-in search engines
if (!this._isDefault) {
return;
}
// Fall through to the data case
case "data":
if (!this._hasPreferredIcon || aIsPreferred) {
this._iconURI = uri;

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>engine-chromeicon</ShortName>
<Image width="16" height="16">chrome://branding/content/icon16.png</Image>
<Image width="32" height="32">chrome://branding/content/icon32.png</Image>
<Url type="text/html" method="GET" template="http://www.google.com/search">
<Param name="q" value="{searchTerms}"/>
</Url>
</SearchPlugin>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>engine-resourceicon</ShortName>
<Image width="16" height="16">resource://search-plugins/icon16.png</Image>
<Image width="32" height="32">resource://search-plugins/icon32.png</Image>
<Url type="text/html" method="GET" template="http://www.google.com/search">
<Param name="q" value="{searchTerms}"/>
</Url>
</SearchPlugin>

View File

@ -2,3 +2,5 @@ engine
engine-pref
engine-rel-searchform-purpose
engine-system-purpose
engine-chromeicon
engine-resourceicon

View File

@ -0,0 +1,31 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* Test that resource URLs can be used in default engines */
"use strict";
function run_test() {
updateAppInfo();
// The test engines used in this test need to be recognized as 'default'
// engines or the resource URL won't be used
let url = "resource://test/data/";
let resProt = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);
resProt.setSubstitution("search-plugins",
Services.io.newURI(url, null, null));
run_next_test();
}
add_task(function* test_defaultresourceicon() {
yield asyncInit();
let engine1 = Services.search.getEngineByName("engine-resourceicon");
do_check_eq(engine1.iconURI.spec, "resource://search-plugins/icon16.png");
do_check_eq(engine1.getIconURLBySize(32,32), "resource://search-plugins/icon32.png");
let engine2 = Services.search.getEngineByName("engine-chromeicon");
do_check_eq(engine2.iconURI.spec, "chrome://branding/content/icon16.png");
do_check_eq(engine2.getIconURLBySize(32,32), "chrome://branding/content/icon32.png");
});

View File

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* Test that an installed engine can't use a resource URL for an icon */
"use strict";
function run_test() {
removeMetadata();
updateAppInfo();
useHttpServer();
run_next_test();
}
add_task(function* test_installedresourceicon() {
let [engine1, engine2] = yield addTestEngines([
{ name: "engine-resourceicon", xmlFileName: "engine-resourceicon.xml" },
{ name: "engine-chromeicon", xmlFileName: "engine-chromeicon.xml" },
]);
do_check_null(engine1.iconURI);
do_check_null(engine2.iconURI);
});

View File

@ -19,6 +19,8 @@ support-files =
data/engine-system-purpose.xml
data/engine-update.xml
data/engineImages.xml
data/engine-chromeicon.xml
data/engine-resourceicon.xml
data/ico-size-16x16-png.ico
data/invalid-engine.xml
data/install.rdf
@ -96,3 +98,6 @@ tags = addons
[test_svg_icon.js]
[test_searchReset.js]
[test_addEngineWithDetails.js]
[test_chromeresource_icon1.js]
[test_chromeresource_icon2.js]