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> |
Dan Beam
2016/06/21 05:24:45
nit: #include <utility>
for std::move()
michaelpg
2016/06/21 19:19:33
Done.
| |
10 #include <vector> | |
10 | 11 |
12 #include "base/feature_list.h" | |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "chrome/common/chrome_features.h" | |
13 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
15 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/common/referrer.h" | 20 #include "content/public/common/referrer.h" |
18 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "url/gurl.h" | 24 #include "url/gurl.h" |
22 | 25 |
23 using content::BrowserThread; | 26 using content::BrowserThread; |
24 using content::NavigationController; | 27 using content::NavigationController; |
25 using content::NavigationEntry; | 28 using content::NavigationEntry; |
26 using content::Referrer; | 29 using content::Referrer; |
27 | 30 |
28 class BrowserAboutHandlerTest : public testing::Test { | 31 class BrowserAboutHandlerTest : public testing::Test { |
32 protected: | |
33 struct AboutURLTestData { | |
Dan Beam
2016/06/21 05:24:45
nit: why does this need to be inside BrowserAboutH
michaelpg
2016/06/21 19:19:33
ummm dunno, is an anonymous namespace better?
Dan Beam
2016/06/21 19:22:50
i would say so because shorter names, yes
| |
34 GURL test_url; | |
35 GURL result_url; | |
Lei Zhang
2016/06/21 07:54:00
Maybe expected_result_url?
michaelpg
2016/06/21 19:19:33
Done, also renamed TestData => TestCase[s]
| |
36 }; | |
37 | |
38 void TestWillHandleBrowserAboutURL( | |
39 const std::vector<AboutURLTestData>& test_data) { | |
40 TestingProfile profile; | |
41 | |
42 for (const auto& test_datum : test_data) { | |
43 GURL url(test_datum.test_url); | |
44 WillHandleBrowserAboutURL(&url, &profile); | |
45 EXPECT_EQ(test_datum.result_url, url); | |
46 } | |
47 } | |
48 | |
49 private: | |
29 content::TestBrowserThreadBundle thread_bundle_; | 50 content::TestBrowserThreadBundle thread_bundle_; |
30 }; | 51 }; |
31 | 52 |
32 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { | 53 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { |
33 std::string chrome_prefix(content::kChromeUIScheme); | 54 std::string chrome_prefix(content::kChromeUIScheme); |
34 chrome_prefix.append(url::kStandardSchemeSeparator); | 55 chrome_prefix.append(url::kStandardSchemeSeparator); |
35 struct AboutURLTestData { | 56 std::vector<BrowserAboutHandlerTest::AboutURLTestData> test_data({ |
36 GURL test_url; | |
37 GURL result_url; | |
38 } test_data[] = { | |
39 { | 57 { |
40 GURL("http://google.com"), | 58 GURL("http://google.com"), |
41 GURL("http://google.com") | 59 GURL("http://google.com") |
42 }, | 60 }, |
43 { | 61 { |
44 GURL(url::kAboutBlankURL), | 62 GURL(url::kAboutBlankURL), |
45 GURL(url::kAboutBlankURL) | 63 GURL(url::kAboutBlankURL) |
46 }, | 64 }, |
47 { | 65 { |
48 GURL(chrome_prefix + chrome::kChromeUIDefaultHost), | 66 GURL(chrome_prefix + chrome::kChromeUIDefaultHost), |
(...skipping 16 matching lines...) Expand all Loading... | |
65 GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost) | 83 GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost) |
66 }, | 84 }, |
67 { | 85 { |
68 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost), | 86 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost), |
69 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost) | 87 GURL(chrome_prefix + chrome::kChromeUIInvalidationsHost) |
70 }, | 88 }, |
71 { | 89 { |
72 GURL(chrome_prefix + "host/path?query#ref"), | 90 GURL(chrome_prefix + "host/path?query#ref"), |
73 GURL(chrome_prefix + "host/path?query#ref"), | 91 GURL(chrome_prefix + "host/path?query#ref"), |
74 } | 92 } |
75 }; | 93 }); |
76 TestingProfile profile; | 94 TestWillHandleBrowserAboutURL(test_data); |
95 } | |
77 | 96 |
78 for (size_t i = 0; i < arraysize(test_data); ++i) { | 97 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURLForOptions) { |
79 GURL url(test_data[i].test_url); | 98 std::string chrome_prefix(content::kChromeUIScheme); |
80 WillHandleBrowserAboutURL(&url, &profile); | 99 chrome_prefix.append(url::kStandardSchemeSeparator); |
81 EXPECT_EQ(test_data[i].result_url, url); | 100 GURL settings_url_result; |
82 } | 101 GURL help_url_result; |
102 #if defined(OS_CHROMEOS) | |
103 settings_url_result = | |
Dan Beam
2016/06/21 05:24:45
this test might be slightly easier to read if the
michaelpg
2016/06/21 19:19:33
changed to 2 separate tests, does seem more readab
| |
104 GURL(chrome_prefix + chrome::kChromeUISettingsFrameHost); | |
105 help_url_result = GURL(chrome_prefix + chrome::kChromeUISettingsFrameHost + | |
106 "/" + chrome::kChromeUIHelpHost); | |
107 #else | |
108 settings_url_result = GURL(chrome_prefix + chrome::kChromeUIUberHost + "/" + | |
109 chrome::kChromeUISettingsHost + "/"); | |
110 help_url_result = GURL(chrome_prefix + chrome::kChromeUIUberHost + "/" + | |
111 chrome::kChromeUIHelpHost + "/"); | |
112 #endif | |
113 | |
114 std::vector<BrowserAboutHandlerTest::AboutURLTestData> test_data({ | |
115 { | |
116 GURL(chrome_prefix + chrome::kChromeUISettingsHost), | |
117 settings_url_result | |
118 }, | |
119 { | |
120 GURL(chrome_prefix + chrome::kChromeUIHelpHost), | |
121 help_url_result | |
122 } | |
123 }); | |
124 TestWillHandleBrowserAboutURL(test_data); | |
125 } | |
126 | |
127 TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURLForMDSettings) { | |
128 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
129 feature_list->InitializeFromCommandLine( | |
130 features::kMaterialDesignSettingsFeature.name, ""); | |
131 base::FeatureList::ClearInstanceForTesting(); | |
132 base::FeatureList::SetInstance(std::move(feature_list)); | |
133 | |
134 std::string chrome_prefix(content::kChromeUIScheme); | |
135 chrome_prefix.append(url::kStandardSchemeSeparator); | |
136 std::vector<BrowserAboutHandlerTest::AboutURLTestData> test_data({ | |
137 { | |
138 GURL(chrome_prefix + chrome::kChromeUISettingsHost), | |
139 GURL(chrome_prefix + chrome::kChromeUISettingsHost) | |
140 }, | |
141 { | |
142 GURL(chrome_prefix + chrome::kChromeUIHelpHost), | |
143 GURL(chrome_prefix + chrome::kChromeUIHelpHost) | |
144 } | |
145 }); | |
146 TestWillHandleBrowserAboutURL(test_data); | |
83 } | 147 } |
84 | 148 |
85 // Ensure that minor BrowserAboutHandler fixup to a URL does not cause us to | 149 // 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. | 150 // keep a separate virtual URL, which would not be updated on redirects. |
87 // See https://crbug.com/449829. | 151 // See https://crbug.com/449829. |
88 TEST_F(BrowserAboutHandlerTest, NoVirtualURLForFixup) { | 152 TEST_F(BrowserAboutHandlerTest, NoVirtualURLForFixup) { |
89 GURL url("view-source:http://.foo"); | 153 GURL url("view-source:http://.foo"); |
90 | 154 |
91 // Fixup will remove the dot and add a slash. | 155 // Fixup will remove the dot and add a slash. |
92 GURL fixed_url("view-source:http://foo/"); | 156 GURL fixed_url("view-source:http://foo/"); |
93 | 157 |
94 // Rewriters will remove the view-source prefix and expect it to stay in the | 158 // Rewriters will remove the view-source prefix and expect it to stay in the |
95 // virtual URL. | 159 // virtual URL. |
96 GURL rewritten_url("http://foo/"); | 160 GURL rewritten_url("http://foo/"); |
97 | 161 |
98 TestingProfile profile; | 162 TestingProfile profile; |
99 std::unique_ptr<NavigationEntry> entry( | 163 std::unique_ptr<NavigationEntry> entry( |
100 NavigationController::CreateNavigationEntry( | 164 NavigationController::CreateNavigationEntry( |
101 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), | 165 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), |
102 &profile)); | 166 &profile)); |
103 EXPECT_EQ(fixed_url, entry->GetVirtualURL()); | 167 EXPECT_EQ(fixed_url, entry->GetVirtualURL()); |
104 EXPECT_EQ(rewritten_url, entry->GetURL()); | 168 EXPECT_EQ(rewritten_url, entry->GetURL()); |
105 } | 169 } |
OLD | NEW |