Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: third_party/WebKit/Source/core/dom/DocumentTest.cpp

Issue 2813123002: Prevent appcache creation from suborigins and sandboxed pages. (Closed)
Patch Set: tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/appcache/ApplicationCacheHost.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/DocumentTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/DocumentTest.cpp b/third_party/WebKit/Source/core/dom/DocumentTest.cpp
index 92e628c238e4023bb291dafafe0b062823f8a596..6002eb4c9a681579c2da9dbe943feeaf2783e9f5 100644
--- a/third_party/WebKit/Source/core/dom/DocumentTest.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentTest.cpp
@@ -40,6 +40,8 @@
#include "core/html/HTMLHeadElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLLinkElement.h"
+#include "core/loader/DocumentLoader.h"
+#include "core/loader/appcache/ApplicationCacheHost.h"
#include "core/page/Page.h"
#include "core/page/ValidationMessageClient.h"
#include "core/testing/DummyPageHolder.h"
@@ -47,6 +49,7 @@
#include "platform/weborigin/ReferrerPolicy.h"
#include "platform/weborigin/SchemeRegistry.h"
#include "platform/weborigin/SecurityOrigin.h"
+#include "public/platform/WebApplicationCacheHost.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -285,6 +288,24 @@ class MockValidationMessageClient
// DEFINE_INLINE_VIRTUAL_TRACE() { ValidationMessageClient::trace(visitor); }
};
+class MockWebApplicationCacheHost
+ : NON_EXPORTED_BASE(public blink::WebApplicationCacheHost) {
+ public:
+ MockWebApplicationCacheHost() {}
+ ~MockWebApplicationCacheHost() override {}
+
+ void SelectCacheWithoutManifest() override {
+ without_manifest_was_called_ = true;
+ }
+ bool SelectCacheWithManifest(const blink::WebURL& manifestURL) override {
+ with_manifest_was_called_ = true;
+ return true;
+ }
+
+ bool with_manifest_was_called_ = false;
+ bool without_manifest_was_called_ = false;
+};
+
} // anonymous namespace
// This tests that we properly resize and re-layout pages for printing in the
@@ -736,4 +757,44 @@ TEST_F(DocumentTest, ValidationMessageCleanup) {
GetPage().SetValidationMessageClient(original_client);
}
+TEST_F(DocumentTest, SandboxDisablesAppCache) {
+ RefPtr<SecurityOrigin> origin =
+ SecurityOrigin::CreateFromString("https://test.com");
+ GetDocument().SetSecurityOrigin(origin);
+ SandboxFlags mask = kSandboxOrigin;
+ GetDocument().EnforceSandboxFlags(mask);
+ GetDocument().SetURL(KURL(KURL(), "https://test.com/foobar/document"));
+
+ ApplicationCacheHost* appcache_host =
+ GetDocument().Loader()->GetApplicationCacheHost();
+ appcache_host->host_ = WTF::MakeUnique<MockWebApplicationCacheHost>();
+ appcache_host->SelectCacheWithManifest(
+ KURL(KURL(), "https://test.com/foobar/manifest"));
+ MockWebApplicationCacheHost* mock_web_host =
+ static_cast<MockWebApplicationCacheHost*>(appcache_host->host_.get());
+ EXPECT_FALSE(mock_web_host->with_manifest_was_called_);
+ EXPECT_TRUE(mock_web_host->without_manifest_was_called_);
+}
+
+TEST_F(DocumentTest, SuboriginDisablesAppCache) {
+ RuntimeEnabledFeatures::setSuboriginsEnabled(true);
+ RefPtr<SecurityOrigin> origin =
+ SecurityOrigin::CreateFromString("https://test.com");
+ Suborigin suborigin;
+ suborigin.SetName("foobar");
+ origin->AddSuborigin(suborigin);
+ GetDocument().SetSecurityOrigin(origin);
+ GetDocument().SetURL(KURL(KURL(), "https://test.com/foobar/document"));
+
+ ApplicationCacheHost* appcache_host =
+ GetDocument().Loader()->GetApplicationCacheHost();
+ appcache_host->host_ = WTF::MakeUnique<MockWebApplicationCacheHost>();
+ appcache_host->SelectCacheWithManifest(
+ KURL(KURL(), "https://test.com/foobar/manifest"));
+ MockWebApplicationCacheHost* mock_web_host =
+ static_cast<MockWebApplicationCacheHost*>(appcache_host->host_.get());
+ EXPECT_FALSE(mock_web_host->with_manifest_was_called_);
+ EXPECT_TRUE(mock_web_host->without_manifest_was_called_);
+}
+
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/appcache/ApplicationCacheHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698