0
Files
src/content/browser/site_isolation_policy_unittest.cc
Robbie McElrath eeda890542 Speculative fix for SiteIsolationPolicyTest on android
This adds a SiteIsolationPolicy::DisableFlagCachingForTesting(); call
that has fixed similar flag-related flakiness on other platforms.

Bug: 351023623
Change-Id: Ic56aa73a29a4c8239494746b947a9a9ed5baea3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5677330
Commit-Queue: Charlie Reis <creis@chromium.org>
Reviewed-by: Charlie Reis <creis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1323089}
2024-07-03 23:18:00 +00:00

80 lines
3.3 KiB
C++

// 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