OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browser_about_handler.h" | 5 #include "chrome/browser/browser_about_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | |
11 #include <vector> | |
10 | 12 |
13 #include "base/feature_list.h" | |
11 #include "base/macros.h" | 14 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "chrome/common/chrome_features.h" | |
13 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
15 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/common/referrer.h" | 21 #include "content/public/common/referrer.h" |
18 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "url/gurl.h" | 25 #include "url/gurl.h" |
22 | 26 |
23 using content::BrowserThread; | 27 using content::BrowserThread; |
24 using content::NavigationController; | 28 using content::NavigationController; |
25 using content::NavigationEntry; | 29 using content::NavigationEntry; |
26 using content::Referrer; | 30 using content::Referrer; |
27 | 31 |
32 namespace { | |
33 struct AboutURLTestCase { | |
Dan Beam
2016/06/21 19:23:18
sweet, lgtm
| |
34 GURL test_url; | |
35 GURL expected_url; | |
36 }; | |
37 } | |
38 | |
28 class BrowserAboutHandlerTest : public testing::Test { | 39 class BrowserAboutHandlerTest : public testing::Test { |
40 protected: | |
41 void TestWillHandleBrowserAboutURL( | |
42 const std::vector<AboutURLTestCase>& test_cases) { | |
43 TestingProfile profile; | |
44 | |
45 for (const auto& test_case : test_cases) { | |
46 GURL url(test_case.test_url); | |
47 WillHandleBrowserAboutURL(&url, &profile); | |
48 EXPECT_EQ(test_case.expected_url, url); | |
49 } | |
50 } | |
51 | |
52 private: | |
29 content::TestBrowserThreadBundle thread_bundle_; | 53 content::TestBrowserThreadBundle thread_bundle_; |
30 }; | 54 }; |
31 | 55 |
32 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { | 56 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { |
33 std::string chrome_prefix(content::kChromeUIScheme); | 57 std::string chrome_prefix(content::kChromeUIScheme); |
34 chrome_prefix.append(url::kStandardSchemeSeparator); | 58 chrome_prefix.append(url::kStandardSchemeSeparator); |
35 struct AboutURLTestData { | 59 std::vector<AboutURLTestCase> test_cases( |
36 GURL test_url; | 60 {{GURL("http://google.com"), GURL("http://google.com")}, |
37 GURL result_url; | 61 {GURL(url::kAboutBlankURL), GURL(url::kAboutBlankURL)}, |
38 } test_data[] = { | 62 {GURL(chrome_prefix + chrome::kChromeUIDefaultHost), |
39 { | 63 GURL(chrome_prefix + chrome::kChromeUIVersionHost)}, |
40 GURL("http://google.com"), | 64 {GURL(chrome_prefix + chrome::kChromeUIAboutHost), |
41 GURL("http://google.com") | 65 GURL(chrome_prefix + chrome::kChromeUIChromeURLsHost)}, |
42 }, | 66 {GURL(chrome_prefix + chrome::kChromeUICacheHost), |
43 { | 67 GURL(chrome_prefix + content::kChromeUINetworkViewCacheHost)}, |
44 GURL(url::kAboutBlankURL), | 68 {GURL(chrome_prefix + chrome::kChromeUISignInInternalsHost), |
45 GURL(url::kAboutBlankURL) | 69 GURL(chrome_prefix + chrome::kChromeUISignInInternalsHost)}, |
46 }, | 70 {GURL(chrome_prefix + chrome::kChromeUISyncHost), |
47 { | 71 GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost)}, |
48 GURL(chrome_prefix + chrome::kChromeUIDefaultHost), | 72 {GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost), |
49 GURL(chrome_prefix + chrome::kChromeUIVersionHost) | 73 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost)}, |
50 }, | 74 { |
51 { | 75 GURL(chrome_prefix + "host/path?query#ref"), |
52 GURL(chrome_prefix + chrome::kChromeUIAboutHost), | 76 GURL(chrome_prefix + "host/path?query#ref"), |
53 GURL(chrome_prefix + chrome::kChromeUIChromeURLsHost) | 77 }}); |
54 }, | 78 TestWillHandleBrowserAboutURL(test_cases); |
55 { | 79 } |
56 GURL(chrome_prefix + chrome::kChromeUICacheHost), | |
57 GURL(chrome_prefix + content::kChromeUINetworkViewCacheHost) | |
58 }, | |
59 { | |
60 GURL(chrome_prefix + chrome::kChromeUISignInInternalsHost), | |
61 GURL(chrome_prefix + chrome::kChromeUISignInInternalsHost) | |
62 }, | |
63 { | |
64 GURL(chrome_prefix + chrome::kChromeUISyncHost), | |
65 GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost) | |
66 }, | |
67 { | |
68 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost), | |
69 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost) | |
70 }, | |
71 { | |
72 GURL(chrome_prefix + "host/path?query#ref"), | |
73 GURL(chrome_prefix + "host/path?query#ref"), | |
74 } | |
75 }; | |
76 TestingProfile profile; | |
77 | 80 |
78 for (size_t i = 0; i < arraysize(test_data); ++i) { | 81 #if defined(OS_CHROMEOS) |
79 GURL url(test_data[i].test_url); | 82 // Chrome OS defaults to showing Options in a window and including About in |
80 WillHandleBrowserAboutURL(&url, &profile); | 83 // Options. |
81 EXPECT_EQ(test_data[i].result_url, url); | 84 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURLForOptionsChromeOS) { |
82 } | 85 std::string chrome_prefix(content::kChromeUIScheme); |
86 chrome_prefix.append(url::kStandardSchemeSeparator); | |
87 std::vector<AboutURLTestCase> test_cases( | |
88 {{GURL(chrome_prefix + chrome::kChromeUISettingsHost), | |
89 GURL(chrome_prefix + chrome::kChromeUISettingsFrameHost)}, | |
90 {GURL(chrome_prefix + chrome::kChromeUIHelpHost), | |
91 GURL(chrome_prefix + chrome::kChromeUISettingsFrameHost + "/" + | |
92 chrome::kChromeUIHelpHost)}}); | |
93 TestWillHandleBrowserAboutURL(test_cases); | |
94 } | |
95 | |
96 #else | |
97 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURLForOptions) { | |
98 std::string chrome_prefix(content::kChromeUIScheme); | |
99 chrome_prefix.append(url::kStandardSchemeSeparator); | |
100 std::vector<AboutURLTestCase> test_cases( | |
101 {{ | |
102 GURL(chrome_prefix + chrome::kChromeUISettingsHost), | |
103 GURL(chrome_prefix + chrome::kChromeUIUberHost + "/" + | |
104 chrome::kChromeUISettingsHost + "/"), | |
105 }, | |
106 { | |
107 GURL(chrome_prefix + chrome::kChromeUIHelpHost), | |
108 GURL(chrome_prefix + chrome::kChromeUIUberHost + "/" + | |
109 chrome::kChromeUIHelpHost + "/"), | |
110 }}); | |
111 TestWillHandleBrowserAboutURL(test_cases); | |
112 } | |
113 #endif | |
114 | |
115 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURLForMDSettings) { | |
116 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
117 feature_list->InitializeFromCommandLine( | |
118 features::kMaterialDesignSettingsFeature.name, ""); | |
119 base::FeatureList::ClearInstanceForTesting(); | |
120 base::FeatureList::SetInstance(std::move(feature_list)); | |
121 | |
122 std::string chrome_prefix(content::kChromeUIScheme); | |
123 chrome_prefix.append(url::kStandardSchemeSeparator); | |
124 std::vector<AboutURLTestCase> test_cases( | |
125 {{GURL(chrome_prefix + chrome::kChromeUISettingsHost), | |
126 GURL(chrome_prefix + chrome::kChromeUISettingsHost)}, | |
127 {GURL(chrome_prefix + chrome::kChromeUIHelpHost), | |
128 GURL(chrome_prefix + chrome::kChromeUIHelpHost)}}); | |
129 TestWillHandleBrowserAboutURL(test_cases); | |
83 } | 130 } |
84 | 131 |
85 // Ensure that minor BrowserAboutHandler fixup to a URL does not cause us to | 132 // Ensure that minor BrowserAboutHandler fixup to a URL does not cause us to |
86 // keep a separate virtual URL, which would not be updated on redirects. | 133 // keep a separate virtual URL, which would not be updated on redirects. |
87 // See https://crbug.com/449829. | 134 // See https://crbug.com/449829. |
88 TEST_F(BrowserAboutHandlerTest, NoVirtualURLForFixup) { | 135 TEST_F(BrowserAboutHandlerTest, NoVirtualURLForFixup) { |
89 GURL url("view-source:http://.foo"); | 136 GURL url("view-source:http://.foo"); |
90 | 137 |
91 // Fixup will remove the dot and add a slash. | 138 // Fixup will remove the dot and add a slash. |
92 GURL fixed_url("view-source:http://foo/"); | 139 GURL fixed_url("view-source:http://foo/"); |
93 | 140 |
94 // Rewriters will remove the view-source prefix and expect it to stay in the | 141 // Rewriters will remove the view-source prefix and expect it to stay in the |
95 // virtual URL. | 142 // virtual URL. |
96 GURL rewritten_url("http://foo/"); | 143 GURL rewritten_url("http://foo/"); |
97 | 144 |
98 TestingProfile profile; | 145 TestingProfile profile; |
99 std::unique_ptr<NavigationEntry> entry( | 146 std::unique_ptr<NavigationEntry> entry( |
100 NavigationController::CreateNavigationEntry( | 147 NavigationController::CreateNavigationEntry( |
101 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), | 148 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), |
102 &profile)); | 149 &profile)); |
103 EXPECT_EQ(fixed_url, entry->GetVirtualURL()); | 150 EXPECT_EQ(fixed_url, entry->GetVirtualURL()); |
104 EXPECT_EQ(rewritten_url, entry->GetURL()); | 151 EXPECT_EQ(rewritten_url, entry->GetURL()); |
105 } | 152 } |
OLD | NEW |