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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp

Issue 2504573002: Don't call isURLAllowed() from layout. (Closed)
Patch Set: Fix bad formatting that caused clang-format-diff to get confused. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/LayoutTestHelper.h" 5 #include "core/layout/LayoutTestHelper.h"
6 6
7 #include "core/fetch/MemoryCache.h" 7 #include "core/fetch/MemoryCache.h"
8 #include "core/frame/FrameHost.h" 8 #include "core/frame/FrameHost.h"
9 #include "core/html/HTMLIFrameElement.h" 9 #include "core/html/HTMLIFrameElement.h"
10 #include "platform/scroll/ScrollbarTheme.h" 10 #include "platform/scroll/ScrollbarTheme.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 LocalFrame* SingleChildFrameLoaderClient::createFrame(
15 const FrameLoadRequest&,
16 const AtomicString& name,
17 HTMLFrameOwnerElement* ownerElement) {
18 DCHECK(!m_child) << "This test helper only supports one child frame.";
19
20 LocalFrame* parentFrame = ownerElement->document().frame();
21 auto* childClient = FrameLoaderClientWithParent::create(parentFrame);
22 m_child = LocalFrame::create(childClient, parentFrame->host(), ownerElement);
23 m_child->createView(IntSize(500, 500), Color(), true /* transparent */);
24 m_child->init();
25
26 return m_child.get();
27 }
28
29 void FrameLoaderClientWithParent::detached(FrameDetachType) {
30 static_cast<SingleChildFrameLoaderClient*>(parent()->client())
31 ->didDetachChild();
32 }
33
14 RenderingTest::RenderingTest(FrameLoaderClient* frameLoaderClient) 34 RenderingTest::RenderingTest(FrameLoaderClient* frameLoaderClient)
15 : m_frameLoaderClient(frameLoaderClient) {} 35 : m_frameLoaderClient(frameLoaderClient) {}
16 36
17 void RenderingTest::SetUp() { 37 void RenderingTest::SetUp() {
18 Page::PageClients pageClients; 38 Page::PageClients pageClients;
19 fillWithEmptyClients(pageClients); 39 fillWithEmptyClients(pageClients);
20 DEFINE_STATIC_LOCAL(EmptyChromeClient, chromeClient, 40 DEFINE_STATIC_LOCAL(EmptyChromeClient, chromeClient,
21 (EmptyChromeClient::create())); 41 (EmptyChromeClient::create()));
22 pageClients.chromeClient = &chromeClient; 42 pageClients.chromeClient = &chromeClient;
23 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients, 43 m_pageHolder = DummyPageHolder::create(
24 m_frameLoaderClient.release(), 44 IntSize(800, 600), &pageClients, m_frameLoaderClient, settingOverrider());
25 settingOverrider());
26 45
27 Settings::setMockScrollbarsEnabled(true); 46 Settings::setMockScrollbarsEnabled(true);
28 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); 47 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
29 EXPECT_TRUE(ScrollbarTheme::theme().usesOverlayScrollbars()); 48 EXPECT_TRUE(ScrollbarTheme::theme().usesOverlayScrollbars());
30 49
31 // This ensures that the minimal DOM tree gets attached 50 // This ensures that the minimal DOM tree gets attached
32 // correctly for tests that don't call setBodyInnerHTML. 51 // correctly for tests that don't call setBodyInnerHTML.
33 document().view()->updateAllLifecyclePhases(); 52 document().view()->updateAllLifecyclePhases();
34 } 53 }
35 54
36 void RenderingTest::TearDown() { 55 void RenderingTest::TearDown() {
37 if (m_subframe) {
38 m_subframe->detach(FrameDetachType::Remove);
39 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())
40 ->setChild(nullptr);
41 document().frame()->host()->decrementSubframeCount();
42 }
43
44 // We need to destroy most of the Blink structure here because derived tests 56 // We need to destroy most of the Blink structure here because derived tests
45 // may restore RuntimeEnabledFeatures setting during teardown, which happens 57 // may restore RuntimeEnabledFeatures setting during teardown, which happens
46 // before our destructor getting invoked, breaking the assumption that REF 58 // before our destructor getting invoked, breaking the assumption that REF
47 // can't change during Blink lifetime. 59 // can't change during Blink lifetime.
48 m_pageHolder = nullptr; 60 m_pageHolder = nullptr;
49 61
50 // Clear memory cache, otherwise we can leak pruned resources. 62 // Clear memory cache, otherwise we can leak pruned resources.
51 memoryCache()->evictResources(); 63 memoryCache()->evictResources();
52 } 64 }
53 65
54 Document& RenderingTest::setupChildIframe(const AtomicString& iframeElementId, 66 void RenderingTest::setChildFrameHTML(const String& html) {
55 const String& htmlContentOfIframe) { 67 childDocument().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
56 // TODO(pdr): This should be refactored to share code with the actual setup 68 childDocument().body()->setInnerHTML(html, ASSERT_NO_EXCEPTION);
57 // instead of partially duplicating it here (e.g., LocalFrame::createView).
58 HTMLIFrameElement& iframe =
59 *toHTMLIFrameElement(document().getElementById(iframeElementId));
60 m_childFrameLoaderClient =
61 FrameLoaderClientWithParent::create(document().frame());
62 m_subframe = LocalFrame::create(m_childFrameLoaderClient.get(),
63 document().frame()->host(), &iframe);
64 m_subframe->setView(FrameView::create(*m_subframe, IntSize(500, 500)));
65 m_subframe->init();
66 m_subframe->view()->setParentVisible(true);
67 m_subframe->view()->setSelfVisible(true);
68 iframe.setWidget(m_subframe->view());
69 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())
70 ->setChild(m_subframe.get());
71 document().frame()->host()->incrementSubframeCount();
72 Document& frameDocument = *iframe.contentDocument();
73
74 frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
75 frameDocument.body()->setInnerHTML(htmlContentOfIframe, ASSERT_NO_EXCEPTION);
76 return frameDocument;
77 } 69 }
78 70
79 } // namespace blink 71 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutTestHelper.h ('k') | third_party/WebKit/Source/core/layout/MapCoordinatesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698