OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "headless/test/headless_browser_test.h" | 5 #include "headless/test/headless_browser_test.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "content/public/test/test_navigation_observer.h" |
14 #include "headless/lib/browser/headless_browser_impl.h" | 15 #include "headless/lib/browser/headless_browser_impl.h" |
| 16 #include "headless/lib/browser/headless_web_contents_impl.h" |
15 #include "headless/lib/headless_content_main_delegate.h" | 17 #include "headless/lib/headless_content_main_delegate.h" |
16 #include "headless/public/devtools/domains/runtime.h" | 18 #include "headless/public/devtools/domains/runtime.h" |
17 #include "headless/public/headless_devtools_client.h" | 19 #include "headless/public/headless_devtools_client.h" |
18 #include "headless/public/headless_devtools_target.h" | 20 #include "headless/public/headless_devtools_target.h" |
19 #include "headless/public/headless_web_contents.h" | 21 #include "headless/public/headless_web_contents.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
22 #include "url/gurl.h" | 24 #include "url/gurl.h" |
23 | 25 |
24 namespace headless { | 26 namespace headless { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 152 |
151 HeadlessBrowser* HeadlessBrowserTest::browser() const { | 153 HeadlessBrowser* HeadlessBrowserTest::browser() const { |
152 return HeadlessContentMainDelegate::GetInstance()->browser(); | 154 return HeadlessContentMainDelegate::GetInstance()->browser(); |
153 } | 155 } |
154 | 156 |
155 HeadlessBrowser::Options* HeadlessBrowserTest::options() const { | 157 HeadlessBrowser::Options* HeadlessBrowserTest::options() const { |
156 return HeadlessContentMainDelegate::GetInstance()->browser()->options(); | 158 return HeadlessContentMainDelegate::GetInstance()->browser()->options(); |
157 } | 159 } |
158 | 160 |
159 bool HeadlessBrowserTest::WaitForLoad(HeadlessWebContents* web_contents) { | 161 bool HeadlessBrowserTest::WaitForLoad(HeadlessWebContents* web_contents) { |
160 SynchronousLoadObserver load_observer(this, web_contents); | 162 HeadlessWebContentsImpl* web_contents_impl = |
161 RunAsynchronousTest(); | 163 HeadlessWebContentsImpl::From(web_contents); |
162 return load_observer.navigation_succeeded(); | 164 content::TestNavigationObserver observer(web_contents_impl->web_contents(), |
| 165 1); |
| 166 observer.Wait(); |
| 167 return observer.last_navigation_succeeded(); |
163 } | 168 } |
164 | 169 |
165 std::unique_ptr<runtime::EvaluateResult> HeadlessBrowserTest::EvaluateScript( | 170 std::unique_ptr<runtime::EvaluateResult> HeadlessBrowserTest::EvaluateScript( |
166 HeadlessWebContents* web_contents, | 171 HeadlessWebContents* web_contents, |
167 const std::string& script) { | 172 const std::string& script) { |
168 EvaluateHelper helper(this, web_contents, script); | 173 EvaluateHelper helper(this, web_contents, script); |
169 RunAsynchronousTest(); | 174 RunAsynchronousTest(); |
170 return helper.TakeResult(); | 175 return helper.TakeResult(); |
171 } | 176 } |
172 | 177 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 if (!render_process_exited_) | 225 if (!render_process_exited_) |
221 web_contents_->GetDevToolsTarget()->DetachClient(devtools_client_.get()); | 226 web_contents_->GetDevToolsTarget()->DetachClient(devtools_client_.get()); |
222 web_contents_->RemoveObserver(this); | 227 web_contents_->RemoveObserver(this); |
223 web_contents_->Close(); | 228 web_contents_->Close(); |
224 web_contents_ = nullptr; | 229 web_contents_ = nullptr; |
225 browser_context_->Close(); | 230 browser_context_->Close(); |
226 browser_context_ = nullptr; | 231 browser_context_ = nullptr; |
227 } | 232 } |
228 | 233 |
229 } // namespace headless | 234 } // namespace headless |
OLD | NEW |