Bug 575561 - External links from within app tabs should always open in new tabs instead of replacing the app tab's page (Tests). r=gavin, a=blocking-beta7
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Thu, 28 Oct 2010 15:00:50 -0700
changeset 56686 91a749304ec9577cb86978ac19a2cf65f2f7cb25
parent 56685 b642534688f81ecb743869afed185a7c000fa356
child 56687 ef7f187f649c0b81cf9b508ba20a580d8f8ddcb0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin, blocking-beta7
bugs575561
milestone2.0b8pre
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 575561 - External links from within app tabs should always open in new tabs instead of replacing the app tab's page (Tests). r=gavin, a=blocking-beta7
browser/base/content/test/Makefile.in
browser/base/content/test/app_bug575561.html
browser/base/content/test/app_subframe_bug575561.html
browser/base/content/test/browser_bug575561.js
toolkit/content/tests/browser/browser_Services.js
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -140,16 +140,17 @@ endif
                  browser_bug555224.js \
                  browser_bug555767.js \
                  browser_bug556061.js \
                  browser_bug559991.js \
                  browser_bug561623.js \
                  browser_bug561636.js \
                  browser_bug562649.js \
                  browser_bug563588.js \
+                 browser_bug575561.js \
                  browser_bug577121.js \
                  browser_bug579872.js \
                  browser_bug580956.js \
                  browser_bug581242.js \
                  browser_bug581253.js \
                  browser_bug581947.js \
                  browser_bug585785.js \
                  browser_bug585830.js \
@@ -213,16 +214,18 @@ endif
                  alltabslistener.html \
                  zoom_test.html \
                  dummy_page.html \
                  browser_tabMatchesInAwesomebar.js \
                  file_bug550565_popup.html \
                  file_bug550565_favicon.ico \
                  browser_overLinkInLocationBar.js \
                  browser_aboutHome.js \
+                 app_bug575561.html \
+                 app_subframe_bug575561.html \
                  $(NULL)
 
 # compartment-disabled
 #                 browser_popupUI.js \
 #                 browser_tab_dragdrop.js \
 
 ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 _BROWSER_FILES += \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/app_bug575561.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=575561
+-->
+  <head>
+    <title>Test for links in app tabs</title>
+  </head>
+  <body>
+    <a href="http://example.com/browser/browser/base/content/test/dummy_page.html">same domain</a>
+    <a href="http://test1.example.com/browser/browser/base/content/test/dummy_page.html">same domain (different subdomain)</a>
+    <a href="http://example.org/browser/browser/base/content/test/dummy_page.html">different domain</a>
+    <a href="http://example.org/browser/browser/base/content/test/dummy_page.html" target="foo">different domain (with target)</a>
+    <iframe src="app_subframe_bug575561.html"></iframe>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/app_subframe_bug575561.html
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=575561
+-->
+  <head>
+    <title>Test for links in app tab subframes</title>
+  </head>
+  <body>
+    <a href="http://example.org/browser/browser/base/content/test/dummy_page.html">different domain</a>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug575561.js
@@ -0,0 +1,77 @@
+function test() {
+  waitForExplicitFinish();
+
+  // Pinned: Link to the same domain should not open a new tab
+  // Tests link to http://example.com/browser/browser/base/content/test/dummy_page.html  
+  testLink(0, true, false, function() {
+    // Pinned: Link to the same domain should not open a new tab
+    // Tests link to http://test1.example.com/browser/browser/base/content/test/dummy_page.html
+    testLink(1, true, false, function() {
+      // Pinned: Link to a different domain should open a new tab
+      // Tests link to http://example.org/browser/browser/base/content/test/dummy_page.html
+      testLink(2, true, true, function() {
+        // Not Pinned: Link to a different domain should not open a new tab
+        // Tests link to http://example.org/browser/browser/base/content/test/dummy_page.html
+        testLink(2, false, false, function() {
+          // Pinned: Targetted link should open a new tab
+          // Tests link to http://example.org/browser/browser/base/content/test/dummy_page.html with target="foo"
+          testLink(3, true, true, function() {
+            // Pinned: Link in a subframe should not open a new tab
+            // Tests link to http://example.org/browser/browser/base/content/test/dummy_page.html in subframe
+            testLink(0, true, false, finish, true);
+          });
+        });
+      });
+    });
+  });
+}
+
+function testLink(aLinkIndex, pinTab, expectNewTab, nextTest, testSubFrame) {
+  let appTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/app_bug575561.html", {skipAnimation: true});
+  if (pinTab)
+    gBrowser.pinTab(appTab);
+  gBrowser.selectedTab = appTab;
+  appTab.linkedBrowser.addEventListener("load", onLoad, true);
+
+  let loadCount = 0;
+  function onLoad() {
+    loadCount++;
+    if (loadCount < 2)
+      return;
+
+    appTab.linkedBrowser.removeEventListener("load", onLoad, true);
+
+    let browser = gBrowser.getBrowserForTab(appTab);
+    if (testSubFrame)
+      browser = browser.contentDocument.getElementsByTagName("iframe")[0];
+
+    let links = browser.contentDocument.getElementsByTagName("a");
+
+    if (expectNewTab)
+      gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
+    else
+      browser.addEventListener("load", onPageLoad, true);
+
+    info("Clicking " + links[aLinkIndex].textContent);
+    EventUtils.sendMouseEvent({type:"click"}, links[aLinkIndex], browser.contentWindow);
+
+    function onPageLoad() {
+      browser.removeEventListener("load", onPageLoad, true);
+      is(browser.contentDocument.location.href, links[aLinkIndex].href, "Link should not open in a new tab");
+      executeSoon(function(){
+        gBrowser.removeTab(appTab);
+        nextTest();
+      });
+    }
+
+    function onTabOpen(event) {
+      gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
+      ok(true, "Link should open a new tab");
+      executeSoon(function(){
+        gBrowser.removeTab(appTab);
+        gBrowser.removeCurrentTab();
+        nextTest();
+      });
+    }
+  }
+}
--- a/toolkit/content/tests/browser/browser_Services.js
+++ b/toolkit/content/tests/browser/browser_Services.js
@@ -45,27 +45,30 @@ function checkService(service, interface
   ok(Services[service] instanceof interface, "Services." + service + " is an " + interface);
 }
 
 function checkServices() {
   checkService("prefs", Ci.nsIPrefBranch2);
   checkService("prefs", Ci.nsIPrefService);
   checkService("contentPrefs", Ci.nsIContentPrefService);
   checkService("wm", Ci.nsIWindowMediator);
+  checkService("obs", Ci.nsIObserverService);
   checkService("perms", Ci.nsIPermissionManager);
   checkService("io", Ci.nsIIOService);
   checkService("io", Ci.nsIIOService2);
   checkService("appinfo", Ci.nsIXULAppInfo);
   checkService("appinfo", Ci.nsIXULRuntime);
   checkService("dirsvc", Ci.nsIDirectoryService);
   checkService("dirsvc", Ci.nsIProperties);
   checkService("prompt", Ci.nsIPromptService);
   if ("nsIBrowserSearchService" in Ci)
     checkService("search", Ci.nsIBrowserSearchService);
   checkService("storage", Ci.mozIStorageService);
   checkService("vc", Ci.nsIVersionComparator);
   checkService("locale", Ci.nsILocaleService);
   checkService("scriptloader", Ci.mozIJSSubScriptLoader);
   checkService("ww", Ci.nsIWindowWatcher);
   checkService("tm", Ci.nsIThreadManager);
+  checkService("droppedLinkHandler", Ci.nsIDroppedLinkHandler);
   checkService("strings", Ci.nsIStringBundleService);
   checkService("urlFormatter", Ci.nsIURLFormatter);
+  checkService("eTLD", Ci.nsIEffectiveTLDService);
 }