Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / html_viewer / layout_test_content_handler_impl.cc
blobaa11737dc10c52eac0fa4b2309454f3657ac3cb9
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"
7 #include "base/bind.h"
8 #include "components/html_viewer/html_document_application_delegate.h"
9 #include "components/html_viewer/web_test_delegate_impl.h"
10 #include "components/test_runner/web_frame_test_proxy.h"
11 #include "components/test_runner/web_test_proxy.h"
12 #include "third_party/WebKit/public/web/WebTestingSupport.h"
13 #include "third_party/WebKit/public/web/WebView.h"
15 namespace html_viewer {
17 class TestHTMLFrame : public HTMLFrame {
18 public:
19 explicit TestHTMLFrame(HTMLFrame::CreateParams* params) : HTMLFrame(params) {}
21 protected:
22 ~TestHTMLFrame() override {}
24 private:
25 // blink::WebFrameClient::
26 void didClearWindowObject(blink::WebLocalFrame* frame) override {
27 HTMLFrame::didClearWindowObject(frame);
28 blink::WebTestingSupport::injectInternalsObject(frame);
31 DISALLOW_COPY_AND_ASSIGN(TestHTMLFrame);
34 LayoutTestContentHandlerImpl::LayoutTestContentHandlerImpl(
35 GlobalState* global_state,
36 mojo::ApplicationImpl* app,
37 mojo::InterfaceRequest<mojo::ContentHandler> request,
38 test_runner::WebTestInterfaces* test_interfaces,
39 WebTestDelegateImpl* test_delegate)
40 : ContentHandlerImpl(global_state, app, request.Pass()),
41 test_interfaces_(test_interfaces),
42 test_delegate_(test_delegate) {
45 LayoutTestContentHandlerImpl::~LayoutTestContentHandlerImpl() {
48 void LayoutTestContentHandlerImpl::StartApplication(
49 mojo::InterfaceRequest<mojo::Application> request,
50 mojo::URLResponsePtr response) {
51 test_interfaces_->SetTestIsRunning(true);
52 test_interfaces_->ConfigureForTestWithURL(GURL(), false);
54 // HTMLDocumentApplicationDelegate deletes itself.
55 HTMLDocumentApplicationDelegate* delegate =
56 new HTMLDocumentApplicationDelegate(
57 request.Pass(), response.Pass(), global_state(),
58 app()->app_lifetime_helper()->CreateAppRefCount());
60 delegate->SetHTMLFrameCreationCallback(base::Bind(
61 &LayoutTestContentHandlerImpl::CreateHTMLFrame, base::Unretained(this)));
64 HTMLFrame* LayoutTestContentHandlerImpl::CreateHTMLFrame(
65 HTMLFrame::CreateParams* params) {
66 // The test harness isn't correctly set-up for iframes yet. So return a normal
67 // HTMLFrame for iframes.
68 if (params->parent)
69 return new HTMLFrame(params);
70 using ProxyType = test_runner::WebTestProxy<
71 test_runner::WebFrameTestProxy<TestHTMLFrame, HTMLFrame::CreateParams*>,
72 HTMLFrame::CreateParams*>;
73 // TODO(sky): this isn't right for all frame types, eg remote frames.
74 ProxyType* proxy = new ProxyType(params);
75 proxy->SetInterfaces(test_interfaces_);
76 proxy->SetDelegate(test_delegate_);
77 proxy->set_base_proxy(proxy);
78 test_delegate_->set_test_proxy(proxy);
79 test_interfaces_->SetWebView(proxy->web_view(), proxy);
80 proxy->set_widget(proxy->web_view());
81 test_interfaces_->BindTo(proxy->web_view()->mainFrame());
82 return proxy;
85 } // namespace html_viewer