| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ | 5 #ifndef CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ |
| 6 #define CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ | 6 #define CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/scoped_temp_dir.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
| 16 #include "chrome_frame/chrome_tab.h" | 17 #include "chrome_frame/chrome_tab.h" |
| 17 #include "chrome_frame/test/chrome_frame_test_utils.h" | 18 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 18 #include "chrome_frame/test/test_server.h" | 19 #include "chrome_frame/test/test_server.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 | 22 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 std::string expected_result_; | 137 std::string expected_result_; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 // Class that: | 140 // Class that: |
| 140 // 1) Starts the local webserver, | 141 // 1) Starts the local webserver, |
| 141 // 2) Supports launching browsers - Internet Explorer with local url | 142 // 2) Supports launching browsers - Internet Explorer with local url |
| 142 // 3) Wait the webserver to finish. It is supposed the test webpage to shutdown | 143 // 3) Wait the webserver to finish. It is supposed the test webpage to shutdown |
| 143 // the server by navigating to "kill" page | 144 // the server by navigating to "kill" page |
| 144 // 4) Supports read the posted results from the test webpage to the "dump" | 145 // 4) Supports read the posted results from the test webpage to the "dump" |
| 145 // webserver directory | 146 // webserver directory |
| 146 class ChromeFrameTestWithWebServer: public testing::Test { | 147 class ChromeFrameTestWithWebServer : public testing::Test { |
| 147 public: | 148 public: |
| 148 ChromeFrameTestWithWebServer(); | 149 ChromeFrameTestWithWebServer(); |
| 149 | 150 |
| 150 protected: | 151 protected: |
| 151 enum BrowserKind { INVALID, IE, CHROME }; | 152 enum BrowserKind { INVALID, IE, CHROME }; |
| 152 | 153 |
| 153 bool LaunchBrowser(BrowserKind browser, const wchar_t* url); | 154 bool LaunchBrowser(BrowserKind browser, const wchar_t* url); |
| 154 bool WaitForTestToComplete(int milliseconds); | 155 bool WaitForTestToComplete(int milliseconds); |
| 155 // Waits for the page to notify us of the window.onload event firing. | 156 // Waits for the page to notify us of the window.onload event firing. |
| 156 // Note that the milliseconds value is only approximate. | 157 // Note that the milliseconds value is only approximate. |
| 157 bool WaitForOnLoad(int milliseconds); | 158 bool WaitForOnLoad(int milliseconds); |
| 158 | 159 |
| 159 // Launches the specified browser and waits for the test to complete | 160 // Launches the specified browser and waits for the test to complete |
| 160 // (see WaitForTestToComplete). Then checks that the outcome is equal | 161 // (see WaitForTestToComplete). Then checks that the outcome is equal |
| 161 // to the expected result. | 162 // to the expected result. |
| 162 // This function uses EXPECT_TRUE and ASSERT_TRUE for all steps performed | 163 // This function uses EXPECT_TRUE and ASSERT_TRUE for all steps performed |
| 163 // hence no return value. | 164 // hence no return value. |
| 164 void SimpleBrowserTestExpectedResult(BrowserKind browser, | 165 void SimpleBrowserTestExpectedResult(BrowserKind browser, |
| 165 const wchar_t* page, const char* result); | 166 const wchar_t* page, const char* result); |
| 166 void SimpleBrowserTest(BrowserKind browser, const wchar_t* page); | 167 void SimpleBrowserTest(BrowserKind browser, const wchar_t* page); |
| 167 | 168 |
| 168 // Test if chrome frame correctly reports its version. | 169 // Test if chrome frame correctly reports its version. |
| 169 void VersionTest(BrowserKind browser, const wchar_t* page); | 170 void VersionTest(BrowserKind browser, const wchar_t* page); |
| 170 | 171 |
| 171 // Closes all browsers in preparation for a test and during cleanup. | |
| 172 void CloseAllBrowsers(); | |
| 173 | |
| 174 void CloseBrowser(); | 172 void CloseBrowser(); |
| 175 | 173 |
| 176 // Ensures (well, at least tries to ensure) that the browser window has focus. | 174 // Ensures (well, at least tries to ensure) that the browser window has focus. |
| 177 bool BringBrowserToTop(); | 175 bool BringBrowserToTop(); |
| 178 | 176 |
| 179 const FilePath& GetCFTestFilePath() { | 177 const FilePath& GetCFTestFilePath() { |
| 180 return test_file_path_; | 178 return test_file_path_; |
| 181 } | 179 } |
| 182 | 180 |
| 183 virtual void SetUp(); | 181 static void SetUpTestCase(); |
| 184 virtual void TearDown(); | 182 static void TearDownTestCase(); |
| 185 | 183 |
| 186 // Important: kind means "sheep" in Icelandic. ?:-o | 184 static const FilePath& GetChromeUserDataDirectory(); |
| 187 const char* ToString(BrowserKind kind) { | 185 |
| 188 switch (kind) { | 186 virtual void SetUp() OVERRIDE; |
| 189 case IE: | 187 virtual void TearDown() OVERRIDE; |
| 190 return "IE"; | 188 |
| 191 case CHROME: | 189 // The on-disk path to our html test files. |
| 192 return "Chrome"; | 190 static FilePath test_file_path_; |
| 193 default: | 191 static FilePath results_dir_; |
| 194 NOTREACHED(); | 192 static FilePath CFInstall_path_; |
| 195 break; | 193 static FilePath CFInstance_path_; |
| 196 } | 194 static FilePath chrome_user_data_dir_; |
| 197 return ""; | 195 |
| 198 } | 196 // The user data directory used for Chrome instances. |
| 197 static ScopedTempDir temp_dir_; |
| 199 | 198 |
| 200 BrowserKind browser_; | 199 BrowserKind browser_; |
| 201 FilePath results_dir_; | |
| 202 base::win::ScopedHandle browser_handle_; | 200 base::win::ScopedHandle browser_handle_; |
| 203 // The on-disk path to our html test files. | |
| 204 FilePath test_file_path_; | |
| 205 | |
| 206 FilePath CFInstall_path_; | |
| 207 FilePath CFInstance_path_; | |
| 208 | |
| 209 chrome_frame_test::TimedMsgLoop loop_; | 201 chrome_frame_test::TimedMsgLoop loop_; |
| 210 testing::StrictMock<MockWebServer> server_mock_; | 202 testing::StrictMock<MockWebServer> server_mock_; |
| 211 }; | 203 }; |
| 212 | 204 |
| 213 // A helper class for doing some bookkeeping when using the | 205 // A helper class for doing some bookkeeping when using the |
| 214 // SimpleWebServer class. | 206 // SimpleWebServer class. |
| 215 class SimpleWebServerTest { | 207 class SimpleWebServerTest { |
| 216 public: | 208 public: |
| 217 explicit SimpleWebServerTest(int port) : server_(port), port_(port) { | 209 explicit SimpleWebServerTest(int port) : server_(port), port_(port) { |
| 218 } | 210 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // Same as above except that the response does not include the no-cache header. | 313 // Same as above except that the response does not include the no-cache header. |
| 322 ACTION_P2(SendAllowCacheResponse, server, invocation) { | 314 ACTION_P2(SendAllowCacheResponse, server, invocation) { |
| 323 server->SendResponseHelper(arg0, arg1, invocation, false); | 315 server->SendResponseHelper(arg0, arg1, invocation, false); |
| 324 } | 316 } |
| 325 | 317 |
| 326 ACTION_P2(HandlePostedResponseHelper, server, invocation) { | 318 ACTION_P2(HandlePostedResponseHelper, server, invocation) { |
| 327 server->HandlePostedResponse(arg0, arg2); | 319 server->HandlePostedResponse(arg0, arg2); |
| 328 } | 320 } |
| 329 | 321 |
| 330 #endif // CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ | 322 #endif // CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ |
| OLD | NEW |