OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/html_viewer/layout_test_content_handler_impl.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/macros.h" | |
11 #include "components/html_viewer/global_state.h" | |
12 #include "components/html_viewer/html_document_application_delegate.h" | |
13 #include "components/html_viewer/html_widget.h" | |
14 #include "components/html_viewer/layout_test_blink_settings_impl.h" | |
15 #include "components/html_viewer/web_test_delegate_impl.h" | |
16 #include "components/test_runner/web_frame_test_proxy.h" | |
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
18 #include "third_party/WebKit/public/web/WebTestingSupport.h" | |
19 #include "third_party/WebKit/public/web/WebView.h" | |
20 | |
21 namespace html_viewer { | |
22 | |
23 class TestHTMLFrame : public HTMLFrame { | |
24 public: | |
25 explicit TestHTMLFrame(HTMLFrame::CreateParams* params) | |
26 : HTMLFrame(params), test_interfaces_(nullptr) {} | |
27 | |
28 void set_test_interfaces(test_runner::WebTestInterfaces* test_interfaces) { | |
29 test_interfaces_ = test_interfaces; | |
30 } | |
31 | |
32 protected: | |
33 ~TestHTMLFrame() override {} | |
34 | |
35 private: | |
36 // blink::WebFrameClient:: | |
37 void didClearWindowObject(blink::WebLocalFrame* frame) override { | |
38 HTMLFrame::didClearWindowObject(frame); | |
39 blink::WebTestingSupport::injectInternalsObject(frame); | |
40 DCHECK(test_interfaces_); | |
41 test_interfaces_->BindTo(frame); | |
42 } | |
43 | |
44 test_runner::WebTestInterfaces* test_interfaces_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(TestHTMLFrame); | |
47 }; | |
48 | |
49 LayoutTestContentHandlerImpl::LayoutTestContentHandlerImpl( | |
50 GlobalState* global_state, | |
51 mojo::Shell* shell, | |
52 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request, | |
53 test_runner::WebTestInterfaces* test_interfaces, | |
54 WebTestDelegateImpl* test_delegate) | |
55 : ContentHandlerImpl(global_state, shell, std::move(request)), | |
56 test_interfaces_(test_interfaces), | |
57 test_delegate_(test_delegate), | |
58 web_widget_proxy_(nullptr), | |
59 app_refcount_(shell->CreateAppRefCount()) {} | |
60 | |
61 LayoutTestContentHandlerImpl::~LayoutTestContentHandlerImpl() { | |
62 } | |
63 | |
64 void LayoutTestContentHandlerImpl::StartApplication( | |
65 mojo::ApplicationRequest request, | |
66 mojo::URLResponsePtr response, | |
67 const mojo::Callback<void()>& destruct_callback) { | |
68 test_interfaces_->SetTestIsRunning(true); | |
69 test_interfaces_->ConfigureForTestWithURL(GURL(), false); | |
70 | |
71 // HTMLDocumentApplicationDelegate deletes itself. | |
72 HTMLDocumentApplicationDelegate* delegate = | |
73 new HTMLDocumentApplicationDelegate( | |
74 std::move(request), std::move(response), global_state(), | |
75 shell()->CreateAppRefCount(), destruct_callback); | |
76 | |
77 delegate->set_html_factory(this); | |
78 } | |
79 | |
80 HTMLWidgetRootLocal* LayoutTestContentHandlerImpl::CreateHTMLWidgetRootLocal( | |
81 HTMLWidgetRootLocal::CreateParams* params) { | |
82 web_widget_proxy_ = new WebWidgetProxy(params); | |
83 return web_widget_proxy_; | |
84 } | |
85 | |
86 HTMLFrame* LayoutTestContentHandlerImpl::CreateHTMLFrame( | |
87 HTMLFrame::CreateParams* params) { | |
88 params->manager->global_state()->set_blink_settings( | |
89 new LayoutTestBlinkSettingsImpl()); | |
90 | |
91 // The test harness isn't correctly set-up for iframes yet. So return a normal | |
92 // HTMLFrame for iframes. | |
93 if (params->parent || !params->window || params->window->id() != params->id) | |
94 return new HTMLFrame(params); | |
95 | |
96 using ProxyType = | |
97 test_runner::WebFrameTestProxy<TestHTMLFrame, HTMLFrame::CreateParams*>; | |
98 ProxyType* proxy = new ProxyType(params); | |
99 proxy->set_test_interfaces(test_interfaces_); | |
100 | |
101 web_widget_proxy_->SetInterfaces(test_interfaces_); | |
102 web_widget_proxy_->SetDelegate(test_delegate_); | |
103 proxy->set_base_proxy(web_widget_proxy_); | |
104 test_delegate_->set_test_proxy(web_widget_proxy_); | |
105 test_interfaces_->SetWebView(web_widget_proxy_->web_view(), | |
106 web_widget_proxy_); | |
107 web_widget_proxy_->set_widget(web_widget_proxy_->web_view()); | |
108 test_interfaces_->BindTo(web_widget_proxy_->web_view()->mainFrame()); | |
109 return proxy; | |
110 } | |
111 | |
112 } // namespace html_viewer | |
OLD | NEW |