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 "content/public/test/browser_test_base.h" | 9 #include "content/public/test/browser_test_base.h" |
10 #include "headless/public/headless_browser.h" | 10 #include "headless/public/headless_browser.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class RunLoop; | 13 class RunLoop; |
14 } | 14 } |
15 | 15 |
16 namespace headless { | 16 namespace headless { |
| 17 namespace runtime { |
| 18 class EvaluateResult; |
| 19 } |
17 class HeadlessWebContents; | 20 class HeadlessWebContents; |
18 | 21 |
19 // Base class for tests which require a full instance of the headless browser. | 22 // Base class for tests which require a full instance of the headless browser. |
20 class HeadlessBrowserTest : public content::BrowserTestBase { | 23 class HeadlessBrowserTest : public content::BrowserTestBase { |
21 public: | 24 public: |
22 // Notify that an asynchronous test is now complete and the test runner should | 25 // Notify that an asynchronous test is now complete and the test runner should |
23 // exit. | 26 // exit. |
24 void FinishAsynchronousTest(); | 27 void FinishAsynchronousTest(); |
25 | 28 |
26 protected: | 29 protected: |
(...skipping 10 matching lines...) Expand all Loading... |
37 // pumps) cannot be set via this method. | 40 // pumps) cannot be set via this method. |
38 void SetBrowserOptions(HeadlessBrowser::Options options); | 41 void SetBrowserOptions(HeadlessBrowser::Options options); |
39 | 42 |
40 // Run an asynchronous test in a nested run loop. The caller should call | 43 // Run an asynchronous test in a nested run loop. The caller should call |
41 // FinishAsynchronousTest() to notify that the test should finish. | 44 // FinishAsynchronousTest() to notify that the test should finish. |
42 void RunAsynchronousTest(); | 45 void RunAsynchronousTest(); |
43 | 46 |
44 // Synchronously waits for a tab to finish loading. | 47 // Synchronously waits for a tab to finish loading. |
45 bool WaitForLoad(HeadlessWebContents* web_contents); | 48 bool WaitForLoad(HeadlessWebContents* web_contents); |
46 | 49 |
| 50 // Synchronously evaluates a script and returns the result. |
| 51 std::unique_ptr<runtime::EvaluateResult> EvaluateScript( |
| 52 HeadlessWebContents* web_contents, |
| 53 const std::string& script); |
| 54 |
47 protected: | 55 protected: |
48 // Returns the browser for the test. | 56 // Returns the browser for the test. |
49 HeadlessBrowser* browser() const; | 57 HeadlessBrowser* browser() const; |
50 | 58 |
51 private: | 59 private: |
52 std::unique_ptr<base::RunLoop> run_loop_; | 60 std::unique_ptr<base::RunLoop> run_loop_; |
53 | 61 |
54 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserTest); | 62 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserTest); |
55 }; | 63 }; |
56 | 64 |
57 } // namespace headless | 65 } // namespace headless |
58 | 66 |
59 #endif // HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ | 67 #endif // HEADLESS_TEST_HEADLESS_BROWSER_TEST_H_ |
OLD | NEW |