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 <memory> |
| 9 #include <string> |
| 10 |
9 #include "content/public/test/browser_test_base.h" | 11 #include "content/public/test/browser_test_base.h" |
10 #include "headless/public/headless_browser.h" | 12 #include "headless/public/headless_browser.h" |
| 13 #include "headless/public/headless_web_contents.h" |
11 | 14 |
12 namespace base { | 15 namespace base { |
13 class RunLoop; | 16 class RunLoop; |
14 } | 17 } |
15 | 18 |
16 namespace headless { | 19 namespace headless { |
17 namespace runtime { | 20 namespace runtime { |
18 class EvaluateResult; | 21 class EvaluateResult; |
19 } | 22 } |
20 class HeadlessWebContents; | 23 class HeadlessDevToolsClient; |
21 | 24 |
22 // Base class for tests which require a full instance of the headless browser. | 25 // Base class for tests which require a full instance of the headless browser. |
23 class HeadlessBrowserTest : public content::BrowserTestBase { | 26 class HeadlessBrowserTest : public content::BrowserTestBase { |
24 public: | 27 public: |
25 // Notify that an asynchronous test is now complete and the test runner should | 28 // Notify that an asynchronous test is now complete and the test runner should |
26 // exit. | 29 // exit. |
27 void FinishAsynchronousTest(); | 30 void FinishAsynchronousTest(); |
28 | 31 |
29 protected: | 32 protected: |
30 HeadlessBrowserTest(); | 33 HeadlessBrowserTest(); |
(...skipping 24 matching lines...) Expand all Loading... |
55 protected: | 58 protected: |
56 // Returns the browser for the test. | 59 // Returns the browser for the test. |
57 HeadlessBrowser* browser() const; | 60 HeadlessBrowser* browser() const; |
58 | 61 |
59 private: | 62 private: |
60 std::unique_ptr<base::RunLoop> run_loop_; | 63 std::unique_ptr<base::RunLoop> run_loop_; |
61 | 64 |
62 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserTest); | 65 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserTest); |
63 }; | 66 }; |
64 | 67 |
| 68 #define HEADLESS_ASYNC_DEVTOOLED_TEST_F(TEST_FIXTURE_NAME) \ |
| 69 IN_PROC_BROWSER_TEST_F(TEST_FIXTURE_NAME, RunAsyncTest) { RunTest(); } \ |
| 70 class AsyncHeadlessBrowserTestNeedsSemicolon##TEST_FIXTURE_NAME {} |
| 71 |
| 72 // Base class for tests that require access to a DevToolsClient. Subclasses |
| 73 // should override the RunDevTooledTest() method, which is called asynchronously |
| 74 // when the DevToolsClient is ready. |
| 75 class HeadlessAsyncDevTooledBrowserTest : public HeadlessBrowserTest, |
| 76 public HeadlessWebContents::Observer { |
| 77 public: |
| 78 HeadlessAsyncDevTooledBrowserTest(); |
| 79 ~HeadlessAsyncDevTooledBrowserTest() override; |
| 80 |
| 81 // HeadlessWebContentsObserver implementation: |
| 82 void DevToolsTargetReady() override; |
| 83 |
| 84 // Implemented by tests and used to send request(s) to DevTools. Subclasses |
| 85 // need to ensure that FinishAsynchronousTest() is called after response(s) |
| 86 // are processed (e.g. in a callback). |
| 87 virtual void RunDevTooledTest() = 0; |
| 88 |
| 89 protected: |
| 90 void RunTest(); |
| 91 |
| 92 HeadlessWebContents* web_contents_; |
| 93 std::unique_ptr<HeadlessDevToolsClient> devtools_client_; |
| 94 }; |
| 95 |
65 } // namespace headless | 96 } // namespace headless |
66 | 97 |
67 #endif // HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ | 98 #endif // HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ |
OLD | NEW |