blob: f15b77f74828bcfb42bfe23eba76e76ab1b8cfe4 [file] [log] [blame]
[email protected]3d831992013-07-04 01:13:291// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
msramek1f4746d2016-08-19 21:37:077#include <list>
bmcquade5d2d9cf32015-06-19 17:42:288#include <map>
msramek1f4746d2016-08-19 21:37:079#include <memory>
bmcquade5d2d9cf32015-06-19 17:42:2810
msramek1f4746d2016-08-19 21:37:0711#include "base/bind.h"
[email protected]30335fdf02014-02-26 19:51:2712#include "base/command_line.h"
avie4d7b6f2015-12-26 00:59:1813#include "base/macros.h"
[email protected]10a9bf92013-11-13 23:34:4814#include "base/metrics/field_trial.h"
msramek22328112017-03-23 16:50:2915#include "base/run_loop.h"
msramek1f4746d2016-08-19 21:37:0716#include "base/strings/stringprintf.h"
mpearson3c6d7af2015-05-13 23:59:5317#include "base/strings/utf_string_conversions.h"
avie4d7b6f2015-12-26 00:59:1818#include "build/build_config.h"
msramek1f4746d2016-08-19 21:37:0719#include "chrome/browser/browsing_data/browsing_data_helper.h"
msramek1c2b3ca2017-03-14 17:57:5620#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
[email protected]10a9bf92013-11-13 23:34:4821#include "chrome/browser/search_engines/template_url_service_factory.h"
msramek1f4746d2016-08-19 21:37:0722#include "chrome/test/base/testing_profile.h"
timvolodinea47291a2015-01-23 14:04:4323#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]bf5c532d2014-07-05 00:29:5324#include "components/search_engines/template_url_service.h"
[email protected]10a9bf92013-11-13 23:34:4825#include "components/variations/entropy_provider.h"
bmcquade5d2d9cf32015-06-19 17:42:2826#include "components/variations/variations_associated_data.h"
sdefresne9fb67692015-08-03 18:48:2227#include "components/version_info/version_info.h"
msrameka3c7cfd2017-02-03 13:34:1328#include "content/public/browser/browsing_data_filter_builder.h"
msrameke169ccb2017-04-26 05:21:4129#include "content/public/browser/browsing_data_remover.h"
[email protected]10a9bf92013-11-13 23:34:4830#include "content/public/browser/navigation_controller.h"
31#include "content/public/browser/navigation_entry.h"
msramek22328112017-03-23 16:50:2932#include "content/public/browser/storage_partition.h"
[email protected]10a9bf92013-11-13 23:34:4833#include "content/public/browser/web_contents.h"
[email protected]30335fdf02014-02-26 19:51:2734#include "content/public/common/content_switches.h"
bmcquade5d2d9cf32015-06-19 17:42:2835#include "content/public/test/test_browser_thread_bundle.h"
Scott Violeta35f9a42018-03-22 22:00:4436#include "media/media_buildflags.h"
msramek1f4746d2016-08-19 21:37:0737#include "testing/gmock/include/gmock/gmock.h"
[email protected]3d831992013-07-04 01:13:2938#include "testing/gtest/include/gtest/gtest.h"
[email protected]5f5ef802013-07-04 16:11:1339#include "url/gurl.h"
[email protected]3d831992013-07-04 01:13:2940
jam1c5a91492016-02-24 20:47:5341#if !defined(OS_ANDROID)
thestigf80564462015-09-29 23:12:0842#include "chrome/browser/ui/browser.h"
43#include "chrome/browser/ui/tabs/tab_strip_model.h"
bengre8a146f2016-03-10 01:20:2244#include "chrome/common/pref_names.h"
thestigf80564462015-09-29 23:12:0845#include "chrome/test/base/browser_with_test_window_test.h"
46#include "chrome/test/base/search_test_utils.h"
47#endif
48
James Cooked46d842017-10-13 19:41:1749#if defined(OS_CHROMEOS)
50#include "ash/public/interfaces/constants.mojom.h"
51#include "content/public/common/service_names.mojom.h"
52#include "services/ui/public/interfaces/constants.mojom.h"
53#endif
54
msrameka3c7cfd2017-02-03 13:34:1355using content::BrowsingDataFilterBuilder;
msramek1f4746d2016-08-19 21:37:0756using testing::_;
mlamourieb40d552015-02-05 00:57:0857using ChromeContentBrowserClientTest = testing::Test;
[email protected]3d831992013-07-04 01:13:2958
[email protected]3d831992013-07-04 01:13:2959TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) {
60 ChromeContentBrowserClient client;
61 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test")));
62 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com")));
63 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com")));
64}
65
jam1c5a91492016-02-24 20:47:5366// BrowserWithTestWindowTest doesn't work on Android.
67#if !defined(OS_ANDROID)
mlamourieb40d552015-02-05 00:57:0868
peterbbcccc12015-02-11 22:23:3369using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest;
70
71static void DidOpenURLForWindowTest(content::WebContents** target_contents,
72 content::WebContents* opened_contents) {
73 DCHECK(target_contents);
74
75 *target_contents = opened_contents;
76}
77
bengre8a146f2016-03-10 01:20:2278TEST_F(ChromeContentBrowserClientWindowTest, IsDataSaverEnabled) {
79 ChromeContentBrowserClient client;
80 content::BrowserContext* context = browser()->profile();
81 EXPECT_FALSE(client.IsDataSaverEnabled(context));
82 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDataSaverEnabled, true);
83 EXPECT_TRUE(client.IsDataSaverEnabled(context));
84}
85
mlamourieb40d552015-02-05 00:57:0886// This test opens two URLs using ContentBrowserClient::OpenURL. It expects the
87// URLs to be opened in new tabs and activated, changing the active tabs after
88// each call and increasing the tab count by 2.
89TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) {
90 ChromeContentBrowserClient client;
91
92 int previous_count = browser()->tab_strip_model()->count();
93
94 GURL urls[] = { GURL("https://www.google.com"),
95 GURL("https://www.chromium.org") };
96
97 for (const GURL& url : urls) {
nick3b04f322016-08-31 19:29:1998 content::OpenURLParams params(url, content::Referrer(),
99 WindowOpenDisposition::NEW_FOREGROUND_TAB,
100 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false);
peterbbcccc12015-02-11 22:23:33101 // TODO(peter): We should have more in-depth browser tests for the window
102 // opening functionality, which also covers Android. This test can currently
103 // only be ran on platforms where OpenURL is implemented synchronously.
104 // See https://crbug.com/457667.
105 content::WebContents* web_contents = nullptr;
106 client.OpenURL(browser()->profile(),
107 params,
108 base::Bind(&DidOpenURLForWindowTest, &web_contents));
109
110 EXPECT_TRUE(web_contents);
mlamourieb40d552015-02-05 00:57:08111
112 content::WebContents* active_contents = browser()->tab_strip_model()->
113 GetActiveWebContents();
peterbbcccc12015-02-11 22:23:33114 EXPECT_EQ(web_contents, active_contents);
mlamourieb40d552015-02-05 00:57:08115 EXPECT_EQ(url, active_contents->GetVisibleURL());
116 }
117
118 EXPECT_EQ(previous_count + 2, browser()->tab_strip_model()->count());
119}
120
jam1c5a91492016-02-24 20:47:53121#endif // !defined(OS_ANDROID)
mlamourieb40d552015-02-05 00:57:08122
[email protected]30335fdf02014-02-26 19:51:27123// NOTE: Any updates to the expectations in these tests should also be done in
124// the browser test WebRtcDisableEncryptionFlagBrowserTest.
125class DisableWebRtcEncryptionFlagTest : public testing::Test {
126 public:
127 DisableWebRtcEncryptionFlagTest()
avi3ef9ec9e2014-12-22 22:50:17128 : from_command_line_(base::CommandLine::NO_PROGRAM),
129 to_command_line_(base::CommandLine::NO_PROGRAM) {}
[email protected]30335fdf02014-02-26 19:51:27130
131 protected:
dchenge1bc7982014-10-30 00:32:40132 void SetUp() override {
[email protected]30335fdf02014-02-26 19:51:27133 from_command_line_.AppendSwitch(switches::kDisableWebRtcEncryption);
134 }
135
sdefresne6e883e42015-07-30 08:05:54136 void MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:27137 ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
138 &to_command_line_,
139 from_command_line_,
140 channel);
141 }
142
avi3ef9ec9e2014-12-22 22:50:17143 base::CommandLine from_command_line_;
144 base::CommandLine to_command_line_;
[email protected]30335fdf02014-02-26 19:51:27145
thestigf80564462015-09-29 23:12:08146 private:
[email protected]30335fdf02014-02-26 19:51:27147 DISALLOW_COPY_AND_ASSIGN(DisableWebRtcEncryptionFlagTest);
148};
149
150TEST_F(DisableWebRtcEncryptionFlagTest, UnknownChannel) {
sdefresne6e883e42015-07-30 08:05:54151 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::UNKNOWN);
[email protected]30335fdf02014-02-26 19:51:27152 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
153}
154
155TEST_F(DisableWebRtcEncryptionFlagTest, CanaryChannel) {
sdefresne6e883e42015-07-30 08:05:54156 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::CANARY);
[email protected]30335fdf02014-02-26 19:51:27157 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
158}
159
160TEST_F(DisableWebRtcEncryptionFlagTest, DevChannel) {
sdefresne6e883e42015-07-30 08:05:54161 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::DEV);
[email protected]30335fdf02014-02-26 19:51:27162 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
163}
164
165TEST_F(DisableWebRtcEncryptionFlagTest, BetaChannel) {
sdefresne6e883e42015-07-30 08:05:54166 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::BETA);
[email protected]30335fdf02014-02-26 19:51:27167#if defined(OS_ANDROID)
168 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
169#else
170 EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
171#endif
172}
173
174TEST_F(DisableWebRtcEncryptionFlagTest, StableChannel) {
sdefresne6e883e42015-07-30 08:05:54175 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::STABLE);
[email protected]30335fdf02014-02-26 19:51:27176 EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
177}
178
bmcquade5d2d9cf32015-06-19 17:42:28179class BlinkSettingsFieldTrialTest : public testing::Test {
180 public:
Gayane Petrosyand6477ee2018-01-10 16:29:46181 static const char kDisallowFetchFieldTrialName[];
182 static const char kCSSExternalScannerFieldTrialName[];
pmeenan9ac669682015-08-17 14:57:03183 static const char kFakeGroupName[];
bmcquade9dd54cc2015-06-22 16:56:52184
bmcquade5d2d9cf32015-06-19 17:42:28185 BlinkSettingsFieldTrialTest()
186 : trial_list_(NULL),
187 command_line_(base::CommandLine::NO_PROGRAM) {}
188
189 void SetUp() override {
190 command_line_.AppendSwitchASCII(
191 switches::kProcessType, switches::kRendererProcess);
192 }
193
194 void TearDown() override {
195 variations::testing::ClearAllVariationParams();
196 }
197
pmeenan9ac669682015-08-17 14:57:03198 void CreateFieldTrial(const char* trial_name, const char* group_name) {
199 base::FieldTrialList::CreateFieldTrial(trial_name, group_name);
bmcquade5d2d9cf32015-06-19 17:42:28200 }
201
bmcquade9dd54cc2015-06-22 16:56:52202 void CreateFieldTrialWithParams(
203 const char* trial_name,
pmeenan9ac669682015-08-17 14:57:03204 const char* group_name,
bmcquade9dd54cc2015-06-22 16:56:52205 const char* key1, const char* value1,
206 const char* key2, const char* value2) {
bmcquade5d2d9cf32015-06-19 17:42:28207 std::map<std::string, std::string> params;
bmcquade9dd54cc2015-06-22 16:56:52208 params.insert(std::make_pair(key1, value1));
209 params.insert(std::make_pair(key2, value2));
pmeenan9ac669682015-08-17 14:57:03210 CreateFieldTrial(trial_name, kFakeGroupName);
211 variations::AssociateVariationParams(trial_name, kFakeGroupName, params);
bmcquade5d2d9cf32015-06-19 17:42:28212 }
213
214 void AppendContentBrowserClientSwitches() {
215 client_.AppendExtraCommandLineSwitches(&command_line_, kFakeChildProcessId);
216 }
217
218 const base::CommandLine& command_line() const {
219 return command_line_;
220 }
221
222 void AppendBlinkSettingsSwitch(const char* value) {
223 command_line_.AppendSwitchASCII(switches::kBlinkSettings, value);
224 }
225
226 private:
227 static const int kFakeChildProcessId = 1;
bmcquade5d2d9cf32015-06-19 17:42:28228
229 ChromeContentBrowserClient client_;
230 base::FieldTrialList trial_list_;
231 base::CommandLine command_line_;
232
233 content::TestBrowserThreadBundle thread_bundle_;
234};
235
Gayane Petrosyand6477ee2018-01-10 16:29:46236const char BlinkSettingsFieldTrialTest::kDisallowFetchFieldTrialName[] =
237 "DisallowFetchForDocWrittenScriptsInMainFrame";
238const char BlinkSettingsFieldTrialTest::kCSSExternalScannerFieldTrialName[] =
239 "CSSExternalScanner";
pmeenan9ac669682015-08-17 14:57:03240const char BlinkSettingsFieldTrialTest::kFakeGroupName[] = "FakeGroup";
bmcquade5d2d9cf32015-06-19 17:42:28241
242TEST_F(BlinkSettingsFieldTrialTest, NoFieldTrial) {
243 AppendContentBrowserClientSwitches();
244 EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings));
245}
246
247TEST_F(BlinkSettingsFieldTrialTest, FieldTrialWithoutParams) {
Gayane Petrosyand6477ee2018-01-10 16:29:46248 CreateFieldTrial(kDisallowFetchFieldTrialName, kFakeGroupName);
bmcquade5d2d9cf32015-06-19 17:42:28249 AppendContentBrowserClientSwitches();
250 EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings));
251}
252
253TEST_F(BlinkSettingsFieldTrialTest, BlinkSettingsSwitchAlreadySpecified) {
254 AppendBlinkSettingsSwitch("foo");
Gayane Petrosyand6477ee2018-01-10 16:29:46255 CreateFieldTrialWithParams(kDisallowFetchFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52256 "key1", "value1", "key2", "value2");
bmcquade5d2d9cf32015-06-19 17:42:28257 AppendContentBrowserClientSwitches();
258 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
259 EXPECT_EQ("foo",
260 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
261}
262
263TEST_F(BlinkSettingsFieldTrialTest, FieldTrialEnabled) {
Gayane Petrosyand6477ee2018-01-10 16:29:46264 CreateFieldTrialWithParams(kDisallowFetchFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52265 "key1", "value1", "key2", "value2");
bmcquade5d2d9cf32015-06-19 17:42:28266 AppendContentBrowserClientSwitches();
267 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
268 EXPECT_EQ("key1=value1,key2=value2",
269 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
270}
271
bmcquade9dd54cc2015-06-22 16:56:52272TEST_F(BlinkSettingsFieldTrialTest, MultipleFieldTrialsEnabled) {
Gayane Petrosyand6477ee2018-01-10 16:29:46273 CreateFieldTrialWithParams(kDisallowFetchFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52274 "key1", "value1", "key2", "value2");
Gayane Petrosyand6477ee2018-01-10 16:29:46275 CreateFieldTrialWithParams(kCSSExternalScannerFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52276 "keyA", "valueA", "keyB", "valueB");
277 AppendContentBrowserClientSwitches();
278 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
279 EXPECT_EQ("key1=value1,key2=value2,keyA=valueA,keyB=valueB",
280 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
281}
282
283TEST_F(BlinkSettingsFieldTrialTest, MultipleFieldTrialsDuplicateKeys) {
Gayane Petrosyand6477ee2018-01-10 16:29:46284 CreateFieldTrialWithParams(kDisallowFetchFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52285 "key1", "value1", "key2", "value2");
Gayane Petrosyand6477ee2018-01-10 16:29:46286 CreateFieldTrialWithParams(kCSSExternalScannerFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52287 "key2", "duplicate", "key3", "value3");
288 AppendContentBrowserClientSwitches();
289 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
290 EXPECT_EQ("key1=value1,key2=value2,key2=duplicate,key3=value3",
291 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
292}
293
jam1c5a91492016-02-24 20:47:53294#if !defined(OS_ANDROID)
[email protected]10a9bf92013-11-13 23:34:48295namespace content {
296
297class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest {
298 protected:
dchenge1bc7982014-10-30 00:32:40299 void SetUp() override {
[email protected]10a9bf92013-11-13 23:34:48300 BrowserWithTestWindowTest::SetUp();
301 field_trial_list_.reset(new base::FieldTrialList(
Jeremy Romanec48d7a2018-03-01 17:35:09302 std::make_unique<variations::SHA1EntropyProvider>("42")));
[email protected]10a9bf92013-11-13 23:34:48303 }
304
305 void InstallTemplateURLWithNewTabPage(GURL new_tab_page_url) {
306 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
307 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
308 TemplateURLService* template_url_service =
309 TemplateURLServiceFactory::GetForProfile(browser()->profile());
thestigf80564462015-09-29 23:12:08310 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
[email protected]10a9bf92013-11-13 23:34:48311
312 TemplateURLData data;
mpearson3c6d7af2015-05-13 23:59:53313 data.SetShortName(base::ASCIIToUTF16("foo.com"));
[email protected]10a9bf92013-11-13 23:34:48314 data.SetURL("http://foo.com/url?bar={searchTerms}");
315 data.new_tab_url = new_tab_page_url.spec();
avi8a64b715b2016-09-02 17:30:04316 TemplateURL* template_url =
Jeremy Romanec48d7a2018-03-01 17:35:09317 template_url_service->Add(std::make_unique<TemplateURL>(data));
[email protected]f1cb5582014-04-25 07:35:26318 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
[email protected]10a9bf92013-11-13 23:34:48319 }
320
dcheng4af48582016-04-19 00:29:35321 std::unique_ptr<base::FieldTrialList> field_trial_list_;
[email protected]10a9bf92013-11-13 23:34:48322};
323
324TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) {
325 const GURL url_original("chrome://newtab");
326 const GURL url_rewritten("https://www.example.com/newtab");
327 InstallTemplateURLWithNewTabPage(url_rewritten);
328 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
329 "Group1 use_cacheable_ntp:1"));
330
331 AddTab(browser(), GURL("chrome://blank"));
332 NavigateAndCommitActiveTab(url_original);
333
334 NavigationEntry* entry = browser()->tab_strip_model()->
335 GetActiveWebContents()->GetController().GetLastCommittedEntry();
336 ASSERT_TRUE(entry != NULL);
337 EXPECT_EQ(url_rewritten, entry->GetURL());
338 EXPECT_EQ(url_original, entry->GetVirtualURL());
339}
340
341} // namespace content
jam1c5a91492016-02-24 20:47:53342#endif // !defined(OS_ANDROID)
kerrnela67fad52017-06-14 20:18:16343
344class ChromeContentBrowserClientGetLoggingFileTest : public testing::Test {};
345
346TEST_F(ChromeContentBrowserClientGetLoggingFileTest, GetLoggingFile) {
Michael Giuffrida6802ffe2017-09-29 03:40:25347 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
kerrnela67fad52017-06-14 20:18:16348 ChromeContentBrowserClient client;
349 base::FilePath log_file_name;
Michael Giuffrida6802ffe2017-09-29 03:40:25350 EXPECT_FALSE(client.GetLoggingFileName(cmd_line).empty());
351}
352
353TEST_F(ChromeContentBrowserClientGetLoggingFileTest,
354 GetLoggingFileFromCommandLine) {
355 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
356 cmd_line.AppendSwitchASCII(switches::kLogFile, "test_log.txt");
357 ChromeContentBrowserClient client;
358 base::FilePath log_file_name;
359 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("test_log.txt")).value(),
360 client.GetLoggingFileName(cmd_line).value());
kerrnela67fad52017-06-14 20:18:16361}
dbeam25472e0c2017-06-23 19:02:31362
363class TestChromeContentBrowserClient : public ChromeContentBrowserClient {
364 public:
365 using ChromeContentBrowserClient::HandleWebUI;
366 using ChromeContentBrowserClient::HandleWebUIReverse;
367};
368
369TEST(ChromeContentBrowserClientTest, HandleWebUI) {
370 TestChromeContentBrowserClient test_content_browser_client;
371 const GURL http_help("http://help/");
372 GURL should_not_redirect = http_help;
373 test_content_browser_client.HandleWebUI(&should_not_redirect, nullptr);
374 EXPECT_EQ(http_help, should_not_redirect);
375
376 const GURL chrome_help("chrome://help/");
377 GURL should_redirect = chrome_help;
378 test_content_browser_client.HandleWebUI(&should_redirect, nullptr);
379 EXPECT_NE(chrome_help, should_redirect);
380}
381
382TEST(ChromeContentBrowserClientTest, HandleWebUIReverse) {
383 TestChromeContentBrowserClient test_content_browser_client;
384 GURL http_settings("http://settings/");
385 EXPECT_FALSE(
386 test_content_browser_client.HandleWebUIReverse(&http_settings, nullptr));
387 GURL chrome_settings("chrome://settings/");
388 EXPECT_TRUE(test_content_browser_client.HandleWebUIReverse(&chrome_settings,
389 nullptr));
390}
Matt Falkenhagen8479b202017-07-14 04:35:31391
392TEST(ChromeContentBrowserClientTest, GetMetricSuffixForURL) {
393 ChromeContentBrowserClient client;
394 // Search is detected.
395 EXPECT_EQ("search", client.GetMetricSuffixForURL(GURL(
396 "https://www.google.co.jp/search?q=whatsgoingon")));
397 // Not a Search host.
398 EXPECT_EQ("", client.GetMetricSuffixForURL(GURL(
399 "https://www.google.example.com/search?q=whatsgoingon")));
400 // For now, non-https is considered a Search host.
401 EXPECT_EQ("search", client.GetMetricSuffixForURL(
402 GURL("http://www.google.com/search?q=whatsgoingon")));
403 // Not a Search result page (no query).
404 EXPECT_EQ("", client.GetMetricSuffixForURL(
405 GURL("https://www.google.com/search?notaquery=nope")));
406}
James Cooked46d842017-10-13 19:41:17407
408#if defined(OS_CHROMEOS)
409
James Cooked46d842017-10-13 19:41:17410TEST(ChromeContentBrowserClientTest, ShouldTerminateOnServiceQuit) {
411 const struct {
412 std::string service_name;
413 bool expect_terminate;
414 } kTestCases[] = {
415 // Don't terminate for invalid service names.
416 {"", false},
417 {"unknown-name", false},
418 // Don't terminate for some well-known browser services.
419 {content::mojom::kBrowserServiceName, false},
420 {content::mojom::kGpuServiceName, false},
421 {content::mojom::kRendererServiceName, false},
422 // Do terminate for some mash-specific cases.
423 {ui::mojom::kServiceName, true},
424 {ash::mojom::kServiceName, true},
425 };
426 ChromeContentBrowserClient client;
427 for (const auto& test : kTestCases) {
428 service_manager::Identity id(test.service_name);
429 EXPECT_EQ(test.expect_terminate, client.ShouldTerminateOnServiceQuit(id))
430 << "for service name " << test.service_name;
431 }
432}
433
434#endif // defined(OS_CHROMEOS)