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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014, Google Inc. All rights reserved. 2 * Copyright (c) 2014, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 #include <memory> 33 #include <memory>
34 #include "bindings/core/v8/V8BindingForTesting.h" 34 #include "bindings/core/v8/V8BindingForTesting.h"
35 #include "core/dom/NodeWithIndex.h" 35 #include "core/dom/NodeWithIndex.h"
36 #include "core/dom/SynchronousMutationObserver.h" 36 #include "core/dom/SynchronousMutationObserver.h"
37 #include "core/dom/Text.h" 37 #include "core/dom/Text.h"
38 #include "core/frame/FrameView.h" 38 #include "core/frame/FrameView.h"
39 #include "core/frame/Settings.h" 39 #include "core/frame/Settings.h"
40 #include "core/html/HTMLHeadElement.h" 40 #include "core/html/HTMLHeadElement.h"
41 #include "core/html/HTMLInputElement.h" 41 #include "core/html/HTMLInputElement.h"
42 #include "core/html/HTMLLinkElement.h" 42 #include "core/html/HTMLLinkElement.h"
43 #include "core/loader/DocumentLoader.h"
44 #include "core/loader/appcache/ApplicationCacheHost.h"
43 #include "core/page/Page.h" 45 #include "core/page/Page.h"
44 #include "core/page/ValidationMessageClient.h" 46 #include "core/page/ValidationMessageClient.h"
45 #include "core/testing/DummyPageHolder.h" 47 #include "core/testing/DummyPageHolder.h"
46 #include "platform/heap/Handle.h" 48 #include "platform/heap/Handle.h"
47 #include "platform/weborigin/ReferrerPolicy.h" 49 #include "platform/weborigin/ReferrerPolicy.h"
48 #include "platform/weborigin/SchemeRegistry.h" 50 #include "platform/weborigin/SchemeRegistry.h"
49 #include "platform/weborigin/SecurityOrigin.h" 51 #include "platform/weborigin/SecurityOrigin.h"
52 #include "public/platform/WebApplicationCacheHost.h"
50 #include "testing/gmock/include/gmock/gmock.h" 53 #include "testing/gmock/include/gmock/gmock.h"
51 #include "testing/gtest/include/gtest/gtest.h" 54 #include "testing/gtest/include/gtest/gtest.h"
52 55
53 namespace blink { 56 namespace blink {
54 57
55 class DocumentTest : public ::testing::Test { 58 class DocumentTest : public ::testing::Test {
56 protected: 59 protected:
57 void SetUp() override; 60 void SetUp() override;
58 61
59 void TearDown() override { ThreadState::Current()->CollectAllGarbage(); } 62 void TearDown() override { ThreadState::Current()->CollectAllGarbage(); }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 will_unload_document_was_called = true; 281 will_unload_document_was_called = true;
279 } 282 }
280 void DocumentDetached(const Document&) override { 283 void DocumentDetached(const Document&) override {
281 document_detached_was_called = true; 284 document_detached_was_called = true;
282 } 285 }
283 void WillBeDestroyed() override {} 286 void WillBeDestroyed() override {}
284 287
285 // DEFINE_INLINE_VIRTUAL_TRACE() { ValidationMessageClient::trace(visitor); } 288 // DEFINE_INLINE_VIRTUAL_TRACE() { ValidationMessageClient::trace(visitor); }
286 }; 289 };
287 290
291 class MockWebApplicationCacheHost
292 : NON_EXPORTED_BASE(public blink::WebApplicationCacheHost) {
293 public:
294 MockWebApplicationCacheHost() {}
295 ~MockWebApplicationCacheHost() override {}
296
297 void SelectCacheWithoutManifest() override {
298 without_manifest_was_called_ = true;
299 }
300 bool SelectCacheWithManifest(const blink::WebURL& manifestURL) override {
301 with_manifest_was_called_ = true;
302 return true;
303 }
304
305 bool with_manifest_was_called_ = false;
306 bool without_manifest_was_called_ = false;
307 };
308
288 } // anonymous namespace 309 } // anonymous namespace
289 310
290 // This tests that we properly resize and re-layout pages for printing in the 311 // This tests that we properly resize and re-layout pages for printing in the
291 // presence of media queries effecting elements in a subtree layout boundary 312 // presence of media queries effecting elements in a subtree layout boundary
292 TEST_F(DocumentTest, PrintRelayout) { 313 TEST_F(DocumentTest, PrintRelayout) {
293 SetHtmlInnerHTML( 314 SetHtmlInnerHTML(
294 "<style>" 315 "<style>"
295 " div {" 316 " div {"
296 " width: 100px;" 317 " width: 100px;"
297 " height: 100px;" 318 " height: 100px;"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // prepareForCommit() unloads the document, and shutdown. 750 // prepareForCommit() unloads the document, and shutdown.
730 GetDocument().GetFrame()->PrepareForCommit(); 751 GetDocument().GetFrame()->PrepareForCommit();
731 EXPECT_TRUE(mock_client->will_unload_document_was_called); 752 EXPECT_TRUE(mock_client->will_unload_document_was_called);
732 EXPECT_TRUE(mock_client->document_detached_was_called); 753 EXPECT_TRUE(mock_client->document_detached_was_called);
733 // Unload handler tried to show a validation message, but it should fail. 754 // Unload handler tried to show a validation message, but it should fail.
734 EXPECT_FALSE(mock_client->show_validation_message_was_called); 755 EXPECT_FALSE(mock_client->show_validation_message_was_called);
735 756
736 GetPage().SetValidationMessageClient(original_client); 757 GetPage().SetValidationMessageClient(original_client);
737 } 758 }
738 759
760 TEST_F(DocumentTest, SandboxDisablesAppCache) {
761 RefPtr<SecurityOrigin> origin =
762 SecurityOrigin::CreateFromString("https://test.com");
763 GetDocument().SetSecurityOrigin(origin);
764 SandboxFlags mask = kSandboxOrigin;
765 GetDocument().EnforceSandboxFlags(mask);
766 GetDocument().SetURL(KURL(KURL(), "https://test.com/foobar/document"));
767
768 ApplicationCacheHost* appcache_host =
769 GetDocument().Loader()->GetApplicationCacheHost();
770 appcache_host->host_ = WTF::MakeUnique<MockWebApplicationCacheHost>();
771 appcache_host->SelectCacheWithManifest(
772 KURL(KURL(), "https://test.com/foobar/manifest"));
773 MockWebApplicationCacheHost* mock_web_host =
774 static_cast<MockWebApplicationCacheHost*>(appcache_host->host_.get());
775 EXPECT_FALSE(mock_web_host->with_manifest_was_called_);
776 EXPECT_TRUE(mock_web_host->without_manifest_was_called_);
777 }
778
779 TEST_F(DocumentTest, SuboriginDisablesAppCache) {
780 RuntimeEnabledFeatures::setSuboriginsEnabled(true);
781 RefPtr<SecurityOrigin> origin =
782 SecurityOrigin::CreateFromString("https://test.com");
783 Suborigin suborigin;
784 suborigin.SetName("foobar");
785 origin->AddSuborigin(suborigin);
786 GetDocument().SetSecurityOrigin(origin);
787 GetDocument().SetURL(KURL(KURL(), "https://test.com/foobar/document"));
788
789 ApplicationCacheHost* appcache_host =
790 GetDocument().Loader()->GetApplicationCacheHost();
791 appcache_host->host_ = WTF::MakeUnique<MockWebApplicationCacheHost>();
792 appcache_host->SelectCacheWithManifest(
793 KURL(KURL(), "https://test.com/foobar/manifest"));
794 MockWebApplicationCacheHost* mock_web_host =
795 static_cast<MockWebApplicationCacheHost*>(appcache_host->host_.get());
796 EXPECT_FALSE(mock_web_host->with_manifest_was_called_);
797 EXPECT_TRUE(mock_web_host->without_manifest_was_called_);
798 }
799
739 } // namespace blink 800 } // namespace blink
OLDNEW
« 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