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