Bug 1263032 turn on pocket addon during tests, r=markh
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 08 Apr 2016 08:06:46 -0700
changeset 349000 1e17a83bd0d7767cdf89eb11a78ef572d6c427bf
parent 348999 1ea84d818c7d58b4bde2766fa9f6e64818d6822d
child 349001 f20a435525b777b6963ce20333311216e0523bf7
push id14989
push userdtownsend@mozilla.com
push dateFri, 08 Apr 2016 20:09:09 +0000
reviewersmarkh
bugs1263032
milestone48.0a1
Bug 1263032 turn on pocket addon during tests, r=markh
browser/base/content/test/general/browser_contextmenu.js
browser/base/content/test/general/browser_contextmenu_input.js
browser/base/content/test/general/contextmenu_common.js
browser/extensions/pocket/bootstrap.js
browser/extensions/pocket/test/browser_pocket_ui_check.js
testing/profiles/prefs_general.js
--- a/browser/base/content/test/general/browser_contextmenu.js
+++ b/browser/base/content/test/general/browser_contextmenu.js
@@ -6,16 +6,18 @@ let LOGIN_FILL_ITEMS = [
   "fill-login", null,
     [
       "fill-login-no-logins", false,
       "---", null,
       "fill-login-saved-passwords", true
     ], null,
 ];
 
+let hasPocket = Services.prefs.getBoolPref("extensions.pocket.enabled");
+
 add_task(function* test_setup() {
   const example_base = "http://example.com/browser/browser/base/content/test/general/";
   const url = example_base + "subtst_contextmenu.html";
   yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
 
   const chrome_base = "chrome://mochitests/content/browser/browser/base/content/test/general/";
   const contextmenu_common = chrome_base + "contextmenu_common.js";
   Services.scriptloader.loadSubScript(contextmenu_common, this);
@@ -33,16 +35,17 @@ let plainTextItems;
 add_task(function* test_plaintext() {
   plainTextItems = ["context-navigation",   null,
                         ["context-back",         false,
                          "context-forward",      false,
                          "context-reload",       true,
                          "context-bookmarkpage", true], null,
                     "---",                  null,
                     "context-savepage",     true,
+                    ...(hasPocket ? ["context-pocket", true] : []),
                     "---",                  null,
                     "context-viewbgimage",  false,
                     "context-selectall",    true,
                     "---",                  null,
                     "context-viewsource",   true,
                     "context-viewinfo",     true
                    ];
   yield test_contextmenu("#test-text", plainTextItems);
@@ -51,16 +54,17 @@ add_task(function* test_plaintext() {
 add_task(function* test_link() {
   yield test_contextmenu("#test-link",
     ["context-openlinkintab", true,
      "context-openlink",      true,
      "context-openlinkprivate", true,
      "---",                   null,
      "context-bookmarklink",  true,
      "context-savelink",      true,
+     ...(hasPocket ? ["context-savelinktopocket", true] : []),
      "context-copylink",      true,
      "context-searchselect",  true
     ]
   );
 });
 
 add_task(function* test_mailto() {
   yield test_contextmenu("#test-mailto",
@@ -191,16 +195,17 @@ add_task(function* test_iframe() {
   yield test_contextmenu("#test-iframe",
     ["context-navigation", null,
          ["context-back",         false,
           "context-forward",      false,
           "context-reload",       true,
           "context-bookmarkpage", true], null,
      "---",                  null,
      "context-savepage",     true,
+     ...(hasPocket ? ["context-pocket", true] : []),
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "frame",                null,
          ["context-showonlythisframe", true,
           "context-openframeintab",    true,
           "context-openframe",         true,
           "---",                       null,
@@ -455,16 +460,17 @@ add_task(function* test_pagemenu() {
      "generated-submenu-1",  true,
          ["+Radio1",             {type: "checkbox", icon: "", checked: false, disabled: false},
           "+Radio2",             {type: "checkbox", icon: "", checked: true, disabled: false},
           "+Radio3",             {type: "checkbox", icon: "", checked: false, disabled: false},
           "---",                 null,
           "+Checkbox",           {type: "checkbox", icon: "", checked: false, disabled: false}], null,
      "---",                  null,
      "context-savepage",     true,
+     ...(hasPocket ? ["context-pocket", true] : []),
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "---",                  null,
      "context-viewsource",   true,
      "context-viewinfo",     true
     ],
     {postCheckContextMenuFn: function*() {
@@ -485,16 +491,17 @@ add_task(function* test_dom_full_screen(
          ["context-back",            false,
           "context-forward",         false,
           "context-reload",          true,
           "context-bookmarkpage",    true], null,
      "---",                          null,
      "context-leave-dom-fullscreen", true,
      "---",                          null,
      "context-savepage",             true,
+     ...(hasPocket ? ["context-pocket", true] : []),
      "---",                          null,
      "context-viewbgimage",          false,
      "context-selectall",            true,
      "---",                          null,
      "context-viewsource",           true,
      "context-viewinfo",             true
     ],
     {
@@ -530,16 +537,17 @@ add_task(function* test_pagemenu2() {
   yield test_contextmenu("#test-text",
     ["context-navigation", null,
          ["context-back",         false,
           "context-forward",      false,
           "context-reload",       true,
           "context-bookmarkpage", true], null,
      "---",                  null,
      "context-savepage",     true,
+     ...(hasPocket ? ["context-pocket", true] : []),
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "---",                  null,
      "context-viewsource",   true,
      "context-viewinfo",     true
     ],
     {shiftkey: true}
@@ -598,16 +606,17 @@ add_task(function* test_select_text_link
 add_task(function* test_imagelink() {
   yield test_contextmenu("#test-image-link",
     ["context-openlinkintab", true,
      "context-openlink",      true,
      "context-openlinkprivate", true,
      "---",                   null,
      "context-bookmarklink",  true,
      "context-savelink",      true,
+     ...(hasPocket ? ["context-savelinktopocket", true] : []),
      "context-copylink",      true,
      "---",                   null,
      "context-viewimage",            true,
      "context-copyimage-contents",   true,
      "context-copyimage",            true,
      "---",                          null,
      "context-saveimage",            true,
      "context-sendimage",            true,
@@ -696,16 +705,17 @@ add_task(function* test_click_to_play_bl
           "context-forward",      false,
           "context-reload",       true,
           "context-bookmarkpage", true], null,
      "---",                  null,
      "context-ctp-play",     true,
      "context-ctp-hide",     true,
      "---",                  null,
      "context-savepage",     true,
+     ...(hasPocket ? ["context-pocket", true] : []),
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "---",                  null,
      "context-viewsource",   true,
      "context-viewinfo",     true
     ],
     {
@@ -739,16 +749,17 @@ add_task(function* test_srcdoc() {
   yield test_contextmenu("#test-srcdoc",
     ["context-navigation", null,
          ["context-back",         false,
           "context-forward",      false,
           "context-reload",       true,
           "context-bookmarkpage", true], null,
      "---",                  null,
      "context-savepage",     true,
+     ...(hasPocket ? ["context-pocket", true] : []),
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "frame",                null,
          ["context-reloadframe",       true,
           "---",                       null,
           "context-saveframe",         true,
           "---",                       null,
--- a/browser/base/content/test/general/browser_contextmenu_input.js
+++ b/browser/base/content/test/general/browser_contextmenu_input.js
@@ -1,11 +1,13 @@
 "use strict";
 
 let contextMenu;
+let hasPocket = Services.prefs.getBoolPref("extensions.pocket.enabled");
+
 add_task(function* test_setup() {
   const example_base = "http://example.com/browser/browser/base/content/test/general/";
   const url = example_base + "subtst_contextmenu_input.html";
   yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
 
   const chrome_base = "chrome://mochitests/content/browser/browser/base/content/test/general/";
   const contextmenu_common = chrome_base + "contextmenu_common.js";
   Services.scriptloader.loadSubScript(contextmenu_common, this);
@@ -182,16 +184,17 @@ add_task(function* test_date_time_color_
     yield test_contextmenu(selector,
       ["context-navigation", null,
            ["context-back",         false,
             "context-forward",      false,
             "context-reload",       true,
             "context-bookmarkpage", true], null,
        "---",                  null,
        "context-savepage",     true,
+       ...(hasPocket ? ["context-pocket", true] : []),
        "---",                  null,
        "context-viewbgimage",  false,
        "context-selectall",    null,
        "---",                  null,
        "context-viewsource",   true,
        "context-viewinfo",     true],
       {skipFocusChange: true}
     );
--- a/browser/base/content/test/general/contextmenu_common.js
+++ b/browser/base/content/test/general/contextmenu_common.js
@@ -57,16 +57,17 @@ function getVisibleMenuItems(aMenu, aDat
             if (isSpellSuggestion) {
               is(key, "", "Spell suggestions shouldn't have an access key");
               items.push("*" + label);
             } else if (isGenerated) {
               items.push("+" + label);
             } else if (item.id.indexOf("spell-check-dictionary-") != 0 &&
                        item.id != "spell-no-suggestions" &&
                        item.id != "spell-add-dictionaries-main" &&
+                       item.id != "context-savelinktopocket" &&
                        item.id != "fill-login-saved-passwords" &&
                        item.id != "fill-login-no-logins") {
               ok(key, "menuitem " + item.id + " has an access key");
               if (accessKeys[key])
                   ok(false, "menuitem " + item.id + " has same accesskey as " + accessKeys[key]);
               else
                   accessKeys[key] = item.id;
             }
--- a/browser/extensions/pocket/bootstrap.js
+++ b/browser/extensions/pocket/bootstrap.js
@@ -268,17 +268,17 @@ var PocketContextMenu = {
     menu = document.getElementById("context-savelinktopocket");
     if (!menu) {
       menu = createElementWithAttrs(document, "menuitem", {
         "id": "context-savelinktopocket",
         "label": gPocketBundle.GetStringFromName("saveLinkToPocketCmd.label"),
         "accesskey": gPocketBundle.GetStringFromName("saveLinkToPocketCmd.accesskey"),
         "oncommand": "Pocket.savePage(gContextMenu.browser, gContextMenu.linkURL);"
       });
-      sibling = document.getElementById("context-savelink");
+      let sibling = document.getElementById("context-savelink");
       if (sibling.nextSibling) {
         sibling.parentNode.insertBefore(menu, sibling.nextSibling);
       } else {
         sibling.parentNode.appendChild(menu);
       }
     }
     menu.hidden = !showSaveLinkToPocket;
   }
@@ -355,16 +355,17 @@ var PocketReader = {
 }
 
 
 function pktUIGetter(prop, window) {
   return {
     get: function() {
       // delete any getters for properties loaded from main.js so we only load main.js once
       delete window.pktUI;
+      delete window.pktApi;
       delete window.pktUIMessaging;
       Services.scriptloader.loadSubScript("chrome://pocket/content/main.js", window);
       return window[prop];
     },
     configurable: true,
     enumerable: true
   };
 }
@@ -397,16 +398,17 @@ var PocketOverlay = {
                       "BMB_pocketSeparator"]) {
         let element = window.document.getElementById(id);
         if (element)
           element.remove();
       }
       this.removeStyles(window);
       // remove script getters/objects
       delete window.Pocket;
+      delete window.pktApi;
       delete window.pktUI;
       delete window.pktUIMessaging;
     }
     CustomizableUI.destroyWidget("pocket-button");
     PocketContextMenu.shutdown();
     PocketReader.shutdown();
   },
   onWindowOpened: function(window) {
@@ -416,16 +418,17 @@ var PocketOverlay = {
     this.addStyles(window);
     this.updateWindow(window);
   },
   setWindowScripts: function(window) {
     XPCOMUtils.defineLazyModuleGetter(window, "Pocket",
                                       "chrome://pocket/content/Pocket.jsm");
     // Can't use XPCOMUtils for these because the scripts try to define the variables
     // on window, and so the defineProperty inside defineLazyGetter fails.
+    Object.defineProperty(window, "pktApi", pktUIGetter("pktApi", window));
     Object.defineProperty(window, "pktUI", pktUIGetter("pktUI", window));
     Object.defineProperty(window, "pktUIMessaging", pktUIGetter("pktUIMessaging", window));
   },
   // called for each window as it is opened
   updateWindow: function(window) {
     // insert our three menu items
     let document = window.document;
     let hidden = !CustomizableUI.getPlacementOfWidget("pocket-button");
--- a/browser/extensions/pocket/test/browser_pocket_ui_check.js
+++ b/browser/extensions/pocket/test/browser_pocket_ui_check.js
@@ -6,23 +6,30 @@ function checkWindowProperties(expectPre
   }
 }
 function checkElements(expectPresent, l) {
   for (let id of l) {
     is(!!document.getElementById(id), expectPresent, "element " + id + (expectPresent ? " is" : " is not") + " present");
   }
 }
 
-add_task(function*() {
-  let enabledOnStartup = yield promisePocketEnabled();
+add_task(function* test_setup() {
+  let clearValue = Services.prefs.prefHasUserValue("extensions.pocket.enabled");
+  let enabledOnStartup = Services.prefs.getBoolPref("extensions.pocket.enabled");
   registerCleanupFunction(() => {
-    // Extra insurance that this is disabled again, but it should have been set
-    // in promisePocketReset.
-    Services.prefs.setBoolPref("extensions.pocket.enabled", enabledOnStartup);
+    if (clearValue) {
+      Services.prefs.clearUserPref("extensions.pocket.enabled");
+    } else {
+      Services.prefs.setBoolPref("extensions.pocket.enabled", enabledOnStartup);
+    }
   });
+});
+
+add_task(function*() {
+  yield promisePocketEnabled();
 
   checkWindowProperties(true, ["Pocket", "pktUI", "pktUIMessaging"]);
   checkElements(true, ["pocket-button", "panelMenu_pocket", "menu_pocket", "BMB_pocket",
                        "panelMenu_pocketSeparator", "menu_pocketSeparator",
                        "BMB_pocketSeparator"]);
 
   // check context menu exists
   info("checking content context menu");
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -93,18 +93,16 @@ user_pref("extensions.update.url", "http
 user_pref("extensions.update.background.url", "http://%(server)s/extensions-dummy/updateBackgroundURL");
 user_pref("extensions.blocklist.detailsURL", "http://%(server)s/extensions-dummy/blocklistDetailsURL");
 user_pref("extensions.blocklist.itemURL", "http://%(server)s/extensions-dummy/blocklistItemURL");
 user_pref("extensions.blocklist.url", "http://%(server)s/extensions-dummy/blocklistURL");
 user_pref("extensions.hotfix.url", "http://%(server)s/extensions-dummy/hotfixURL");
 user_pref("extensions.systemAddon.update.url", "http://%(server)s/dummy-system-addons.xml");
 // Turn off extension updates so they don't bother tests
 user_pref("extensions.update.enabled", false);
-// Bug 1235627 Turn off pocket add-on so it doesn't bother tests
-user_pref("extensions.pocket.enabled", false);
 // Make sure opening about:addons won't hit the network
 user_pref("extensions.webservice.discoverURL", "http://%(server)s/extensions-dummy/discoveryURL");
 // Make sure AddonRepository won't hit the network
 user_pref("extensions.getAddons.maxResults", 0);
 user_pref("extensions.getAddons.get.url", "http://%(server)s/extensions-dummy/repositoryGetURL");
 user_pref("extensions.getAddons.getWithPerformance.url", "http://%(server)s/extensions-dummy/repositoryGetWithPerformanceURL");
 user_pref("extensions.getAddons.search.browseURL", "http://%(server)s/extensions-dummy/repositoryBrowseURL");
 user_pref("extensions.getAddons.search.url", "http://%(server)s/extensions-dummy/repositorySearchURL");