1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/html_viewer/layout_test_content_handler_impl.h"
8 #include "components/html_viewer/html_document_application_delegate.h"
9 #include "components/html_viewer/html_widget.h"
10 #include "components/html_viewer/web_test_delegate_impl.h"
11 #include "components/test_runner/web_frame_test_proxy.h"
12 #include "third_party/WebKit/public/web/WebLocalFrame.h"
13 #include "third_party/WebKit/public/web/WebTestingSupport.h"
14 #include "third_party/WebKit/public/web/WebView.h"
16 namespace html_viewer
{
18 class TestHTMLFrame
: public HTMLFrame
{
20 explicit TestHTMLFrame(HTMLFrame::CreateParams
* params
)
21 : HTMLFrame(params
), test_interfaces_(nullptr) {}
23 void set_test_interfaces(test_runner::WebTestInterfaces
* test_interfaces
) {
24 test_interfaces_
= test_interfaces
;
28 ~TestHTMLFrame() override
{}
31 // blink::WebFrameClient::
32 void didClearWindowObject(blink::WebLocalFrame
* frame
) override
{
33 HTMLFrame::didClearWindowObject(frame
);
34 blink::WebTestingSupport::injectInternalsObject(frame
);
35 DCHECK(test_interfaces_
);
36 test_interfaces_
->BindTo(frame
);
39 test_runner::WebTestInterfaces
* test_interfaces_
;
41 DISALLOW_COPY_AND_ASSIGN(TestHTMLFrame
);
44 LayoutTestContentHandlerImpl::LayoutTestContentHandlerImpl(
45 GlobalState
* global_state
,
46 mojo::ApplicationImpl
* app
,
47 mojo::InterfaceRequest
<mojo::ContentHandler
> request
,
48 test_runner::WebTestInterfaces
* test_interfaces
,
49 WebTestDelegateImpl
* test_delegate
)
50 : ContentHandlerImpl(global_state
, app
, request
.Pass()),
51 test_interfaces_(test_interfaces
),
52 test_delegate_(test_delegate
),
53 web_widget_proxy_(nullptr) {}
55 LayoutTestContentHandlerImpl::~LayoutTestContentHandlerImpl() {
58 void LayoutTestContentHandlerImpl::StartApplication(
59 mojo::InterfaceRequest
<mojo::Application
> request
,
60 mojo::URLResponsePtr response
) {
61 test_interfaces_
->SetTestIsRunning(true);
62 test_interfaces_
->ConfigureForTestWithURL(GURL(), false);
64 // HTMLDocumentApplicationDelegate deletes itself.
65 HTMLDocumentApplicationDelegate
* delegate
=
66 new HTMLDocumentApplicationDelegate(
67 request
.Pass(), response
.Pass(), global_state(),
68 app()->app_lifetime_helper()->CreateAppRefCount());
70 delegate
->set_html_factory(this);
73 HTMLWidgetRootLocal
* LayoutTestContentHandlerImpl::CreateHTMLWidgetRootLocal(
74 HTMLWidgetRootLocal::CreateParams
* params
) {
75 web_widget_proxy_
= new WebWidgetProxy(params
);
76 return web_widget_proxy_
;
79 HTMLFrame
* LayoutTestContentHandlerImpl::CreateHTMLFrame(
80 HTMLFrame::CreateParams
* params
) {
81 // The test harness isn't correctly set-up for iframes yet. So return a normal
82 // HTMLFrame for iframes.
83 if (params
->parent
|| !params
->view
|| params
->view
->id() != params
->id
)
84 return new HTMLFrame(params
);
87 test_runner::WebFrameTestProxy
<TestHTMLFrame
, HTMLFrame::CreateParams
*>;
88 ProxyType
* proxy
= new ProxyType(params
);
89 proxy
->set_test_interfaces(test_interfaces_
);
91 web_widget_proxy_
->SetInterfaces(test_interfaces_
);
92 web_widget_proxy_
->SetDelegate(test_delegate_
);
93 proxy
->set_base_proxy(web_widget_proxy_
);
94 test_delegate_
->set_test_proxy(web_widget_proxy_
);
95 test_interfaces_
->SetWebView(web_widget_proxy_
->web_view(),
97 web_widget_proxy_
->set_widget(web_widget_proxy_
->web_view());
98 test_interfaces_
->BindTo(web_widget_proxy_
->web_view()->mainFrame());
102 } // namespace html_viewer