chrome_content_browser_client_unittest.cc 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. // 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. #include "chrome/browser/chrome_content_browser_client.h"
  5. #include <list>
  6. #include <map>
  7. #include <memory>
  8. #include "ash/webui/camera_app_ui/url_constants.h"
  9. #include "base/bind.h"
  10. #include "base/callback_helpers.h"
  11. #include "base/command_line.h"
  12. #include "base/memory/raw_ptr.h"
  13. #include "base/metrics/field_trial.h"
  14. #include "base/run_loop.h"
  15. #include "base/strings/utf_string_conversions.h"
  16. #include "base/test/gtest_util.h"
  17. #include "base/test/metrics/histogram_tester.h"
  18. #include "base/test/scoped_feature_list.h"
  19. #include "base/values.h"
  20. #include "build/build_config.h"
  21. #include "build/chromeos_buildflags.h"
  22. #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
  23. #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
  24. #include "chrome/browser/first_party_sets/first_party_sets_pref_names.h"
  25. #include "chrome/browser/search_engines/template_url_service_factory.h"
  26. #include "chrome/browser/web_applications/web_app_helpers.h"
  27. #include "chrome/common/chrome_features.h"
  28. #include "chrome/common/chrome_switches.h"
  29. #include "chrome/common/webui_url_constants.h"
  30. #include "chrome/test/base/chrome_render_view_host_test_harness.h"
  31. #include "chrome/test/base/scoped_testing_local_state.h"
  32. #include "chrome/test/base/testing_browser_process.h"
  33. #include "chrome/test/base/testing_profile.h"
  34. #include "components/browsing_data/content/browsing_data_helper.h"
  35. #include "components/captive_portal/core/buildflags.h"
  36. #include "components/content_settings/core/browser/host_content_settings_map.h"
  37. #include "components/policy/core/common/policy_pref_names.h"
  38. #include "components/search_engines/template_url_service.h"
  39. #include "components/services/storage/public/cpp/storage_prefs.h"
  40. #include "components/variations/variations_associated_data.h"
  41. #include "components/version_info/version_info.h"
  42. #include "content/public/browser/browsing_data_filter_builder.h"
  43. #include "content/public/browser/browsing_data_remover.h"
  44. #include "content/public/browser/navigation_controller.h"
  45. #include "content/public/browser/navigation_entry.h"
  46. #include "content/public/browser/site_instance.h"
  47. #include "content/public/browser/site_isolation_policy.h"
  48. #include "content/public/browser/storage_partition.h"
  49. #include "content/public/browser/web_contents.h"
  50. #include "content/public/common/content_switches.h"
  51. #include "content/public/test/browser_task_environment.h"
  52. #include "content/public/test/mock_render_process_host.h"
  53. #include "media/media_buildflags.h"
  54. #include "net/base/url_util.h"
  55. #include "testing/gmock/include/gmock/gmock.h"
  56. #include "testing/gtest/include/gtest/gtest.h"
  57. #include "third_party/blink/public/common/switches.h"
  58. #include "url/gurl.h"
  59. #if !BUILDFLAG(IS_ANDROID)
  60. #include "chrome/browser/ui/browser.h"
  61. #include "chrome/browser/ui/tabs/tab_strip_model.h"
  62. #include "chrome/common/pref_names.h"
  63. #include "chrome/test/base/browser_with_test_window_test.h"
  64. #include "chrome/test/base/search_test_utils.h"
  65. #include "ui/base/page_transition_types.h"
  66. #else
  67. #include "base/system/sys_info.h"
  68. #endif
  69. #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
  70. #include "components/captive_portal/content/captive_portal_tab_helper.h"
  71. #endif
  72. #if BUILDFLAG(IS_CHROMEOS_ASH)
  73. #include "ash/webui/scanning/url_constants.h"
  74. #include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
  75. #include "chrome/browser/ash/system_web_apps/test_support/test_system_web_app_manager.h"
  76. #include "chrome/browser/policy/networking/policy_cert_service.h"
  77. #include "chrome/browser/policy/networking/policy_cert_service_factory.h"
  78. #include "chrome/browser/web_applications/web_app_provider.h"
  79. #include "components/user_manager/scoped_user_manager.h"
  80. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  81. #if BUILDFLAG(IS_CHROMEOS)
  82. #include "chrome/browser/policy/system_features_disable_list_policy_handler.h"
  83. #endif // BUILDFLAG(IS_CHROMEOS)
  84. #if BUILDFLAG(ENABLE_EXTENSIONS)
  85. #include "chrome/browser/web_applications/isolation_prefs_utils.h"
  86. #include "chrome/browser/web_applications/web_app.h"
  87. #include "content/public/browser/storage_partition_config.h"
  88. #include "third_party/blink/public/common/features.h"
  89. #endif // BUILDFLAG(ENABLE_EXTENSIONS)
  90. using content::BrowsingDataFilterBuilder;
  91. using testing::_;
  92. using testing::NotNull;
  93. class ChromeContentBrowserClientTest : public testing::Test {
  94. public:
  95. ChromeContentBrowserClientTest()
  96. #if BUILDFLAG(IS_CHROMEOS_ASH)
  97. : test_system_web_app_manager_creator_(base::BindRepeating(
  98. &ChromeContentBrowserClientTest::CreateSystemWebAppManager,
  99. base::Unretained(this)))
  100. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  101. {
  102. }
  103. protected:
  104. #if BUILDFLAG(IS_CHROMEOS_ASH)
  105. std::unique_ptr<KeyedService> CreateSystemWebAppManager(Profile* profile) {
  106. auto* provider = web_app::WebAppProvider::GetForLocalAppsUnchecked(profile);
  107. DCHECK(provider);
  108. // Unit tests need SWAs from production. Creates real SystemWebAppManager
  109. // instead of `TestSystemWebAppManager::BuildDefault()` for
  110. // `TestingProfile`.
  111. auto swa_manager = std::make_unique<ash::SystemWebAppManager>(profile);
  112. swa_manager->ConnectSubsystems(provider);
  113. return swa_manager;
  114. }
  115. // The custom manager creator should be constructed before `TestingProfile`.
  116. ash::TestSystemWebAppManagerCreator test_system_web_app_manager_creator_;
  117. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  118. content::BrowserTaskEnvironment task_environment_;
  119. TestingProfile profile_;
  120. };
  121. TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) {
  122. ChromeContentBrowserClient client;
  123. EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test")));
  124. EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com")));
  125. EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com")));
  126. }
  127. // BrowserWithTestWindowTest doesn't work on Android.
  128. #if !BUILDFLAG(IS_ANDROID)
  129. using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest;
  130. static void DidOpenURLForWindowTest(content::WebContents** target_contents,
  131. content::WebContents* opened_contents) {
  132. DCHECK(target_contents);
  133. *target_contents = opened_contents;
  134. }
  135. // This test opens two URLs using ContentBrowserClient::OpenURL. It expects the
  136. // URLs to be opened in new tabs and activated, changing the active tabs after
  137. // each call and increasing the tab count by 2.
  138. TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) {
  139. ChromeContentBrowserClient client;
  140. int previous_count = browser()->tab_strip_model()->count();
  141. GURL urls[] = {GURL("https://www.google.com"),
  142. GURL("https://www.chromium.org")};
  143. for (const GURL& url : urls) {
  144. content::OpenURLParams params(url, content::Referrer(),
  145. WindowOpenDisposition::NEW_FOREGROUND_TAB,
  146. ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false);
  147. // TODO(peter): We should have more in-depth browser tests for the window
  148. // opening functionality, which also covers Android. This test can currently
  149. // only be ran on platforms where OpenURL is implemented synchronously.
  150. // See https://crbug.com/457667.
  151. content::WebContents* web_contents = nullptr;
  152. scoped_refptr<content::SiteInstance> site_instance =
  153. content::SiteInstance::Create(browser()->profile());
  154. client.OpenURL(site_instance.get(), params,
  155. base::BindOnce(&DidOpenURLForWindowTest, &web_contents));
  156. EXPECT_TRUE(web_contents);
  157. content::WebContents* active_contents =
  158. browser()->tab_strip_model()->GetActiveWebContents();
  159. EXPECT_EQ(web_contents, active_contents);
  160. EXPECT_EQ(url, active_contents->GetVisibleURL());
  161. }
  162. EXPECT_EQ(previous_count + 2, browser()->tab_strip_model()->count());
  163. }
  164. // TODO(crbug.com/566091): Remove the need for ShouldStayInParentProcessForNTP()
  165. // and associated test.
  166. TEST_F(ChromeContentBrowserClientWindowTest, ShouldStayInParentProcessForNTP) {
  167. ChromeContentBrowserClient client;
  168. // Remote 3P NTPs effectively have a URL chrome-search://remote-ntp. This
  169. // is so an iframe with the src of chrome-search://most-visited/title.html can
  170. // be embedded within the remote NTP.
  171. scoped_refptr<content::SiteInstance> site_instance =
  172. content::SiteInstance::CreateForURL(browser()->profile(),
  173. GURL("chrome-search://remote-ntp"));
  174. EXPECT_TRUE(client.ShouldStayInParentProcessForNTP(
  175. GURL("chrome-search://remote-ntp"), site_instance.get()));
  176. site_instance = content::SiteInstance::CreateForURL(
  177. browser()->profile(), GURL("chrome://new-tab-page"));
  178. // chrome://new-tab-page is an NTP replacing local-ntp and supports OOPIFs.
  179. // ShouldStayInParentProcessForNTP() should only return true for NTPs hosted
  180. // under the chrome-search: scheme.
  181. EXPECT_FALSE(client.ShouldStayInParentProcessForNTP(
  182. GURL("chrome://new-tab-page"), site_instance.get()));
  183. }
  184. TEST_F(ChromeContentBrowserClientWindowTest, OverrideNavigationParams) {
  185. ChromeContentBrowserClient client;
  186. ui::PageTransition transition;
  187. bool is_renderer_initiated;
  188. content::Referrer referrer = content::Referrer();
  189. absl::optional<url::Origin> initiator_origin = absl::nullopt;
  190. scoped_refptr<content::SiteInstance> site_instance =
  191. content::SiteInstance::CreateForURL(browser()->profile(),
  192. GURL("chrome-search://remote-ntp"));
  193. transition = ui::PAGE_TRANSITION_LINK;
  194. is_renderer_initiated = true;
  195. // The origin is a placeholder to test that |initiator_origin| is set to
  196. // absl::nullopt and is not meant to represent what would happen in practice.
  197. initiator_origin = url::Origin::Create(GURL("https://www.example.com"));
  198. client.OverrideNavigationParams(site_instance.get(), &transition,
  199. &is_renderer_initiated, &referrer,
  200. &initiator_origin);
  201. EXPECT_TRUE(ui::PageTransitionCoreTypeIs(ui::PAGE_TRANSITION_AUTO_BOOKMARK,
  202. transition));
  203. EXPECT_FALSE(is_renderer_initiated);
  204. EXPECT_EQ(absl::nullopt, initiator_origin);
  205. site_instance = content::SiteInstance::CreateForURL(
  206. browser()->profile(), GURL("chrome://new-tab-page"));
  207. transition = ui::PAGE_TRANSITION_LINK;
  208. is_renderer_initiated = true;
  209. initiator_origin = url::Origin::Create(GURL("https://www.example.com"));
  210. client.OverrideNavigationParams(site_instance.get(), &transition,
  211. &is_renderer_initiated, &referrer,
  212. &initiator_origin);
  213. EXPECT_TRUE(ui::PageTransitionCoreTypeIs(ui::PAGE_TRANSITION_AUTO_BOOKMARK,
  214. transition));
  215. EXPECT_FALSE(is_renderer_initiated);
  216. EXPECT_EQ(absl::nullopt, initiator_origin);
  217. // No change for transitions that are not PAGE_TRANSITION_LINK.
  218. site_instance = content::SiteInstance::CreateForURL(
  219. browser()->profile(), GURL("chrome://new-tab-page"));
  220. transition = ui::PAGE_TRANSITION_TYPED;
  221. client.OverrideNavigationParams(site_instance.get(), &transition,
  222. &is_renderer_initiated, &referrer,
  223. &initiator_origin);
  224. EXPECT_TRUE(
  225. ui::PageTransitionCoreTypeIs(ui::PAGE_TRANSITION_TYPED, transition));
  226. // No change for transitions on a non-NTP page.
  227. site_instance = content::SiteInstance::CreateForURL(
  228. browser()->profile(), GURL("https://www.example.com"));
  229. transition = ui::PAGE_TRANSITION_LINK;
  230. client.OverrideNavigationParams(site_instance.get(), &transition,
  231. &is_renderer_initiated, &referrer,
  232. &initiator_origin);
  233. EXPECT_TRUE(
  234. ui::PageTransitionCoreTypeIs(ui::PAGE_TRANSITION_LINK, transition));
  235. }
  236. #endif // !BUILDFLAG(IS_ANDROID)
  237. // NOTE: Any updates to the expectations in these tests should also be done in
  238. // the browser test WebRtcDisableEncryptionFlagBrowserTest.
  239. class DisableWebRtcEncryptionFlagTest : public testing::Test {
  240. public:
  241. DisableWebRtcEncryptionFlagTest()
  242. : from_command_line_(base::CommandLine::NO_PROGRAM),
  243. to_command_line_(base::CommandLine::NO_PROGRAM) {}
  244. DisableWebRtcEncryptionFlagTest(const DisableWebRtcEncryptionFlagTest&) =
  245. delete;
  246. DisableWebRtcEncryptionFlagTest& operator=(
  247. const DisableWebRtcEncryptionFlagTest&) = delete;
  248. protected:
  249. void SetUp() override {
  250. from_command_line_.AppendSwitch(switches::kDisableWebRtcEncryption);
  251. }
  252. void MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel channel) {
  253. ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
  254. &to_command_line_, from_command_line_, channel);
  255. }
  256. base::CommandLine from_command_line_;
  257. base::CommandLine to_command_line_;
  258. };
  259. TEST_F(DisableWebRtcEncryptionFlagTest, UnknownChannel) {
  260. MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::UNKNOWN);
  261. EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
  262. }
  263. TEST_F(DisableWebRtcEncryptionFlagTest, CanaryChannel) {
  264. MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::CANARY);
  265. EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
  266. }
  267. TEST_F(DisableWebRtcEncryptionFlagTest, DevChannel) {
  268. MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::DEV);
  269. EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
  270. }
  271. TEST_F(DisableWebRtcEncryptionFlagTest, BetaChannel) {
  272. MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::BETA);
  273. #if BUILDFLAG(IS_ANDROID)
  274. EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
  275. #else
  276. EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
  277. #endif
  278. }
  279. TEST_F(DisableWebRtcEncryptionFlagTest, StableChannel) {
  280. MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::STABLE);
  281. EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption));
  282. }
  283. class BlinkSettingsFieldTrialTest : public testing::Test {
  284. public:
  285. static const char kDisallowFetchFieldTrialName[];
  286. static const char kFakeGroupName[];
  287. BlinkSettingsFieldTrialTest()
  288. : command_line_(base::CommandLine::NO_PROGRAM),
  289. testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
  290. void SetUp() override {
  291. command_line_.AppendSwitchASCII(switches::kProcessType,
  292. switches::kRendererProcess);
  293. }
  294. void TearDown() override { variations::testing::ClearAllVariationParams(); }
  295. void CreateFieldTrial(const char* trial_name, const char* group_name) {
  296. base::FieldTrialList::CreateFieldTrial(trial_name, group_name);
  297. }
  298. void CreateFieldTrialWithParams(const char* trial_name,
  299. const char* group_name,
  300. const char* key1,
  301. const char* value1,
  302. const char* key2,
  303. const char* value2) {
  304. std::map<std::string, std::string> params;
  305. params.insert(std::make_pair(key1, value1));
  306. params.insert(std::make_pair(key2, value2));
  307. CreateFieldTrial(trial_name, kFakeGroupName);
  308. variations::AssociateVariationParams(trial_name, kFakeGroupName, params);
  309. }
  310. void AppendContentBrowserClientSwitches() {
  311. client_.AppendExtraCommandLineSwitches(&command_line_, kFakeChildProcessId);
  312. }
  313. const base::CommandLine& command_line() const { return command_line_; }
  314. void AppendBlinkSettingsSwitch(const char* value) {
  315. command_line_.AppendSwitchASCII(blink::switches::kBlinkSettings, value);
  316. }
  317. private:
  318. static const int kFakeChildProcessId = 1;
  319. ChromeContentBrowserClient client_;
  320. base::CommandLine command_line_;
  321. content::BrowserTaskEnvironment task_environment_;
  322. ScopedTestingLocalState testing_local_state_;
  323. };
  324. const char BlinkSettingsFieldTrialTest::kDisallowFetchFieldTrialName[] =
  325. "DisallowFetchForDocWrittenScriptsInMainFrame";
  326. const char BlinkSettingsFieldTrialTest::kFakeGroupName[] = "FakeGroup";
  327. TEST_F(BlinkSettingsFieldTrialTest, NoFieldTrial) {
  328. AppendContentBrowserClientSwitches();
  329. EXPECT_FALSE(command_line().HasSwitch(blink::switches::kBlinkSettings));
  330. }
  331. TEST_F(BlinkSettingsFieldTrialTest, FieldTrialWithoutParams) {
  332. CreateFieldTrial(kDisallowFetchFieldTrialName, kFakeGroupName);
  333. AppendContentBrowserClientSwitches();
  334. EXPECT_FALSE(command_line().HasSwitch(blink::switches::kBlinkSettings));
  335. }
  336. TEST_F(BlinkSettingsFieldTrialTest, BlinkSettingsSwitchAlreadySpecified) {
  337. AppendBlinkSettingsSwitch("foo");
  338. CreateFieldTrialWithParams(kDisallowFetchFieldTrialName, kFakeGroupName,
  339. "key1", "value1", "key2", "value2");
  340. AppendContentBrowserClientSwitches();
  341. EXPECT_TRUE(command_line().HasSwitch(blink::switches::kBlinkSettings));
  342. EXPECT_EQ("foo", command_line().GetSwitchValueASCII(
  343. blink::switches::kBlinkSettings));
  344. }
  345. TEST_F(BlinkSettingsFieldTrialTest, FieldTrialEnabled) {
  346. CreateFieldTrialWithParams(kDisallowFetchFieldTrialName, kFakeGroupName,
  347. "key1", "value1", "key2", "value2");
  348. AppendContentBrowserClientSwitches();
  349. EXPECT_TRUE(command_line().HasSwitch(blink::switches::kBlinkSettings));
  350. EXPECT_EQ("key1=value1,key2=value2", command_line().GetSwitchValueASCII(
  351. blink::switches::kBlinkSettings));
  352. }
  353. #if !BUILDFLAG(IS_ANDROID)
  354. namespace content {
  355. class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest {
  356. protected:
  357. void InstallTemplateURLWithNewTabPage(GURL new_tab_page_url) {
  358. TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
  359. profile(),
  360. base::BindRepeating(&TemplateURLServiceFactory::BuildInstanceFor));
  361. TemplateURLService* template_url_service =
  362. TemplateURLServiceFactory::GetForProfile(browser()->profile());
  363. search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
  364. TemplateURLData data;
  365. data.SetShortName(u"foo.com");
  366. data.SetURL("http://foo.com/url?bar={searchTerms}");
  367. data.new_tab_url = new_tab_page_url.spec();
  368. TemplateURL* template_url =
  369. template_url_service->Add(std::make_unique<TemplateURL>(data));
  370. template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
  371. }
  372. };
  373. TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) {
  374. const GURL url_original(chrome::kChromeUINewTabURL);
  375. const GURL url_rewritten("https://www.example.com/newtab");
  376. InstallTemplateURLWithNewTabPage(url_rewritten);
  377. ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
  378. "InstantExtended", "Group1 use_cacheable_ntp:1"));
  379. AddTab(browser(), GURL(url::kAboutBlankURL));
  380. NavigateAndCommitActiveTab(url_original);
  381. NavigationEntry* entry = browser()
  382. ->tab_strip_model()
  383. ->GetActiveWebContents()
  384. ->GetController()
  385. .GetLastCommittedEntry();
  386. ASSERT_THAT(entry, NotNull());
  387. EXPECT_EQ(url_rewritten, entry->GetURL());
  388. EXPECT_EQ(url_original, entry->GetVirtualURL());
  389. }
  390. } // namespace content
  391. #endif // !BUILDFLAG(IS_ANDROID)
  392. class ChromeContentBrowserClientGetLoggingFileTest : public testing::Test {};
  393. TEST_F(ChromeContentBrowserClientGetLoggingFileTest, GetLoggingFile) {
  394. base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
  395. ChromeContentBrowserClient client;
  396. base::FilePath log_file_name;
  397. EXPECT_FALSE(client.GetLoggingFileName(cmd_line).empty());
  398. }
  399. TEST_F(ChromeContentBrowserClientGetLoggingFileTest,
  400. GetLoggingFileFromCommandLine) {
  401. base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
  402. cmd_line.AppendSwitchASCII(switches::kLogFile, "test_log.txt");
  403. ChromeContentBrowserClient client;
  404. base::FilePath log_file_name;
  405. EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("test_log.txt")).value(),
  406. client.GetLoggingFileName(cmd_line).value());
  407. }
  408. class TestChromeContentBrowserClient : public ChromeContentBrowserClient {
  409. public:
  410. using ChromeContentBrowserClient::HandleWebUI;
  411. using ChromeContentBrowserClient::HandleWebUIReverse;
  412. };
  413. TEST_F(ChromeContentBrowserClientTest, HandleWebUI) {
  414. TestChromeContentBrowserClient test_content_browser_client;
  415. const GURL http_help("http://help/");
  416. GURL should_not_redirect = http_help;
  417. test_content_browser_client.HandleWebUI(&should_not_redirect, &profile_);
  418. EXPECT_EQ(http_help, should_not_redirect);
  419. const GURL chrome_help(chrome::kChromeUIHelpURL);
  420. GURL should_redirect = chrome_help;
  421. test_content_browser_client.HandleWebUI(&should_redirect, &profile_);
  422. EXPECT_NE(chrome_help, should_redirect);
  423. }
  424. TEST_F(ChromeContentBrowserClientTest, HandleWebUIReverse) {
  425. TestChromeContentBrowserClient test_content_browser_client;
  426. GURL http_settings("http://settings/");
  427. EXPECT_FALSE(test_content_browser_client.HandleWebUIReverse(&http_settings,
  428. &profile_));
  429. GURL chrome_settings(chrome::kChromeUISettingsURL);
  430. EXPECT_TRUE(test_content_browser_client.HandleWebUIReverse(&chrome_settings,
  431. &profile_));
  432. }
  433. TEST_F(ChromeContentBrowserClientTest, RedirectSiteDataURL) {
  434. base::test::ScopedFeatureList feature_list(
  435. features::kConsolidatedSiteStorageControls);
  436. TestChromeContentBrowserClient test_content_browser_client;
  437. base::HistogramTester histogram_tester;
  438. const std::string histogram_name = "Settings.AllSites.DeprecatedRedirect";
  439. GURL settings_url = GURL(chrome::kChromeUISettingsURL);
  440. settings_url = net::AppendQueryParameter(settings_url, "foo", "bar");
  441. GURL::Replacements replacements;
  442. replacements.SetPathStr(chrome::kChromeUISiteDataDeprecatedPath);
  443. GURL site_data_url = settings_url.ReplaceComponents(replacements);
  444. replacements.SetPathStr(chrome::kChromeUIAllSitesPath);
  445. GURL all_sites_url = settings_url.ReplaceComponents(replacements);
  446. test_content_browser_client.HandleWebUI(&site_data_url, &profile_);
  447. EXPECT_EQ(all_sites_url, site_data_url);
  448. histogram_tester.ExpectUniqueSample(histogram_name, true, 1);
  449. test_content_browser_client.HandleWebUI(&all_sites_url, &profile_);
  450. histogram_tester.ExpectBucketCount(histogram_name, false, 1);
  451. histogram_tester.ExpectTotalCount(histogram_name, 2);
  452. }
  453. #if BUILDFLAG(IS_CHROMEOS)
  454. class ChromeContentSettingsRedirectTest
  455. : public ChromeContentBrowserClientTest {
  456. public:
  457. ChromeContentSettingsRedirectTest()
  458. : testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
  459. protected:
  460. ScopedTestingLocalState testing_local_state_;
  461. };
  462. TEST_F(ChromeContentSettingsRedirectTest, RedirectSettingsURL) {
  463. TestChromeContentBrowserClient test_content_browser_client;
  464. const GURL settings_url(chrome::kChromeUISettingsURL);
  465. GURL dest_url = settings_url;
  466. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  467. EXPECT_EQ(settings_url, dest_url);
  468. base::Value list(base::Value::Type::LIST);
  469. list.Append(static_cast<int>(policy::SystemFeature::kBrowserSettings));
  470. testing_local_state_.Get()->Set(
  471. policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
  472. dest_url = settings_url;
  473. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  474. EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
  475. }
  476. #if BUILDFLAG(IS_CHROMEOS_ASH)
  477. TEST_F(ChromeContentSettingsRedirectTest, RedirectOSSettingsURL) {
  478. TestChromeContentBrowserClient test_content_browser_client;
  479. const GURL os_settings_url(chrome::kChromeUIOSSettingsURL);
  480. GURL dest_url = os_settings_url;
  481. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  482. EXPECT_EQ(os_settings_url, dest_url);
  483. base::Value list(base::Value::Type::LIST);
  484. list.Append(static_cast<int>(policy::SystemFeature::kOsSettings));
  485. testing_local_state_.Get()->Set(
  486. policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
  487. dest_url = os_settings_url;
  488. EXPECT_TRUE(test_content_browser_client.HandleWebUI(&dest_url, &profile_));
  489. EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
  490. GURL os_settings_pwa_url =
  491. GURL(chrome::kChromeUIOSSettingsURL).Resolve("pwa.html");
  492. dest_url = os_settings_pwa_url;
  493. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  494. EXPECT_EQ(os_settings_pwa_url, dest_url);
  495. }
  496. TEST_F(ChromeContentSettingsRedirectTest, RedirectScanningAppURL) {
  497. TestChromeContentBrowserClient test_content_browser_client;
  498. const GURL scanning_app_url(ash::kChromeUIScanningAppUrl);
  499. GURL dest_url = scanning_app_url;
  500. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  501. EXPECT_EQ(scanning_app_url, dest_url);
  502. base::Value list(base::Value::Type::LIST);
  503. list.Append(static_cast<int>(policy::SystemFeature::kScanning));
  504. testing_local_state_.Get()->Set(
  505. policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
  506. dest_url = scanning_app_url;
  507. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  508. EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
  509. }
  510. TEST_F(ChromeContentSettingsRedirectTest, RedirectCameraAppURL) {
  511. // This test needs `SystemWebAppType::CAMERA` (`CameraSystemAppDelegate`)
  512. // registered in `SystemWebAppManager`.
  513. TestChromeContentBrowserClient test_content_browser_client;
  514. const GURL camera_app_url(ash::kChromeUICameraAppMainURL);
  515. GURL dest_url = camera_app_url;
  516. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  517. EXPECT_EQ(camera_app_url, dest_url);
  518. base::Value list(base::Value::Type::LIST);
  519. list.Append(static_cast<int>(policy::SystemFeature::kCamera));
  520. testing_local_state_.Get()->Set(
  521. policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
  522. dest_url = camera_app_url;
  523. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  524. EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
  525. }
  526. TEST_F(ChromeContentSettingsRedirectTest, RedirectHelpURL) {
  527. TestChromeContentBrowserClient test_content_browser_client;
  528. const GURL help_url(chrome::kChromeUIHelpURL);
  529. GURL dest_url = help_url;
  530. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  531. EXPECT_EQ(GURL("chrome://settings/help"), dest_url);
  532. base::Value list(base::Value::Type::LIST);
  533. list.Append(static_cast<int>(policy::SystemFeature::kBrowserSettings));
  534. testing_local_state_.Get()->Set(
  535. policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
  536. dest_url = help_url;
  537. test_content_browser_client.HandleWebUI(&dest_url, &profile_);
  538. EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
  539. }
  540. namespace {
  541. constexpr char kEmail[] = "test@test.com";
  542. std::unique_ptr<KeyedService> CreateTestPolicyCertService(
  543. content::BrowserContext* context) {
  544. return policy::PolicyCertService::CreateForTesting(
  545. Profile::FromBrowserContext(context));
  546. }
  547. } // namespace
  548. // Test to verify that the PolicyCertService is correctly updated when a policy
  549. // provided trust anchor is used.
  550. class ChromeContentSettingsPolicyTrustAnchor
  551. : public ChromeContentBrowserClientTest {
  552. public:
  553. ChromeContentSettingsPolicyTrustAnchor()
  554. : testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
  555. void SetUp() override {
  556. // Add a profile
  557. auto fake_user_manager = std::make_unique<ash::FakeChromeUserManager>();
  558. AccountId account_id = AccountId::FromUserEmailGaiaId(kEmail, "gaia_id");
  559. user_manager::User* user =
  560. fake_user_manager->AddUserWithAffiliationAndTypeAndProfile(
  561. account_id, false /*is_affiliated*/,
  562. user_manager::USER_TYPE_REGULAR, &profile_);
  563. fake_user_manager->UserLoggedIn(account_id, user->username_hash(),
  564. false /* browser_restart */,
  565. false /* is_child */);
  566. scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(
  567. std::move(fake_user_manager));
  568. // Create a PolicyCertServiceFactory
  569. ASSERT_TRUE(
  570. policy::PolicyCertServiceFactory::GetInstance()
  571. ->SetTestingFactoryAndUse(
  572. &profile_, base::BindRepeating(&CreateTestPolicyCertService)));
  573. }
  574. void TearDown() override { scoped_user_manager_.reset(); }
  575. protected:
  576. ScopedTestingLocalState testing_local_state_;
  577. std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_;
  578. };
  579. TEST_F(ChromeContentSettingsPolicyTrustAnchor, PolicyTrustAnchor) {
  580. ChromeContentBrowserClient client;
  581. EXPECT_FALSE(policy::PolicyCertServiceFactory::GetForProfile(&profile_)
  582. ->UsedPolicyCertificates());
  583. client.OnTrustAnchorUsed(&profile_);
  584. EXPECT_TRUE(policy::PolicyCertServiceFactory::GetForProfile(&profile_)
  585. ->UsedPolicyCertificates());
  586. }
  587. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  588. #endif // BUILDFLAG(IS_CHROMEOS)
  589. class CaptivePortalCheckProcessHost : public content::MockRenderProcessHost {
  590. public:
  591. explicit CaptivePortalCheckProcessHost(
  592. content::BrowserContext* browser_context)
  593. : MockRenderProcessHost(browser_context) {}
  594. CaptivePortalCheckProcessHost(const CaptivePortalCheckProcessHost&) = delete;
  595. CaptivePortalCheckProcessHost& operator=(
  596. const CaptivePortalCheckProcessHost&) = delete;
  597. void CreateURLLoaderFactory(
  598. mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver,
  599. network::mojom::URLLoaderFactoryParamsPtr params) override {
  600. *invoked_url_factory_ = true;
  601. DCHECK_EQ(expected_disable_secure_dns_, params->disable_secure_dns);
  602. }
  603. void SetupForTracking(bool* invoked_url_factory,
  604. bool expected_disable_secure_dns) {
  605. invoked_url_factory_ = invoked_url_factory;
  606. expected_disable_secure_dns_ = expected_disable_secure_dns;
  607. }
  608. private:
  609. raw_ptr<bool> invoked_url_factory_ = nullptr;
  610. bool expected_disable_secure_dns_ = false;
  611. };
  612. class CaptivePortalCheckRenderProcessHostFactory
  613. : public content::RenderProcessHostFactory {
  614. public:
  615. CaptivePortalCheckRenderProcessHostFactory() = default;
  616. CaptivePortalCheckRenderProcessHostFactory(
  617. const CaptivePortalCheckRenderProcessHostFactory&) = delete;
  618. CaptivePortalCheckRenderProcessHostFactory& operator=(
  619. const CaptivePortalCheckRenderProcessHostFactory&) = delete;
  620. content::RenderProcessHost* CreateRenderProcessHost(
  621. content::BrowserContext* browser_context,
  622. content::SiteInstance* site_instance) override {
  623. auto rph = std::make_unique<CaptivePortalCheckProcessHost>(browser_context);
  624. content::RenderProcessHost* result = rph.get();
  625. processes_.push_back(std::move(rph));
  626. return result;
  627. }
  628. void SetupForTracking(bool* invoked_url_factory,
  629. bool expected_disable_secure_dns) {
  630. processes_.back()->SetupForTracking(invoked_url_factory,
  631. expected_disable_secure_dns);
  632. }
  633. void ClearRenderProcessHosts() { processes_.clear(); }
  634. private:
  635. std::list<std::unique_ptr<CaptivePortalCheckProcessHost>> processes_;
  636. };
  637. class ChromeContentBrowserClientCaptivePortalBrowserTest
  638. : public ChromeRenderViewHostTestHarness {
  639. public:
  640. protected:
  641. void SetUp() override {
  642. SetRenderProcessHostFactory(&cp_rph_factory_);
  643. ChromeRenderViewHostTestHarness::SetUp();
  644. }
  645. void TearDown() override {
  646. DeleteContents();
  647. cp_rph_factory_.ClearRenderProcessHosts();
  648. ChromeRenderViewHostTestHarness::TearDown();
  649. }
  650. CaptivePortalCheckRenderProcessHostFactory cp_rph_factory_;
  651. };
  652. TEST_F(ChromeContentBrowserClientCaptivePortalBrowserTest,
  653. NotCaptivePortalWindow) {
  654. bool invoked_url_factory = false;
  655. cp_rph_factory_.SetupForTracking(&invoked_url_factory,
  656. false /* expected_disable_secure_dns */);
  657. NavigateAndCommit(GURL("https://www.google.com"), ui::PAGE_TRANSITION_LINK);
  658. EXPECT_TRUE(invoked_url_factory);
  659. }
  660. #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
  661. TEST_F(ChromeContentBrowserClientCaptivePortalBrowserTest,
  662. CaptivePortalWindow) {
  663. bool invoked_url_factory = false;
  664. cp_rph_factory_.SetupForTracking(&invoked_url_factory,
  665. true /* expected_disable_secure_dns */);
  666. captive_portal::CaptivePortalTabHelper::CreateForWebContents(
  667. web_contents(), CaptivePortalServiceFactory::GetForProfile(profile()),
  668. base::NullCallback());
  669. captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents())
  670. ->set_is_captive_portal_window();
  671. NavigateAndCommit(GURL("https://www.google.com"), ui::PAGE_TRANSITION_LINK);
  672. EXPECT_TRUE(invoked_url_factory);
  673. }
  674. #endif
  675. #if BUILDFLAG(ENABLE_EXTENSIONS)
  676. class ChromeContentBrowserClientStoragePartitionTest
  677. : public ChromeContentBrowserClientTest {
  678. public:
  679. void SetUp() override {
  680. content::SiteIsolationPolicy::DisableFlagCachingForTesting();
  681. }
  682. protected:
  683. static constexpr char kAppId[] = "appid";
  684. static constexpr char kScope[] = "https://example.com";
  685. content::StoragePartitionConfig CreateDefaultStoragePartitionConfig() {
  686. return content::StoragePartitionConfig::CreateDefault(&profile_);
  687. }
  688. void RegisterAppIsolationState(const std::string& app_id,
  689. const std::string& scope,
  690. bool isolated) {
  691. web_app::WebApp app(app_id);
  692. app.SetScope(GURL(scope));
  693. app.SetStorageIsolated(isolated);
  694. web_app::RecordOrRemoveAppIsolationState(profile_.GetPrefs(), app);
  695. }
  696. };
  697. // static
  698. constexpr char ChromeContentBrowserClientStoragePartitionTest::kAppId[];
  699. constexpr char ChromeContentBrowserClientStoragePartitionTest::kScope[];
  700. TEST_F(ChromeContentBrowserClientStoragePartitionTest, DefaultPartition) {
  701. TestChromeContentBrowserClient test_content_browser_client;
  702. content::StoragePartitionConfig config =
  703. test_content_browser_client.GetStoragePartitionConfigForSite(
  704. &profile_, GURL("https://google.com"));
  705. EXPECT_EQ(CreateDefaultStoragePartitionConfig(), config);
  706. }
  707. TEST_F(ChromeContentBrowserClientStoragePartitionTest, IsolationDisabled) {
  708. RegisterAppIsolationState(kAppId, kScope, /*isolated=*/true);
  709. TestChromeContentBrowserClient test_content_browser_client;
  710. content::StoragePartitionConfig config =
  711. test_content_browser_client.GetStoragePartitionConfigForSite(
  712. &profile_, GURL(kScope));
  713. EXPECT_EQ(CreateDefaultStoragePartitionConfig(), config);
  714. EXPECT_FALSE(
  715. test_content_browser_client.ShouldUrlUseApplicationIsolationLevel(
  716. &profile_, GURL(kScope)));
  717. }
  718. TEST_F(ChromeContentBrowserClientStoragePartitionTest, NonIsolatedPWA) {
  719. RegisterAppIsolationState(kAppId, kScope, /*isolated=*/false);
  720. TestChromeContentBrowserClient test_content_browser_client;
  721. content::StoragePartitionConfig config =
  722. test_content_browser_client.GetStoragePartitionConfigForSite(
  723. &profile_, GURL(kScope));
  724. EXPECT_EQ(CreateDefaultStoragePartitionConfig(), config);
  725. EXPECT_FALSE(
  726. test_content_browser_client.ShouldUrlUseApplicationIsolationLevel(
  727. &profile_, GURL(kScope)));
  728. }
  729. TEST_F(ChromeContentBrowserClientStoragePartitionTest, IsolationEnabled) {
  730. RegisterAppIsolationState(kAppId, kScope, /*isolated=*/true);
  731. base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
  732. switches::kIsolatedAppOrigins, kScope);
  733. TestChromeContentBrowserClient test_content_browser_client;
  734. content::StoragePartitionConfig config =
  735. test_content_browser_client.GetStoragePartitionConfigForSite(
  736. &profile_, GURL(kScope));
  737. auto expected_config = content::StoragePartitionConfig::Create(
  738. &profile_, /*partition_domain=*/kAppId, /*partition_name=*/"",
  739. /*in_memory=*/false);
  740. EXPECT_EQ(expected_config, config);
  741. EXPECT_TRUE(test_content_browser_client.ShouldUrlUseApplicationIsolationLevel(
  742. &profile_, GURL(kScope)));
  743. }
  744. #endif // BUILDFLAG(ENABLE_EXTENSIONS)
  745. class ChromeContentBrowserClientSwitchTest
  746. : public ChromeRenderViewHostTestHarness {
  747. public:
  748. ChromeContentBrowserClientSwitchTest()
  749. : testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
  750. protected:
  751. void AppendSwitchInCurrentProcess(const base::StringPiece& switch_string) {
  752. base::CommandLine::ForCurrentProcess()->AppendSwitch(switch_string);
  753. }
  754. base::CommandLine FetchCommandLineSwitchesForRendererProcess() {
  755. base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
  756. command_line.AppendSwitchASCII(switches::kProcessType,
  757. switches::kRendererProcess);
  758. client_.AppendExtraCommandLineSwitches(&command_line, process()->GetID());
  759. return command_line;
  760. }
  761. private:
  762. ScopedTestingLocalState testing_local_state_;
  763. ChromeContentBrowserClient client_;
  764. };
  765. TEST_F(ChromeContentBrowserClientSwitchTest, WebSQLAccessDefault) {
  766. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  767. EXPECT_FALSE(result.HasSwitch(blink::switches::kWebSQLAccess));
  768. }
  769. TEST_F(ChromeContentBrowserClientSwitchTest, WebSQLAccessDisabled) {
  770. profile()->GetPrefs()->SetBoolean(storage::kWebSQLAccess, false);
  771. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  772. EXPECT_FALSE(result.HasSwitch(blink::switches::kWebSQLAccess));
  773. }
  774. TEST_F(ChromeContentBrowserClientSwitchTest, WebSQLAccessEnabled) {
  775. profile()->GetPrefs()->SetBoolean(storage::kWebSQLAccess, true);
  776. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  777. EXPECT_TRUE(result.HasSwitch(blink::switches::kWebSQLAccess));
  778. }
  779. TEST_F(ChromeContentBrowserClientSwitchTest,
  780. WebSQLNonSecureContextEnabledDefault) {
  781. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  782. EXPECT_FALSE(
  783. result.HasSwitch(blink::switches::kWebSQLNonSecureContextEnabled));
  784. }
  785. TEST_F(ChromeContentBrowserClientSwitchTest,
  786. WebSQLNonSecureContextEnabledDisabled) {
  787. profile()->GetPrefs()->SetBoolean(storage::kWebSQLNonSecureContextEnabled,
  788. false);
  789. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  790. EXPECT_FALSE(
  791. result.HasSwitch(blink::switches::kWebSQLNonSecureContextEnabled));
  792. }
  793. TEST_F(ChromeContentBrowserClientSwitchTest,
  794. WebSQLNonSecureContextEnabledEnabled) {
  795. profile()->GetPrefs()->SetBoolean(storage::kWebSQLNonSecureContextEnabled,
  796. true);
  797. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  798. EXPECT_TRUE(
  799. result.HasSwitch(blink::switches::kWebSQLNonSecureContextEnabled));
  800. }
  801. TEST_F(ChromeContentBrowserClientSwitchTest, PersistentQuotaEnabledDefault) {
  802. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  803. EXPECT_FALSE(result.HasSwitch(blink::switches::kPersistentQuotaEnabled));
  804. }
  805. TEST_F(ChromeContentBrowserClientSwitchTest, PersistentQuotaEnabledDisabled) {
  806. profile()->GetPrefs()->SetBoolean(storage::kPersistentQuotaEnabled, false);
  807. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  808. EXPECT_FALSE(result.HasSwitch(blink::switches::kPersistentQuotaEnabled));
  809. }
  810. TEST_F(ChromeContentBrowserClientSwitchTest, PersistentQuotaEnabledEnabled) {
  811. profile()->GetPrefs()->SetBoolean(storage::kPersistentQuotaEnabled, true);
  812. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  813. EXPECT_TRUE(result.HasSwitch(blink::switches::kPersistentQuotaEnabled));
  814. }
  815. #if BUILDFLAG(IS_CHROMEOS)
  816. TEST_F(ChromeContentBrowserClientSwitchTest,
  817. ShouldSetForceAppModeSwitchInRendererProcessIfItIsSetInCurrentProcess) {
  818. AppendSwitchInCurrentProcess(switches::kForceAppMode);
  819. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  820. EXPECT_TRUE(result.HasSwitch(switches::kForceAppMode));
  821. }
  822. TEST_F(
  823. ChromeContentBrowserClientSwitchTest,
  824. ShouldNotSetForceAppModeSwitchInRendererProcessIfItIsUnsetInCurrentProcess) {
  825. // We don't set the `kForceAppMode` flag in the current process.
  826. base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
  827. EXPECT_FALSE(result.HasSwitch(switches::kForceAppMode));
  828. }
  829. #endif // BUILDFLAG(IS_CHROMEOS)