Commit a9d828aa authored by Charlie Hu's avatar Charlie Hu Committed by Commit Bot

Let PageTestBase::NavigateTo accept all http headers

This CL modifies PageTestBase::NavigateTo accept all http headers through a HashMap. Previously the method only accepts feature policy header and CSP header.

The modification is prework to add test for document policy which has its own header.

Change-Id: I7cabaaba3c099ff5e77040891ba9950a25271f8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080438
Commit-Queue: Charlie Hu <chenleihu@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745575}
parent 5c614415
...@@ -552,8 +552,8 @@ TEST_F(DocumentTest, OutgoingReferrer) { ...@@ -552,8 +552,8 @@ TEST_F(DocumentTest, OutgoingReferrer) {
} }
TEST_F(DocumentTest, OutgoingReferrerWithUniqueOrigin) { TEST_F(DocumentTest, OutgoingReferrerWithUniqueOrigin) {
NavigateTo(KURL("https://www.example.com/hoge#fuga?piyo"), "", NavigateTo(KURL("https://www.example.com/hoge#fuga?piyo"),
"sandbox allow-scripts"); {{http_names::kContentSecurityPolicy, "sandbox allow-scripts"}});
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque());
EXPECT_EQ(String(), GetDocument().OutgoingReferrer()); EXPECT_EQ(String(), GetDocument().OutgoingReferrer());
} }
...@@ -588,11 +588,13 @@ TEST_F(DocumentTest, StyleVersion) { ...@@ -588,11 +588,13 @@ TEST_F(DocumentTest, StyleVersion) {
} }
TEST_F(DocumentTest, EnforceSandboxFlags) { TEST_F(DocumentTest, EnforceSandboxFlags) {
NavigateTo(KURL("http://example.test/"), "", "sandbox allow-same-origin"); NavigateTo(KURL("http://example.test/"), {{http_names::kContentSecurityPolicy,
"sandbox allow-same-origin"}});
EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsOpaque()); EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsOpaque());
EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy()); EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy());
NavigateTo(KURL("http://example.test/"), "", "sandbox"); NavigateTo(KURL("http://example.test/"),
{{http_names::kContentSecurityPolicy, "sandbox"}});
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque());
EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy()); EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy());
...@@ -602,16 +604,19 @@ TEST_F(DocumentTest, EnforceSandboxFlags) { ...@@ -602,16 +604,19 @@ TEST_F(DocumentTest, EnforceSandboxFlags) {
url::AddStandardScheme("very-special-scheme", url::SCHEME_WITH_HOST); url::AddStandardScheme("very-special-scheme", url::SCHEME_WITH_HOST);
SchemeRegistry::RegisterURLSchemeBypassingSecureContextCheck( SchemeRegistry::RegisterURLSchemeBypassingSecureContextCheck(
"very-special-scheme"); "very-special-scheme");
NavigateTo(KURL("very-special-scheme://example.test"), "", "sandbox"); NavigateTo(KURL("very-special-scheme://example.test"),
{{http_names::kContentSecurityPolicy, "sandbox"}});
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque());
EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy()); EXPECT_FALSE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy());
SchemeRegistry::RegisterURLSchemeAsSecure("very-special-scheme"); SchemeRegistry::RegisterURLSchemeAsSecure("very-special-scheme");
NavigateTo(KURL("very-special-scheme://example.test"), "", "sandbox"); NavigateTo(KURL("very-special-scheme://example.test"),
{{http_names::kContentSecurityPolicy, "sandbox"}});
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque());
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy());
NavigateTo(KURL("https://example.test"), "", "sandbox"); NavigateTo(KURL("https://example.test"),
{{http_names::kContentSecurityPolicy, "sandbox"}});
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsOpaque());
EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy()); EXPECT_TRUE(GetDocument().GetSecurityOrigin()->IsPotentiallyTrustworthy());
} }
...@@ -859,7 +864,8 @@ TEST_F(DocumentTest, ValidationMessageCleanup) { ...@@ -859,7 +864,8 @@ TEST_F(DocumentTest, ValidationMessageCleanup) {
} }
TEST_F(DocumentTest, SandboxDisablesAppCache) { TEST_F(DocumentTest, SandboxDisablesAppCache) {
NavigateTo(KURL("https://test.com/foobar/document"), "", "sandbox"); NavigateTo(KURL("https://test.com/foobar/document"),
{{http_names::kContentSecurityPolicy, "sandbox"}});
GetDocument().Loader()->SetApplicationCacheHostForTesting( GetDocument().Loader()->SetApplicationCacheHostForTesting(
MakeGarbageCollected<MockApplicationCacheHost>(GetDocument().Loader())); MakeGarbageCollected<MockApplicationCacheHost>(GetDocument().Loader()));
...@@ -1034,7 +1040,8 @@ INSTANTIATE_TEST_SUITE_P(All, ...@@ -1034,7 +1040,8 @@ INSTANTIATE_TEST_SUITE_P(All,
testing::Values(true, false)); testing::Values(true, false));
TEST_F(DocumentTest, CanExecuteScriptsWithSandboxAndIsolatedWorld) { TEST_F(DocumentTest, CanExecuteScriptsWithSandboxAndIsolatedWorld) {
NavigateTo(KURL("https://www.example.com/"), "", "sandbox"); NavigateTo(KURL("https://www.example.com/"),
{{http_names::kContentSecurityPolicy, "sandbox"}});
LocalFrame* frame = GetDocument().GetFrame(); LocalFrame* frame = GetDocument().GetFrame();
frame->GetSettings()->SetScriptEnabled(true); frame->GetSettings()->SetScriptEnabled(true);
......
...@@ -202,18 +202,13 @@ void PageTestBase::InsertStyleElement(const std::string& style_rules) { ...@@ -202,18 +202,13 @@ void PageTestBase::InsertStyleElement(const std::string& style_rules) {
} }
void PageTestBase::NavigateTo(const KURL& url, void PageTestBase::NavigateTo(const KURL& url,
const String& feature_policy_header, const WTF::HashMap<String, String>& headers) {
const String& csp_header) {
auto params = auto params =
WebNavigationParams::CreateWithHTMLBuffer(SharedBuffer::Create(), url); WebNavigationParams::CreateWithHTMLBuffer(SharedBuffer::Create(), url);
if (!feature_policy_header.IsEmpty()) {
params->response.SetHttpHeaderField(http_names::kFeaturePolicy, for (const auto& header : headers)
feature_policy_header); params->response.SetHttpHeaderField(header.key, header.value);
}
if (!csp_header.IsEmpty()) {
params->response.SetHttpHeaderField(http_names::kContentSecurityPolicy,
csp_header);
}
GetFrame().Loader().CommitNavigation(std::move(params), GetFrame().Loader().CommitNavigation(std::move(params),
nullptr /* extra_data */); nullptr /* extra_data */);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "third_party/blink/renderer/core/testing/mock_clipboard_host.h" #include "third_party/blink/renderer/core/testing/mock_clipboard_host.h"
#include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h" #include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
namespace base { namespace base {
class TickClock; class TickClock;
...@@ -74,8 +75,7 @@ class PageTestBase : public testing::Test, public ScopedMockOverlayScrollbars { ...@@ -74,8 +75,7 @@ class PageTestBase : public testing::Test, public ScopedMockOverlayScrollbars {
// Navigate to |url| providing an empty response but // Navigate to |url| providing an empty response but
// URL and security origin of the Document will be set to |url|. // URL and security origin of the Document will be set to |url|.
void NavigateTo(const KURL& url, void NavigateTo(const KURL& url,
const String& feature_policy_header = String(), const WTF::HashMap<String, String>& headers = {});
const String& csp_header = String());
Document& GetDocument() const; Document& GetDocument() const;
Page& GetPage() const; Page& GetPage() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment