| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome_frame/test/test_with_web_server.h" | |
| 6 | |
| 7 #include "base/base_paths.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/file_version_info.h" | |
| 10 #include "base/files/memory_mapped_file.h" | |
| 11 #include "base/files/scoped_temp_dir.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/process/kill.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | |
| 16 #include "base/test/test_timeouts.h" | |
| 17 #include "base/win/windows_version.h" | |
| 18 #include "chrome/common/chrome_switches.h" | |
| 19 #include "chrome/installer/util/helper.h" | |
| 20 #include "chrome/installer/util/install_util.h" | |
| 21 #include "chrome/installer/util/product.h" | |
| 22 #include "chrome_frame/html_utils.h" | |
| 23 #include "chrome_frame/test/chrome_frame_test_utils.h" | |
| 24 #include "chrome_frame/test/mock_ie_event_sink_actions.h" | |
| 25 #include "chrome_frame/test/mock_ie_event_sink_test.h" | |
| 26 #include "chrome_frame/test/test_scrubber.h" | |
| 27 #include "chrome_frame/utils.h" | |
| 28 #include "net/base/mime_util.h" | |
| 29 #include "net/http/http_util.h" | |
| 30 #include "net/socket/stream_listen_socket.h" | |
| 31 | |
| 32 using chrome_frame_test::kChromeFrameLongNavigationTimeout; | |
| 33 using chrome_frame_test::kChromeFrameVeryLongNavigationTimeout; | |
| 34 | |
| 35 using testing::_; | |
| 36 using testing::StrCaseEq; | |
| 37 | |
| 38 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; | |
| 39 | |
| 40 namespace { | |
| 41 | |
| 42 // Helper method for creating the appropriate HTTP response headers. | |
| 43 std::string CreateHttpHeaders(CFInvocation invocation, | |
| 44 bool add_no_cache_header, | |
| 45 const std::string& content_type) { | |
| 46 std::ostringstream ss; | |
| 47 ss << "HTTP/1.1 200 OK\r\n" | |
| 48 << "Connection: close\r\n" | |
| 49 << "Content-Type: " << content_type << "\r\n"; | |
| 50 if (invocation.type() == CFInvocation::HTTP_HEADER) | |
| 51 ss << "X-UA-Compatible: chrome=1\r\n"; | |
| 52 if (add_no_cache_header) { | |
| 53 ss << "Cache-Control: no-cache\r\n"; | |
| 54 ss << "Expires: Tue, 15 Nov 1994 08:12:31 GMT\r\n"; | |
| 55 } | |
| 56 return ss.str(); | |
| 57 } | |
| 58 | |
| 59 std::string GetMockHttpHeaders(const base::FilePath& mock_http_headers_path) { | |
| 60 std::string headers; | |
| 61 base::ReadFileToString(mock_http_headers_path, &headers); | |
| 62 return headers; | |
| 63 } | |
| 64 | |
| 65 class ChromeFrameTestEnvironment: public testing::Environment { | |
| 66 public: | |
| 67 virtual ~ChromeFrameTestEnvironment() {} | |
| 68 virtual void SetUp() OVERRIDE { | |
| 69 ScopedChromeFrameRegistrar::RegisterDefaults(); | |
| 70 } | |
| 71 }; | |
| 72 | |
| 73 ::testing::Environment* const chrome_frame_env = | |
| 74 ::testing::AddGlobalTestEnvironment(new ChromeFrameTestEnvironment); | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 78 base::FilePath ChromeFrameTestWithWebServer::test_file_path_; | |
| 79 base::FilePath ChromeFrameTestWithWebServer::results_dir_; | |
| 80 base::FilePath ChromeFrameTestWithWebServer::CFInstall_path_; | |
| 81 base::FilePath ChromeFrameTestWithWebServer::CFInstance_path_; | |
| 82 base::ScopedTempDir ChromeFrameTestWithWebServer::temp_dir_; | |
| 83 base::FilePath ChromeFrameTestWithWebServer::chrome_user_data_dir_; | |
| 84 chrome_frame_test::TimedMsgLoop* ChromeFrameTestWithWebServer::loop_; | |
| 85 std::string ChromeFrameTestWithWebServer::local_address_; | |
| 86 testing::StrictMock<MockWebServerListener>* | |
| 87 ChromeFrameTestWithWebServer::listener_mock_; | |
| 88 testing::StrictMock<MockWebServer>* ChromeFrameTestWithWebServer::server_mock_; | |
| 89 | |
| 90 ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() { | |
| 91 } | |
| 92 | |
| 93 // static | |
| 94 void ChromeFrameTestWithWebServer::SetUpTestCase() { | |
| 95 base::FilePath chrome_frame_source_path; | |
| 96 PathService::Get(base::DIR_SOURCE_ROOT, &chrome_frame_source_path); | |
| 97 chrome_frame_source_path = chrome_frame_source_path.Append( | |
| 98 FILE_PATH_LITERAL("chrome_frame")); | |
| 99 | |
| 100 test_file_path_ = chrome_frame_source_path | |
| 101 .Append(FILE_PATH_LITERAL("test")) | |
| 102 .Append(FILE_PATH_LITERAL("data")); | |
| 103 | |
| 104 results_dir_ = chrome_frame_test::GetTestDataFolder().AppendASCII("dump"); | |
| 105 | |
| 106 // Copy the CFInstance.js and CFInstall.js files from src\chrome_frame to | |
| 107 // src\chrome_frame\test\data. | |
| 108 base::FilePath CFInstance_src_path; | |
| 109 base::FilePath CFInstall_src_path; | |
| 110 | |
| 111 CFInstance_src_path = chrome_frame_source_path.AppendASCII("CFInstance.js"); | |
| 112 CFInstance_path_ = test_file_path_.AppendASCII("CFInstance.js"); | |
| 113 | |
| 114 ASSERT_TRUE(base::CopyFile(CFInstance_src_path, CFInstance_path_)); | |
| 115 | |
| 116 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js"); | |
| 117 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); | |
| 118 | |
| 119 ASSERT_TRUE(base::CopyFile(CFInstall_src_path, CFInstall_path_)); | |
| 120 | |
| 121 loop_ = new chrome_frame_test::TimedMsgLoop(); | |
| 122 loop_->set_snapshot_on_timeout(true); | |
| 123 local_address_ = chrome_frame_test::GetLocalIPv4Address(); | |
| 124 listener_mock_ = new testing::StrictMock<MockWebServerListener>(); | |
| 125 server_mock_ = new testing::StrictMock<MockWebServer>( | |
| 126 1337, base::ASCIIToWide(local_address_), | |
| 127 chrome_frame_test::GetTestDataFolder()); | |
| 128 server_mock_->set_listener(listener_mock_); | |
| 129 } | |
| 130 | |
| 131 // static | |
| 132 void ChromeFrameTestWithWebServer::TearDownTestCase() { | |
| 133 delete server_mock_; | |
| 134 server_mock_ = NULL; | |
| 135 delete listener_mock_; | |
| 136 listener_mock_ = NULL; | |
| 137 local_address_.clear(); | |
| 138 delete loop_; | |
| 139 loop_ = NULL; | |
| 140 base::DeleteFile(CFInstall_path_, false); | |
| 141 base::DeleteFile(CFInstance_path_, false); | |
| 142 if (temp_dir_.IsValid()) | |
| 143 EXPECT_TRUE(temp_dir_.Delete()); | |
| 144 } | |
| 145 | |
| 146 // static | |
| 147 const base::FilePath& | |
| 148 ChromeFrameTestWithWebServer::GetChromeUserDataDirectory() { | |
| 149 if (!temp_dir_.IsValid()) { | |
| 150 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 151 chrome_user_data_dir_ = temp_dir_.path().AppendASCII("User Data"); | |
| 152 } | |
| 153 return chrome_user_data_dir_; | |
| 154 } | |
| 155 | |
| 156 void ChromeFrameTestWithWebServer::SetUp() { | |
| 157 // Make sure that we are not accidentally enabling gcf protocol. | |
| 158 SetConfigBool(kAllowUnsafeURLs, false); | |
| 159 | |
| 160 server_mock().ClearResults(); | |
| 161 server_mock().ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | |
| 162 server_mock().set_expected_result("OK"); | |
| 163 } | |
| 164 | |
| 165 void ChromeFrameTestWithWebServer::TearDown() { | |
| 166 CloseBrowser(); | |
| 167 loop().RunUntilIdle(); | |
| 168 testing::Mock::VerifyAndClear(listener_mock_); | |
| 169 testing::Mock::VerifyAndClear(server_mock_); | |
| 170 } | |
| 171 | |
| 172 bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, | |
| 173 const wchar_t* page) { | |
| 174 std::wstring url = page; | |
| 175 | |
| 176 // We should resolve the URL only if it is a relative url. | |
| 177 GURL parsed_url(base::WideToUTF8(page)); | |
| 178 if (!parsed_url.has_scheme()) { | |
| 179 url = server_mock().Resolve(page); | |
| 180 } | |
| 181 | |
| 182 browser_ = browser; | |
| 183 if (browser == IE) { | |
| 184 browser_handle_.Set(chrome_frame_test::LaunchIE(url)); | |
| 185 } else if (browser == CHROME) { | |
| 186 const base::FilePath& user_data_dir = GetChromeUserDataDirectory(); | |
| 187 chrome_frame_test::OverrideDataDirectoryForThisTest(user_data_dir.value()); | |
| 188 browser_handle_.Set(chrome_frame_test::LaunchChrome(url, user_data_dir)); | |
| 189 } else { | |
| 190 NOTREACHED(); | |
| 191 } | |
| 192 | |
| 193 return browser_handle_.IsValid(); | |
| 194 } | |
| 195 | |
| 196 void ChromeFrameTestWithWebServer::CloseBrowser() { | |
| 197 if (!browser_handle_.IsValid()) | |
| 198 return; | |
| 199 | |
| 200 int attempts = 0; | |
| 201 if (browser_ == IE) { | |
| 202 attempts = chrome_frame_test::CloseAllIEWindows(); | |
| 203 } else { | |
| 204 attempts = chrome_frame_test::CloseVisibleWindowsOnAllThreads( | |
| 205 browser_handle_); | |
| 206 } | |
| 207 | |
| 208 if (attempts > 0) { | |
| 209 DWORD wait = ::WaitForSingleObject(browser_handle_, 20000); | |
| 210 if (wait == WAIT_OBJECT_0) { | |
| 211 browser_handle_.Close(); | |
| 212 } else { | |
| 213 LOG(ERROR) << "WaitForSingleObject returned " << wait; | |
| 214 } | |
| 215 } else { | |
| 216 LOG(ERROR) << "No attempts to close browser windows"; | |
| 217 } | |
| 218 | |
| 219 if (browser_handle_.IsValid()) { | |
| 220 DWORD exit_code = 0; | |
| 221 if (!::GetExitCodeProcess(browser_handle_, &exit_code) || | |
| 222 exit_code == STILL_ACTIVE) { | |
| 223 LOG(ERROR) << L"Forcefully killing browser process. Exit:" << exit_code; | |
| 224 base::KillProcess(browser_handle_, 0, true); | |
| 225 } | |
| 226 browser_handle_.Close(); | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 bool ChromeFrameTestWithWebServer::BringBrowserToTop() { | |
| 231 return simulate_input::EnsureProcessInForeground( | |
| 232 GetProcessId(browser_handle_)); | |
| 233 } | |
| 234 | |
| 235 bool ChromeFrameTestWithWebServer::WaitForTestToComplete( | |
| 236 base::TimeDelta duration) { | |
| 237 loop().RunFor(duration); | |
| 238 return !loop().WasTimedOut(); | |
| 239 } | |
| 240 | |
| 241 bool ChromeFrameTestWithWebServer::WaitForOnLoad(int milliseconds) { | |
| 242 return false; | |
| 243 } | |
| 244 | |
| 245 const wchar_t kPostedResultSubstring[] = L"/writefile/"; | |
| 246 | |
| 247 void ChromeFrameTestWithWebServer::SimpleBrowserTestExpectedResult( | |
| 248 BrowserKind browser, const wchar_t* page, const char* result) { | |
| 249 if (browser == IE && chrome_frame_test::GetInstalledIEVersion() >= IE_9) { | |
| 250 LOG(INFO) << "Temporarily disabling IE9 web server tests. " | |
| 251 "See http://crbug.com/143699"; | |
| 252 return; | |
| 253 } | |
| 254 | |
| 255 int tries = 0; | |
| 256 ExpectAndHandlePostedResult(); | |
| 257 // Retry tests that timeout once; see http://crbug.com/96449. | |
| 258 do { | |
| 259 // NOTE: Failed ASSERTs cause this function to exit immediately. | |
| 260 // Don't take a snapshot on the first try. | |
| 261 loop().set_snapshot_on_timeout(tries != 0); | |
| 262 ASSERT_TRUE(LaunchBrowser(browser, page)); | |
| 263 if (WaitForTestToComplete(TestTimeouts::action_max_timeout())) { | |
| 264 // The test exited without timing out. Confirm that the expected response | |
| 265 // was posted and return. | |
| 266 ASSERT_EQ(result, server_mock().posted_result()); | |
| 267 break; | |
| 268 } | |
| 269 ASSERT_EQ(std::string(), server_mock().posted_result()) | |
| 270 << "Test timed out yet provided a result."; | |
| 271 ASSERT_EQ(0, tries++) << "Failing test due to two timeouts."; | |
| 272 // Close the browser and try a second time. | |
| 273 CloseBrowser(); | |
| 274 LOG(ERROR) << "Retrying test once since it timed out."; | |
| 275 } while (true); | |
| 276 loop().set_snapshot_on_timeout(true); | |
| 277 } | |
| 278 | |
| 279 void ChromeFrameTestWithWebServer::SimpleBrowserTest(BrowserKind browser, | |
| 280 const wchar_t* page) { | |
| 281 SimpleBrowserTestExpectedResult(browser, page, "OK"); | |
| 282 } | |
| 283 | |
| 284 void ChromeFrameTestWithWebServer::ExpectAndHandlePostedResult() { | |
| 285 EXPECT_CALL(listener_mock(), OnExpectedResponse()) | |
| 286 .WillRepeatedly(QUIT_LOOP_SOON(loop(), | |
| 287 base::TimeDelta::FromMilliseconds(100))); | |
| 288 server_mock().ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), | |
| 289 kPostedResultSubstring); | |
| 290 } | |
| 291 | |
| 292 void ChromeFrameTestWithWebServer::VersionTest(BrowserKind browser, | |
| 293 const wchar_t* page) { | |
| 294 base::FilePath plugin_path; | |
| 295 PathService::Get(base::DIR_MODULE, &plugin_path); | |
| 296 plugin_path = plugin_path.Append(kChromeFrameDllName); | |
| 297 | |
| 298 static FileVersionInfo* version_info = | |
| 299 FileVersionInfo::CreateFileVersionInfo(plugin_path); | |
| 300 | |
| 301 std::wstring version; | |
| 302 if (version_info) | |
| 303 version = version_info->product_version(); | |
| 304 | |
| 305 // If we can't find the Chrome Frame DLL in the src tree, we turn to | |
| 306 // the directory where chrome is installed. | |
| 307 if (!version_info) { | |
| 308 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 309 Version ver_system; | |
| 310 InstallUtil::GetChromeVersion(dist, true, &ver_system); | |
| 311 Version ver_user; | |
| 312 InstallUtil::GetChromeVersion(dist, false, &ver_system); | |
| 313 ASSERT_TRUE(ver_system.IsValid() || ver_user.IsValid()); | |
| 314 | |
| 315 bool system_install = ver_system.IsValid(); | |
| 316 base::FilePath cf_dll_path(installer::GetChromeInstallPath(system_install, d
ist)); | |
| 317 cf_dll_path = cf_dll_path.Append(base::UTF8ToWide( | |
| 318 ver_system.IsValid() ? ver_system.GetString() : ver_user.GetString())); | |
| 319 cf_dll_path = cf_dll_path.Append(kChromeFrameDllName); | |
| 320 version_info = FileVersionInfo::CreateFileVersionInfo(cf_dll_path); | |
| 321 if (version_info) | |
| 322 version = version_info->product_version(); | |
| 323 } | |
| 324 | |
| 325 server_mock().set_expected_result(base::WideToUTF8(version)); | |
| 326 | |
| 327 EXPECT_TRUE(version_info); | |
| 328 EXPECT_FALSE(version.empty()); | |
| 329 | |
| 330 SimpleBrowserTestExpectedResult(browser, page, WideToASCII(version).c_str()); | |
| 331 } | |
| 332 | |
| 333 // MockWebServer methods | |
| 334 void MockWebServer::ExpectAndServeRequest(CFInvocation invocation, | |
| 335 const std::wstring& url) { | |
| 336 ExpectAndServeRequestWithCardinality(invocation, url, testing::Exactly(1)); | |
| 337 } | |
| 338 | |
| 339 void MockWebServer::ExpectAndServeRequestWithCardinality( | |
| 340 CFInvocation invocation, const std::wstring& url, | |
| 341 testing::Cardinality cardinality) { | |
| 342 EXPECT_CALL(*this, Get(_, chrome_frame_test::UrlPathEq(url), _)) | |
| 343 .Times(cardinality) | |
| 344 .WillRepeatedly(SendResponse(this, invocation)); | |
| 345 } | |
| 346 | |
| 347 void MockWebServer::ExpectAndServeRequestAllowCache(CFInvocation invocation, | |
| 348 const std::wstring &url) { | |
| 349 EXPECT_CALL(*this, Get(_, chrome_frame_test::UrlPathEq(url), _)) | |
| 350 .WillOnce(SendResponse(this, invocation)); | |
| 351 } | |
| 352 | |
| 353 void MockWebServer::ExpectAndServeRequestAnyNumberTimes( | |
| 354 CFInvocation invocation, const std::wstring& path_prefix) { | |
| 355 EXPECT_CALL(*this, Get(_, testing::StartsWith(path_prefix), _)) | |
| 356 .WillRepeatedly(SendResponse(this, invocation)); | |
| 357 } | |
| 358 | |
| 359 void MockWebServer::ExpectAndHandlePostedResult( | |
| 360 CFInvocation invocation, const std::wstring& post_suffix) { | |
| 361 EXPECT_CALL(*this, Post(_, testing::HasSubstr(post_suffix), _)) | |
| 362 .WillRepeatedly(HandlePostedResponseHelper(this, invocation)); | |
| 363 } | |
| 364 | |
| 365 void MockWebServer::HandlePostedResponse( | |
| 366 test_server::ConfigurableConnection* connection, | |
| 367 const test_server::Request& request) { | |
| 368 posted_result_ = request.content(); | |
| 369 if (listener_ && posted_result_ == expected_result_) | |
| 370 listener_->OnExpectedResponse(); | |
| 371 connection->Send("HTTP/1.1 200 OK\r\n", ""); | |
| 372 } | |
| 373 | |
| 374 void MockWebServer::SendResponseHelper( | |
| 375 test_server::ConfigurableConnection* connection, | |
| 376 const std::wstring& request_uri, | |
| 377 const test_server::Request& request, | |
| 378 CFInvocation invocation, | |
| 379 bool add_no_cache_header) { | |
| 380 static const wchar_t kEchoHeader[] = L"/echoheader?"; | |
| 381 if (request_uri.find(kEchoHeader) != std::wstring::npos) { | |
| 382 std::wstring header = request_uri.substr( | |
| 383 wcslen(kEchoHeader), | |
| 384 request_uri.length() - wcslen(kEchoHeader)); | |
| 385 | |
| 386 std::string header_value = http_utils::GetHttpHeaderFromHeaderList( | |
| 387 base::WideToUTF8(header), request.headers()); | |
| 388 connection->Send(header_value, ""); | |
| 389 return; | |
| 390 } | |
| 391 // Convert |request_uri| to a path. | |
| 392 std::wstring path = request_uri; | |
| 393 size_t query_index = request_uri.find(L"?"); | |
| 394 if (query_index != std::string::npos) { | |
| 395 path = path.erase(query_index); | |
| 396 } | |
| 397 base::FilePath file_path = root_dir_; | |
| 398 if (path.size()) | |
| 399 file_path = file_path.Append(path.substr(1)); // remove first '/' | |
| 400 | |
| 401 std::string headers, body; | |
| 402 std::string content_type; | |
| 403 if (base::PathExists(file_path) && | |
| 404 !base::DirectoryExists(file_path)) { | |
| 405 base::FilePath mock_http_headers(file_path.value() + L".mock-http-headers"); | |
| 406 if (base::PathExists(mock_http_headers)) { | |
| 407 headers = GetMockHttpHeaders(mock_http_headers); | |
| 408 content_type = http_utils::GetHttpHeaderFromHeaderList("Content-type", | |
| 409 headers); | |
| 410 } else { | |
| 411 EXPECT_TRUE(net::GetMimeTypeFromFile(file_path, &content_type)); | |
| 412 VLOG(1) << "Going to send file (" << base::WideToUTF8(file_path.value()) | |
| 413 << ") with content type (" << content_type << ")"; | |
| 414 headers = CreateHttpHeaders(invocation, add_no_cache_header, | |
| 415 content_type); | |
| 416 } | |
| 417 | |
| 418 EXPECT_FALSE(headers.empty()); | |
| 419 | |
| 420 EXPECT_TRUE(base::ReadFileToString(file_path, &body)) | |
| 421 << "Could not read file (" | |
| 422 << base::WideToUTF8(file_path.value()) << ")"; | |
| 423 if (invocation.type() == CFInvocation::META_TAG && | |
| 424 StartsWithASCII(content_type, "text/html", false)) { | |
| 425 EXPECT_TRUE(chrome_frame_test::AddCFMetaTag(&body)) << "Could not add " | |
| 426 << "meta tag to HTML file."; | |
| 427 } | |
| 428 } else { | |
| 429 VLOG(1) << "Going to send 404 for non-existent file (" | |
| 430 << base::WideToUTF8(file_path.value()) << ")"; | |
| 431 headers = "HTTP/1.1 404 Not Found"; | |
| 432 body = ""; | |
| 433 } | |
| 434 connection->Send(headers, body); | |
| 435 } | |
| 436 | |
| 437 const wchar_t kPostMessageBasicPage[] = L"postmessage_basic_host.html"; | |
| 438 | |
| 439 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_PostMessageBasic) { | |
| 440 SimpleBrowserTest(IE, kPostMessageBasicPage); | |
| 441 } | |
| 442 | |
| 443 TEST_F(ChromeFrameTestWithWebServer, FullTabIE_MIMEFilterBasic) { | |
| 444 const wchar_t kMIMEFilterBasicPage[] = | |
| 445 L"chrome_frame_mime_filter_test.html"; | |
| 446 | |
| 447 // If this test fails for IE8 then it is possible that prebinding is enabled. | |
| 448 // A known workaround is to disable it until CF properly handles it. | |
| 449 // | |
| 450 // HKCU\Software\Microsoft\Internet Explorer\Main | |
| 451 // Value name: EnablePreBinding (REG_DWORD) | |
| 452 // Value: 0 | |
| 453 SimpleBrowserTest(IE, kMIMEFilterBasicPage); | |
| 454 } | |
| 455 | |
| 456 // Times out: http://crbug.com/163728 | |
| 457 TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_Resize) { | |
| 458 SimpleBrowserTest(IE, L"chrome_frame_resize.html"); | |
| 459 } | |
| 460 | |
| 461 const wchar_t kNavigateURLAbsolutePage[] = | |
| 462 L"navigateurl_absolute_host.html"; | |
| 463 | |
| 464 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_NavigateURLAbsolute) { | |
| 465 SimpleBrowserTest(IE, kNavigateURLAbsolutePage); | |
| 466 } | |
| 467 | |
| 468 const wchar_t kNavigateURLRelativePage[] = | |
| 469 L"navigateurl_relative_host.html"; | |
| 470 | |
| 471 // Flaky, crbug.com/160497. | |
| 472 TEST_F(ChromeFrameTestWithWebServer, | |
| 473 DISABLED_WidgetModeIE_NavigateURLRelative) { | |
| 474 SimpleBrowserTest(IE, kNavigateURLRelativePage); | |
| 475 } | |
| 476 | |
| 477 const wchar_t kNavigateSimpleObjectFocus[] = L"simple_object_focus.html"; | |
| 478 | |
| 479 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_ObjectFocus) { | |
| 480 SimpleBrowserTest(IE, kNavigateSimpleObjectFocus); | |
| 481 } | |
| 482 | |
| 483 const wchar_t kiframeBasicPage[] = L"iframe_basic_host.html"; | |
| 484 | |
| 485 | |
| 486 // Flaky, crbug.com/160497. | |
| 487 TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_iframeBasic) { | |
| 488 SimpleBrowserTest(IE, kiframeBasicPage); | |
| 489 } | |
| 490 | |
| 491 const wchar_t kSrcPropertyTestPage[] = L"src_property_host.html"; | |
| 492 | |
| 493 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_SrcProperty) { | |
| 494 SimpleBrowserTest(IE, kSrcPropertyTestPage); | |
| 495 } | |
| 496 | |
| 497 const wchar_t kCFInstanceBasicTestPage[] = L"CFInstance_basic_host.html"; | |
| 498 | |
| 499 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceBasic) { | |
| 500 SimpleBrowserTest(IE, kCFInstanceBasicTestPage); | |
| 501 } | |
| 502 | |
| 503 const wchar_t kCFISingletonPage[] = L"CFInstance_singleton_host.html"; | |
| 504 | |
| 505 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceSingleton) { | |
| 506 SimpleBrowserTest(IE, kCFISingletonPage); | |
| 507 } | |
| 508 | |
| 509 const wchar_t kCFIDelayPage[] = L"CFInstance_delay_host.html"; | |
| 510 | |
| 511 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceDelay) { | |
| 512 SimpleBrowserTest(IE, kCFIDelayPage); | |
| 513 } | |
| 514 | |
| 515 const wchar_t kCFIFallbackPage[] = L"CFInstance_fallback_host.html"; | |
| 516 | |
| 517 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceFallback) { | |
| 518 SimpleBrowserTest(IE, kCFIFallbackPage); | |
| 519 } | |
| 520 | |
| 521 const wchar_t kCFINoSrcPage[] = L"CFInstance_no_src_host.html"; | |
| 522 | |
| 523 // Flaky, crbug.com/160497. | |
| 524 TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_CFInstanceNoSrc) { | |
| 525 SimpleBrowserTest(IE, kCFINoSrcPage); | |
| 526 } | |
| 527 | |
| 528 const wchar_t kCFIIfrOnLoadPage[] = L"CFInstance_iframe_onload_host.html"; | |
| 529 | |
| 530 // disabled since it's unlikely that we care about this case | |
| 531 TEST_F(ChromeFrameTestWithWebServer, | |
| 532 DISABLED_WidgetModeIE_CFInstanceIfrOnLoad) { | |
| 533 SimpleBrowserTest(IE, kCFIIfrOnLoadPage); | |
| 534 } | |
| 535 | |
| 536 const wchar_t kCFIZeroSizePage[] = L"CFInstance_zero_size_host.html"; | |
| 537 | |
| 538 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceZeroSize) { | |
| 539 SimpleBrowserTest(IE, kCFIZeroSizePage); | |
| 540 } | |
| 541 | |
| 542 const wchar_t kCFIIfrPostPage[] = L"CFInstance_iframe_post_host.html"; | |
| 543 | |
| 544 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceIfrPost) { | |
| 545 SimpleBrowserTest(IE, kCFIIfrPostPage); | |
| 546 } | |
| 547 | |
| 548 TEST_F(ChromeFrameTestWithWebServer, WidgetModeChrome_CFInstanceIfrPost) { | |
| 549 SimpleBrowserTest(CHROME, kCFIIfrPostPage); | |
| 550 } | |
| 551 | |
| 552 const wchar_t kCFIPostPage[] = L"CFInstance_post_host.html"; | |
| 553 | |
| 554 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstancePost) { | |
| 555 if (chrome_frame_test::GetInstalledIEVersion() == IE_9) { | |
| 556 LOG(INFO) << "Not running test on Vista/Windows 7 with IE9"; | |
| 557 return; | |
| 558 } | |
| 559 SimpleBrowserTest(IE, kCFIPostPage); | |
| 560 } | |
| 561 | |
| 562 // This test randomly fails on the ChromeFrame builder. | |
| 563 TEST_F(ChromeFrameTestWithWebServer, WidgetModeChrome_CFInstancePost) { | |
| 564 SimpleBrowserTest(CHROME, kCFIPostPage); | |
| 565 } | |
| 566 | |
| 567 const wchar_t kCFIRPCPage[] = L"CFInstance_rpc_host.html"; | |
| 568 | |
| 569 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceRPC) { | |
| 570 if (chrome_frame_test::GetInstalledIEVersion() == IE_9) { | |
| 571 LOG(INFO) << "Not running test on Vista/Windows 7 with IE9"; | |
| 572 return; | |
| 573 } | |
| 574 SimpleBrowserTest(IE, kCFIRPCPage); | |
| 575 } | |
| 576 | |
| 577 TEST_F(ChromeFrameTestWithWebServer, WidgetModeChrome_CFInstanceRPC) { | |
| 578 SimpleBrowserTest(CHROME, kCFIRPCPage); | |
| 579 } | |
| 580 | |
| 581 const wchar_t kCFIRPCInternalPage[] = | |
| 582 L"CFInstance_rpc_internal_host.html"; | |
| 583 | |
| 584 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceRPCInternal) { | |
| 585 if (chrome_frame_test::GetInstalledIEVersion() == IE_9) { | |
| 586 LOG(INFO) << "Not running test on Vista/Windows 7 with IE9"; | |
| 587 return; | |
| 588 } | |
| 589 SimpleBrowserTest(IE, kCFIRPCInternalPage); | |
| 590 } | |
| 591 | |
| 592 TEST_F(ChromeFrameTestWithWebServer, WidgetModeChrome_CFInstanceRPCInternal) { | |
| 593 SimpleBrowserTest(CHROME, kCFIRPCInternalPage); | |
| 594 } | |
| 595 | |
| 596 const wchar_t kCFIDefaultCtorPage[] = | |
| 597 L"CFInstance_default_ctor_host.html"; | |
| 598 | |
| 599 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceDefaultCtor) { | |
| 600 SimpleBrowserTest(IE, kCFIDefaultCtorPage); | |
| 601 } | |
| 602 | |
| 603 const wchar_t kCFInstallBasicTestPage[] = L"CFInstall_basic.html"; | |
| 604 | |
| 605 TEST_F(ChromeFrameTestWithWebServer, FullTabIE_CFInstallBasic) { | |
| 606 SimpleBrowserTest(IE, kCFInstallBasicTestPage); | |
| 607 } | |
| 608 | |
| 609 const wchar_t kCFInstallPlaceTestPage[] = L"CFInstall_place.html"; | |
| 610 | |
| 611 TEST_F(ChromeFrameTestWithWebServer, FullTabIE_CFInstallPlace) { | |
| 612 SimpleBrowserTest(IE, kCFInstallPlaceTestPage); | |
| 613 } | |
| 614 | |
| 615 const wchar_t kCFInstallOverlayTestPage[] = L"CFInstall_overlay.html"; | |
| 616 | |
| 617 TEST_F(ChromeFrameTestWithWebServer, FullTabIE_CFInstallOverlay) { | |
| 618 SimpleBrowserTest(IE, kCFInstallOverlayTestPage); | |
| 619 } | |
| 620 | |
| 621 const wchar_t kCFInstallDismissTestPage[] = L"CFInstall_dismiss.html"; | |
| 622 | |
| 623 TEST_F(ChromeFrameTestWithWebServer, FullTabIE_CFInstallDismiss) { | |
| 624 SimpleBrowserTest(IE, kCFInstallDismissTestPage); | |
| 625 } | |
| 626 | |
| 627 const wchar_t kInitializeHiddenPage[] = L"initialize_hidden.html"; | |
| 628 // Times out: http://crbug.com/163728 | |
| 629 TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_InitializeHidden) { | |
| 630 SimpleBrowserTest(IE, kInitializeHiddenPage); | |
| 631 } | |
| 632 | |
| 633 const wchar_t kFullTabHttpHeaderPage[] = L"chrome_frame_http_header.html"; | |
| 634 | |
| 635 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_CFHttpHeaderBasic) { | |
| 636 SimpleBrowserTest(IE, kFullTabHttpHeaderPage); | |
| 637 } | |
| 638 | |
| 639 const wchar_t kFullTabHttpHeaderPageIFrame[] = | |
| 640 L"chrome_frame_http_header_host.html"; | |
| 641 | |
| 642 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_CFHttpHeaderIFrame) { | |
| 643 SimpleBrowserTest(IE, kFullTabHttpHeaderPageIFrame); | |
| 644 } | |
| 645 | |
| 646 const wchar_t kFullTabHttpHeaderPageFrameset[] = | |
| 647 L"chrome_frame_http_header_frameset.html"; | |
| 648 | |
| 649 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_CFHttpHeaderFrameSet) { | |
| 650 SimpleBrowserTest(IE, kFullTabHttpHeaderPageFrameset); | |
| 651 } | |
| 652 | |
| 653 const wchar_t kVersionPage[] = L"version.html"; | |
| 654 | |
| 655 // Flaky, crbug.com/160497. | |
| 656 TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_Version) { | |
| 657 VersionTest(IE, kVersionPage); | |
| 658 } | |
| 659 | |
| 660 const wchar_t kEventListenerPage[] = L"event_listener.html"; | |
| 661 | |
| 662 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_EventListener) { | |
| 663 SimpleBrowserTest(IE, kEventListenerPage); | |
| 664 } | |
| 665 | |
| 666 const wchar_t kPrivilegedApisPage[] = L"privileged_apis_host.html"; | |
| 667 | |
| 668 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_PrivilegedApis) { | |
| 669 SimpleBrowserTest(IE, kPrivilegedApisPage); | |
| 670 } | |
| 671 | |
| 672 const wchar_t kMetaTagPage[] = L"meta_tag.html"; | |
| 673 // Flaky, crbug.com/160497. | |
| 674 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_MetaTag) { | |
| 675 SimpleBrowserTest(IE, kMetaTagPage); | |
| 676 } | |
| 677 | |
| 678 // Times out: http://crbug.com/163728 | |
| 679 const wchar_t kCFProtocolPage[] = L"cf_protocol.html"; | |
| 680 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_CFProtocol) { | |
| 681 // Temporarily enable gcf: protocol for this test. | |
| 682 SetConfigBool(kAllowUnsafeURLs, true); | |
| 683 SimpleBrowserTest(IE, kCFProtocolPage); | |
| 684 SetConfigBool(kAllowUnsafeURLs, false); | |
| 685 } | |
| 686 | |
| 687 const wchar_t kPersistentCookieTest[] = | |
| 688 L"persistent_cookie_test_page.html"; | |
| 689 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_PersistentCookieTest) { | |
| 690 SimpleBrowserTest(IE, kPersistentCookieTest); | |
| 691 } | |
| 692 | |
| 693 const wchar_t kNavigateOutPage[] = L"navigate_out.html"; | |
| 694 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_NavigateOut) { | |
| 695 SimpleBrowserTest(IE, kNavigateOutPage); | |
| 696 } | |
| 697 | |
| 698 const wchar_t kReferrerMainTest[] = L"referrer_main.html"; | |
| 699 | |
| 700 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_ReferrerTest) { | |
| 701 SimpleBrowserTest(IE, kReferrerMainTest); | |
| 702 } | |
| 703 | |
| 704 // Times out: http://crbug.com/163728 | |
| 705 const wchar_t kSubFrameTestPage[] = L"full_tab_sub_frame_main.html"; | |
| 706 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_SubFrame) { | |
| 707 SimpleBrowserTest(IE, kSubFrameTestPage); | |
| 708 } | |
| 709 | |
| 710 const wchar_t kSubIFrameTestPage[] = L"full_tab_sub_iframe_main.html"; | |
| 711 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_SubIFrame) { | |
| 712 SimpleBrowserTest(IE, kSubIFrameTestPage); | |
| 713 } | |
| 714 | |
| 715 const wchar_t kXMLHttpRequestTestUrl[] = | |
| 716 L"xmlhttprequest_test.html"; | |
| 717 | |
| 718 // Flaky, crbug.com/160497. | |
| 719 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_XHRTest) { | |
| 720 SimpleBrowserTest(IE, kXMLHttpRequestTestUrl); | |
| 721 } | |
| 722 | |
| 723 const wchar_t kInstallFlowTestUrl[] = | |
| 724 L"install_flow_test.html"; | |
| 725 | |
| 726 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_InstallFlowTest) { | |
| 727 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
| 728 ScopedChromeFrameRegistrar::UnregisterAtPath( | |
| 729 GetChromeFrameBuildPath().value(), | |
| 730 chrome_frame_test::GetTestBedType()); | |
| 731 | |
| 732 ASSERT_TRUE(LaunchBrowser(IE, kInstallFlowTestUrl)); | |
| 733 | |
| 734 loop().RunFor(kChromeFrameLongNavigationTimeout); | |
| 735 | |
| 736 ScopedChromeFrameRegistrar::RegisterAtPath( | |
| 737 GetChromeFrameBuildPath().value(), | |
| 738 chrome_frame_test::GetTestBedType()); | |
| 739 | |
| 740 ExpectAndHandlePostedResult(); | |
| 741 loop().RunFor(kChromeFrameLongNavigationTimeout); | |
| 742 | |
| 743 chrome_frame_test::CloseAllIEWindows(); | |
| 744 ASSERT_EQ("OK", server_mock().posted_result()); | |
| 745 } | |
| 746 } | |
| 747 | |
| 748 const wchar_t kMultipleCFInstancesTestUrl[] = | |
| 749 L"multiple_cf_instances_main.html"; | |
| 750 | |
| 751 TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_MultipleCFInstances) { | |
| 752 SimpleBrowserTest(IE, kMultipleCFInstancesTestUrl); | |
| 753 } | |
| 754 | |
| 755 const wchar_t kXHRHeaderTestUrl[] = | |
| 756 L"xmlhttprequest_header_test.html"; | |
| 757 | |
| 758 // Marking as flaky since it occasionally times out. crbug.com/127395. | |
| 759 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_XHRHeaderTest) { | |
| 760 SimpleBrowserTest(IE, kXHRHeaderTestUrl); | |
| 761 } | |
| 762 | |
| 763 const wchar_t kDeleteCookieTest[] = | |
| 764 L"fulltab_delete_cookie_test.html"; | |
| 765 | |
| 766 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_DeleteCookieTest) { | |
| 767 SimpleBrowserTest(IE, kDeleteCookieTest); | |
| 768 } | |
| 769 | |
| 770 const wchar_t kAnchorUrlNavigate[] = | |
| 771 L"fulltab_anchor_url_navigate.html#chrome_frame"; | |
| 772 | |
| 773 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_AnchorUrlNavigateTest) { | |
| 774 SimpleBrowserTest(IE, kAnchorUrlNavigate); | |
| 775 } | |
| 776 | |
| 777 // Test whether POST-ing a form from an mshtml page to a CF page will cause | |
| 778 // the request to get reissued. It should not. | |
| 779 // https://code.google.com/p/chromium/issues/detail?id=143699 | |
| 780 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_TestPostReissue) { | |
| 781 // The order of pages in this array is assumed to be mshtml, cf, script. | |
| 782 const wchar_t* kPages[] = { | |
| 783 L"full_tab_post_mshtml.html", | |
| 784 L"full_tab_post_target_cf.html", | |
| 785 L"chrome_frame_tester_helpers.js", | |
| 786 }; | |
| 787 | |
| 788 SimpleWebServerTest server(local_address_, 46664); | |
| 789 server.PopulateStaticFileListT<test_server::FileResponse>(kPages, | |
| 790 arraysize(kPages), GetCFTestFilePath()); | |
| 791 | |
| 792 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); | |
| 793 | |
| 794 loop().RunFor(kChromeFrameLongNavigationTimeout); | |
| 795 | |
| 796 const test_server::Request* request = NULL; | |
| 797 server.FindRequest("/quit?OK", &request); | |
| 798 ASSERT_TRUE(request != NULL); | |
| 799 EXPECT_EQ("OK", request->arguments()); | |
| 800 | |
| 801 if (request->arguments().compare("OK") == 0) { | |
| 802 // Check how many requests we got for the cf page. Also expect it to be | |
| 803 // a POST. | |
| 804 int requests = server.GetRequestCountForPage(kPages[1], "POST"); | |
| 805 EXPECT_EQ(1, requests); | |
| 806 } | |
| 807 } | |
| 808 | |
| 809 // Test whether following a link from an mshtml page to a CF page will cause | |
| 810 // multiple network requests. It should not. | |
| 811 // Flaky, crbug.com/160497. | |
| 812 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_TestMultipleGet) { | |
| 813 // The order of pages in this array is assumed to be mshtml, cf, script. | |
| 814 const wchar_t* kPages[] = { | |
| 815 L"full_tab_get_mshtml.html", | |
| 816 L"full_tab_get_target_cf.html", | |
| 817 L"chrome_frame_tester_helpers.js", | |
| 818 }; | |
| 819 | |
| 820 SimpleWebServerTest server(local_address_, 46664); | |
| 821 | |
| 822 server.PopulateStaticFileListT<test_server::FileResponse>(kPages, | |
| 823 arraysize(kPages), GetCFTestFilePath()); | |
| 824 | |
| 825 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); | |
| 826 | |
| 827 loop().RunFor(kChromeFrameVeryLongNavigationTimeout); | |
| 828 | |
| 829 const test_server::Request* request = NULL; | |
| 830 server.FindRequest("/quit?OK", &request); | |
| 831 ASSERT_TRUE(request != NULL); | |
| 832 EXPECT_EQ("OK", request->arguments()); | |
| 833 | |
| 834 if (request->arguments().compare("OK") == 0) { | |
| 835 // Check how many requests we got for the cf page and check that it was | |
| 836 // a GET. | |
| 837 int requests = server.GetRequestCountForPage(kPages[1], "GET"); | |
| 838 EXPECT_EQ(1, requests); | |
| 839 } | |
| 840 } | |
| 841 | |
| 842 const wchar_t kSetCookieTest[] = | |
| 843 L"fulltab_set_cookie_test.html"; | |
| 844 | |
| 845 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_SetCookieTest) { | |
| 846 SimpleBrowserTest(IE, kSetCookieTest); | |
| 847 } | |
| 848 | |
| 849 const wchar_t kXHRConditionalHeaderTestUrl[] = | |
| 850 L"xmlhttprequest_conditional_header_test.html"; | |
| 851 | |
| 852 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_XHRConditionalHeaderTest) { | |
| 853 SimpleBrowserTest(IE, kXHRConditionalHeaderTestUrl); | |
| 854 } | |
| 855 | |
| 856 const wchar_t kWindowCloseTestUrl[] = | |
| 857 L"window_close.html"; | |
| 858 | |
| 859 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_WindowClose) { | |
| 860 SimpleBrowserTest(IE, kWindowCloseTestUrl); | |
| 861 } | |
| 862 | |
| 863 std::string GetHeaderValue(const std::string& headers, | |
| 864 const char* header_name) { | |
| 865 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), | |
| 866 "\r\n"); | |
| 867 while (it.GetNext()) { | |
| 868 if (lstrcmpiA(it.name().c_str(), header_name) == 0) { | |
| 869 return it.values(); | |
| 870 } | |
| 871 } | |
| 872 return ""; | |
| 873 } | |
| 874 | |
| 875 // Specialized implementation of test_server::FileResponse that supports | |
| 876 // adding the request's User-Agent header to the returned document. | |
| 877 // The class also supports $request_id$ which will be replaced with an | |
| 878 // id that's incremented each time the response is sent over a socket. | |
| 879 class UaTemplateFileResponse : public test_server::FileResponse { | |
| 880 public: | |
| 881 typedef test_server::FileResponse SuperClass; | |
| 882 | |
| 883 UaTemplateFileResponse(const char* request_path, | |
| 884 const base::FilePath& file_path) | |
| 885 : test_server::FileResponse(request_path, file_path), request_id_(0) { | |
| 886 } | |
| 887 | |
| 888 virtual bool Matches(const test_server::Request& r) const { | |
| 889 bool ret = SuperClass::Matches(r); | |
| 890 if (ret) | |
| 891 ua_ = GetHeaderValue(r.headers(), "User-Agent"); | |
| 892 return ret; | |
| 893 } | |
| 894 | |
| 895 virtual size_t ContentLength() const { | |
| 896 const char kRequestIdTemplate[] = "$request_id$"; | |
| 897 const char kUserAgentTemplate[] = "$UA$"; | |
| 898 | |
| 899 size_t length = SuperClass::ContentLength(); | |
| 900 DCHECK(length); | |
| 901 content_.assign(reinterpret_cast<const char*>(file_->data()), | |
| 902 file_->length()); | |
| 903 size_t i = content_.find(kUserAgentTemplate); | |
| 904 if (i != std::string::npos) | |
| 905 content_.replace(i, arraysize(kUserAgentTemplate) - 1, ua_); | |
| 906 i = content_.find(kRequestIdTemplate); | |
| 907 if (i != std::string::npos) { | |
| 908 content_.replace(i, arraysize(kRequestIdTemplate) - 1, | |
| 909 base::StringPrintf("%i", request_id_)); | |
| 910 } | |
| 911 return content_.length(); | |
| 912 } | |
| 913 | |
| 914 virtual void WriteContents(net::StreamListenSocket* socket) const { | |
| 915 DCHECK(content_.length()); | |
| 916 socket->Send(content_.c_str(), content_.length(), false); | |
| 917 request_id_++; | |
| 918 } | |
| 919 | |
| 920 protected: | |
| 921 mutable std::string ua_; | |
| 922 mutable std::string content_; | |
| 923 mutable int request_id_; | |
| 924 }; | |
| 925 | |
| 926 // This test simulates a URL that on first request returns a document | |
| 927 // that should be rendered in mshtml, then pops up a sign-in page that | |
| 928 // after signing in, refreshes the original page that should then return | |
| 929 // a page that needs to be rendered in GCF. | |
| 930 // | |
| 931 // This test currently fails because GCF does not add the chromeframe header | |
| 932 // to requests that mshtml initiates via IInternetSession::CreateBinding. | |
| 933 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_RefreshMshtmlTest) { | |
| 934 const wchar_t* kPages[] = { | |
| 935 L"mshtml_refresh_test.html", | |
| 936 L"mshtml_refresh_test_popup.html", | |
| 937 }; | |
| 938 | |
| 939 SimpleWebServerTest server(local_address_, 46664); | |
| 940 server.PopulateStaticFileListT<UaTemplateFileResponse>(kPages, | |
| 941 arraysize(kPages), GetCFTestFilePath()); | |
| 942 | |
| 943 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); | |
| 944 | |
| 945 loop().RunFor(kChromeFrameLongNavigationTimeout); | |
| 946 | |
| 947 test_server::SimpleWebServer* ws = server.web_server(); | |
| 948 const test_server::ConnectionList& connections = ws->connections(); | |
| 949 test_server::ConnectionList::const_iterator it = connections.begin(); | |
| 950 int requests_for_first_page = 0; | |
| 951 for (; it != connections.end(); ++it) { | |
| 952 test_server::Connection* c = (*it); | |
| 953 const test_server::Request& r = c->request(); | |
| 954 if (!r.path().empty() && | |
| 955 base::ASCIIToWide(r.path().substr(1)).compare(kPages[0]) == 0) { | |
| 956 requests_for_first_page++; | |
| 957 std::string ua(GetHeaderValue(r.headers(), "User-Agent")); | |
| 958 EXPECT_NE(std::string::npos, ua.find("chromeframe")); | |
| 959 } | |
| 960 } | |
| 961 EXPECT_GT(requests_for_first_page, 1); | |
| 962 } | |
| 963 | |
| 964 // See bug 36694 for details. http://crbug.com/36694 | |
| 965 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) { | |
| 966 chrome_frame_test::MockWindowObserver win_observer_mock; | |
| 967 win_observer_mock.WatchWindow("File Download", ""); | |
| 968 win_observer_mock.WatchWindow("View Downloads*", ""); | |
| 969 | |
| 970 // The content of our HTML test page. This will be returned whenever | |
| 971 // we reply to a GET request. | |
| 972 static const char kHtml[] = | |
| 973 "<html><head>\n" | |
| 974 "<title>ChromeFrame Form Download Test</title>\n" | |
| 975 // To see how this test runs with only IE (no CF in the picture), comment | |
| 976 // out this meta tag. The outcome of the test should be identical. | |
| 977 "<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />\n" | |
| 978 "</head>\n" | |
| 979 "<script language=\"javascript\">\n" | |
| 980 "function SubmitForm() {\n" | |
| 981 " var form = document.forms['myform'];\n" | |
| 982 " form.action = document.location;\n" | |
| 983 " form.submit();\n" | |
| 984 " return true;\n" | |
| 985 "}\n" | |
| 986 "</script>\n" | |
| 987 "<body onload=\"SubmitForm();\">\n" | |
| 988 "<form method=\"post\" action=\"foo.html\" id=\"myform\">\n" | |
| 989 " <input type=\"hidden\" name=\"Field1\" value=\"myvalue\" />\n" | |
| 990 " <input type=\"button\" name=\"btn\" value=\"Test Download\" " | |
| 991 "onclick=\"return SubmitForm();\" id=\"Button1\"/>\n" | |
| 992 "</form></body></html>\n"; | |
| 993 | |
| 994 // The content of our HTML test page. This will be returned whenever | |
| 995 // we reply to a POST request. | |
| 996 static const char kText[] = | |
| 997 "This is a text file (in case you were wondering)."; | |
| 998 | |
| 999 // This http response class will return an HTML document that contains | |
| 1000 // a form whenever it receives a GET request. Whenever it gets a POST | |
| 1001 // request, it will respond with a text file that needs to be downloaded | |
| 1002 // (content-disposition is "attachment"). | |
| 1003 class CustomResponse : public test_server::ResponseForPath { | |
| 1004 public: | |
| 1005 explicit CustomResponse(const char* path) | |
| 1006 : test_server::ResponseForPath(path), is_post_(false), | |
| 1007 post_requests_(0), get_requests_(0) { | |
| 1008 } | |
| 1009 | |
| 1010 virtual bool GetContentType(std::string* content_type) const { | |
| 1011 DCHECK(!is_post_); | |
| 1012 return false; | |
| 1013 } | |
| 1014 | |
| 1015 virtual size_t ContentLength() const { | |
| 1016 DCHECK(!is_post_); | |
| 1017 return sizeof(kHtml) - 1; | |
| 1018 } | |
| 1019 | |
| 1020 virtual bool GetCustomHeaders(std::string* headers) const { | |
| 1021 if (!is_post_) | |
| 1022 return false; | |
| 1023 *headers = base::StringPrintf( | |
| 1024 "HTTP/1.1 200 OK\r\n" | |
| 1025 "Content-Disposition: attachment;filename=\"test.txt\"\r\n" | |
| 1026 "Content-Type: application/text\r\n" | |
| 1027 "Connection: close\r\n" | |
| 1028 "Content-Length: %i\r\n\r\n", sizeof(kText) - 1); | |
| 1029 return true; | |
| 1030 } | |
| 1031 | |
| 1032 virtual bool Matches(const test_server::Request& r) const { | |
| 1033 bool match = __super::Matches(r); | |
| 1034 if (match) { | |
| 1035 is_post_ = LowerCaseEqualsASCII(r.method().c_str(), "post"); | |
| 1036 } | |
| 1037 return match; | |
| 1038 } | |
| 1039 | |
| 1040 virtual void WriteContents(net::StreamListenSocket* socket) const { | |
| 1041 if (is_post_) { | |
| 1042 socket->Send(kText, sizeof(kText) - 1, false); | |
| 1043 } else { | |
| 1044 socket->Send(kHtml, sizeof(kHtml) - 1, false); | |
| 1045 } | |
| 1046 } | |
| 1047 | |
| 1048 virtual void IncrementAccessCounter() { | |
| 1049 __super::IncrementAccessCounter(); | |
| 1050 if (is_post_) { | |
| 1051 post_requests_++; | |
| 1052 } else { | |
| 1053 get_requests_++; | |
| 1054 } | |
| 1055 } | |
| 1056 | |
| 1057 size_t get_request_count() const { | |
| 1058 return get_requests_; | |
| 1059 } | |
| 1060 | |
| 1061 size_t post_request_count() const { | |
| 1062 return get_requests_; | |
| 1063 } | |
| 1064 | |
| 1065 protected: | |
| 1066 mutable bool is_post_; | |
| 1067 size_t post_requests_; | |
| 1068 size_t get_requests_; | |
| 1069 }; | |
| 1070 | |
| 1071 EXPECT_CALL(win_observer_mock, OnWindowOpen(_)) | |
| 1072 .Times(testing::AtMost(1)) | |
| 1073 .WillOnce(chrome_frame_test::DoCloseWindow()); | |
| 1074 | |
| 1075 EXPECT_CALL(win_observer_mock, OnWindowClose(_)) | |
| 1076 .Times(testing::AtMost(1)) | |
| 1077 .WillOnce(QUIT_LOOP(loop())); | |
| 1078 | |
| 1079 SimpleWebServerTest server(local_address_, 46664); | |
| 1080 CustomResponse* response = new CustomResponse("/form.html"); | |
| 1081 server.web_server()->AddResponse(response); | |
| 1082 | |
| 1083 std::wstring url(server.FormatHttpPath(L"form.html")); | |
| 1084 | |
| 1085 ASSERT_TRUE(LaunchBrowser(IE, url.c_str())); | |
| 1086 loop().RunFor(kChromeFrameLongNavigationTimeout); | |
| 1087 | |
| 1088 EXPECT_EQ(1, response->get_request_count()); | |
| 1089 EXPECT_EQ(1, response->post_request_count()); | |
| 1090 } | |
| 1091 | |
| 1092 // This test loads a large page and ensures that the full page contents are | |
| 1093 // actually loaded via a self-validating HTML page. This is done due to a bug | |
| 1094 // whereby the middle of the response stream would sometimes be truncated when | |
| 1095 // loading a CF document. See http://crbug.com/178421 for details. | |
| 1096 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_LargePageLoad) { | |
| 1097 const wchar_t kLargePageLoadPage[] = | |
| 1098 L"chrome_frame_large_page.html"; | |
| 1099 | |
| 1100 SimpleBrowserTest(IE, kLargePageLoadPage); | |
| 1101 } | |
| OLD | NEW |