blob: 6249451a6940635f3496e6ab900d6a84ef5c70e9 [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"
msramek1f4746d2016-08-19 21:37:0714#include "base/memory/ptr_util.h"
15#include "base/message_loop/message_loop.h"
[email protected]10a9bf92013-11-13 23:34:4816#include "base/metrics/field_trial.h"
msramek22328112017-03-23 16:50:2917#include "base/run_loop.h"
msramek1f4746d2016-08-19 21:37:0718#include "base/strings/stringprintf.h"
mpearson3c6d7af2015-05-13 23:59:5319#include "base/strings/utf_string_conversions.h"
avie4d7b6f2015-12-26 00:59:1820#include "build/build_config.h"
msramek1f4746d2016-08-19 21:37:0721#include "chrome/browser/browsing_data/browsing_data_helper.h"
msramek1c2b3ca2017-03-14 17:57:5622#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
[email protected]10a9bf92013-11-13 23:34:4823#include "chrome/browser/search_engines/template_url_service_factory.h"
msramek1f4746d2016-08-19 21:37:0724#include "chrome/test/base/testing_profile.h"
timvolodinea47291a2015-01-23 14:04:4325#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]bf5c532d2014-07-05 00:29:5326#include "components/search_engines/template_url_service.h"
[email protected]10a9bf92013-11-13 23:34:4827#include "components/variations/entropy_provider.h"
bmcquade5d2d9cf32015-06-19 17:42:2828#include "components/variations/variations_associated_data.h"
sdefresne9fb67692015-08-03 18:48:2229#include "components/version_info/version_info.h"
msrameka3c7cfd2017-02-03 13:34:1330#include "content/public/browser/browsing_data_filter_builder.h"
msrameke169ccb2017-04-26 05:21:4131#include "content/public/browser/browsing_data_remover.h"
[email protected]10a9bf92013-11-13 23:34:4832#include "content/public/browser/navigation_controller.h"
33#include "content/public/browser/navigation_entry.h"
msramek22328112017-03-23 16:50:2934#include "content/public/browser/storage_partition.h"
[email protected]10a9bf92013-11-13 23:34:4835#include "content/public/browser/web_contents.h"
[email protected]30335fdf02014-02-26 19:51:2736#include "content/public/common/content_switches.h"
bmcquade5d2d9cf32015-06-19 17:42:2837#include "content/public/test/test_browser_thread_bundle.h"
Brett Wilson0748bf412016-11-22 17:55:4638#include "media/media_features.h"
msramek1f4746d2016-08-19 21:37:0739#include "testing/gmock/include/gmock/gmock.h"
[email protected]3d831992013-07-04 01:13:2940#include "testing/gtest/include/gtest/gtest.h"
[email protected]5f5ef802013-07-04 16:11:1341#include "url/gurl.h"
[email protected]3d831992013-07-04 01:13:2942
jam1c5a91492016-02-24 20:47:5343#if !defined(OS_ANDROID)
thestigf80564462015-09-29 23:12:0844#include "chrome/browser/ui/browser.h"
45#include "chrome/browser/ui/tabs/tab_strip_model.h"
bengre8a146f2016-03-10 01:20:2246#include "chrome/common/pref_names.h"
thestigf80564462015-09-29 23:12:0847#include "chrome/test/base/browser_with_test_window_test.h"
48#include "chrome/test/base/search_test_utils.h"
49#endif
50
James Cooked46d842017-10-13 19:41:1751#if defined(OS_CHROMEOS)
52#include "ash/public/interfaces/constants.mojom.h"
53#include "content/public/common/service_names.mojom.h"
54#include "services/ui/public/interfaces/constants.mojom.h"
55#endif
56
msrameka3c7cfd2017-02-03 13:34:1357using content::BrowsingDataFilterBuilder;
msramek1f4746d2016-08-19 21:37:0758using testing::_;
mlamourieb40d552015-02-05 00:57:0859using ChromeContentBrowserClientTest = testing::Test;
[email protected]3d831992013-07-04 01:13:2960
[email protected]3d831992013-07-04 01:13:2961TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) {
62 ChromeContentBrowserClient client;
63 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test")));
64 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com")));
65 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com")));
66}
67
jam1c5a91492016-02-24 20:47:5368// BrowserWithTestWindowTest doesn't work on Android.
69#if !defined(OS_ANDROID)
mlamourieb40d552015-02-05 00:57:0870
peterbbcccc12015-02-11 22:23:3371using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest;
72
73static void DidOpenURLForWindowTest(content::WebContents** target_contents,
74 content::WebContents* opened_contents) {
75 DCHECK(target_contents);
76
77 *target_contents = opened_contents;
78}
79
bengre8a146f2016-03-10 01:20:2280TEST_F(ChromeContentBrowserClientWindowTest, IsDataSaverEnabled) {
81 ChromeContentBrowserClient client;
82 content::BrowserContext* context = browser()->profile();
83 EXPECT_FALSE(client.IsDataSaverEnabled(context));
84 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDataSaverEnabled, true);
85 EXPECT_TRUE(client.IsDataSaverEnabled(context));
86}
87
mlamourieb40d552015-02-05 00:57:0888// This test opens two URLs using ContentBrowserClient::OpenURL. It expects the
89// URLs to be opened in new tabs and activated, changing the active tabs after
90// each call and increasing the tab count by 2.
91TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) {
92 ChromeContentBrowserClient client;
93
94 int previous_count = browser()->tab_strip_model()->count();
95
96 GURL urls[] = { GURL("https://www.google.com"),
97 GURL("https://www.chromium.org") };
98
99 for (const GURL& url : urls) {
nick3b04f322016-08-31 19:29:19100 content::OpenURLParams params(url, content::Referrer(),
101 WindowOpenDisposition::NEW_FOREGROUND_TAB,
102 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false);
peterbbcccc12015-02-11 22:23:33103 // TODO(peter): We should have more in-depth browser tests for the window
104 // opening functionality, which also covers Android. This test can currently
105 // only be ran on platforms where OpenURL is implemented synchronously.
106 // See https://crbug.com/457667.
107 content::WebContents* web_contents = nullptr;
108 client.OpenURL(browser()->profile(),
109 params,
110 base::Bind(&DidOpenURLForWindowTest, &web_contents));
111
112 EXPECT_TRUE(web_contents);
mlamourieb40d552015-02-05 00:57:08113
114 content::WebContents* active_contents = browser()->tab_strip_model()->
115 GetActiveWebContents();
peterbbcccc12015-02-11 22:23:33116 EXPECT_EQ(web_contents, active_contents);
mlamourieb40d552015-02-05 00:57:08117 EXPECT_EQ(url, active_contents->GetVisibleURL());
118 }
119
120 EXPECT_EQ(previous_count + 2, browser()->tab_strip_model()->count());
121}
122
jam1c5a91492016-02-24 20:47:53123#endif // !defined(OS_ANDROID)
mlamourieb40d552015-02-05 00:57:08124
Brett Wilson0748bf412016-11-22 17:55:46125#if BUILDFLAG(ENABLE_WEBRTC)
brettwa68ea2b2015-02-01 02:54:07126
[email protected]30335fdf02014-02-26 19:51:27127// NOTE: Any updates to the expectations in these tests should also be done in
128// the browser test WebRtcDisableEncryptionFlagBrowserTest.
129class DisableWebRtcEncryptionFlagTest : public testing::Test {
130 public:
131 DisableWebRtcEncryptionFlagTest()
avi3ef9ec9e2014-12-22 22:50:17132 : from_command_line_(base::CommandLine::NO_PROGRAM),
133 to_command_line_(base::CommandLine::NO_PROGRAM) {}
[email protected]30335fdf02014-02-26 19:51:27134
135 protected:
dchenge1bc7982014-10-30 00:32:40136 void SetUp() override {
[email protected]30335fdf02014-02-26 19:51:27137 from_command_line_.AppendSwitch(switches::kDisableWebRtcEncryption);
138 }
139
sdefresne6e883e42015-07-30 08:05:54140 void MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:27141 ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
142 &to_command_line_,
143 from_command_line_,
144 channel);
145 }
146
avi3ef9ec9e2014-12-22 22:50:17147 base::CommandLine from_command_line_;
148 base::CommandLine to_command_line_;
[email protected]30335fdf02014-02-26 19:51:27149
thestigf80564462015-09-29 23:12:08150 private:
[email protected]30335fdf02014-02-26 19:51:27151 DISALLOW_COPY_AND_ASSIGN(DisableWebRtcEncryptionFlagTest);
152};
153
154TEST_F(DisableWebRtcEncryptionFlagTest, UnknownChannel) {
sdefresne6e883e42015-07-30 08:05:54155 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::UNKNOWN);
[email protected]30335fdf02014-02-26 19:51:27156 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
157}
158
159TEST_F(DisableWebRtcEncryptionFlagTest, CanaryChannel) {
sdefresne6e883e42015-07-30 08:05:54160 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::CANARY);
[email protected]30335fdf02014-02-26 19:51:27161 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
162}
163
164TEST_F(DisableWebRtcEncryptionFlagTest, DevChannel) {
sdefresne6e883e42015-07-30 08:05:54165 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::DEV);
[email protected]30335fdf02014-02-26 19:51:27166 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
167}
168
169TEST_F(DisableWebRtcEncryptionFlagTest, BetaChannel) {
sdefresne6e883e42015-07-30 08:05:54170 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::BETA);
[email protected]30335fdf02014-02-26 19:51:27171#if defined(OS_ANDROID)
172 EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
173#else
174 EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
175#endif
176}
177
178TEST_F(DisableWebRtcEncryptionFlagTest, StableChannel) {
sdefresne6e883e42015-07-30 08:05:54179 MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::STABLE);
[email protected]30335fdf02014-02-26 19:51:27180 EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
181}
182
brettwa68ea2b2015-02-01 02:54:07183#endif // ENABLE_WEBRTC
184
bmcquade5d2d9cf32015-06-19 17:42:28185class BlinkSettingsFieldTrialTest : public testing::Test {
186 public:
bmcquade9dd54cc2015-06-22 16:56:52187 static const char kParserFieldTrialName[];
japhet97188b22017-05-02 21:25:53188 static const char kPreloadScanningFieldTrialName[];
pmeenan9ac669682015-08-17 14:57:03189 static const char kFakeGroupName[];
190 static const char kDefaultGroupName[];
bmcquade9dd54cc2015-06-22 16:56:52191
bmcquade5d2d9cf32015-06-19 17:42:28192 BlinkSettingsFieldTrialTest()
193 : trial_list_(NULL),
194 command_line_(base::CommandLine::NO_PROGRAM) {}
195
196 void SetUp() override {
197 command_line_.AppendSwitchASCII(
198 switches::kProcessType, switches::kRendererProcess);
199 }
200
201 void TearDown() override {
202 variations::testing::ClearAllVariationParams();
203 }
204
pmeenan9ac669682015-08-17 14:57:03205 void CreateFieldTrial(const char* trial_name, const char* group_name) {
206 base::FieldTrialList::CreateFieldTrial(trial_name, group_name);
bmcquade5d2d9cf32015-06-19 17:42:28207 }
208
bmcquade9dd54cc2015-06-22 16:56:52209 void CreateFieldTrialWithParams(
210 const char* trial_name,
pmeenan9ac669682015-08-17 14:57:03211 const char* group_name,
bmcquade9dd54cc2015-06-22 16:56:52212 const char* key1, const char* value1,
213 const char* key2, const char* value2) {
bmcquade5d2d9cf32015-06-19 17:42:28214 std::map<std::string, std::string> params;
bmcquade9dd54cc2015-06-22 16:56:52215 params.insert(std::make_pair(key1, value1));
216 params.insert(std::make_pair(key2, value2));
pmeenan9ac669682015-08-17 14:57:03217 CreateFieldTrial(trial_name, kFakeGroupName);
218 variations::AssociateVariationParams(trial_name, kFakeGroupName, params);
bmcquade5d2d9cf32015-06-19 17:42:28219 }
220
221 void AppendContentBrowserClientSwitches() {
222 client_.AppendExtraCommandLineSwitches(&command_line_, kFakeChildProcessId);
223 }
224
225 const base::CommandLine& command_line() const {
226 return command_line_;
227 }
228
229 void AppendBlinkSettingsSwitch(const char* value) {
230 command_line_.AppendSwitchASCII(switches::kBlinkSettings, value);
231 }
232
233 private:
234 static const int kFakeChildProcessId = 1;
bmcquade5d2d9cf32015-06-19 17:42:28235
236 ChromeContentBrowserClient client_;
237 base::FieldTrialList trial_list_;
238 base::CommandLine command_line_;
239
240 content::TestBrowserThreadBundle thread_bundle_;
241};
242
bmcquade9dd54cc2015-06-22 16:56:52243const char BlinkSettingsFieldTrialTest::kParserFieldTrialName[] =
bmcquade5d2d9cf32015-06-19 17:42:28244 "BackgroundHtmlParserTokenLimits";
japhet97188b22017-05-02 21:25:53245const char BlinkSettingsFieldTrialTest::kPreloadScanningFieldTrialName[] =
246 "HtmlPreloadScanning";
pmeenan9ac669682015-08-17 14:57:03247const char BlinkSettingsFieldTrialTest::kFakeGroupName[] = "FakeGroup";
248const char BlinkSettingsFieldTrialTest::kDefaultGroupName[] = "Default";
bmcquade5d2d9cf32015-06-19 17:42:28249
250TEST_F(BlinkSettingsFieldTrialTest, NoFieldTrial) {
251 AppendContentBrowserClientSwitches();
252 EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings));
253}
254
255TEST_F(BlinkSettingsFieldTrialTest, FieldTrialWithoutParams) {
pmeenan9ac669682015-08-17 14:57:03256 CreateFieldTrial(kParserFieldTrialName, kFakeGroupName);
bmcquade5d2d9cf32015-06-19 17:42:28257 AppendContentBrowserClientSwitches();
258 EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings));
259}
260
261TEST_F(BlinkSettingsFieldTrialTest, BlinkSettingsSwitchAlreadySpecified) {
262 AppendBlinkSettingsSwitch("foo");
pmeenan9ac669682015-08-17 14:57:03263 CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52264 "key1", "value1", "key2", "value2");
bmcquade5d2d9cf32015-06-19 17:42:28265 AppendContentBrowserClientSwitches();
266 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
267 EXPECT_EQ("foo",
268 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
269}
270
271TEST_F(BlinkSettingsFieldTrialTest, FieldTrialEnabled) {
pmeenan9ac669682015-08-17 14:57:03272 CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52273 "key1", "value1", "key2", "value2");
bmcquade5d2d9cf32015-06-19 17:42:28274 AppendContentBrowserClientSwitches();
275 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
276 EXPECT_EQ("key1=value1,key2=value2",
277 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
278}
279
bmcquade9dd54cc2015-06-22 16:56:52280TEST_F(BlinkSettingsFieldTrialTest, MultipleFieldTrialsEnabled) {
pmeenan9ac669682015-08-17 14:57:03281 CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52282 "key1", "value1", "key2", "value2");
japhet97188b22017-05-02 21:25:53283 CreateFieldTrialWithParams(kPreloadScanningFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52284 "keyA", "valueA", "keyB", "valueB");
285 AppendContentBrowserClientSwitches();
286 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
287 EXPECT_EQ("key1=value1,key2=value2,keyA=valueA,keyB=valueB",
288 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
289}
290
291TEST_F(BlinkSettingsFieldTrialTest, MultipleFieldTrialsDuplicateKeys) {
pmeenan9ac669682015-08-17 14:57:03292 CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52293 "key1", "value1", "key2", "value2");
japhet97188b22017-05-02 21:25:53294 CreateFieldTrialWithParams(kPreloadScanningFieldTrialName, kFakeGroupName,
bmcquade9dd54cc2015-06-22 16:56:52295 "key2", "duplicate", "key3", "value3");
296 AppendContentBrowserClientSwitches();
297 EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings));
298 EXPECT_EQ("key1=value1,key2=value2,key2=duplicate,key3=value3",
299 command_line().GetSwitchValueASCII(switches::kBlinkSettings));
300}
301
jam1c5a91492016-02-24 20:47:53302#if !defined(OS_ANDROID)
[email protected]10a9bf92013-11-13 23:34:48303namespace content {
304
305class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest {
306 protected:
dchenge1bc7982014-10-30 00:32:40307 void SetUp() override {
[email protected]10a9bf92013-11-13 23:34:48308 BrowserWithTestWindowTest::SetUp();
309 field_trial_list_.reset(new base::FieldTrialList(
robliao79393ffb2016-09-21 18:45:29310 base::MakeUnique<metrics::SHA1EntropyProvider>("42")));
[email protected]10a9bf92013-11-13 23:34:48311 }
312
313 void InstallTemplateURLWithNewTabPage(GURL new_tab_page_url) {
314 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
315 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
316 TemplateURLService* template_url_service =
317 TemplateURLServiceFactory::GetForProfile(browser()->profile());
thestigf80564462015-09-29 23:12:08318 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
[email protected]10a9bf92013-11-13 23:34:48319
320 TemplateURLData data;
mpearson3c6d7af2015-05-13 23:59:53321 data.SetShortName(base::ASCIIToUTF16("foo.com"));
[email protected]10a9bf92013-11-13 23:34:48322 data.SetURL("http://foo.com/url?bar={searchTerms}");
323 data.new_tab_url = new_tab_page_url.spec();
avi8a64b715b2016-09-02 17:30:04324 TemplateURL* template_url =
325 template_url_service->Add(base::MakeUnique<TemplateURL>(data));
[email protected]f1cb5582014-04-25 07:35:26326 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
[email protected]10a9bf92013-11-13 23:34:48327 }
328
dcheng4af48582016-04-19 00:29:35329 std::unique_ptr<base::FieldTrialList> field_trial_list_;
[email protected]10a9bf92013-11-13 23:34:48330};
331
332TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) {
333 const GURL url_original("chrome://newtab");
334 const GURL url_rewritten("https://www.example.com/newtab");
335 InstallTemplateURLWithNewTabPage(url_rewritten);
336 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
337 "Group1 use_cacheable_ntp:1"));
338
339 AddTab(browser(), GURL("chrome://blank"));
340 NavigateAndCommitActiveTab(url_original);
341
342 NavigationEntry* entry = browser()->tab_strip_model()->
343 GetActiveWebContents()->GetController().GetLastCommittedEntry();
344 ASSERT_TRUE(entry != NULL);
345 EXPECT_EQ(url_rewritten, entry->GetURL());
346 EXPECT_EQ(url_original, entry->GetVirtualURL());
347}
348
349} // namespace content
jam1c5a91492016-02-24 20:47:53350#endif // !defined(OS_ANDROID)
kerrnela67fad52017-06-14 20:18:16351
352class ChromeContentBrowserClientGetLoggingFileTest : public testing::Test {};
353
354TEST_F(ChromeContentBrowserClientGetLoggingFileTest, GetLoggingFile) {
Michael Giuffrida6802ffe2017-09-29 03:40:25355 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
kerrnela67fad52017-06-14 20:18:16356 ChromeContentBrowserClient client;
357 base::FilePath log_file_name;
Michael Giuffrida6802ffe2017-09-29 03:40:25358 EXPECT_FALSE(client.GetLoggingFileName(cmd_line).empty());
359}
360
361TEST_F(ChromeContentBrowserClientGetLoggingFileTest,
362 GetLoggingFileFromCommandLine) {
363 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
364 cmd_line.AppendSwitchASCII(switches::kLogFile, "test_log.txt");
365 ChromeContentBrowserClient client;
366 base::FilePath log_file_name;
367 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("test_log.txt")).value(),
368 client.GetLoggingFileName(cmd_line).value());
kerrnela67fad52017-06-14 20:18:16369}
dbeam25472e0c2017-06-23 19:02:31370
371class TestChromeContentBrowserClient : public ChromeContentBrowserClient {
372 public:
373 using ChromeContentBrowserClient::HandleWebUI;
374 using ChromeContentBrowserClient::HandleWebUIReverse;
375};
376
377TEST(ChromeContentBrowserClientTest, HandleWebUI) {
378 TestChromeContentBrowserClient test_content_browser_client;
379 const GURL http_help("http://help/");
380 GURL should_not_redirect = http_help;
381 test_content_browser_client.HandleWebUI(&should_not_redirect, nullptr);
382 EXPECT_EQ(http_help, should_not_redirect);
383
384 const GURL chrome_help("chrome://help/");
385 GURL should_redirect = chrome_help;
386 test_content_browser_client.HandleWebUI(&should_redirect, nullptr);
387 EXPECT_NE(chrome_help, should_redirect);
388}
389
390TEST(ChromeContentBrowserClientTest, HandleWebUIReverse) {
391 TestChromeContentBrowserClient test_content_browser_client;
392 GURL http_settings("http://settings/");
393 EXPECT_FALSE(
394 test_content_browser_client.HandleWebUIReverse(&http_settings, nullptr));
395 GURL chrome_settings("chrome://settings/");
396 EXPECT_TRUE(test_content_browser_client.HandleWebUIReverse(&chrome_settings,
397 nullptr));
398}
Matt Falkenhagen8479b202017-07-14 04:35:31399
400TEST(ChromeContentBrowserClientTest, GetMetricSuffixForURL) {
401 ChromeContentBrowserClient client;
402 // Search is detected.
403 EXPECT_EQ("search", client.GetMetricSuffixForURL(GURL(
404 "https://www.google.co.jp/search?q=whatsgoingon")));
405 // Not a Search host.
406 EXPECT_EQ("", client.GetMetricSuffixForURL(GURL(
407 "https://www.google.example.com/search?q=whatsgoingon")));
408 // For now, non-https is considered a Search host.
409 EXPECT_EQ("search", client.GetMetricSuffixForURL(
410 GURL("http://www.google.com/search?q=whatsgoingon")));
411 // Not a Search result page (no query).
412 EXPECT_EQ("", client.GetMetricSuffixForURL(
413 GURL("https://www.google.com/search?notaquery=nope")));
414}
James Cooked46d842017-10-13 19:41:17415
416#if defined(OS_CHROMEOS)
417
418// This behavior only matters on Chrome OS, which is why this isn't wrapped in
419// ENABLE_MASH_PACKAGED_SERVICES (which is used for Linux Ozone).
420TEST(ChromeContentBrowserClientTest, ShouldTerminateOnServiceQuit) {
421 const struct {
422 std::string service_name;
423 bool expect_terminate;
424 } kTestCases[] = {
425 // Don't terminate for invalid service names.
426 {"", false},
427 {"unknown-name", false},
428 // Don't terminate for some well-known browser services.
429 {content::mojom::kBrowserServiceName, false},
430 {content::mojom::kGpuServiceName, false},
431 {content::mojom::kRendererServiceName, false},
432 // Do terminate for some mash-specific cases.
433 {ui::mojom::kServiceName, true},
434 {ash::mojom::kServiceName, true},
435 };
436 ChromeContentBrowserClient client;
437 for (const auto& test : kTestCases) {
438 service_manager::Identity id(test.service_name);
439 EXPECT_EQ(test.expect_terminate, client.ShouldTerminateOnServiceQuit(id))
440 << "for service name " << test.service_name;
441 }
442}
443
444#endif // defined(OS_CHROMEOS)