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

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

Issue 2504573002: Don't call isURLAllowed() from layout. (Closed)
Patch Set: Fix everything 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 DCHECK(!m_childHTML.isEmpty()) << "Markup for the child frame was not set.";
20
21 LocalFrame* parentFrame = ownerElement->document().frame();
22 auto* childClient = FrameLoaderClientWithParent::create(parentFrame);
23 m_child = LocalFrame::create(childClient, parentFrame->host(), ownerElement);
24 m_child->createView(IntSize(500, 500), Color(), true /* transparent */);
25 m_child->init();
26
27 m_child->document()->setBaseURLOverride(
28 KURL(ParsedURLString, "http://test.com"));
29 m_child->document()->body()->setInnerHTML(m_childHTML, ASSERT_NO_EXCEPTION);
30
31 return m_child.get();
32 }
33
34 void FrameLoaderClientWithParent::detached(FrameDetachType) {
35 static_cast<SingleChildFrameLoaderClient*>(parent()->client())
36 ->didDetachChild();
37 }
38
14 RenderingTest::RenderingTest(FrameLoaderClient* frameLoaderClient) 39 RenderingTest::RenderingTest(FrameLoaderClient* frameLoaderClient)
15 : m_frameLoaderClient(frameLoaderClient) {} 40 : m_frameLoaderClient(frameLoaderClient) {}
16 41
17 void RenderingTest::SetUp() { 42 void RenderingTest::SetUp() {
18 Page::PageClients pageClients; 43 Page::PageClients pageClients;
19 fillWithEmptyClients(pageClients); 44 fillWithEmptyClients(pageClients);
20 DEFINE_STATIC_LOCAL(EmptyChromeClient, chromeClient, 45 DEFINE_STATIC_LOCAL(EmptyChromeClient, chromeClient,
21 (EmptyChromeClient::create())); 46 (EmptyChromeClient::create()));
22 pageClients.chromeClient = &chromeClient; 47 pageClients.chromeClient = &chromeClient;
23 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients, 48 m_pageHolder = DummyPageHolder::create(
24 m_frameLoaderClient.release(), 49 IntSize(800, 600), &pageClients, m_frameLoaderClient, settingOverrider());
25 settingOverrider());
26 50
27 Settings::setMockScrollbarsEnabled(true); 51 Settings::setMockScrollbarsEnabled(true);
28 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); 52 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
29 EXPECT_TRUE(ScrollbarTheme::theme().usesOverlayScrollbars()); 53 EXPECT_TRUE(ScrollbarTheme::theme().usesOverlayScrollbars());
30 54
31 // This ensures that the minimal DOM tree gets attached 55 // This ensures that the minimal DOM tree gets attached
32 // correctly for tests that don't call setBodyInnerHTML. 56 // correctly for tests that don't call setBodyInnerHTML.
33 document().view()->updateAllLifecyclePhases(); 57 document().view()->updateAllLifecyclePhases();
34 } 58 }
35 59
36 void RenderingTest::TearDown() { 60 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 61 // We need to destroy most of the Blink structure here because derived tests
45 // may restore RuntimeEnabledFeatures setting during teardown, which happens 62 // may restore RuntimeEnabledFeatures setting during teardown, which happens
46 // before our destructor getting invoked, breaking the assumption that REF 63 // before our destructor getting invoked, breaking the assumption that REF
47 // can't change during Blink lifetime. 64 // can't change during Blink lifetime.
48 m_pageHolder = nullptr; 65 m_pageHolder = nullptr;
49 66
50 // Clear memory cache, otherwise we can leak pruned resources. 67 // Clear memory cache, otherwise we can leak pruned resources.
51 memoryCache()->evictResources(); 68 memoryCache()->evictResources();
52 } 69 }
53 70
54 Document& RenderingTest::setupChildIframe(const AtomicString& iframeElementId,
55 const String& htmlContentOfIframe) {
56 // TODO(pdr): This should be refactored to share code with the actual setup
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 }
78
79 } // namespace blink 71 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698