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

Side by Side Diff: components/web_view/test_runner/test_runner_application_delegate.cc

Issue 1677293002: Bye bye Mandoline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moar Created 4 years, 10 months 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
(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/web_view/test_runner/test_runner_application_delegate.h"
6
7 #include <iostream>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h"
15 #include "base/location.h"
16 #include "base/path_service.h"
17 #include "base/thread_task_runner_handle.h"
18 #include "base/threading/thread_restrictions.h"
19 #include "build/build_config.h"
20 #include "components/mus/public/cpp/scoped_window_ptr.h"
21 #include "components/mus/public/cpp/window.h"
22 #include "components/mus/public/cpp/window_tree_connection.h"
23 #include "components/mus/public/cpp/window_tree_host_factory.h"
24 #include "components/test_runner/blink_test_platform_support.h"
25 #include "mojo/converters/geometry/geometry_type_converters.h"
26 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
27 #include "mojo/shell/public/cpp/connection.h"
28 #include "mojo/shell/public/cpp/shell.h"
29 #include "ui/gfx/geometry/rect.h"
30 #include "ui/gfx/geometry/size.h"
31 #include "url/gurl.h"
32
33 #if defined(OS_WIN)
34 #include "base/strings/sys_string_conversions.h"
35 #include "base/strings/utf_string_conversions.h"
36 #endif
37
38 namespace web_view {
39
40 TestRunnerApplicationDelegate::TestRunnerApplicationDelegate()
41 : shell_(nullptr), root_(nullptr), content_(nullptr) {}
42
43 TestRunnerApplicationDelegate::~TestRunnerApplicationDelegate() {
44 if (root_)
45 mus::ScopedWindowPtr::DeleteWindowOrWindowManager(root_);
46 }
47
48 void TestRunnerApplicationDelegate::LaunchURL(const GURL& test_url) {
49 if (!web_view_) {
50 web_view_.reset(new WebView(this));
51 web_view_->Init(shell_, content_);
52 }
53 mojo::URLRequestPtr request(mojo::URLRequest::New());
54 request->url = test_url.spec();
55 web_view_->web_view()->LoadRequest(std::move(request));
56 }
57
58 void TestRunnerApplicationDelegate::Terminate() {
59 if (root_)
60 mus::ScopedWindowPtr::DeleteWindowOrWindowManager(root_);
61 }
62
63 ////////////////////////////////////////////////////////////////////////////////
64 // mojo::ShellClient implementation:
65
66 void TestRunnerApplicationDelegate::Initialize(mojo::Shell* shell,
67 const std::string& url,
68 uint32_t id) {
69 if (!test_runner::BlinkTestPlatformInitialize()) {
70 NOTREACHED() << "Test environment could not be properly set up for blink.";
71 }
72 shell_ = shell;
73 mus::CreateWindowTreeHost(shell_, this, &host_, nullptr);
74 }
75
76 bool TestRunnerApplicationDelegate::AcceptConnection(
77 mojo::Connection* connection) {
78 connection->AddService<web_view::LayoutTestRunner>(this);
79 return true;
80 }
81
82 ////////////////////////////////////////////////////////////////////////////////
83 // mus::WindowTreeDelegate implementation:
84
85 void TestRunnerApplicationDelegate::OnEmbed(mus::Window* root) {
86 root_ = root;
87
88 // If this is a sys-check, then terminate in the next cycle.
89 const char kCheckLayoutTestSysDeps[] = "check-layout-test-sys-deps";
90 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
91 kCheckLayoutTestSysDeps)) {
92 base::ThreadTaskRunnerHandle::Get()->PostTask(
93 FROM_HERE, base::Bind(&TestRunnerApplicationDelegate::Terminate,
94 base::Unretained(this)));
95 return;
96 }
97
98 const gfx::Size kViewportSize(800, 600);
99 host_->SetSize(mojo::Size::From(kViewportSize));
100
101 content_ = root_->connection()->NewWindow();
102 root_->AddChild(content_);
103 content_->SetBounds(gfx::Rect(kViewportSize));
104 content_->SetVisible(true);
105
106 std::cout << "#READY\n";
107 std::cout.flush();
108
109 auto cmdline_args = base::CommandLine::ForCurrentProcess()->GetArgs();
110 test_extractor_.reset(new test_runner::TestInfoExtractor(cmdline_args));
111
112 scoped_ptr<test_runner::TestInfo> test_info = test_extractor_->GetNextTest();
113 if (test_info)
114 LaunchURL(test_info->url);
115 }
116
117 void TestRunnerApplicationDelegate::OnConnectionLost(
118 mus::WindowTreeConnection* connection) {
119 root_ = nullptr;
120 shell_->Quit();
121 }
122
123 ////////////////////////////////////////////////////////////////////////////////
124 // mojom::WebViewClient implementation:
125
126 void TestRunnerApplicationDelegate::TopLevelNavigateRequest(
127 mojo::URLRequestPtr request) {
128 web_view_->web_view()->LoadRequest(std::move(request));
129 }
130
131 void TestRunnerApplicationDelegate::TopLevelNavigationStarted(
132 const mojo::String& url) {}
133 void TestRunnerApplicationDelegate::LoadingStateChanged(bool is_loading,
134 double progress) {}
135 void TestRunnerApplicationDelegate::BackForwardChanged(
136 mojom::ButtonState back_button,
137 mojom::ButtonState forward_button) {}
138 void TestRunnerApplicationDelegate::TitleChanged(const mojo::String& title) {}
139
140 ////////////////////////////////////////////////////////////////////////////////
141 // LayoutTestRunner implementation:
142
143 void TestRunnerApplicationDelegate::TestFinished() {
144 std::cout << "#EOF\n";
145 std::cout.flush();
146
147 std::cerr << "#EOF\n";
148 std::cerr.flush();
149
150 scoped_ptr<test_runner::TestInfo> test_info = test_extractor_->GetNextTest();
151 if (test_info)
152 LaunchURL(test_info->url);
153 else
154 Terminate();
155 }
156
157 ////////////////////////////////////////////////////////////////////////////////
158 // mojo::InterfaceFactory<LayoutTestRunner> implementation:
159
160 void TestRunnerApplicationDelegate::Create(
161 mojo::Connection* connection,
162 mojo::InterfaceRequest<web_view::LayoutTestRunner> request) {
163 layout_test_runner_.AddBinding(this, std::move(request));
164 }
165
166 } // namespace web_view
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698