OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 5 #ifndef CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
6 #define CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 6 #define CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
7 | 7 |
8 #include "chrome/app/scoped_ole_initializer.h" | |
9 #include "chrome/common/notification_registrar.h" | 8 #include "chrome/common/notification_registrar.h" |
10 #include "chrome/common/notification_observer.h" | 9 #include "chrome/common/notification_observer.h" |
11 #include "net/url_request/url_request_unittest.h" | 10 #include "net/url_request/url_request_unittest.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 | 12 |
14 class Browser; | 13 class Browser; |
15 class Profile; | 14 class Profile; |
16 | 15 |
17 // Base class for tests wanting to bring up a browser in the unit test process. | 16 // Base class for tests wanting to bring up a browser in the unit test process. |
18 // Writing tests with InProcessBrowserTest is slightly different than that of | 17 // Writing tests with InProcessBrowserTest is slightly different than that of |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 66 |
68 // Starts an HTTP server. | 67 // Starts an HTTP server. |
69 HTTPTestServer* StartHTTPServer(); | 68 HTTPTestServer* StartHTTPServer(); |
70 | 69 |
71 // Creates a browser with a single tab (about:blank), waits for the tab to | 70 // Creates a browser with a single tab (about:blank), waits for the tab to |
72 // finish loading and shows the browser. | 71 // finish loading and shows the browser. |
73 // | 72 // |
74 // This is invoked from Setup. | 73 // This is invoked from Setup. |
75 virtual Browser* CreateBrowser(Profile* profile); | 74 virtual Browser* CreateBrowser(Profile* profile); |
76 | 75 |
| 76 // Sets some test states (see below for comments). Call this in your test |
| 77 // constructor. |
| 78 void set_show_window(bool show) { show_window_ = show; } |
| 79 void EnableDOMAutomation() { dom_automation_enabled_ = true; } |
| 80 |
77 private: | 81 private: |
78 // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and | 82 // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and |
79 // destroys the browser. | 83 // destroys the browser. |
80 void RunTestOnMainThreadLoop(); | 84 void RunTestOnMainThreadLoop(); |
81 | 85 |
82 // Browser created from CreateBrowser. | 86 // Browser created from CreateBrowser. |
83 Browser* browser_; | 87 Browser* browser_; |
84 | 88 |
85 // Used to track when the browser is deleted. | 89 // Used to track when the browser is deleted. |
86 NotificationRegistrar registrar_; | 90 NotificationRegistrar registrar_; |
87 | 91 |
88 // HTTPServer, created when StartHTTPServer is invoked. | 92 // HTTPServer, created when StartHTTPServer is invoked. |
89 scoped_refptr<HTTPTestServer> http_server_; | 93 scoped_refptr<HTTPTestServer> http_server_; |
90 | 94 |
91 ScopedOleInitializer ole_initializer_; | 95 // Whether this test requires the browser windows to be shown (interactive |
| 96 // tests for example need the windows shown). |
| 97 bool show_window_; |
| 98 |
| 99 // Whether the JavaScript can access the DOMAutomationController (a JS object |
| 100 // that can send messages back to the browser). |
| 101 bool dom_automation_enabled_; |
92 | 102 |
93 DISALLOW_COPY_AND_ASSIGN(InProcessBrowserTest); | 103 DISALLOW_COPY_AND_ASSIGN(InProcessBrowserTest); |
94 }; | 104 }; |
95 | 105 |
96 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ | 106 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ |
97 parent_id)\ | 107 parent_id)\ |
98 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ | 108 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ |
99 public:\ | 109 public:\ |
100 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ | 110 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ |
101 protected:\ | 111 protected:\ |
(...skipping 14 matching lines...) Expand all Loading... |
116 parent_class::TearDownTestCase, \ | 126 parent_class::TearDownTestCase, \ |
117 new ::testing::internal::TestFactoryImpl<\ | 127 new ::testing::internal::TestFactoryImpl<\ |
118 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ | 128 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ |
119 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 129 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
120 | 130 |
121 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ | 131 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ |
122 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ | 132 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ |
123 ::testing::internal::GetTypeId<test_fixture>()) | 133 ::testing::internal::GetTypeId<test_fixture>()) |
124 | 134 |
125 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 135 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
OLD | NEW |