| 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/common/notification_registrar.h" | 8 #include "chrome/common/notification_registrar.h" |
| 9 #include "chrome/common/notification_observer.h" | 9 #include "chrome/common/notification_observer.h" |
| 10 #include "net/url_request/url_request_unittest.h" | 10 #include "net/url_request/url_request_unittest.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 class Browser; | 13 class Browser; |
| 14 class Profile; | 14 class Profile; |
| 15 namespace net { |
| 16 class RuleBasedHostMapper; |
| 17 } |
| 15 | 18 |
| 16 // Base class for tests wanting to bring up a browser in the unit test process. | 19 // Base class for tests wanting to bring up a browser in the unit test process. |
| 17 // Writing tests with InProcessBrowserTest is slightly different than that of | 20 // Writing tests with InProcessBrowserTest is slightly different than that of |
| 18 // other tests. This is necessitated by InProcessBrowserTest running a message | 21 // other tests. This is necessitated by InProcessBrowserTest running a message |
| 19 // loop. To use InProcessBrowserTest do the following: | 22 // loop. To use InProcessBrowserTest do the following: |
| 20 // . Use the macro IN_PROC_BROWSER_TEST_F to define your test. | 23 // . Use the macro IN_PROC_BROWSER_TEST_F to define your test. |
| 21 // . Your test method is invoked on the ui thread. If you need to block until | 24 // . Your test method is invoked on the ui thread. If you need to block until |
| 22 // state changes you'll need to run the message loop from your test method. | 25 // state changes you'll need to run the message loop from your test method. |
| 23 // For example, if you need to wait till a find bar has completely been shown | 26 // For example, if you need to wait till a find bar has completely been shown |
| 24 // you'll need to invoke ui_test_utils::RunMessageLoop. When the message bar | 27 // you'll need to invoke ui_test_utils::RunMessageLoop. When the message bar |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 const NotificationSource& source, | 60 const NotificationSource& source, |
| 58 const NotificationDetails& details); | 61 const NotificationDetails& details); |
| 59 | 62 |
| 60 protected: | 63 protected: |
| 61 // Returns the browser created by CreateBrowser. | 64 // Returns the browser created by CreateBrowser. |
| 62 Browser* browser() const { return browser_; } | 65 Browser* browser() const { return browser_; } |
| 63 | 66 |
| 64 // Override this rather than TestBody. | 67 // Override this rather than TestBody. |
| 65 virtual void RunTestOnMainThread() = 0; | 68 virtual void RunTestOnMainThread() = 0; |
| 66 | 69 |
| 70 // Allows subclasses to configure the host mapper. By default this blocks |
| 71 // requests to google.com as Chrome pings that on startup and we don't want to |
| 72 // do that during testing. |
| 73 virtual void ConfigureHostMapper(net::RuleBasedHostMapper* host_mapper); |
| 74 |
| 67 // Starts an HTTP server. | 75 // Starts an HTTP server. |
| 68 HTTPTestServer* StartHTTPServer(); | 76 HTTPTestServer* StartHTTPServer(); |
| 69 | 77 |
| 70 // Creates a browser with a single tab (about:blank), waits for the tab to | 78 // Creates a browser with a single tab (about:blank), waits for the tab to |
| 71 // finish loading and shows the browser. | 79 // finish loading and shows the browser. |
| 72 // | 80 // |
| 73 // This is invoked from Setup. | 81 // This is invoked from Setup. |
| 74 virtual Browser* CreateBrowser(Profile* profile); | 82 virtual Browser* CreateBrowser(Profile* profile); |
| 75 | 83 |
| 76 // Sets some test states (see below for comments). Call this in your test | 84 // Sets some test states (see below for comments). Call this in your test |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 parent_class::TearDownTestCase, \ | 145 parent_class::TearDownTestCase, \ |
| 138 new ::testing::internal::TestFactoryImpl<\ | 146 new ::testing::internal::TestFactoryImpl<\ |
| 139 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ | 147 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ |
| 140 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 148 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
| 141 | 149 |
| 142 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ | 150 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ |
| 143 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ | 151 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ |
| 144 ::testing::internal::GetTypeId<test_fixture>()) | 152 ::testing::internal::GetTypeId<test_fixture>()) |
| 145 | 153 |
| 146 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 154 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
| OLD | NEW |