Bug 513653 Fix switching to an existing tab when trying to open a content tab with the same url. Also fix correctly setting content-primary on a newly opened tab. r=asuth
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 01 Sep 2009 20:53:03 +0100
changeset 3482 014559d2105b491a9e47f691a0786d579df4fb49
parent 3481 33eddeb4cdea0581f89dc6e53009bfcbd426c685
child 3483 49795b7f767f41d824036347128de7dec8fef443
push idunknown
push userunknown
push dateunknown
reviewersasuth
bugs513653
Bug 513653 Fix switching to an existing tab when trying to open a content tab with the same url. Also fix correctly setting content-primary on a newly opened tab. r=asuth
mail/base/content/specialTabs.js
mail/test/mozmill/content-tabs/html/whatsnew.html
mail/test/mozmill/content-tabs/test-content-tab.js
mail/test/mozmill/mozmilltests.list
--- a/mail/base/content/specialTabs.js
+++ b/mail/base/content/specialTabs.js
@@ -83,55 +83,62 @@ var specialTabs = {
       // to re-use the same tab.
       let regEx = new RegExp("#.*");
 
       let contentUrl = aContentPage.replace(regEx, "");
 
       for (let selectedIndex = 0; selectedIndex < tabInfo.length;
            ++selectedIndex) {
         if (tabInfo[selectedIndex].mode.name == this.name &&
-            tabInfo[selectedIndex].browser
-                                  .getAttribute("src")
+            tabInfo[selectedIndex].browser.currentURI.spec
                                   .replace(regEx, "") == contentUrl) {
           // Ensure we go to the correct location on the page.
           tabInfo[selectedIndex].browser
                                 .setAttribute("src", aContentPage);
           return selectedIndex;
         }
       }
       return -1;
     },
-    openTab: function onTabOpened(aTab, {contentPage: aContentPage}) {
+    openTab: function onTabOpened(aTab, aArgs) {
+      if (!"contentPage" in aArgs)
+        throw("contentPage must be specified");
+
       // First clone the page and set up the basics.
       let clone = document.getElementById("contentTab").firstChild.cloneNode(true);
 
       clone.setAttribute("id", "contentTab" + this.lastBrowserId);
       clone.setAttribute("collapsed", false);
-      clone.setAttribute("type", "content-primary");
 
       aTab.panel.appendChild(clone);
 
       // Start setting up the browser.
       aTab.browser = aTab.panel.getElementsByTagName("browser")[0];
 
+      // As we're opening this tab, showTab may not get called, so set
+      // the type according to if we're opening in background or not.
+      let background = ("background" in aArgs) && aArgs.background;
+      aTab.browser.setAttribute("type", background ? "content-targetable" :
+                                                     "content-primary");
+
       aTab.browser.setAttribute("id", "contentTabBrowser" + this.lastBrowserId);
 
       // Now initialise the find bar.
       aTab.findbar = aTab.panel.getElementsByTagName("findbar")[0];
       aTab.findbar.setAttribute("browserid",
                                 "contentTabBrowser" + this.lastBrowserId);
 
       // Now set up the listeners.
       this._setUpTitleListener(aTab);
       this._setUpCloseWindowListener(aTab);
 
       // Now start loading the content.
       aTab.title = this.loadingTabString;
 
-      aTab.browser.loadURI(aContentPage);
+      aTab.browser.loadURI(aArgs.contentPage);
 
       this.lastBrowserId++;
     },
     closeTab: function onTabClosed(aTab) {
       aTab.browser.removeEventListener("DOMTitleChanged",
                                        aTab.titleListener, true);
       aTab.browser.removeEventListener("DOMWindowClose",
                                        aTab.closeListener, true);
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/content-tabs/html/whatsnew.html
@@ -0,0 +1,8 @@
+<html>
+  <head>
+    <title>What's New Content Test</title> 
+  </head>
+  <body bgcolor="#FFFFFF">
+    <h1>What's New Content Test</h1>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/content-tabs/test-content-tab.js
@@ -0,0 +1,115 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Messaging.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mark Banner <mark@standard8.plus.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var MODULE_NAME = 'test-content-tab';
+
+var RELATIVE_ROOT = '../shared-modules';
+var MODULE_REQUIRES = ['window-helpers'];
+
+var controller = {};
+Components.utils.import('resource://mozmill/modules/controller.js', controller)
+;
+var mozmill = {};
+Components.utils.import('resource://mozmill/modules/mozmill.js', mozmill);
+var elementslib = {};
+Components.utils.import('resource://mozmill/modules/elementslib.js', elementslib);
+
+var windowHelper;
+var mainController = null;
+var mc;
+
+// RELATIVE_ROOT messes with the collector, so we have to bring the path back
+// so we get the right path for the resources.
+var url = collector.addHttpResource('../content-tabs/html', 'content-tabs');
+
+var setupModule = function (module) {
+  windowHelper = collector.getModule('window-helpers');
+  mc = mainController = windowHelper.wait_for_existing_window("mail:3pane");
+  windowHelper.installInto(module);
+  windowHelper.augment_controller(mc);
+};
+
+function test_content_tab_open() {
+  let preCount = mc.tabmail.tabContainer.childNodes.length;
+  let whatsUrl = url + "whatsnew.html";
+
+  // Set the pref so that what's new opens a local url
+  Components.classes["@mozilla.org/preferences-service;1"]
+            .getService(Components.interfaces.nsIPrefBranch)
+            .setCharPref("mailnews.start_page.override_url",
+                         whatsUrl);
+
+  mc.click(new elementslib.Elem(mc.menus.helpMenu.whatsNew));
+
+  controller.sleep(0);
+  // XXX When bug 508999 is fixed, remove the sleep and use the waitForEval
+  // instead.
+  // controller.waitForEval("subject.busy == false", 1000, 100, newTab);
+  controller.sleep(400);
+
+  if (mc.tabmail.tabContainer.childNodes.length != preCount + 1)
+    throw new Error("The content tab didn't open");
+
+  if (mc.tabmail.selectedTab.title != "What's New Content Test")
+    throw new Error("The content tab has an incorrect title");
+
+  // Check that window.content is set up correctly wrt content-primary and
+  // content-targetable.
+  if (mc.window.content.location != whatsUrl)
+    throw new Error("window.content is not set to the url loaded, incorrect type=\"...\"?");
+}
+
+function test_content_tab_open_same() {
+  let preCount = mc.tabmail.tabContainer.childNodes.length;
+
+  mc.click(new elementslib.Elem(mc.menus.helpMenu.whatsNew));
+
+  controller.sleep(0);
+
+  if (mc.tabmail.tabContainer.childNodes.length != preCount)
+    throw new Error("A new content tab was opened when it shouldn't have been");
+
+  // Double-check browser is still the same.
+  if (mc.window.content.location != whatsUrl)
+    throw new Error("window.content is not set to the url loaded, incorrect type=\"...\"?");
+}
+
+// XXX todo
+// - Open second tab
+// - test find bar
+// - window.close within tab
+// - zoom?
--- a/mail/test/mozmill/mozmilltests.list
+++ b/mail/test/mozmill/mozmilltests.list
@@ -1,4 +1,5 @@
 folder-display
 junk-commands
 search-window
 content-policy
+content-tabs