| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome_frame/test/test_with_web_server.h" | 5 #include "chrome_frame/test/test_with_web_server.h" |
| 5 | 6 |
| 6 #include "base/file_version_info.h" | 7 #include "base/file_version_info.h" |
| 8 #include "base/utf_string_conversions.h" |
| 7 #include "base/win_util.h" | 9 #include "base/win_util.h" |
| 8 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/installer/util/install_util.h" | 11 #include "chrome/installer/util/install_util.h" |
| 10 #include "chrome/installer/util/helper.h" | 12 #include "chrome/installer/util/helper.h" |
| 11 #include "chrome_frame/utils.h" | 13 #include "chrome_frame/utils.h" |
| 12 #include "chrome_frame/test/chrome_frame_test_utils.h" | 14 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 15 #include "chrome_frame/test/mock_ie_event_sink_actions.h" |
| 16 #include "net/base/mime_util.h" |
| 13 | 17 |
| 14 using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; | 18 using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; |
| 19 using testing::_; |
| 20 using testing::StrCaseEq; |
| 15 | 21 |
| 16 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; | 22 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; |
| 17 const int kLongWaitTimeout = 60 * 1000; | 23 const int kLongWaitTimeout = 60 * 1000; |
| 18 const int kShortWaitTimeout = 25 * 1000; | 24 const int kShortWaitTimeout = 25 * 1000; |
| 19 | 25 |
| 26 namespace { |
| 27 |
| 28 // Helper method for creating the appropriate HTTP response headers. |
| 29 std::string CreateHttpHeaders(CFInvocation invocation, |
| 30 bool add_no_cache_header, |
| 31 const std::string& content_type) { |
| 32 std::ostringstream ss; |
| 33 ss << "HTTP/1.1 200 OK\r\n" |
| 34 << "Connection: close\r\n" |
| 35 << "Content-Type: " << content_type << "\r\n"; |
| 36 if (invocation.type() == CFInvocation::HTTP_HEADER) |
| 37 ss << "X-UA-Compatible: chrome=1\r\n"; |
| 38 if (add_no_cache_header) |
| 39 ss << "Cache-Control: no-cache\r\n"; |
| 40 return ss.str(); |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
| 20 class ChromeFrameTestEnvironment: public testing::Environment { | 45 class ChromeFrameTestEnvironment: public testing::Environment { |
| 21 public: | 46 public: |
| 22 ~ChromeFrameTestEnvironment() {} | 47 ~ChromeFrameTestEnvironment() {} |
| 23 void SetUp() { | 48 void SetUp() { |
| 24 ScopedChromeFrameRegistrar::RegisterDefaults(); | 49 ScopedChromeFrameRegistrar::RegisterDefaults(); |
| 25 } | 50 } |
| 26 void TearDown() {} | 51 void TearDown() {} |
| 27 }; | 52 }; |
| 28 | 53 |
| 29 ::testing::Environment* const chrome_frame_env = | 54 ::testing::Environment* const chrome_frame_env = |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 version = version_info->product_version(); | 254 version = version_info->product_version(); |
| 230 } | 255 } |
| 231 | 256 |
| 232 EXPECT_TRUE(version_info); | 257 EXPECT_TRUE(version_info); |
| 233 EXPECT_FALSE(version.empty()); | 258 EXPECT_FALSE(version.empty()); |
| 234 EXPECT_TRUE(LaunchBrowser(browser, page)); | 259 EXPECT_TRUE(LaunchBrowser(browser, page)); |
| 235 ASSERT_TRUE(WaitForTestToComplete(kLongWaitTimeout)); | 260 ASSERT_TRUE(WaitForTestToComplete(kLongWaitTimeout)); |
| 236 ASSERT_TRUE(CheckResultFile(result_file_to_check, WideToUTF8(version))); | 261 ASSERT_TRUE(CheckResultFile(result_file_to_check, WideToUTF8(version))); |
| 237 } | 262 } |
| 238 | 263 |
| 264 // MockWebServer methods |
| 265 void MockWebServer::ExpectAndServeRequest(CFInvocation invocation, |
| 266 const std::wstring& url) { |
| 267 EXPECT_CALL(*this, Get(_, chrome_frame_test::UrlPathEq(url), _)) |
| 268 .WillOnce(SendResponse(this, invocation)); |
| 269 } |
| 270 |
| 271 void MockWebServer::ExpectAndServeRequestAllowCache(CFInvocation invocation, |
| 272 const std::wstring &url) { |
| 273 EXPECT_CALL(*this, Get(_, chrome_frame_test::UrlPathEq(url), _)) |
| 274 .WillOnce(SendResponse(this, invocation)); |
| 275 } |
| 276 |
| 277 void MockWebServer::ExpectAndServeRequestAnyNumberTimes( |
| 278 CFInvocation invocation, const std::wstring& path_prefix) { |
| 279 EXPECT_CALL(*this, Get(_, testing::StartsWith(path_prefix), _)) |
| 280 .WillRepeatedly(SendResponse(this, invocation)); |
| 281 } |
| 282 |
| 283 void MockWebServer::SendResponseHelper( |
| 284 test_server::ConfigurableConnection* connection, |
| 285 const std::wstring& request_uri, |
| 286 CFInvocation invocation, |
| 287 bool add_no_cache_header) { |
| 288 // Convert |request_uri| to a path. |
| 289 std::wstring path = request_uri; |
| 290 size_t query_index = request_uri.find(L"?"); |
| 291 if (query_index != std::string::npos) { |
| 292 path = path.erase(query_index); |
| 293 } |
| 294 FilePath file_path = root_dir_; |
| 295 if (path.size()) |
| 296 file_path = file_path.Append(path.substr(1)); // remove first '/' |
| 297 |
| 298 std::string headers, body; |
| 299 if (file_util::PathExists(file_path)) { |
| 300 std::string content_type; |
| 301 EXPECT_TRUE(net::GetMimeTypeFromFile(file_path, &content_type)); |
| 302 DLOG(INFO) << "Going to send file (" << WideToUTF8(file_path.value()) |
| 303 << ") with content type (" << content_type << ")"; |
| 304 headers = CreateHttpHeaders(invocation, add_no_cache_header, content_type); |
| 305 |
| 306 EXPECT_TRUE(file_util::ReadFileToString(file_path, &body)) |
| 307 << "Could not read file (" << WideToUTF8(file_path.value()) << ")"; |
| 308 if (invocation.type() == CFInvocation::META_TAG && |
| 309 StartsWithASCII(content_type, "text/html", false)) { |
| 310 EXPECT_TRUE(chrome_frame_test::AddCFMetaTag(&body)) << "Could not add " |
| 311 << "meta tag to HTML file."; |
| 312 } |
| 313 } else { |
| 314 DLOG(INFO) << "Going to send 404 for non-existent file (" |
| 315 << WideToUTF8(file_path.value()) << ")"; |
| 316 headers = "HTTP/1.1 404 Not Found"; |
| 317 body = ""; |
| 318 } |
| 319 connection->Send(headers, body); |
| 320 } |
| 321 |
| 239 const wchar_t kPostMessageBasicPage[] = L"files/postmessage_basic_host.html"; | 322 const wchar_t kPostMessageBasicPage[] = L"files/postmessage_basic_host.html"; |
| 240 | 323 |
| 241 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_PostMessageBasic) { | 324 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_PostMessageBasic) { |
| 242 SimpleBrowserTest(IE, kPostMessageBasicPage, L"PostMessage"); | 325 SimpleBrowserTest(IE, kPostMessageBasicPage, L"PostMessage"); |
| 243 } | 326 } |
| 244 | 327 |
| 245 TEST_F(ChromeFrameTestWithWebServer, WidgetModeFF_PostMessageBasic) { | 328 TEST_F(ChromeFrameTestWithWebServer, WidgetModeFF_PostMessageBasic) { |
| 246 SimpleBrowserTest(FIREFOX, kPostMessageBasicPage, L"PostMessage"); | 329 SimpleBrowserTest(FIREFOX, kPostMessageBasicPage, L"PostMessage"); |
| 247 } | 330 } |
| 248 | 331 |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 chrome_frame_test::TimedMsgLoop loop; | 992 chrome_frame_test::TimedMsgLoop loop; |
| 910 ASSERT_TRUE(LaunchBrowser(IE, kXHRConditionalHeaderTestUrl)); | 993 ASSERT_TRUE(LaunchBrowser(IE, kXHRConditionalHeaderTestUrl)); |
| 911 | 994 |
| 912 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 995 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| 913 | 996 |
| 914 chrome_frame_test::CloseAllIEWindows(); | 997 chrome_frame_test::CloseAllIEWindows(); |
| 915 ASSERT_TRUE(CheckResultFile(L"FullTab_XMLHttpRequestConditionalHeaderTest", | 998 ASSERT_TRUE(CheckResultFile(L"FullTab_XMLHttpRequestConditionalHeaderTest", |
| 916 "OK")); | 999 "OK")); |
| 917 } | 1000 } |
| 918 | 1001 |
| OLD | NEW |