Bug 1475347 - Cleanup search API - use camelCase and promise. r=aswan
authorMichael Kaply <mozilla@kaply.com>
Thu, 12 Jul 2018 15:55:25 -0500
changeset 426588 91cd5bee61ef
parent 426587 d2b1558a677c
child 426589 703da935b1e0
push id34276
push userncsoregi@mozilla.com
push date2018-07-14 09:41 +0000
treeherdermozilla-central@04dd259d71db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1475347
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1475347 - Cleanup search API - use camelCase and promise. r=aswan MozReview-Commit-ID: 2HJYk8irppL
browser/components/extensions/parent/ext-search.js
browser/components/extensions/schemas/search.json
browser/components/extensions/test/browser/browser_ext_search.js
--- a/browser/components/extensions/parent/ext-search.js
+++ b/browser/components/extensions/parent/ext-search.js
@@ -32,32 +32,32 @@ this.search = class extends ExtensionAPI
   getAPI(context) {
     return {
       search: {
         async get() {
           await searchInitialized;
           let engines = Services.search.getEngines();
           let visibleEngines = engines.filter(engine => !engine.hidden);
           return Promise.all(visibleEngines.map(async engine => {
-            let favicon_url = null;
+            let favIconUrl;
             if (engine.iconURI) {
               if (engine.iconURI.schemeIs("resource") ||
                   engine.iconURI.schemeIs("chrome")) {
                 // Convert internal URLs to data URLs
-                favicon_url = await getDataURI(engine.iconURI.spec);
+                favIconUrl = await getDataURI(engine.iconURI.spec);
               } else {
-                favicon_url = engine.iconURI.spec;
+                favIconUrl = engine.iconURI.spec;
               }
             }
 
             return {
               name: engine.name,
-              is_default: engine === Services.search.currentEngine,
-              alias: engine.alias,
-              favicon_url,
+              isDefault: engine === Services.search.currentEngine,
+              alias: engine.alias || undefined,
+              favIconUrl,
             };
           }));
         },
 
         async search(name, searchTerms, tabId) {
           await searchInitialized;
           let engine = Services.search.getEngineByName(name);
           if (!engine) {
--- a/browser/components/extensions/schemas/search.json
+++ b/browser/components/extensions/schemas/search.json
@@ -10,24 +10,24 @@
       {
         "id": "SearchEngine",
         "type": "object",
         "description": "An object encapsulating a search engine",
         "properties": {
           "name": {
             "type": "string"
           },
-          "is_default": {
+          "isDefault": {
             "type": "boolean"
           },
           "alias": {
             "type": "string",
             "optional": true
           },
-          "favicon_url": {
+          "favIconUrl": {
             "type": "string",
             "optional": true,
             "format": "url"
           }
         }
       }
     ],
     "functions": [
@@ -38,16 +38,17 @@
         "async": true,
         "parameters": []
       },
       {
         "name": "search",
         "type": "function",
         "requireUserInput": true,
         "description": "Perform a search.",
+        "async": true,
         "parameters": [
           {
             "name": "engineName",
             "type": "string"
           },
           {
             "name": "searchTerms",
             "type": "string"
--- a/browser/components/extensions/test/browser/browser_ext_search.js
+++ b/browser/components/extensions/test/browser/browser_ext_search.js
@@ -41,17 +41,17 @@ add_task(async function test_search() {
     background,
     useAddonManager: "temporary",
   });
   await extension.startup();
 
   let addonEngines = await extension.awaitMessage("engines");
   let engines = Services.search.getEngines().filter(engine => !engine.hidden);
   is(addonEngines.length, engines.length, "Engine lengths are the same.");
-  let defaultEngine = addonEngines.filter(engine => engine.is_default === true);
+  let defaultEngine = addonEngines.filter(engine => engine.isDefault === true);
   is(defaultEngine.length, 1, "One default engine");
   is(defaultEngine[0].name, Services.search.currentEngine.name, "Default engine is correct");
   await clickBrowserAction(extension);
   let url = await extension.awaitMessage("searchLoaded");
   is(url, SEARCH_URL.replace("{searchTerms}", SEARCH_TERM), "Loaded page matches search");
   await extension.unload();
 });