OLD | NEW |
1 // Copyright (c) 2012 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 #include "chrome_frame/test/test_with_web_server.h" | 5 #include "chrome_frame/test/test_with_web_server.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js"); | 116 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js"); |
117 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); | 117 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); |
118 | 118 |
119 ASSERT_TRUE(base::CopyFile(CFInstall_src_path, CFInstall_path_)); | 119 ASSERT_TRUE(base::CopyFile(CFInstall_src_path, CFInstall_path_)); |
120 | 120 |
121 loop_ = new chrome_frame_test::TimedMsgLoop(); | 121 loop_ = new chrome_frame_test::TimedMsgLoop(); |
122 loop_->set_snapshot_on_timeout(true); | 122 loop_->set_snapshot_on_timeout(true); |
123 local_address_ = chrome_frame_test::GetLocalIPv4Address(); | 123 local_address_ = chrome_frame_test::GetLocalIPv4Address(); |
124 listener_mock_ = new testing::StrictMock<MockWebServerListener>(); | 124 listener_mock_ = new testing::StrictMock<MockWebServerListener>(); |
125 server_mock_ = new testing::StrictMock<MockWebServer>( | 125 server_mock_ = new testing::StrictMock<MockWebServer>( |
126 1337, ASCIIToWide(local_address_), | 126 1337, base::ASCIIToWide(local_address_), |
127 chrome_frame_test::GetTestDataFolder()); | 127 chrome_frame_test::GetTestDataFolder()); |
128 server_mock_->set_listener(listener_mock_); | 128 server_mock_->set_listener(listener_mock_); |
129 } | 129 } |
130 | 130 |
131 // static | 131 // static |
132 void ChromeFrameTestWithWebServer::TearDownTestCase() { | 132 void ChromeFrameTestWithWebServer::TearDownTestCase() { |
133 delete server_mock_; | 133 delete server_mock_; |
134 server_mock_ = NULL; | 134 server_mock_ = NULL; |
135 delete listener_mock_; | 135 delete listener_mock_; |
136 listener_mock_ = NULL; | 136 listener_mock_ = NULL; |
(...skipping 30 matching lines...) Expand all Loading... |
167 loop().RunUntilIdle(); | 167 loop().RunUntilIdle(); |
168 testing::Mock::VerifyAndClear(listener_mock_); | 168 testing::Mock::VerifyAndClear(listener_mock_); |
169 testing::Mock::VerifyAndClear(server_mock_); | 169 testing::Mock::VerifyAndClear(server_mock_); |
170 } | 170 } |
171 | 171 |
172 bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, | 172 bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, |
173 const wchar_t* page) { | 173 const wchar_t* page) { |
174 std::wstring url = page; | 174 std::wstring url = page; |
175 | 175 |
176 // We should resolve the URL only if it is a relative url. | 176 // We should resolve the URL only if it is a relative url. |
177 GURL parsed_url(WideToUTF8(page)); | 177 GURL parsed_url(base::WideToUTF8(page)); |
178 if (!parsed_url.has_scheme()) { | 178 if (!parsed_url.has_scheme()) { |
179 url = server_mock().Resolve(page); | 179 url = server_mock().Resolve(page); |
180 } | 180 } |
181 | 181 |
182 browser_ = browser; | 182 browser_ = browser; |
183 if (browser == IE) { | 183 if (browser == IE) { |
184 browser_handle_.Set(chrome_frame_test::LaunchIE(url)); | 184 browser_handle_.Set(chrome_frame_test::LaunchIE(url)); |
185 } else if (browser == CHROME) { | 185 } else if (browser == CHROME) { |
186 const base::FilePath& user_data_dir = GetChromeUserDataDirectory(); | 186 const base::FilePath& user_data_dir = GetChromeUserDataDirectory(); |
187 chrome_frame_test::OverrideDataDirectoryForThisTest(user_data_dir.value()); | 187 chrome_frame_test::OverrideDataDirectoryForThisTest(user_data_dir.value()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (!version_info) { | 307 if (!version_info) { |
308 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 308 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
309 base::Version ver_system; | 309 base::Version ver_system; |
310 InstallUtil::GetChromeVersion(dist, true, &ver_system); | 310 InstallUtil::GetChromeVersion(dist, true, &ver_system); |
311 base::Version ver_user; | 311 base::Version ver_user; |
312 InstallUtil::GetChromeVersion(dist, false, &ver_system); | 312 InstallUtil::GetChromeVersion(dist, false, &ver_system); |
313 ASSERT_TRUE(ver_system.IsValid() || ver_user.IsValid()); | 313 ASSERT_TRUE(ver_system.IsValid() || ver_user.IsValid()); |
314 | 314 |
315 bool system_install = ver_system.IsValid(); | 315 bool system_install = ver_system.IsValid(); |
316 base::FilePath cf_dll_path(installer::GetChromeInstallPath(system_install, d
ist)); | 316 base::FilePath cf_dll_path(installer::GetChromeInstallPath(system_install, d
ist)); |
317 cf_dll_path = cf_dll_path.Append(UTF8ToWide( | 317 cf_dll_path = cf_dll_path.Append(base::UTF8ToWide( |
318 ver_system.IsValid() ? ver_system.GetString() : ver_user.GetString())); | 318 ver_system.IsValid() ? ver_system.GetString() : ver_user.GetString())); |
319 cf_dll_path = cf_dll_path.Append(kChromeFrameDllName); | 319 cf_dll_path = cf_dll_path.Append(kChromeFrameDllName); |
320 version_info = FileVersionInfo::CreateFileVersionInfo(cf_dll_path); | 320 version_info = FileVersionInfo::CreateFileVersionInfo(cf_dll_path); |
321 if (version_info) | 321 if (version_info) |
322 version = version_info->product_version(); | 322 version = version_info->product_version(); |
323 } | 323 } |
324 | 324 |
325 server_mock().set_expected_result(WideToUTF8(version)); | 325 server_mock().set_expected_result(base::WideToUTF8(version)); |
326 | 326 |
327 EXPECT_TRUE(version_info); | 327 EXPECT_TRUE(version_info); |
328 EXPECT_FALSE(version.empty()); | 328 EXPECT_FALSE(version.empty()); |
329 | 329 |
330 SimpleBrowserTestExpectedResult(browser, page, WideToASCII(version).c_str()); | 330 SimpleBrowserTestExpectedResult(browser, page, WideToASCII(version).c_str()); |
331 } | 331 } |
332 | 332 |
333 // MockWebServer methods | 333 // MockWebServer methods |
334 void MockWebServer::ExpectAndServeRequest(CFInvocation invocation, | 334 void MockWebServer::ExpectAndServeRequest(CFInvocation invocation, |
335 const std::wstring& url) { | 335 const std::wstring& url) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 const test_server::Request& request, | 377 const test_server::Request& request, |
378 CFInvocation invocation, | 378 CFInvocation invocation, |
379 bool add_no_cache_header) { | 379 bool add_no_cache_header) { |
380 static const wchar_t kEchoHeader[] = L"/echoheader?"; | 380 static const wchar_t kEchoHeader[] = L"/echoheader?"; |
381 if (request_uri.find(kEchoHeader) != std::wstring::npos) { | 381 if (request_uri.find(kEchoHeader) != std::wstring::npos) { |
382 std::wstring header = request_uri.substr( | 382 std::wstring header = request_uri.substr( |
383 wcslen(kEchoHeader), | 383 wcslen(kEchoHeader), |
384 request_uri.length() - wcslen(kEchoHeader)); | 384 request_uri.length() - wcslen(kEchoHeader)); |
385 | 385 |
386 std::string header_value = http_utils::GetHttpHeaderFromHeaderList( | 386 std::string header_value = http_utils::GetHttpHeaderFromHeaderList( |
387 WideToUTF8(header), request.headers()); | 387 base::WideToUTF8(header), request.headers()); |
388 connection->Send(header_value, ""); | 388 connection->Send(header_value, ""); |
389 return; | 389 return; |
390 } | 390 } |
391 // Convert |request_uri| to a path. | 391 // Convert |request_uri| to a path. |
392 std::wstring path = request_uri; | 392 std::wstring path = request_uri; |
393 size_t query_index = request_uri.find(L"?"); | 393 size_t query_index = request_uri.find(L"?"); |
394 if (query_index != std::string::npos) { | 394 if (query_index != std::string::npos) { |
395 path = path.erase(query_index); | 395 path = path.erase(query_index); |
396 } | 396 } |
397 base::FilePath file_path = root_dir_; | 397 base::FilePath file_path = root_dir_; |
398 if (path.size()) | 398 if (path.size()) |
399 file_path = file_path.Append(path.substr(1)); // remove first '/' | 399 file_path = file_path.Append(path.substr(1)); // remove first '/' |
400 | 400 |
401 std::string headers, body; | 401 std::string headers, body; |
402 std::string content_type; | 402 std::string content_type; |
403 if (base::PathExists(file_path) && | 403 if (base::PathExists(file_path) && |
404 !base::DirectoryExists(file_path)) { | 404 !base::DirectoryExists(file_path)) { |
405 base::FilePath mock_http_headers(file_path.value() + L".mock-http-headers"); | 405 base::FilePath mock_http_headers(file_path.value() + L".mock-http-headers"); |
406 if (base::PathExists(mock_http_headers)) { | 406 if (base::PathExists(mock_http_headers)) { |
407 headers = GetMockHttpHeaders(mock_http_headers); | 407 headers = GetMockHttpHeaders(mock_http_headers); |
408 content_type = http_utils::GetHttpHeaderFromHeaderList("Content-type", | 408 content_type = http_utils::GetHttpHeaderFromHeaderList("Content-type", |
409 headers); | 409 headers); |
410 } else { | 410 } else { |
411 EXPECT_TRUE(net::GetMimeTypeFromFile(file_path, &content_type)); | 411 EXPECT_TRUE(net::GetMimeTypeFromFile(file_path, &content_type)); |
412 VLOG(1) << "Going to send file (" << WideToUTF8(file_path.value()) | 412 VLOG(1) << "Going to send file (" << base::WideToUTF8(file_path.value()) |
413 << ") with content type (" << content_type << ")"; | 413 << ") with content type (" << content_type << ")"; |
414 headers = CreateHttpHeaders(invocation, add_no_cache_header, | 414 headers = CreateHttpHeaders(invocation, add_no_cache_header, |
415 content_type); | 415 content_type); |
416 } | 416 } |
417 | 417 |
418 EXPECT_FALSE(headers.empty()); | 418 EXPECT_FALSE(headers.empty()); |
419 | 419 |
420 EXPECT_TRUE(base::ReadFileToString(file_path, &body)) | 420 EXPECT_TRUE(base::ReadFileToString(file_path, &body)) |
421 << "Could not read file (" << WideToUTF8(file_path.value()) << ")"; | 421 << "Could not read file (" |
| 422 << base::WideToUTF8(file_path.value()) << ")"; |
422 if (invocation.type() == CFInvocation::META_TAG && | 423 if (invocation.type() == CFInvocation::META_TAG && |
423 StartsWithASCII(content_type, "text/html", false)) { | 424 StartsWithASCII(content_type, "text/html", false)) { |
424 EXPECT_TRUE(chrome_frame_test::AddCFMetaTag(&body)) << "Could not add " | 425 EXPECT_TRUE(chrome_frame_test::AddCFMetaTag(&body)) << "Could not add " |
425 << "meta tag to HTML file."; | 426 << "meta tag to HTML file."; |
426 } | 427 } |
427 } else { | 428 } else { |
428 VLOG(1) << "Going to send 404 for non-existent file (" | 429 VLOG(1) << "Going to send 404 for non-existent file (" |
429 << WideToUTF8(file_path.value()) << ")"; | 430 << base::WideToUTF8(file_path.value()) << ")"; |
430 headers = "HTTP/1.1 404 Not Found"; | 431 headers = "HTTP/1.1 404 Not Found"; |
431 body = ""; | 432 body = ""; |
432 } | 433 } |
433 connection->Send(headers, body); | 434 connection->Send(headers, body); |
434 } | 435 } |
435 | 436 |
436 const wchar_t kPostMessageBasicPage[] = L"postmessage_basic_host.html"; | 437 const wchar_t kPostMessageBasicPage[] = L"postmessage_basic_host.html"; |
437 | 438 |
438 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_PostMessageBasic) { | 439 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_PostMessageBasic) { |
439 SimpleBrowserTest(IE, kPostMessageBasicPage); | 440 SimpleBrowserTest(IE, kPostMessageBasicPage); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 loop().RunFor(kChromeFrameLongNavigationTimeout); | 945 loop().RunFor(kChromeFrameLongNavigationTimeout); |
945 | 946 |
946 test_server::SimpleWebServer* ws = server.web_server(); | 947 test_server::SimpleWebServer* ws = server.web_server(); |
947 const test_server::ConnectionList& connections = ws->connections(); | 948 const test_server::ConnectionList& connections = ws->connections(); |
948 test_server::ConnectionList::const_iterator it = connections.begin(); | 949 test_server::ConnectionList::const_iterator it = connections.begin(); |
949 int requests_for_first_page = 0; | 950 int requests_for_first_page = 0; |
950 for (; it != connections.end(); ++it) { | 951 for (; it != connections.end(); ++it) { |
951 test_server::Connection* c = (*it); | 952 test_server::Connection* c = (*it); |
952 const test_server::Request& r = c->request(); | 953 const test_server::Request& r = c->request(); |
953 if (!r.path().empty() && | 954 if (!r.path().empty() && |
954 ASCIIToWide(r.path().substr(1)).compare(kPages[0]) == 0) { | 955 base::ASCIIToWide(r.path().substr(1)).compare(kPages[0]) == 0) { |
955 requests_for_first_page++; | 956 requests_for_first_page++; |
956 std::string ua(GetHeaderValue(r.headers(), "User-Agent")); | 957 std::string ua(GetHeaderValue(r.headers(), "User-Agent")); |
957 EXPECT_NE(std::string::npos, ua.find("chromeframe")); | 958 EXPECT_NE(std::string::npos, ua.find("chromeframe")); |
958 } | 959 } |
959 } | 960 } |
960 EXPECT_GT(requests_for_first_page, 1); | 961 EXPECT_GT(requests_for_first_page, 1); |
961 } | 962 } |
962 | 963 |
963 // See bug 36694 for details. http://crbug.com/36694 | 964 // See bug 36694 for details. http://crbug.com/36694 |
964 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) { | 965 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 // This test loads a large page and ensures that the full page contents are | 1092 // This test loads a large page and ensures that the full page contents are |
1092 // actually loaded via a self-validating HTML page. This is done due to a bug | 1093 // actually loaded via a self-validating HTML page. This is done due to a bug |
1093 // whereby the middle of the response stream would sometimes be truncated when | 1094 // whereby the middle of the response stream would sometimes be truncated when |
1094 // loading a CF document. See http://crbug.com/178421 for details. | 1095 // loading a CF document. See http://crbug.com/178421 for details. |
1095 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_LargePageLoad) { | 1096 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_LargePageLoad) { |
1096 const wchar_t kLargePageLoadPage[] = | 1097 const wchar_t kLargePageLoadPage[] = |
1097 L"chrome_frame_large_page.html"; | 1098 L"chrome_frame_large_page.html"; |
1098 | 1099 |
1099 SimpleBrowserTest(IE, kLargePageLoadPage); | 1100 SimpleBrowserTest(IE, kLargePageLoadPage); |
1100 } | 1101 } |
OLD | NEW |