From b3ad146d98e8e67187e4f072676afbe210e73042 Mon Sep 17 00:00:00 2001 From: sadrul Date: Fri, 21 Aug 2015 12:17:36 -0700 Subject: [PATCH] html_viewer: Make sure window.internals is set-up correctly in layout-tests. Inject window.internals from WebFrameClient::didClearWindowObject() override instead of right after creation, since that's how //content sets it up as well. Also, fix a couple of crashes during start-up and tear-down. BUG=none Review URL: https://codereview.chromium.org/1297173002 Cr-Commit-Position: refs/heads/master@{#344833} --- .../layout_test_content_handler_impl.cc | 25 +++++++++++++++++++--- components/html_viewer/web_test_delegate_impl.cc | 10 ++++++++- components/html_viewer/web_test_delegate_impl.h | 2 ++ components/test_runner/web_test_delegate.h | 2 ++ components/test_runner/web_test_proxy.cc | 1 + .../renderer/layout_test/blink_test_runner.cc | 4 ++++ .../shell/renderer/layout_test/blink_test_runner.h | 1 + 7 files changed, 41 insertions(+), 4 deletions(-) diff --git a/components/html_viewer/layout_test_content_handler_impl.cc b/components/html_viewer/layout_test_content_handler_impl.cc index a4441778386b..aa11737dc10c 100644 --- a/components/html_viewer/layout_test_content_handler_impl.cc +++ b/components/html_viewer/layout_test_content_handler_impl.cc @@ -14,6 +14,23 @@ namespace html_viewer { +class TestHTMLFrame : public HTMLFrame { + public: + explicit TestHTMLFrame(HTMLFrame::CreateParams* params) : HTMLFrame(params) {} + + protected: + ~TestHTMLFrame() override {} + + private: + // blink::WebFrameClient:: + void didClearWindowObject(blink::WebLocalFrame* frame) override { + HTMLFrame::didClearWindowObject(frame); + blink::WebTestingSupport::injectInternalsObject(frame); + } + + DISALLOW_COPY_AND_ASSIGN(TestHTMLFrame); +}; + LayoutTestContentHandlerImpl::LayoutTestContentHandlerImpl( GlobalState* global_state, mojo::ApplicationImpl* app, @@ -46,8 +63,12 @@ void LayoutTestContentHandlerImpl::StartApplication( HTMLFrame* LayoutTestContentHandlerImpl::CreateHTMLFrame( HTMLFrame::CreateParams* params) { + // The test harness isn't correctly set-up for iframes yet. So return a normal + // HTMLFrame for iframes. + if (params->parent) + return new HTMLFrame(params); using ProxyType = test_runner::WebTestProxy< - test_runner::WebFrameTestProxy, + test_runner::WebFrameTestProxy, HTMLFrame::CreateParams*>; // TODO(sky): this isn't right for all frame types, eg remote frames. ProxyType* proxy = new ProxyType(params); @@ -57,8 +78,6 @@ HTMLFrame* LayoutTestContentHandlerImpl::CreateHTMLFrame( test_delegate_->set_test_proxy(proxy); test_interfaces_->SetWebView(proxy->web_view(), proxy); proxy->set_widget(proxy->web_view()); - blink::WebTestingSupport::injectInternalsObject( - proxy->web_view()->mainFrame()->toWebLocalFrame()); test_interfaces_->BindTo(proxy->web_view()->mainFrame()); return proxy; } diff --git a/components/html_viewer/web_test_delegate_impl.cc b/components/html_viewer/web_test_delegate_impl.cc index 12474ec54769..5385a660b454 100644 --- a/components/html_viewer/web_test_delegate_impl.cc +++ b/components/html_viewer/web_test_delegate_impl.cc @@ -228,7 +228,8 @@ void WebTestDelegateImpl::SetLocale(const std::string& locale) { void WebTestDelegateImpl::TestFinished() { test_interfaces_->SetTestIsRunning(false); - fprintf(stderr, "%s", proxy_->CaptureTree(false, false).c_str()); + fprintf(stderr, "%s", proxy_ ? proxy_->CaptureTree(false, false).c_str() + : dump_tree_.c_str()); } void WebTestDelegateImpl::CloseRemainingWindows() { @@ -324,4 +325,11 @@ blink::WebPlugin* WebTestDelegateImpl::CreatePluginPlaceholder( return nullptr; } +void WebTestDelegateImpl::OnWebTestProxyBaseDestroy( + test_runner::WebTestProxyBase* base) { + DCHECK_EQ(proxy_, base); + dump_tree_ = proxy_->CaptureTree(false, false); + proxy_ = nullptr; +} + } // namespace html_viewer diff --git a/components/html_viewer/web_test_delegate_impl.h b/components/html_viewer/web_test_delegate_impl.h index 023b5325369d..3125d68a6143 100644 --- a/components/html_viewer/web_test_delegate_impl.h +++ b/components/html_viewer/web_test_delegate_impl.h @@ -112,10 +112,12 @@ class WebTestDelegateImpl : public test_runner::WebTestDelegate { blink::WebPlugin* CreatePluginPlaceholder( blink::WebLocalFrame* frame, const blink::WebPluginParams& params) override; + void OnWebTestProxyBaseDestroy(test_runner::WebTestProxyBase* base) override; test_runner::TestPreferences prefs_; test_runner::WebTestInterfaces* test_interfaces_; test_runner::WebTestProxyBase* proxy_; + std::string dump_tree_; DISALLOW_COPY_AND_ASSIGN(WebTestDelegateImpl); }; diff --git a/components/test_runner/web_test_delegate.h b/components/test_runner/web_test_delegate.h index cbef50ab8b27..a59416fc1910 100644 --- a/components/test_runner/web_test_delegate.h +++ b/components/test_runner/web_test_delegate.h @@ -258,6 +258,8 @@ class WebTestDelegate { virtual blink::WebPlugin* CreatePluginPlaceholder( blink::WebLocalFrame* frame, const blink::WebPluginParams& params) = 0; + + virtual void OnWebTestProxyBaseDestroy(WebTestProxyBase* proxy) = 0; }; } // namespace test_runner diff --git a/components/test_runner/web_test_proxy.cc b/components/test_runner/web_test_proxy.cc index 23f020db3757..d4e21fc62f40 100644 --- a/components/test_runner/web_test_proxy.cc +++ b/components/test_runner/web_test_proxy.cc @@ -392,6 +392,7 @@ WebTestProxyBase::WebTestProxyBase() WebTestProxyBase::~WebTestProxyBase() { test_interfaces_->WindowClosed(this); + delegate_->OnWebTestProxyBaseDestroy(this); } void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { diff --git a/content/shell/renderer/layout_test/blink_test_runner.cc b/content/shell/renderer/layout_test/blink_test_runner.cc index 7e23c0353404..a3cd68cc43e1 100644 --- a/content/shell/renderer/layout_test/blink_test_runner.cc +++ b/content/shell/renderer/layout_test/blink_test_runner.cc @@ -700,6 +700,10 @@ blink::WebPlugin* BlinkTestRunner::CreatePluginPlaceholder( return placeholder->plugin(); } +void BlinkTestRunner::OnWebTestProxyBaseDestroy( + test_runner::WebTestProxyBase* proxy) { +} + // RenderViewObserver -------------------------------------------------------- void BlinkTestRunner::DidClearWindowObject(WebLocalFrame* frame) { diff --git a/content/shell/renderer/layout_test/blink_test_runner.h b/content/shell/renderer/layout_test/blink_test_runner.h index a70ee0fa80b7..f1b45a6935fb 100644 --- a/content/shell/renderer/layout_test/blink_test_runner.h +++ b/content/shell/renderer/layout_test/blink_test_runner.h @@ -139,6 +139,7 @@ class BlinkTestRunner : public RenderViewObserver, blink::WebPlugin* CreatePluginPlaceholder( blink::WebLocalFrame* frame, const blink::WebPluginParams& params) override; + void OnWebTestProxyBaseDestroy(test_runner::WebTestProxyBase* proxy) override; void Reset(); -- 2.11.4.GIT