summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 10:07:11 +0000
committerdilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 10:07:11 +0000
commit07afd7c54e974e537fd094f0f4c41784ab5919b1 (patch)
tree84edcd71fedbfb4f19ca63c3c70fc144dfb08926
parent9ada3e8ddf24fad1f34d02527708de8f7f29083a (diff)
downloadchromium_src-07afd7c54e974e537fd094f0f4c41784ab5919b1.zip
chromium_src-07afd7c54e974e537fd094f0f4c41784ab5919b1.tar.gz
chromium_src-07afd7c54e974e537fd094f0f4c41784ab5919b1.tar.bz2
Enhance search for SINGLETON_TAB in case of ignore_path flag.
If we are ignoring path then it makes sense to ignore also a Query part. If there are several matches: prefer currently selected tab. BUG=chromium-os:11047 TEST=Manual Review URL: http://codereview.chromium.org/6489002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75245 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/browser_navigator.cc19
-rw-r--r--chrome/browser/ui/browser_navigator_browsertest.cc37
2 files changed, 47 insertions, 9 deletions
diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc
index bcd40cf..f009028 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -1,9 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/browser_navigator.h"
+#include <algorithm>
+
#include "base/command_line.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_url_handler.h"
@@ -82,21 +84,28 @@ int GetIndexOfSingletonTab(browser::NavigateParams* params) {
params->browser->profile(),
&reverse_on_redirect);
- for (int i = 0; i < params->browser->tab_count(); ++i) {
+ // If there are several matches: prefer currently selected tab. So we are
+ // starting our search at selected tab.
+ int start_index = std::max(0, params->browser->selected_index());
+ int tab_count = params->browser->tab_count();
+ for (int i = 0; i < tab_count; ++i) {
+ int tab_index = (start_index + i) % tab_count;
TabContentsWrapper* tab =
- params->browser->GetTabContentsWrapperAt(i);
+ params->browser->GetTabContentsWrapperAt(tab_index);
url_canon::Replacements<char> replacements;
replacements.ClearRef();
- if (params->ignore_path)
+ if (params->ignore_path) {
replacements.ClearPath();
+ replacements.ClearQuery();
+ }
if (CompareURLsWithReplacements(tab->tab_contents()->GetURL(),
params->url, replacements) ||
CompareURLsWithReplacements(tab->tab_contents()->GetURL(),
rewritten_url, replacements)) {
params->target_contents = tab;
- return i;
+ return tab_index;
}
}
diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc
index 53f613c..a9d153c 100644
--- a/chrome/browser/ui/browser_navigator_browsertest.cc
+++ b/chrome/browser/ui/browser_navigator_browsertest.cc
@@ -555,7 +555,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
-// and |ignore_paths| = true opens a new tab navigated to the specified URL if
+// and |ignore_path| = true opens a new tab navigated to the specified URL if
// no previous tab with that URL (minus the path) exists.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
Disposition_SingletonTabNew_IgnorePath) {
@@ -585,7 +585,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
-// and |ignore_paths| = true opens an existing tab with the matching URL (minus
+// and |ignore_path| = true opens an existing tab with the matching URL (minus
// the path) which is navigated to the specified URL.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
Disposition_SingletonTabExisting_IgnorePath) {
@@ -617,7 +617,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
-// and |ignore_paths| = true opens an existing tab with the matching URL (minus
+// and |ignore_path| = true opens an existing tab with the matching URL (minus
// the path) which is navigated to the specified URL.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
Disposition_SingletonTabExistingSubPath_IgnorePath) {
@@ -649,7 +649,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
-// and |ignore_paths| = true will update the current tab's URL if the currently
+// and |ignore_path| = true will update the current tab's URL if the currently
// selected tab is a match but has a different path.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
Disposition_SingletonTabFocused_IgnorePath) {
@@ -679,6 +679,35 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
browser()->GetSelectedTabContents()->GetURL());
}
+// This test verifies that constructing params with disposition = SINGLETON_TAB
+// and |ignore_path| = true will open an existing matching tab
+// with a different query.
+IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
+ Disposition_SingletonTabExisting_IgnoreQuery) {
+ int initial_tab_count = browser()->tab_count();
+ GURL singleton_url_current("chrome://settings/internet");
+ browser()->AddSelectedTabWithURL(singleton_url_current, PageTransition::LINK);
+
+ EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
+ EXPECT_EQ(initial_tab_count, browser()->selected_index());
+
+ // Navigate to a different settings path.
+ GURL singleton_url_target(
+ "chrome://settings/internet?"
+ "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
+ browser::NavigateParams p(MakeNavigateParams());
+ p.disposition = SINGLETON_TAB;
+ p.url = singleton_url_target;
+ p.show_window = true;
+ p.ignore_path = true;
+ browser::Navigate(&p);
+
+ // Last tab should still be selected.
+ EXPECT_EQ(browser(), p.browser);
+ EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
+ EXPECT_EQ(initial_tab_count, browser()->selected_index());
+}
+
// This test verifies that the settings page isn't opened in the incognito
// window.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,