Commit 1c0d4ec3 authored by Shahbaz Youssefi's avatar Shahbaz Youssefi Committed by Commit Bot

Rename BrowserSwitcherSitelist::ShouldRedirect()

The new name is ShouldSwitch, to avoid confusion with http's redirect.

Bug: 880470
Change-Id: Ia25c476a75fb90b1e919df7c114d923da3d688d9
Reviewed-on: https://chromium-review.googlesource.com/1205480Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589295}
parent c72bfab8
...@@ -85,7 +85,7 @@ BrowserSwitcherSitelist::BrowserSwitcherSitelist(PrefService* prefs) ...@@ -85,7 +85,7 @@ BrowserSwitcherSitelist::BrowserSwitcherSitelist(PrefService* prefs)
BrowserSwitcherSitelist::~BrowserSwitcherSitelist() {} BrowserSwitcherSitelist::~BrowserSwitcherSitelist() {}
bool BrowserSwitcherSitelist::ShouldRedirect(const GURL& url) const { bool BrowserSwitcherSitelist::ShouldSwitch(const GURL& url) const {
// Translated from the LBS extension: // Translated from the LBS extension:
// https://github.com/LegacyBrowserSupport/legacy-browser-support/blob/8caa623692b94dc0154074ce904de8f60ee8a404/chrome_extension/js/extension_logic.js#L205 // https://github.com/LegacyBrowserSupport/legacy-browser-support/blob/8caa623692b94dc0154074ce904de8f60ee8a404/chrome_extension/js/extension_logic.js#L205
if (!url.SchemeIsHTTPOrHTTPS() && !url.SchemeIsFile()) { if (!url.SchemeIsHTTPOrHTTPS() && !url.SchemeIsFile()) {
......
...@@ -21,7 +21,7 @@ class BrowserSwitcherSitelist { ...@@ -21,7 +21,7 @@ class BrowserSwitcherSitelist {
~BrowserSwitcherSitelist(); ~BrowserSwitcherSitelist();
// Returns true if the given URL should be open in an alternative browser. // Returns true if the given URL should be open in an alternative browser.
bool ShouldRedirect(const GURL& url) const; bool ShouldSwitch(const GURL& url) const;
private: private:
PrefService* const prefs_; PrefService* const prefs_;
......
...@@ -45,84 +45,81 @@ class BrowserSwitcherSitelistTest : public testing::Test { ...@@ -45,84 +45,81 @@ class BrowserSwitcherSitelistTest : public testing::Test {
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectWildcard) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectWildcard) {
// A "*" by itself means everything matches. // A "*" by itself means everything matches.
Initialize({"*"}, {}); Initialize({"*"}, {});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("https://example.com/foobar/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("https://example.com/foobar/")));
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/foobar/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/foobar/")));
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://google.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://google.com/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectHost) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectHost) {
// A string without slashes means compare the URL's host (case-insensitive). // A string without slashes means compare the URL's host (case-insensitive).
Initialize({"example.com"}, {}); Initialize({"example.com"}, {});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("https://example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("https://example.com/")));
EXPECT_TRUE( EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://subdomain.example.com/")));
sitelist()->ShouldRedirect(GURL("http://subdomain.example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/foobar/")));
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/foobar/"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://google.com/")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://google.com/"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://example.ca/")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://example.ca/")));
// For backwards compatibility, this should also match, even if it's not the // For backwards compatibility, this should also match, even if it's not the
// same host. // same host.
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("https://notexample.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("https://notexample.com/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectHostNotLowerCase) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectHostNotLowerCase) {
// Host is not in lowercase form, but we compare ignoring case. // Host is not in lowercase form, but we compare ignoring case.
Initialize({"eXaMpLe.CoM"}, {}); Initialize({"eXaMpLe.CoM"}, {});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectWrongScheme) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectWrongScheme) {
Initialize({"example.com"}, {}); Initialize({"example.com"}, {});
// Scheme is not one of 'http', 'https' or 'file'. // Scheme is not one of 'http', 'https' or 'file'.
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("ftp://example.com/"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("ftp://example.com/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectPrefix) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectPrefix) {
// A string with slashes means check if it's a prefix (case-sensitive). // A string with slashes means check if it's a prefix (case-sensitive).
Initialize({"http://example.com/foobar"}, {}); Initialize({"http://example.com/foobar"}, {});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/foobar"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/foobar")));
EXPECT_TRUE(
sitelist()->ShouldSwitch(GURL("http://example.com/foobar/subroute/")));
EXPECT_TRUE( EXPECT_TRUE(
sitelist()->ShouldRedirect(GURL("http://example.com/foobar/subroute/"))); sitelist()->ShouldSwitch(GURL("http://example.com/foobar#fragment")));
EXPECT_TRUE( EXPECT_TRUE(
sitelist()->ShouldRedirect(GURL("http://example.com/foobar#fragment"))); sitelist()->ShouldSwitch(GURL("http://example.com/foobar?query=param")));
EXPECT_TRUE(sitelist()->ShouldRedirect( EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
GURL("http://example.com/foobar?query=param"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("https://example.com/foobar")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("HTTP://EXAMPLE.COM/FOOBAR")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("https://example.com/foobar"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://subdomain.example.com/")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("HTTP://EXAMPLE.COM/FOOBAR"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://google.com/")));
EXPECT_FALSE(
sitelist()->ShouldRedirect(GURL("http://subdomain.example.com/")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://google.com/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectPrefixNotLowerCase) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectPrefixNotLowerCase) {
// The scheme and host are case-insensitive, but the rest is case-sensitive. // The scheme and host are case-insensitive, but the rest is case-sensitive.
Initialize({"HTTP://EXAMPLE.COM/SUBROUTE"}, {}); Initialize({"HTTP://EXAMPLE.COM/SUBROUTE"}, {});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/SUBROUTE"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/SUBROUTE")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://example.com/subroute"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://example.com/subroute")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectInvertedMatch) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectInvertedMatch) {
// The most specific (i.e., longest string) rule should have priority. // The most specific (i.e., longest string) rule should have priority.
Initialize({"!subdomain.example.com", "example.com"}, {}); Initialize({"!subdomain.example.com", "example.com"}, {});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
EXPECT_FALSE( EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://subdomain.example.com/")));
sitelist()->ShouldRedirect(GURL("http://subdomain.example.com/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectGreylist) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectGreylist) {
// The most specific (i.e., longest string) rule should have priority. // The most specific (i.e., longest string) rule should have priority.
Initialize({"example.com"}, {"http://example.com/login/"}); Initialize({"example.com"}, {"http://example.com/login/"});
EXPECT_TRUE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_TRUE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://example.com/login/"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://example.com/login/")));
} }
TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectGreylistWildcard) { TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectGreylistWildcard) {
Initialize({"*"}, {"*"}); Initialize({"*"}, {"*"});
// If both are wildcards, prefer the greylist. // If both are wildcards, prefer the greylist.
EXPECT_FALSE(sitelist()->ShouldRedirect(GURL("http://example.com/"))); EXPECT_FALSE(sitelist()->ShouldSwitch(GURL("http://example.com/")));
} }
} // namespace browser_switcher } // namespace browser_switcher
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment