Chromium Code Reviews| Index: chrome_frame/test/test_with_web_server.cc |
| diff --git a/chrome_frame/test/test_with_web_server.cc b/chrome_frame/test/test_with_web_server.cc |
| index e01733efdfbab2e351e9ea721a3c464627b4833b..ec95d9e401a828d4e9ad65b98aaa4fc8278461f6 100644 |
| --- a/chrome_frame/test/test_with_web_server.cc |
| +++ b/chrome_frame/test/test_with_web_server.cc |
| @@ -24,8 +24,8 @@ |
| #include "net/base/mime_util.h" |
| #include "net/http/http_util.h" |
| -using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; |
| -using chrome_frame_test::kChromeFrameVeryLongNavigationTimeoutInSeconds; |
| +using chrome_frame_test::kChromeFrameLongNavigationTimeout; |
| +using chrome_frame_test::kChromeFrameVeryLongNavigationTimeout; |
| using testing::_; |
| using testing::StrCaseEq; |
| @@ -44,8 +44,10 @@ std::string CreateHttpHeaders(CFInvocation invocation, |
| << "Content-Type: " << content_type << "\r\n"; |
| if (invocation.type() == CFInvocation::HTTP_HEADER) |
| ss << "X-UA-Compatible: chrome=1\r\n"; |
| - if (add_no_cache_header) |
| + if (add_no_cache_header) { |
| ss << "Cache-Control: no-cache\r\n"; |
| + ss << "Expires: Tue, 15 Nov 1994 08:12:31 GMT\r\n"; |
| + } |
| return ss.str(); |
| } |
| @@ -74,11 +76,12 @@ FilePath ChromeFrameTestWithWebServer::CFInstall_path_; |
| FilePath ChromeFrameTestWithWebServer::CFInstance_path_; |
| ScopedTempDir ChromeFrameTestWithWebServer::temp_dir_; |
| FilePath ChromeFrameTestWithWebServer::chrome_user_data_dir_; |
| +chrome_frame_test::TimedMsgLoop* ChromeFrameTestWithWebServer::loop_; |
| +testing::StrictMock<MockWebServerListener>* |
| + ChromeFrameTestWithWebServer::listener_mock_; |
| +testing::StrictMock<MockWebServer>* ChromeFrameTestWithWebServer::server_mock_; |
| -ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() |
| - : loop_(), |
| - server_mock_(1337, L"127.0.0.1", |
| - chrome_frame_test::GetTestDataFolder()) { |
| +ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() { |
| } |
| // static |
| @@ -108,13 +111,28 @@ void ChromeFrameTestWithWebServer::SetUpTestCase() { |
| CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); |
| ASSERT_TRUE(file_util::CopyFile(CFInstall_src_path, CFInstall_path_)); |
| + |
| + loop_ = new chrome_frame_test::TimedMsgLoop(); |
| + loop_->set_snapshot_on_timeout(true); |
| + listener_mock_ = new testing::StrictMock<MockWebServerListener>(); |
| + server_mock_ = new testing::StrictMock<MockWebServer>( |
| + 1337, ASCIIToWide(chrome_frame_test::GetLocalIPv4Address()), |
| + chrome_frame_test::GetTestDataFolder()); |
| + server_mock_->set_listener(listener_mock_); |
| } |
| // static |
| void ChromeFrameTestWithWebServer::TearDownTestCase() { |
| + delete server_mock_; |
| + server_mock_ = NULL; |
| + delete listener_mock_; |
| + listener_mock_ = NULL; |
| + delete loop_; |
| + loop_ = NULL; |
| file_util::Delete(CFInstall_path_, false); |
| file_util::Delete(CFInstance_path_, false); |
| - EXPECT_TRUE(temp_dir_.Delete()); |
| + if (temp_dir_.IsValid()) |
| + EXPECT_TRUE(temp_dir_.Delete()); |
| } |
| // static |
| @@ -130,12 +148,16 @@ void ChromeFrameTestWithWebServer::SetUp() { |
| // Make sure that we are not accidentally enabling gcf protocol. |
| SetConfigBool(kAllowUnsafeURLs, false); |
| - server_mock_.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| - server_mock_.set_expected_result("OK"); |
| + server_mock().ClearResults(); |
| + server_mock().ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| + server_mock().set_expected_result("OK"); |
| } |
| void ChromeFrameTestWithWebServer::TearDown() { |
| CloseBrowser(); |
| + loop().RunAllPending(); |
| + testing::Mock::VerifyAndClear(listener_mock_); |
| + testing::Mock::VerifyAndClear(server_mock_); |
| } |
| bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, |
| @@ -145,7 +167,7 @@ bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, |
| // We should resolve the URL only if it is a relative url. |
| GURL parsed_url(WideToUTF8(page)); |
| if (!parsed_url.has_scheme()) { |
| - url = server_mock_.Resolve(page); |
| + url = server_mock().Resolve(page); |
| } |
| browser_ = browser; |
| @@ -201,9 +223,10 @@ bool ChromeFrameTestWithWebServer::BringBrowserToTop() { |
| GetProcessId(browser_handle_)); |
| } |
| -bool ChromeFrameTestWithWebServer::WaitForTestToComplete(int milliseconds) { |
| - loop_.RunFor(milliseconds/1000); |
| - return true; |
| +bool ChromeFrameTestWithWebServer::WaitForTestToComplete( |
| + base::TimeDelta duration) { |
| + loop().RunFor(duration); |
| + return !loop().WasTimedOut(); |
| } |
| bool ChromeFrameTestWithWebServer::WaitForOnLoad(int milliseconds) { |
| @@ -214,11 +237,27 @@ const wchar_t kPostedResultSubstring[] = L"/writefile/"; |
| void ChromeFrameTestWithWebServer::SimpleBrowserTestExpectedResult( |
| BrowserKind browser, const wchar_t* page, const char* result) { |
| - server_mock_.ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), |
| - kPostedResultSubstring); |
| - ASSERT_TRUE(LaunchBrowser(browser, page)); |
| - WaitForTestToComplete(TestTimeouts::action_max_timeout_ms()); |
| - ASSERT_EQ(result, server_mock_.posted_result()); |
| + int tries = 0; |
| + ExpectAndHandlePostedResult(); |
| + // Retry tests that timeout once; see http://crbug.com/96449. |
| + do { |
| + // Don't take a snapshot on the first try. |
| + loop().set_snapshot_on_timeout(tries != 0); |
| + ASSERT_TRUE(LaunchBrowser(browser, page)); |
| + if (WaitForTestToComplete(TestTimeouts::action_max_timeout())) { |
| + // The test exited without timing out. Confirm that the expected response |
| + // was posted and return. |
| + ASSERT_EQ(result, server_mock().posted_result()); |
| + break; |
| + } |
| + ASSERT_EQ(std::string(), server_mock().posted_result()) |
| + << "Test timed out yet provided a result."; |
| + ASSERT_EQ(0, tries++) << "Test timed out twice."; |
|
robertshield
2012/04/11 17:03:36
Please explicitly mark this with a comment as the
grt (UTC plus 2)
2012/04/11 17:33:08
Done.
|
| + // Close the browser and try a second time. |
| + CloseBrowser(); |
| + LOG(ERROR) << "Retrying test once since it timed out."; |
| + } while (true); |
| + loop().set_snapshot_on_timeout(true); |
| } |
| void ChromeFrameTestWithWebServer::SimpleBrowserTest(BrowserKind browser, |
| @@ -226,6 +265,14 @@ void ChromeFrameTestWithWebServer::SimpleBrowserTest(BrowserKind browser, |
| SimpleBrowserTestExpectedResult(browser, page, "OK"); |
| } |
| +void ChromeFrameTestWithWebServer::ExpectAndHandlePostedResult() { |
| + EXPECT_CALL(listener_mock(), OnExpectedResponse()) |
| + .WillRepeatedly(QUIT_LOOP_SOON(loop(), |
| + base::TimeDelta::FromMilliseconds(100))); |
| + server_mock().ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), |
| + kPostedResultSubstring); |
| +} |
| + |
| void ChromeFrameTestWithWebServer::VersionTest(BrowserKind browser, |
| const wchar_t* page) { |
| FilePath plugin_path; |
| @@ -257,15 +304,12 @@ void ChromeFrameTestWithWebServer::VersionTest(BrowserKind browser, |
| version = version_info->product_version(); |
| } |
| - server_mock_.set_expected_result(WideToUTF8(version)); |
| + server_mock().set_expected_result(WideToUTF8(version)); |
| EXPECT_TRUE(version_info); |
| EXPECT_FALSE(version.empty()); |
| - server_mock_.ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), |
| - kPostedResultSubstring); |
| - EXPECT_TRUE(LaunchBrowser(browser, page)); |
| - WaitForTestToComplete(TestTimeouts::action_max_timeout_ms()); |
| - ASSERT_EQ(version, UTF8ToWide(server_mock_.posted_result())); |
| + |
| + SimpleBrowserTestExpectedResult(browser, page, WideToASCII(version).c_str()); |
| } |
| // MockWebServer methods |
| @@ -304,11 +348,8 @@ void MockWebServer::HandlePostedResponse( |
| test_server::ConfigurableConnection* connection, |
| const test_server::Request& request) { |
| posted_result_ = request.content(); |
| - if (posted_result_ == expected_result_) { |
| - MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| - MessageLoop::QuitClosure(), |
| - 100); |
| - } |
| + if (listener_ && posted_result_ == expected_result_) |
| + listener_->OnExpectedResponse(); |
| connection->Send("HTTP/1.1 200 OK\r\n", ""); |
| } |
| @@ -425,7 +466,7 @@ TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_iframeBasic) { |
| const wchar_t kSrcPropertyTestPage[] = L"src_property_host.html"; |
| -TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_SrcProperty) { |
| +TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_SrcProperty) { |
| SimpleBrowserTest(IE, kSrcPropertyTestPage); |
| } |
| @@ -443,14 +484,13 @@ TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceSingleton) { |
| const wchar_t kCFIDelayPage[] = L"CFInstance_delay_host.html"; |
| -TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_CFInstanceDelay) { |
| +TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceDelay) { |
| SimpleBrowserTest(IE, kCFIDelayPage); |
| } |
| const wchar_t kCFIFallbackPage[] = L"CFInstance_fallback_host.html"; |
| -// http://crbug.com/37088 |
| -TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_CFInstanceFallback) { |
| +TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceFallback) { |
| SimpleBrowserTest(IE, kCFIFallbackPage); |
| } |
| @@ -476,8 +516,7 @@ TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceZeroSize) { |
| const wchar_t kCFIIfrPostPage[] = L"CFInstance_iframe_post_host.html"; |
| -// http://crbug.com/32321 |
| -TEST_F(ChromeFrameTestWithWebServer, DISABLED_WidgetModeIE_CFInstanceIfrPost) { |
| +TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceIfrPost) { |
| SimpleBrowserTest(IE, kCFIIfrPostPage); |
| } |
| @@ -502,14 +541,7 @@ TEST_F(ChromeFrameTestWithWebServer, WidgetModeChrome_CFInstancePost) { |
| const wchar_t kCFIRPCPage[] = L"CFInstance_rpc_host.html"; |
| -// This test consistently times out in debug builds; see http://crbug.com/112599 |
| -#ifndef NDEBUG |
| -#define MAYBE_WidgetModeIE_CFInstanceRPC DISABLED_WidgetModeIE_CFInstanceRPC |
| -#else |
| -#define MAYBE_WidgetModeIE_CFInstanceRPC WidgetModeIE_CFInstanceRPC |
| -#endif |
| - |
| -TEST_F(ChromeFrameTestWithWebServer, MAYBE_WidgetModeIE_CFInstanceRPC) { |
| +TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_CFInstanceRPC) { |
| if (chrome_frame_test::GetInstalledIEVersion() == IE_9) { |
| LOG(INFO) << "Not running test on Vista/Windows 7 with IE9"; |
| return; |
| @@ -669,18 +701,17 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_InstallFlowTest) { |
| ASSERT_TRUE(LaunchBrowser(IE, kInstallFlowTestUrl)); |
| - loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| + loop().RunFor(kChromeFrameLongNavigationTimeout); |
| ScopedChromeFrameRegistrar::RegisterAtPath( |
| GetChromeFrameBuildPath().value(), |
| chrome_frame_test::GetTestBedType()); |
| - server_mock_.ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), |
| - kPostedResultSubstring); |
| - loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| + ExpectAndHandlePostedResult(); |
| + loop().RunFor(kChromeFrameLongNavigationTimeout); |
| chrome_frame_test::CloseAllIEWindows(); |
| - ASSERT_EQ("OK", server_mock_.posted_result()); |
| + ASSERT_EQ("OK", server_mock().posted_result()); |
| } |
| } |
| @@ -728,7 +759,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestPostReissue) { |
| ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); |
| - loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| + loop().RunFor(kChromeFrameLongNavigationTimeout); |
| const test_server::Request* request = NULL; |
| server.FindRequest("/quit?OK", &request); |
| @@ -760,7 +791,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestMultipleGet) { |
| ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); |
| - loop_.RunFor(kChromeFrameVeryLongNavigationTimeoutInSeconds); |
| + loop().RunFor(kChromeFrameVeryLongNavigationTimeout); |
| const test_server::Request* request = NULL; |
| server.FindRequest("/quit?OK", &request); |
| @@ -792,8 +823,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_XHRConditionalHeaderTest) { |
| const wchar_t kWindowCloseTestUrl[] = |
| L"window_close.html"; |
| -// http://code.google.com/p/chromium/issues/detail?id=111074 |
| -TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_WindowClose) { |
| +TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_WindowClose) { |
| SimpleBrowserTest(IE, kWindowCloseTestUrl); |
| } |
| @@ -878,7 +908,7 @@ TEST_F(ChromeFrameTestWithWebServer, FAILS_FullTabModeIE_RefreshMshtmlTest) { |
| ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); |
| - loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| + loop().RunFor(kChromeFrameLongNavigationTimeout); |
| test_server::SimpleWebServer* ws = server.web_server(); |
| const test_server::ConnectionList& connections = ws->connections(); |
| @@ -1010,7 +1040,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) { |
| EXPECT_CALL(win_observer_mock, OnWindowClose(_)) |
| .Times(testing::AtMost(1)) |
| - .WillOnce(QUIT_LOOP(loop_)); |
| + .WillOnce(QUIT_LOOP(loop())); |
| SimpleWebServerTest server(46664); |
| CustomResponse* response = new CustomResponse("/form.html"); |
| @@ -1019,7 +1049,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) { |
| std::wstring url(server.FormatHttpPath(L"form.html")); |
| ASSERT_TRUE(LaunchBrowser(IE, url.c_str())); |
| - loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| + loop().RunFor(kChromeFrameLongNavigationTimeout); |
| EXPECT_EQ(1, response->get_request_count()); |
| EXPECT_EQ(1, response->post_request_count()); |