1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
content / browser / site_isolation_policy_unittest.cc [blame]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/public/browser/site_isolation_policy.h"
#include "base/command_line.h"
#include "base/test/scoped_command_line.h"
#include "build/build_config.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
TEST(SiteIsolationPolicyTest, DisableSiteIsolationSwitch) {
// Skip this test if the --site-per-process switch is present (e.g. on Site
// Isolation Android chromium.fyi bot). The test is still valid if
// SitePerProcess is the default (e.g. via ContentBrowserClient's
// ShouldEnableStrictSiteIsolation method) - don't skip the test in such case.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSitePerProcess)) {
return;
}
SiteIsolationPolicy::DisableFlagCachingForTesting();
base::test::ScopedCommandLine scoped_command_line;
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitch(switches::kDisableSiteIsolation);
EXPECT_FALSE(SiteIsolationPolicy::UseDedicatedProcessesForAllSites());
EXPECT_FALSE(SiteIsolationPolicy::AreIsolatedOriginsEnabled());
EXPECT_FALSE(SiteIsolationPolicy::AreDynamicIsolatedOriginsEnabled());
// Error page isolation should not be affected by --disable-site-isolation-...
// switches.
EXPECT_TRUE(SiteIsolationPolicy::IsErrorPageIsolationEnabled(true));
}
#if BUILDFLAG(IS_ANDROID)
// Since https://crbug.com/910273, the kDisableSiteIsolationForPolicy switch is
// only available/used on Android.
TEST(SiteIsolationPolicyTest, DisableSiteIsolationForPolicySwitch) {
// Skip this test if the --site-per-process switch is present (e.g. on Site
// Isolation Android chromium.fyi bot). The test is still valid if
// SitePerProcess is the default (e.g. via ContentBrowserClient's
// ShouldEnableStrictSiteIsolation method) - don't skip the test in such case.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSitePerProcess)) {
return;
}
SiteIsolationPolicy::DisableFlagCachingForTesting();
base::test::ScopedCommandLine scoped_command_line;
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitch(switches::kDisableSiteIsolationForPolicy);
EXPECT_FALSE(SiteIsolationPolicy::UseDedicatedProcessesForAllSites());
EXPECT_FALSE(SiteIsolationPolicy::AreIsolatedOriginsEnabled());
EXPECT_FALSE(SiteIsolationPolicy::AreDynamicIsolatedOriginsEnabled());
// Error page isolation should not be affected by --disable-site-isolation-...
// switches.
EXPECT_TRUE(SiteIsolationPolicy::IsErrorPageIsolationEnabled(true));
}
#endif
class ApplicationIsolationEnablingBrowserClient : public ContentBrowserClient {
public:
bool ShouldUrlUseApplicationIsolationLevel(BrowserContext* browser_context,
const GURL& url) override {
return url.SchemeIs("isolated-app");
}
};
} // namespace content