Bug 1267346 - Implement chrome.PageAction.hide on Android r?kmag draft
authorMatthew Wein <mwein@mozilla.com>
Fri, 13 May 2016 15:52:24 -0700
changeset 367554 5ab63d2df7828be4f5eb41c288efb80a91919da5
parent 367552 ccc23c5390aeebab035a0fdd9bc1de318e7201aa
child 521036 45a3942a93910719a4ff04921745d434dfa989f4
push id18268
push usermwein@mozilla.com
push dateMon, 16 May 2016 20:58:57 +0000
reviewerskmag
bugs1267346
milestone49.0a1
Bug 1267346 - Implement chrome.PageAction.hide on Android r?kmag MozReview-Commit-ID: Isxgovo3Txb
mobile/android/components/extensions/ext-pageAction.js
mobile/android/components/extensions/extension.svg
mobile/android/components/extensions/jar.mn
mobile/android/components/extensions/schemas/page_action.json
mobile/android/components/extensions/test/mochitest/test_ext_pageAction.html
--- a/mobile/android/components/extensions/ext-pageAction.js
+++ b/mobile/android/components/extensions/ext-pageAction.js
@@ -38,22 +38,26 @@ function PageAction(options, extension) 
 PageAction.prototype = {
   show(tabId) {
     // TODO: Only show the PageAction for the tab with the provided tabId.
     if (!this.id) {
       this.id = PageActions.add(this.options);
     }
   },
 
-  shutdown() {
+  hide(tabId) {
     if (this.id) {
       PageActions.remove(this.id);
       this.id = null;
     }
   },
+
+  shutdown() {
+    this.hide();
+  },
 };
 
 /* eslint-disable mozilla/balanced-listeners */
 extensions.on("manifest_page_action", (type, directive, extension, manifest) => {
   let pageAction = new PageAction(manifest.page_action, extension);
   pageActionMap.set(extension, pageAction);
 });
 
@@ -76,11 +80,14 @@ extensions.registerSchemaAPI("pageAction
         return () => {
           pageActionMap.get(extension).off("click", listener);
         };
       }).api(),
 
       show(tabId) {
         pageActionMap.get(extension).show(tabId);
       },
+      hide(tabId) {
+        pageActionMap.get(extension).hide(tabId);
+      },
     },
   };
 });
deleted file mode 100644
--- a/mobile/android/components/extensions/extension.svg
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
-     width="64" height="64" viewBox="0 0 64 64">
-  <defs>
-    <style>
-      .style-puzzle-piece {
-        fill: url('#gradient-linear-puzzle-piece');
-      }
-    </style>
-    <linearGradient id="gradient-linear-puzzle-piece" x1="0%" y1="0%" x2="0%" y2="100%">
-      <stop offset="0%" stop-color="#66cc52" stop-opacity="1"/>
-      <stop offset="100%" stop-color="#60bf4c" stop-opacity="1"/>
-    </linearGradient>
-  </defs>
-  <path class="style-puzzle-piece" d="M42,62c2.2,0,4-1.8,4-4l0-14.2c0,0,0.4-3.7,2.8-3.7c2.4,0,2.2,3.9,6.7,3.9c2.3,0,6.2-1.2,6.2-8.2 c0-7-3.9-7.9-6.2-7.9c-4.5,0-4.3,3.7-6.7,3.7c-2.4,0-2.8-3.8-2.8-3.8V22c0-2.2-1.8-4-4-4H31.5c0,0-3.4-0.6-3.4-3 c0-2.4,3.8-2.6,3.8-7.1c0-2.3-1.3-5.9-8.3-5.9s-8,3.6-8,5.9c0,4.5,3.4,4.7,3.4,7.1c0,2.4-3.4,3-3.4,3H6c-2.2,0-4,1.8-4,4l0,7.8 c0,0-0.4,6,4.4,6c3.1,0,3.2-4.1,7.3-4.1c2,0,4,1.9,4,6c0,4.2-2,6.3-4,6.3c-4,0-4.2-4.1-7.3-4.1c-4.8,0-4.4,5.8-4.4,5.8L2,58 c0,2.2,1.8,4,4,4H19c0,0,6.3,0.4,6.3-4.4c0-3.1-4-3.6-4-7.7c0-2,2.2-4.5,6.4-4.5c4.2,0,6.6,2.5,6.6,4.5c0,4-3.9,4.6-3.9,7.7 c0,4.9,6.3,4.4,6.3,4.4H42z"/>
-</svg>
--- a/mobile/android/components/extensions/jar.mn
+++ b/mobile/android/components/extensions/jar.mn
@@ -1,7 +1,6 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 chrome.jar:
-    content/extension.svg
     content/ext-pageAction.js
\ No newline at end of file
--- a/mobile/android/components/extensions/schemas/page_action.json
+++ b/mobile/android/components/extensions/schemas/page_action.json
@@ -59,17 +59,16 @@
         "type": "function",
         "description": "Shows the page action. The page action is shown whenever the tab is selected.",
         "parameters": [
           {"type": "integer", "name": "tabId", "minimum": 0, "description": "The id of the tab for which you want to modify the page action."}
         ]
       },
       {
         "name": "hide",
-        "unsupported": true,
         "type": "function",
         "description": "Hides the page action.",
         "parameters": [
           {"type": "integer", "name": "tabId", "minimum": 0, "description": "The id of the tab for which you want to modify the page action."}
         ]
       },
       {
         "name": "setTitle",
--- a/mobile/android/components/extensions/test/mochitest/test_ext_pageAction.html
+++ b/mobile/android/components/extensions/test/mochitest/test_ext_pageAction.html
@@ -14,45 +14,63 @@
 "use strict";
 
 function backgroundScript() {
   browser.test.assertTrue("pageAction" in browser, "Namespace 'pageAction' exists in browser");
   browser.test.assertTrue("show" in browser.pageAction, "API method 'show' exists in browser.pageAction");
 
   // TODO: Use the Tabs API to obtain the tab ids for showing pageActions.
   let tabId = 1;
-
-  browser.pageAction.show(tabId);
-  browser.test.sendMessage("page-action-shown");
+  browser.test.onMessage.addListener(msg => {
+    if (msg === "pageAction-show") {
+      browser.pageAction.show(tabId);
+      browser.test.sendMessage("page-action-shown");
+    } else if (msg === "pageAction-hide") {
+      browser.pageAction.hide(tabId);
+      browser.test.sendMessage("page-action-hidden");
+    }
+  });
 
   browser.pageAction.onClicked.addListener(tab => {
-    // TODO: Make sure we get the correct tab once the tabs API is supported.
-    browser.test.notifyPass("pageAction-clicked");
+    // TODO: Make sure we get the correct tab once basic tabs support is added.
+    browser.test.sendMessage("page-action-clicked");
   });
+
+  browser.test.sendMessage("ready");
 }
 
 add_task(function* test_contentscript() {
   let extension = ExtensionTestUtils.loadExtension({
     background: "(" + backgroundScript.toString() + ")()",
     manifest: {
       "name": "PageAction Extension",
       "page_action": {
         "default_title": "Page Action",
       },
     },
   });
 
   yield extension.startup();
+  yield extension.awaitMessage("ready");
+
+  extension.sendMessage("pageAction-show");
   yield extension.awaitMessage("page-action-shown");
+  ok(isPageActionShown(extension.id), "The PageAction should be shown");
 
-  is(isPageActionShown(extension.id), true, "The PageAction should be shown");
+  extension.sendMessage("pageAction-hide");
+  yield extension.awaitMessage("page-action-hidden");
+  ok(!isPageActionShown(extension.id), "The PageAction should be hidden");
+
+  extension.sendMessage("pageAction-show");
+  yield extension.awaitMessage("page-action-shown");
+  ok(isPageActionShown(extension.id), "The PageAction should be shown");
 
   clickPageAction(extension.id);
+  yield extension.awaitMessage("page-action-clicked");
+  ok(isPageActionShown(extension.id), "The PageAction should still be shown after being clicked");
 
-  yield extension.awaitFinish("pageAction-clicked");
   yield extension.unload();
-
-  is(isPageActionShown(extension.id), false, "The PageAction should be removed after unload");
+  ok(!isPageActionShown(extension.id), "The PageAction should be removed after unload");
 });
 </script>
 
 </body>
 </html>