| 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" | |
| 9 #include "chrome/common/notification_observer.h" | |
| 10 #include "net/url_request/url_request_unittest.h" | 8 #include "net/url_request/url_request_unittest.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 10 |
| 13 class Browser; | 11 class Browser; |
| 14 class Profile; | 12 class Profile; |
| 15 namespace net { | 13 namespace net { |
| 16 class RuleBasedHostMapper; | 14 class RuleBasedHostMapper; |
| 17 } | 15 } |
| 18 | 16 |
| 19 // Base class for tests wanting to bring up a browser in the unit test process. | 17 // Base class for tests wanting to bring up a browser in the unit test process. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 // | 30 // |
| 33 // By default InProcessBrowserTest creates a single Browser (as returned from | 31 // By default InProcessBrowserTest creates a single Browser (as returned from |
| 34 // the CreateBrowser method). You can obviously create more as needed. | 32 // the CreateBrowser method). You can obviously create more as needed. |
| 35 | 33 |
| 36 // Browsers created while InProcessBrowserTest is running are shown hidden. Use | 34 // Browsers created while InProcessBrowserTest is running are shown hidden. Use |
| 37 // the command line switch --show-windows to make them visible when debugging. | 35 // the command line switch --show-windows to make them visible when debugging. |
| 38 // | 36 // |
| 39 // InProcessBrowserTest disables the sandbox when running. | 37 // InProcessBrowserTest disables the sandbox when running. |
| 40 // | 38 // |
| 41 // See ui_test_utils for a handful of methods designed for use with this class. | 39 // See ui_test_utils for a handful of methods designed for use with this class. |
| 42 class InProcessBrowserTest : public testing::Test, public NotificationObserver { | 40 class InProcessBrowserTest : public testing::Test { |
| 43 public: | 41 public: |
| 44 InProcessBrowserTest(); | 42 InProcessBrowserTest(); |
| 45 | 43 |
| 46 // We do this so we can be used in a Task. | 44 // We do this so we can be used in a Task. |
| 47 void AddRef() {} | 45 void AddRef() {} |
| 48 void Release() {} | 46 void Release() {} |
| 49 | 47 |
| 50 // Configures everything for an in process browser test, then invokes | 48 // Configures everything for an in process browser test, then invokes |
| 51 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop. | 49 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop. |
| 52 virtual void SetUp(); | 50 virtual void SetUp(); |
| 53 | 51 |
| 54 // Restores state configured in SetUp. | 52 // Restores state configured in SetUp. |
| 55 virtual void TearDown(); | 53 virtual void TearDown(); |
| 56 | 54 |
| 57 // Used to track when the browser_ is destroyed. Resets the |browser_| field | |
| 58 // to NULL. | |
| 59 virtual void Observe(NotificationType type, | |
| 60 const NotificationSource& source, | |
| 61 const NotificationDetails& details); | |
| 62 | |
| 63 protected: | 55 protected: |
| 64 // Returns the browser created by CreateBrowser. | 56 // Returns the browser created by CreateBrowser. |
| 65 Browser* browser() const { return browser_; } | 57 Browser* browser() const { return browser_; } |
| 66 | 58 |
| 67 // Override this rather than TestBody. | 59 // Override this rather than TestBody. |
| 68 virtual void RunTestOnMainThread() = 0; | 60 virtual void RunTestOnMainThread() = 0; |
| 69 | 61 |
| 70 // Override this to add command line flags specific to your test. | 62 // Override this to add command line flags specific to your test. |
| 71 virtual void SetUpCommandLine(CommandLine* command_line) {} | 63 virtual void SetUpCommandLine(CommandLine* command_line) {} |
| 72 | 64 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 void EnableSingleProcess() { single_process_ = true; } | 83 void EnableSingleProcess() { single_process_ = true; } |
| 92 | 84 |
| 93 private: | 85 private: |
| 94 // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and | 86 // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and |
| 95 // destroys the browser. | 87 // destroys the browser. |
| 96 void RunTestOnMainThreadLoop(); | 88 void RunTestOnMainThreadLoop(); |
| 97 | 89 |
| 98 // Browser created from CreateBrowser. | 90 // Browser created from CreateBrowser. |
| 99 Browser* browser_; | 91 Browser* browser_; |
| 100 | 92 |
| 101 // Used to track when the browser is deleted. | |
| 102 NotificationRegistrar registrar_; | |
| 103 | |
| 104 // HTTPServer, created when StartHTTPServer is invoked. | 93 // HTTPServer, created when StartHTTPServer is invoked. |
| 105 scoped_refptr<HTTPTestServer> http_server_; | 94 scoped_refptr<HTTPTestServer> http_server_; |
| 106 | 95 |
| 107 // Whether this test requires the browser windows to be shown (interactive | 96 // Whether this test requires the browser windows to be shown (interactive |
| 108 // tests for example need the windows shown). | 97 // tests for example need the windows shown). |
| 109 bool show_window_; | 98 bool show_window_; |
| 110 | 99 |
| 111 // Whether the JavaScript can access the DOMAutomationController (a JS object | 100 // Whether the JavaScript can access the DOMAutomationController (a JS object |
| 112 // that can send messages back to the browser). | 101 // that can send messages back to the browser). |
| 113 bool dom_automation_enabled_; | 102 bool dom_automation_enabled_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 parent_class::TearDownTestCase, \ | 137 parent_class::TearDownTestCase, \ |
| 149 new ::testing::internal::TestFactoryImpl<\ | 138 new ::testing::internal::TestFactoryImpl<\ |
| 150 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ | 139 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ |
| 151 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 140 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
| 152 | 141 |
| 153 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ | 142 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ |
| 154 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ | 143 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ |
| 155 ::testing::internal::GetTypeId<test_fixture>()) | 144 ::testing::internal::GetTypeId<test_fixture>()) |
| 156 | 145 |
| 157 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 146 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
| OLD | NEW |