Second try of 157576 https://chromiumcodereview.appspot.com/10780013/
Add reverse URL handler for shortening uber URLs
BUG=120493
TEST=Open the settings page. The address bar should show "chrome://settings". Click the "extensions" button on the left. The address bar should show "chrome://extensions". Click the "settings" button on the left, "show advanced settings", "content settings". The address bar should show "chrome://settings/content".
Review URL: https://chromiumcodereview.appspot.com/10941050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158504 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc
index 04be5f7c..3b0510d 100644
--- a/chrome/browser/ui/browser_navigator_browsertest.cc
+++ b/chrome/browser/ui/browser_navigator_browsertest.cc
@@ -40,8 +40,7 @@
}
GURL GetSettingsURL() {
- return GURL(chrome::kChromeUIUberURL).Resolve(
- chrome::kChromeUISettingsHost + std::string("/"));
+ return GURL(chrome::kChromeUISettingsURL);
}
GURL GetContentSettingsURL() {
@@ -52,6 +51,20 @@
return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
}
+// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
+// ("chrome://foo/"). This should be used to convert the return value of
+// WebContentsImpl::GetURL before comparison because it can return either the
+// real URL or the virtual URL.
+GURL ShortenUberURL(const GURL& url) {
+ std::string url_string = url.spec();
+ const std::string long_prefix = "chrome://chrome/";
+ const std::string short_prefix = "chrome://";
+ if (url_string.find(long_prefix) != 0)
+ return url;
+ url_string.replace(0, long_prefix.length(), short_prefix);
+ return GURL(url_string);
+}
+
} // namespace
chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
@@ -722,7 +735,7 @@
EXPECT_EQ(3, browser()->tab_count());
EXPECT_EQ(2, browser()->active_index());
EXPECT_EQ(GetContentSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
@@ -755,7 +768,7 @@
EXPECT_EQ(3, browser()->tab_count());
EXPECT_EQ(1, browser()->active_index());
EXPECT_EQ(GetContentSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
@@ -788,7 +801,7 @@
EXPECT_EQ(3, browser()->tab_count());
EXPECT_EQ(1, browser()->active_index());
EXPECT_EQ(GetClearBrowsingDataURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
@@ -820,7 +833,7 @@
EXPECT_EQ(3, browser()->tab_count());
EXPECT_EQ(1, browser()->active_index());
EXPECT_EQ(singleton_url1,
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
@@ -851,7 +864,7 @@
EXPECT_EQ(2, browser()->tab_count());
EXPECT_EQ(1, browser()->active_index());
EXPECT_EQ(singleton_url_target,
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// This test verifies that constructing params with disposition = SINGLETON_TAB
@@ -910,7 +923,7 @@
EXPECT_EQ(1u, BrowserList::size());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// Settings page is expected to always open in normal mode regardless
@@ -994,7 +1007,7 @@
}
EXPECT_EQ(1, browser()->tab_count());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
@@ -1012,7 +1025,7 @@
}
EXPECT_EQ(1, browser()->tab_count());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
@@ -1033,7 +1046,7 @@
}
EXPECT_EQ(1, browser()->tab_count());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
@@ -1053,7 +1066,7 @@
}
EXPECT_EQ(2, browser()->tab_count());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
@@ -1079,7 +1092,7 @@
}
EXPECT_EQ(2, browser()->tab_count());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
@@ -1144,7 +1157,7 @@
}
EXPECT_EQ(2, browser()->tab_count());
EXPECT_EQ(GetSettingsURL(),
- chrome::GetActiveWebContents(browser())->GetURL());
+ ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
}
// Tests that when a new tab is opened from the omnibox, the focus is moved from