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 #ifndef HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ | 5 #ifndef HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ |
6 #define HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ | 6 #define HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include "content/public/test/browser_test_base.h" | 9 #include "content/public/test/browser_test_base.h" |
9 #include "headless/public/headless_browser.h" | 10 #include "headless/public/headless_browser.h" |
10 | 11 |
| 12 namespace base { |
| 13 class RunLoop; |
| 14 } |
| 15 |
11 namespace headless { | 16 namespace headless { |
12 class HeadlessWebContents; | 17 class HeadlessWebContents; |
13 | 18 |
14 // Base class for tests which require a full instance of the headless browser. | 19 // Base class for tests which require a full instance of the headless browser. |
15 class HeadlessBrowserTest : public content::BrowserTestBase { | 20 class HeadlessBrowserTest : public content::BrowserTestBase { |
| 21 public: |
| 22 // Notify that an asynchronous test is now complete and the test runner should |
| 23 // exit. |
| 24 void FinishAsynchronousTest(); |
| 25 |
16 protected: | 26 protected: |
17 HeadlessBrowserTest(); | 27 HeadlessBrowserTest(); |
18 ~HeadlessBrowserTest() override; | 28 ~HeadlessBrowserTest() override; |
19 | 29 |
20 // BrowserTestBase: | 30 // BrowserTestBase: |
21 void RunTestOnMainThreadLoop() override; | 31 void RunTestOnMainThreadLoop() override; |
22 void SetUpOnMainThread() override; | 32 void SetUpOnMainThread() override; |
23 void TearDownOnMainThread() override; | 33 void TearDownOnMainThread() override; |
24 | 34 |
25 // Customize the options used in this test. Note that options which take | 35 // Customize the options used in this test. Note that options which take |
26 // effect before the message loop has been started (e.g., custom message | 36 // effect before the message loop has been started (e.g., custom message |
27 // pumps) cannot be set via this method. | 37 // pumps) cannot be set via this method. |
28 void SetBrowserOptions(const HeadlessBrowser::Options& options); | 38 void SetBrowserOptions(const HeadlessBrowser::Options& options); |
29 | 39 |
30 // Navigate to |url| and wait for the document load to complete. | 40 // Run an asynchronous test in a nested run loop. The caller should call |
31 bool NavigateAndWaitForLoad(HeadlessWebContents* web_contents, | 41 // FinishAsynchronousTest() to notify that the test should finish. |
32 const GURL& url); | 42 void RunAsynchronousTest(); |
| 43 |
| 44 // Synchronously waits for a tab to finish loading. |
| 45 bool WaitForLoad(HeadlessWebContents* web_contents); |
33 | 46 |
34 protected: | 47 protected: |
35 // Returns the browser for the test. | 48 // Returns the browser for the test. |
36 HeadlessBrowser* browser() const; | 49 HeadlessBrowser* browser() const; |
37 | 50 |
38 private: | 51 private: |
| 52 std::unique_ptr<base::RunLoop> run_loop_; |
| 53 |
39 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserTest); | 54 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserTest); |
40 }; | 55 }; |
41 | 56 |
42 } // namespace headless | 57 } // namespace headless |
43 | 58 |
44 #endif // HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ | 59 #endif // HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ |
OLD | NEW |