diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-30 23:29:54 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-30 23:29:54 +0000 |
commit | 5d9c52a60b5e91819c2664572a6e0ef343a3ea28 (patch) | |
tree | 30406e4c144cf8d036a4ef1e4dabebcc1b6a8e05 | |
parent | 997c8ca739b3f79ff76adbbf421c7056af8ccdcb (diff) | |
download | chromium_src-5d9c52a60b5e91819c2664572a6e0ef343a3ea28.zip chromium_src-5d9c52a60b5e91819c2664572a6e0ef343a3ea28.tar.gz chromium_src-5d9c52a60b5e91819c2664572a6e0ef343a3ea28.tar.bz2 |
Revert 7508.7509 and 7510
Review URL: http://codereview.chromium.org/17030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7514 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 493 insertions, 1038 deletions
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index 160c3ab..ca89162 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -55,12 +55,10 @@ bool ActivateTabByClick(AutomationProxy* automation, } // namespace TEST_F(BrowserFocusTest, BrowsersRememberFocus) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // First we navigate to our test page. - GURL url = server->TestServerPageW(kSimplePage); + GURL url = server.TestServerPageW(kSimplePage); scoped_ptr<TabProxy> tab(GetActiveTab()); EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tab->NavigateToURL(url)); @@ -132,9 +130,7 @@ TEST_F(BrowserFocusTest, BrowsersRememberFocus) { // Tabs remember focus. TEST_F(BrowserFocusTest, TabsRememberFocus) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); ASSERT_TRUE(window.get() != NULL); @@ -143,7 +139,7 @@ TEST_F(BrowserFocusTest, TabsRememberFocus) { ASSERT_TRUE(browser.get() != NULL); // First we navigate to our test page. - GURL url = server->TestServerPageW(kSimplePage); + GURL url = server.TestServerPageW(kSimplePage); scoped_ptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(url); @@ -198,12 +194,10 @@ TEST_F(BrowserFocusTest, TabsRememberFocus) { // Background window does not steal focus. TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // First we navigate to our test page. - GURL simple_page_url = server->TestServerPageW(kSimplePage); + GURL simple_page_url = server.TestServerPageW(kSimplePage); scoped_ptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(simple_page_url); @@ -221,7 +215,7 @@ TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { automation()->GetBrowserForWindow(new_window.get())); ASSERT_TRUE(new_browser.get() != NULL); - GURL steal_focus_url = server->TestServerPageW(kStealFocusPage); + GURL steal_focus_url = server.TestServerPageW(kStealFocusPage); new_browser->AppendTab(steal_focus_url); // Make the first browser active @@ -238,12 +232,10 @@ TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { // Page cannot steal focus when focus is on location bar. TEST_F(BrowserFocusTest, LocationBarLockFocus) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // Open the page that steals focus. - GURL url = server->TestServerPageW(kStealFocusPage); + GURL url = server.TestServerPageW(kStealFocusPage); scoped_ptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(url); @@ -272,12 +264,10 @@ TEST_F(BrowserFocusTest, LocationBarLockFocus) { // Focus traversal TEST_F(BrowserFocusTest, FocusTraversal) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // Open the page the test page. - GURL url = server->TestServerPageW(kTypicalPage); + GURL url = server.TestServerPageW(kTypicalPage); scoped_ptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(url); @@ -347,12 +337,10 @@ TEST_F(BrowserFocusTest, FocusTraversal) { // Make sure Find box can request focus, even when it is already open. TEST_F(BrowserFocusTest, FindFocusTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // Open some page (any page that doesn't steal focus). - GURL url = server->TestServerPageW(kTypicalPage); + GURL url = server.TestServerPageW(kTypicalPage); scoped_ptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(url); diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index 237c0bd..f4ca495 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -240,9 +240,7 @@ TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { return; const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); std::wstring test_file(test_data_directory_); scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); scoped_ptr<TabProxy> tab(window->GetActiveTab()); @@ -280,9 +278,7 @@ TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { return; const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); std::wstring test_file(test_data_directory_); scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); scoped_ptr<TabProxy> tab(window->GetActiveTab()); diff --git a/chrome/browser/errorpage_uitest.cc b/chrome/browser/errorpage_uitest.cc index a071fb2..ec63430 100644 --- a/chrome/browser/errorpage_uitest.cc +++ b/chrome/browser/errorpage_uitest.cc @@ -38,10 +38,8 @@ TEST_F(ErrorPageTest, IFrame404) { // In this test, the iframe sets the title of the parent page to "SUCCESS" // when the iframe loads. If the iframe fails to load (because an alternate // error page loads instead), then the title will remain as "FAIL". - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); - GURL test_url = server->TestServerPage("files/iframe404.html"); + TestServer server(L"chrome/test/data"); + GURL test_url = server.TestServerPage("files/iframe404.html"); NavigateToURL(test_url); // Verify that the url is in the title. Since it's set via Javascript, we diff --git a/chrome/browser/history/redirect_uitest.cc b/chrome/browser/history/redirect_uitest.cc index 4002500..272c59a 100644 --- a/chrome/browser/history/redirect_uitest.cc +++ b/chrome/browser/history/redirect_uitest.cc @@ -30,12 +30,10 @@ class RedirectTest : public UITest { // Tests a single server redirect TEST_F(RedirectTest, Server) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); - GURL final_url = server->TestServerPageW(std::wstring()); - GURL first_url = server->TestServerPageW( + GURL final_url = server.TestServerPageW(std::wstring()); + GURL first_url = server.TestServerPageW( std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec())); NavigateToURL(first_url); @@ -52,12 +50,10 @@ TEST_F(RedirectTest, Server) { // Tests a single client redirect. TEST_F(RedirectTest, Client) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); - GURL final_url = server->TestServerPageW(std::wstring()); - GURL first_url = server->TestServerPageW( + GURL final_url = server.TestServerPageW(std::wstring()); + GURL first_url = server.TestServerPageW( std::wstring(L"client-redirect?") + UTF8ToWide(final_url.spec())); // We need the sleep for the client redirects, because it appears as two @@ -76,32 +72,30 @@ TEST_F(RedirectTest, Client) { } TEST_F(RedirectTest, ClientEmptyReferer) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - - GURL final_url = server->TestServerPageW(std::wstring()); - std::wstring test_file = test_data_directory_; - file_util::AppendToPath(&test_file, L"file_client_redirect.html"); - GURL first_url = net::FilePathToFileURL(test_file); - - NavigateToURL(first_url); - std::vector<GURL> redirects; - // We need the sleeps for the client redirects, because it appears as two - // page visits in the browser. And note for this test the browser actually - // loads the html file on disk, rather than just getting a response from - // the TestServer. - for (int i = 0; i < 10; ++i) { - Sleep(kWaitForActionMaxMsec / 10); - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); - ASSERT_TRUE(tab_proxy.get()); - ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); - if (!redirects.empty()) - break; - } + TestServer server(kDocRoot); + + GURL final_url = server.TestServerPageW(std::wstring()); + std::wstring test_file = test_data_directory_; + file_util::AppendToPath(&test_file, L"file_client_redirect.html"); + GURL first_url = net::FilePathToFileURL(test_file); + + NavigateToURL(first_url); + std::vector<GURL> redirects; + // We need the sleeps for the client redirects, because it appears as two + // page visits in the browser. And note for this test the browser actually + // loads the html file on disk, rather than just getting a response from + // the TestServer. + for (int i = 0; i < 10; ++i) { + Sleep(kWaitForActionMaxMsec / 10); + scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + ASSERT_TRUE(tab_proxy.get()); + ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); + if (!redirects.empty()) + break; + } - EXPECT_EQ(1, redirects.size()); - EXPECT_EQ(final_url.spec(), redirects[0].spec()); + EXPECT_EQ(1, redirects.size()); + EXPECT_EQ(final_url.spec(), redirects[0].spec()); } // Tests to make sure a location change when a pending redirect exists isn't @@ -142,16 +136,14 @@ TEST_F(RedirectTest, ClientCancelled) { // TODO(creis): This is disabled temporarily while I figure out why it is // failing. TEST_F(RedirectTest, DISABLED_ClientServerServer) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); - GURL final_url = server->TestServerPageW(std::wstring()); - GURL next_to_last = server->TestServerPageW( + GURL final_url = server.TestServerPageW(std::wstring()); + GURL next_to_last = server.TestServerPageW( std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec())); - GURL second_url = server->TestServerPageW( + GURL second_url = server.TestServerPageW( std::wstring(L"server-redirect?") + UTF8ToWide(next_to_last.spec())); - GURL first_url = server->TestServerPageW( + GURL first_url = server.TestServerPageW( std::wstring(L"client-redirect?") + UTF8ToWide(second_url.spec())); std::vector<GURL> redirects; @@ -176,14 +168,12 @@ TEST_F(RedirectTest, DISABLED_ClientServerServer) { // Tests that the "#reference" gets preserved across server redirects. TEST_F(RedirectTest, ServerReference) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); const std::string ref("reference"); - GURL final_url = server->TestServerPageW(std::wstring()); - GURL initial_url = server->TestServerPageW( + GURL final_url = server.TestServerPageW(std::wstring()); + GURL initial_url = server.TestServerPageW( std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec()) + L"#" + UTF8ToWide(ref)); @@ -197,14 +187,12 @@ TEST_F(RedirectTest, ServerReference) { // A) does not crash the browser or confuse the redirect chain, see bug 1080873 // B) does not take place. TEST_F(RedirectTest, NoHttpToFile) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); std::wstring test_file = test_data_directory_; file_util::AppendToPath(&test_file, L"http_to_file.html"); GURL file_url = net::FilePathToFileURL(test_file); - GURL initial_url = server->TestServerPageW( + GURL initial_url = server.TestServerPageW( std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec())); NavigateToURL(initial_url); @@ -220,10 +208,7 @@ TEST_F(RedirectTest, NoHttpToFile) { // Ensures that non-user initiated location changes (within page) are // flagged as client redirects. See bug 1139823. TEST_F(RedirectTest, ClientFragments) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(kDocRoot); std::wstring test_file = test_data_directory_; file_util::AppendToPath(&test_file, L"ref_redirect.html"); GURL first_url = net::FilePathToFileURL(test_file); @@ -244,27 +229,24 @@ TEST_F(RedirectTest, ClientFragments) { } // TODO(timsteele): This is disabled because our current testserver can't -// handle multiple requests in parallel, making it hang on the first request -// to /slow?60. It's unable to serve our second request for files/title2.html -// until /slow? completes, which doesn't give the desired behavior. We could -// alternatively load the second page from disk, but we would need to start -// the browser for this testcase with --process-per-tab, and I don't think -// we can do this at test-case-level granularity at the moment. -TEST_F(RedirectTest, - DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) { +// handle multiple requests in parallel, making it hang on the first request to +// /slow?60. It's unable to serve our second request for files/title2.html until +// /slow? completes, which doesn't give the desired behavior. We could +// alternatively load the second page from disk, but we would need to start the +// browser for this testcase with --process-per-tab, and I don't think we can do +// this at test-case-level granularity at the moment. +TEST_F(RedirectTest, DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) { // We want to initiate a second navigation after the provisional load for // the client redirect destination has started, but before this load is // committed. To achieve this, we tell the browser to load a slow page, // which causes it to start a provisional load, and while it is waiting // for the response (which means it hasn't committed the load for the client // redirect destination page yet), we issue a new navigation request. - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - - GURL final_url = server->TestServerPageW(std::wstring(L"files/title2.html")); - GURL slow = server->TestServerPageW(std::wstring(L"slow?60")); - GURL first_url = server->TestServerPageW( + TestServer server(kDocRoot); + + GURL final_url = server.TestServerPageW(std::wstring(L"files/title2.html")); + GURL slow = server.TestServerPageW(std::wstring(L"slow?60")); + GURL first_url = server.TestServerPageW( std::wstring(L"client-redirect?") + UTF8ToWide(slow.spec())); std::vector<GURL> redirects; @@ -274,7 +256,7 @@ TEST_F(RedirectTest, // started it's provisional load for the client redirect destination page but // hasn't completed. Our time is now! NavigateToURL(final_url); - + std::wstring tab_title; std::wstring final_url_title = L"Title Of Awesomeness"; // Wait till the final page has been loaded. @@ -289,9 +271,9 @@ TEST_F(RedirectTest, } } - // Check to make sure the navigation did in fact take place and we are + // Check to make sure the navigation did in fact take place and we are // at the expected page. - EXPECT_EQ(final_url_title, tab_title); + EXPECT_EQ(final_url_title, tab_title); bool final_navigation_not_redirect = true; // Check to make sure our request for files/title2.html doesn't get flagged diff --git a/chrome/browser/interstitial_page_uitest.cc b/chrome/browser/interstitial_page_uitest.cc index c3d675c..a50908c9 100644 --- a/chrome/browser/interstitial_page_uitest.cc +++ b/chrome/browser/interstitial_page_uitest.cc @@ -52,13 +52,10 @@ class InterstitialPageTest : public UITest { // causes the actual navigation entry (title) to be modified by the content of // the interstitial. TEST_F(InterstitialPageTest, TestShowHideInterstitial) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); NavigateTab(tab.get(), - server->TestServerPageW(L"files/interstitial_page/google.html")); + server.TestServerPageW(L"files/interstitial_page/google.html")); NavigationEntry::PageType page_type; EXPECT_TRUE(tab->GetPageType(&page_type)); EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); @@ -81,13 +78,10 @@ TEST_F(InterstitialPageTest, TestShowHideInterstitial) { // the interstitial. In the mean time, we are treating Back like cancelling // the interstitial, which breaks this test because no notification occurs. TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenBack) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); NavigateTab(tab.get(), - server->TestServerPageW(L"files/interstitial_page/google.html")); + server.TestServerPageW(L"files/interstitial_page/google.html")); EXPECT_EQ(L"Google", GetActiveTabTitle()); tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); @@ -100,31 +94,26 @@ TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenBack) { // Shows an interstitial page then navigates to a new URL. // Flacky on Windows 2000 bot. Disabled for now bug #1173138. TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenNavigate) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); NavigateTab(tab.get(), - server->TestServerPageW(L"files/interstitial_page/google.html")); + server.TestServerPageW(L"files/interstitial_page/google.html")); EXPECT_EQ(L"Google", GetActiveTabTitle()); tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); EXPECT_EQ(L"Interstitial page", GetActiveTabTitle()); tab->NavigateToURL( - server->TestServerPageW(L"files/interstitial_page/shopping.html")); + server.TestServerPageW(L"files/interstitial_page/shopping.html")); EXPECT_EQ(L"Google Product Search", GetActiveTabTitle()); } // Shows an interstitial page then closes the tab (to make sure we don't crash). TEST_F(InterstitialPageTest, TestShowInterstitialThenCloseTab) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // Create 2 tabs so closing one does not close the browser. - AppendTab(server->TestServerPageW(L"files/interstitial_page/google.html")); + AppendTab(server.TestServerPageW(L"files/interstitial_page/google.html")); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); EXPECT_EQ(L"Google", GetActiveTabTitle()); @@ -137,13 +126,11 @@ TEST_F(InterstitialPageTest, TestShowInterstitialThenCloseTab) { // crash). // This test is disabled. See bug #1119448. TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenCloseBrowser) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); tab->NavigateToURL( - server->TestServerPageW(L"files/interstitial_page/google.html")); + server.TestServerPageW(L"files/interstitial_page/google.html")); EXPECT_EQ(L"Google", GetActiveTabTitle()); tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); diff --git a/chrome/browser/login_prompt_uitest.cc b/chrome/browser/login_prompt_uitest.cc index 1d7d25c..3969ccf 100644 --- a/chrome/browser/login_prompt_uitest.cc +++ b/chrome/browser/login_prompt_uitest.cc @@ -62,11 +62,9 @@ wstring ExpectedTitleFromAuth(wstring username, wstring password) { // Test that "Basic" HTTP authentication works. TEST_F(LoginPromptTest, TestBasicAuth) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); - NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-basic")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); @@ -74,7 +72,7 @@ TEST_F(LoginPromptTest, TestBasicAuth) { EXPECT_TRUE(tab->CancelAuth()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); - NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-basic")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); @@ -84,18 +82,16 @@ TEST_F(LoginPromptTest, TestBasicAuth) { // Test that "Digest" HTTP authentication works. TEST_F(LoginPromptTest, TestDigestAuth) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); - NavigateTab(tab.get(), server->TestServerPageW(L"auth-digest")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-digest")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_)); EXPECT_TRUE(tab->CancelAuth()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); - NavigateTab(tab.get(), server->TestServerPageW(L"auth-digest")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-digest")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); @@ -105,16 +101,14 @@ TEST_F(LoginPromptTest, TestDigestAuth) { // Test that logging in on 2 tabs at once works. TEST_F(LoginPromptTest, TestTwoAuths) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> basic_tab(GetActiveTabProxy()); - NavigateTab(basic_tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(basic_tab.get(), server.TestServerPageW(L"auth-basic")); AppendTab(GURL("about:blank")); ::scoped_ptr<TabProxy> digest_tab(GetActiveTabProxy()); - NavigateTab(digest_tab.get(), server->TestServerPageW(L"auth-digest")); + NavigateTab(digest_tab.get(), server.TestServerPageW(L"auth-digest")); // TODO(devint): http://b/1158262 basic_tab is not active, so this logs in to // a page whose tab isn't active, which isn't actually possible for the user @@ -135,36 +129,34 @@ TEST_F(LoginPromptTest, TestTwoAuths) { // Test that cancelling authentication works. TEST_F(LoginPromptTest, TestCancelAuth) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); // First navigate to a test server page so we have something to go back to. - EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"a"))); + EXPECT_TRUE(tab->NavigateToURL(server.TestServerPageW(L"a"))); // Navigating while auth is requested is the same as cancelling. - NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-basic")); EXPECT_TRUE(tab->NeedsAuth()); - EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"b"))); + EXPECT_TRUE(tab->NavigateToURL(server.TestServerPageW(L"b"))); EXPECT_FALSE(tab->NeedsAuth()); - NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-basic")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a' EXPECT_FALSE(tab->NeedsAuth()); // Now add a page and go back, so we have something to go forward to. - EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"c"))); + EXPECT_TRUE(tab->NavigateToURL(server.TestServerPageW(L"c"))); EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a' - NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-basic")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->GoForward()); // should bring us to 'c' EXPECT_FALSE(tab->NeedsAuth()); // Now test that cancelling works as expected. - NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); + NavigateTab(tab.get(), server.TestServerPageW(L"auth-basic")); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->CancelAuth()); EXPECT_FALSE(tab->NeedsAuth()); diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc index 086c2b9..a8c5059 100644 --- a/chrome/browser/printing/printing_layout_uitest.cc +++ b/chrome/browser/printing/printing_layout_uitest.cc @@ -457,8 +457,7 @@ class DismissTheWindow : public base::RefCountedThreadSafe<DismissTheWindow> { dialog_window, WM_COMMAND, print_button_id, - reinterpret_cast<LPARAM>(GetDlgItem(dialog_window, - print_button_id))); + reinterpret_cast<LPARAM>(GetDlgItem(dialog_window, print_button_id))); // Try again. if (res) return; @@ -499,11 +498,8 @@ TEST_F(PrintingLayoutTextTest, DISABLED_Complex) { return; // Print a document, check its output. - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - - NavigateToURL(server->TestServerPage("files/printing/test1.html")); + TestServer server(kDocRoot); + NavigateToURL(server.TestServerPage("files/printing/test1.html")); PrintNowTab(); EXPECT_EQ(0., CompareWithResult(L"test1")); } @@ -528,16 +524,13 @@ TEST_F(PrintingLayoutTestHidden, ManyTimes) { if (IsTestCaseDisabled()) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(kDocRoot); ASSERT_GT(arraysize(kTestPool), 0u); for (int i = 0; i < arraysize(kTestPool); ++i) { if (i) CleanupDumpDirectory(); const TestPool& test = kTestPool[i % arraysize(kTestPool)]; - NavigateToURL(server->TestServerPageW(test.source)); + NavigateToURL(server.TestServerPageW(test.source)); PrintNowTab(); EXPECT_EQ(0., CompareWithResult(test.result)) << test.result; CleanupDumpDirectory(); @@ -561,15 +554,13 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { if (win_util::GetWinVersion() < win_util::WINVERSION_XP) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); { scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); bool is_timeout = true; - GURL url = server->TestServerPage("files/printing/popup_delayed_print.htm"); + GURL url = server.TestServerPage("files/printing/popup_delayed_print.htm"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); @@ -588,7 +579,7 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { worker->Stop(); // Force a navigation elsewhere to verify that it's fine with it. - url = server->TestServerPage("files/printing/test1.html"); + url = server.TestServerPage("files/printing/test1.html"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); } @@ -603,14 +594,12 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { if (IsTestCaseDisabled()) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); { scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); - GURL url = server->TestServerPage("files/printing/iframe.htm"); + GURL url = server.TestServerPage("files/printing/iframe.htm"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); @@ -628,7 +617,7 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { worker->Stop(); // Force a navigation elsewhere to verify that it's fine with it. - url = server->TestServerPage("files/printing/test1.html"); + url = server.TestServerPage("files/printing/test1.html"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); } diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc index 350e544..6d276ee 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc @@ -89,15 +89,12 @@ TEST_F(ResourceDispatcherTest, ContentDispositionInline) { // Test for bug #1091358. TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); EXPECT_TRUE(browser_proxy.get()); scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); - tab->NavigateToURL(server->TestServerPageW( - L"files/sync_xmlhttprequest.html")); + tab->NavigateToURL(server.TestServerPageW(L"files/sync_xmlhttprequest.html")); // Let's check the XMLHttpRequest ran successfully. bool success = false; @@ -112,16 +109,14 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { // if executed while navigating to a new page. TEST_F(ResourceDispatcherTest, SyncXMLHttpRequestDuringUnload) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); EXPECT_TRUE(browser_proxy.get()); scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); tab->NavigateToURL( - server->TestServerPageW(L"files/sync_xmlhttprequest_during_unload.html")); + server.TestServerPageW(L"files/sync_xmlhttprequest_during_unload.html")); // Confirm that the page has loaded (since it changes its title during load). std::wstring tab_title; @@ -131,7 +126,7 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequestDuringUnload) { // Navigate to a new page, to dispatch unload event and trigger xhr. // (the bug would make this step hang the renderer). bool timed_out = false; - tab->NavigateToURLWithTimeout(server->TestServerPageW(L"files/title2.html"), + tab->NavigateToURLWithTimeout(server.TestServerPageW(L"files/title2.html"), kWaitForActionMaxMsec, &timed_out); EXPECT_FALSE(timed_out); @@ -147,15 +142,13 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequestDuringUnload) { // Tests that onunload is run for cross-site requests. (Bug 1114994) TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); EXPECT_TRUE(browser_proxy.get()); scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); - GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); + GURL url(server.TestServerPageW(L"files/onunload_cookie.html")); tab->NavigateToURL(url); // Confirm that the page has loaded (since it changes its title during load). @@ -226,15 +219,13 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { // away from the link doctor page. (Bug 1235537) TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); EXPECT_TRUE(browser_proxy.get()); scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); - GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); + GURL url(server.TestServerPageW(L"files/onunload_cookie.html")); tab->NavigateToURL(url); // Confirm that the page has loaded (since it changes its title during load). @@ -268,7 +259,7 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { // WebContents was in the NORMAL state, it would ignore the attempt to run // the onunload handler, and the navigation would fail. // (Test by redirecting to javascript:window.location='someURL'.) - GURL test_url(server->TestServerPageW(L"files/title2.html")); + GURL test_url(server.TestServerPageW(L"files/title2.html")); std::wstring redirect_url = L"javascript:window.location='" + ASCIIToWide(test_url.possibly_invalid_spec()) + L"'"; tab->NavigateToURLAsync(GURL(redirect_url)); diff --git a/chrome/browser/session_history_uitest.cc b/chrome/browser/session_history_uitest.cc index bc8fadc..251a3ba 100644 --- a/chrome/browser/session_history_uitest.cc +++ b/chrome/browser/session_history_uitest.cc @@ -107,24 +107,22 @@ class SessionHistoryTest : public UITest { } // namespace TEST_F(SessionHistoryTest, BasicBackForward) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // about:blank should be loaded first. ASSERT_FALSE(tab_->GoBack()); EXPECT_EQ(L"", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot1.html"))); + server.TestServerPage("files/session_history/bot1.html"))); EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot2.html"))); + server.TestServerPage("files/session_history/bot2.html"))); EXPECT_EQ(L"bot2", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + server.TestServerPage("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, bot2, *bot3] @@ -142,7 +140,7 @@ TEST_F(SessionHistoryTest, BasicBackForward) { EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + server.TestServerPage("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, *bot3] @@ -173,9 +171,7 @@ TEST_F(SessionHistoryTest, FrameBackForward) { if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // about:blank should be loaded first. GURL home(homepage_); @@ -183,7 +179,7 @@ TEST_F(SessionHistoryTest, FrameBackForward) { EXPECT_EQ(L"", GetTabTitle()); EXPECT_EQ(home, GetTabURL()); - GURL frames(server->TestServerPage("files/session_history/frames.html")); + GURL frames(server.TestServerPage("files/session_history/frames.html")); ASSERT_TRUE(tab_->NavigateToURL(frames)); EXPECT_EQ(L"bot1", GetTabTitle()); EXPECT_EQ(frames, GetTabURL()); @@ -239,15 +235,13 @@ TEST_F(SessionHistoryTest, FrameBackForward) { // Test that back/forward preserves POST data and document state in subframes. TEST_F(SessionHistoryTest, FrameFormBackForward) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // about:blank should be loaded first. ASSERT_FALSE(tab_->GoBack()); EXPECT_EQ(L"", GetTabTitle()); - GURL frames(server->TestServerPage("files/session_history/frames.html")); + GURL frames(server.TestServerPage("files/session_history/frames.html")); ASSERT_TRUE(tab_->NavigateToURL(frames)); EXPECT_EQ(L"bot1", GetTabTitle()); @@ -301,15 +295,13 @@ TEST_F(SessionHistoryTest, FrameFormBackForward) { // Test that back/forward preserves POST data and document state when navigating // across frames (ie, from frame -> nonframe). TEST_F(SessionHistoryTest, CrossFrameFormBackForward) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // about:blank should be loaded first. ASSERT_FALSE(tab_->GoBack()); EXPECT_EQ(L"", GetTabTitle()); - GURL frames(server->TestServerPage("files/session_history/frames.html")); + GURL frames(server.TestServerPage("files/session_history/frames.html")); ASSERT_TRUE(tab_->NavigateToURL(frames)); EXPECT_EQ(L"bot1", GetTabTitle()); @@ -345,18 +337,16 @@ TEST_F(SessionHistoryTest, CrossFrameFormBackForward) { } #endif -// Test that back/forward entries are created for reference fragment -// navigations. Bug 730379. +// Test that back/forward entries are created for reference fragment navigations. +// Bug 730379. TEST_F(SessionHistoryTest, FragmentBackForward) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // about:blank should be loaded first. ASSERT_FALSE(tab_->GoBack()); EXPECT_EQ(L"", GetTabTitle()); - GURL fragment(server->TestServerPage("files/session_history/fragment.html")); + GURL fragment(server.TestServerPage("files/session_history/fragment.html")); ASSERT_TRUE(tab_->NavigateToURL(fragment)); EXPECT_EQ(L"fragment", GetTabTitle()); EXPECT_EQ(fragment, GetTabURL()); @@ -395,7 +385,7 @@ TEST_F(SessionHistoryTest, FragmentBackForward) { ASSERT_TRUE(tab_->GoForward()); EXPECT_EQ(fragment_a, GetTabURL()); - GURL bot3(server->TestServerPage("files/session_history/bot3.html")); + GURL bot3(server.TestServerPage("files/session_history/bot3.html")); ASSERT_TRUE(tab_->NavigateToURL(bot3)); EXPECT_EQ(L"bot3", GetTabTitle()); EXPECT_EQ(bot3, GetTabURL()); @@ -418,24 +408,22 @@ TEST_F(SessionHistoryTest, FragmentBackForward) { // means the test will hang if it attempts to navigate too far forward or back, // since we'll be waiting forever for a load stop event. TEST_F(SessionHistoryTest, JavascriptHistory) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // about:blank should be loaded first. ASSERT_FALSE(tab_->GoBack()); EXPECT_EQ(L"", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot1.html"))); + server.TestServerPage("files/session_history/bot1.html"))); EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot2.html"))); + server.TestServerPage("files/session_history/bot2.html"))); EXPECT_EQ(L"bot2", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + server.TestServerPage("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, bot2, *bot3] @@ -467,7 +455,7 @@ TEST_F(SessionHistoryTest, JavascriptHistory) { EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + server.TestServerPage("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, *bot3] @@ -501,12 +489,10 @@ TEST_F(SessionHistoryTest, JavascriptHistory) { TEST_F(SessionHistoryTest, LocationReplace) { // Test that using location.replace doesn't leave the title of the old page // visible. - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); - ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( - "files/session_history/replace.html?no-title.html"))); + ASSERT_TRUE(tab_->NavigateToURL( + server.TestServerPage("files/session_history/replace.html?no-title.html"))); EXPECT_EQ(L"", GetTabTitle()); } diff --git a/chrome/browser/sessions/session_restore_uitest.cc b/chrome/browser/sessions/session_restore_uitest.cc index 434f937..8843567 100644 --- a/chrome/browser/sessions/session_restore_uitest.cc +++ b/chrome/browser/sessions/session_restore_uitest.cc @@ -145,10 +145,8 @@ TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { // cross-site page and then forward again works. (Bug 1204135) TEST_F(SessionRestoreUITest, RestoresCrossSiteForwardAndBackwardNavs) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - GURL cross_site_url(server->TestServerPageW(L"files/title2.html")); + TestServer server(kDocRoot); + GURL cross_site_url(server.TestServerPageW(L"files/title2.html")); // Visit URLs on different sites. NavigateToURL(url1); diff --git a/chrome/browser/ssl_uitest.cc b/chrome/browser/ssl_uitest.cc index 13a8759..ccef280 100644 --- a/chrome/browser/ssl_uitest.cc +++ b/chrome/browser/ssl_uitest.cc @@ -41,17 +41,17 @@ class SSLUITest : public UITest { EXPECT_TRUE(browser_proxy->AppendTab(url)); } - HTTPTestServer* PlainServer() { - return HTTPTestServer::CreateServer(kDocRoot); + TestServer* PlainServer() { + return new TestServer(kDocRoot); } HTTPSTestServer* GoodCertServer() { - return HTTPSTestServer::CreateServer(util_.kHostName, util_.kOKHTTPSPort, + return new HTTPSTestServer(util_.kHostName, util_.kOKHTTPSPort, kDocRoot, util_.GetOKCertPath().ToWStringHack()); } HTTPSTestServer* BadCertServer() { - return HTTPSTestServer::CreateServer(util_.kHostName, util_.kBadHTTPSPort, + return new HTTPSTestServer(util_.kHostName, util_.kBadHTTPSPort, kDocRoot, util_.GetExpiredCertPath().ToWStringHack()); } @@ -65,7 +65,7 @@ class SSLUITest : public UITest { // Visits a regular page over http. TEST_F(SSLUITest, TestHTTP) { - scoped_ptr<HTTPTestServer> server(PlainServer()); + scoped_ptr<TestServer> server(PlainServer()); scoped_ptr<TabProxy> tab(GetActiveTabProxy()); NavigateTab(tab.get(), server->TestServerPageW(L"files/ssl/google.html")); @@ -87,7 +87,7 @@ TEST_F(SSLUITest, TestHTTP) { // Visits a page over http which includes broken https resources (status should // be OK). TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) { - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer()); scoped_ptr<TabProxy> tab(GetActiveTabProxy()); @@ -164,7 +164,7 @@ TEST_F(SSLUITest, TestHTTPSExpiredCert) { // Visits a page with mixed content. TEST_F(SSLUITest, TestMixedContents) { scoped_ptr<HTTPSTestServer> https_server(GoodCertServer()); - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); // Load a page with mixed-content, the default behavior is to show the mixed // content. @@ -286,7 +286,7 @@ TEST_F(SSLUITest, TestUnsafeContents) { // Visits a page with mixed content loaded by JS (after the initial page load). TEST_F(SSLUITest, TestMixedContentsLoadedFromJS) { scoped_ptr<HTTPSTestServer> https_server(GoodCertServer()); - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<TabProxy> tab(GetActiveTabProxy()); NavigateTab(tab.get(), https_server->TestServerPageW( @@ -325,7 +325,7 @@ TEST_F(SSLUITest, TestMixedContentsLoadedFromJS) { // memory cache). TEST_F(SSLUITest, TestCachedMixedContents) { scoped_ptr<HTTPSTestServer> https_server(GoodCertServer()); - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<TabProxy> tab(GetActiveTabProxy()); NavigateTab(tab.get(), http_server->TestServerPageW( @@ -364,10 +364,9 @@ TEST_F(SSLUITest, TestCachedMixedContents) { // TODO(jcampan): this test is flacky and fails sometimes (bug #1065095) TEST_F(SSLUITest, DISABLED_TestCNInvalidStickiness) { const std::string kLocalHost = "localhost"; - scoped_refptr<HTTPSTestServer> https_server = - HTTPSTestServer::CreateServer(kLocalHost, util_.kOKHTTPSPort, - kDocRoot, util_.GetOKCertPath().ToWStringHack()); - ASSERT_TRUE(NULL != https_server.get()); + scoped_ptr<HTTPSTestServer> https_server( + new HTTPSTestServer(kLocalHost, util_.kOKHTTPSPort, + kDocRoot, util_.GetOKCertPath().ToWStringHack())); // First we hit the server with hostname, this generates an invalid policy // error. @@ -476,7 +475,7 @@ TEST_F(SSLUITest, TestRefNavigation) { // (bug #1966). // Disabled because flaky (bug #2136). TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) { - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer()); scoped_ptr<TabProxy> tab(GetActiveTabProxy()); @@ -562,7 +561,7 @@ TEST_F(SSLUITest, TestRedirectGoodToBadHTTPS) { // Visit a page over http that is a redirect to a page with https (good and // bad). TEST_F(SSLUITest, TestRedirectHTTPToHTTPS) { - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer()); scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer()); @@ -605,7 +604,7 @@ TEST_F(SSLUITest, TestRedirectHTTPToHTTPS) { // Visit a page over https that is a redirect to a page with http (to make sure // we don't keep the secure state). TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) { - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<HTTPSTestServer> https_server(GoodCertServer()); scoped_ptr<TabProxy> tab(GetActiveTabProxy()); @@ -661,7 +660,7 @@ TEST_F(SSLUITest, TestConnectToBadPort) { // back // - navigate to HTTP (expect mixed content), then back TEST_F(SSLUITest, TestGoodFrameNavigation) { - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer()); scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer()); @@ -799,7 +798,7 @@ TEST_F(SSLUITest, TestBadFrameNavigation) { // From an HTTP top frame, navigate to good and bad HTTPS (security state should // stay unauthenticated). TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) { - scoped_ptr<HTTPTestServer> http_server(PlainServer()); + scoped_ptr<TestServer> http_server(PlainServer()); scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer()); scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer()); diff --git a/chrome/browser/tab_restore_uitest.cc b/chrome/browser/tab_restore_uitest.cc index facd015..0bf2dbe 100644 --- a/chrome/browser/tab_restore_uitest.cc +++ b/chrome/browser/tab_restore_uitest.cc @@ -133,11 +133,9 @@ TEST_F(TabRestoreUITest, RestoreToDifferentWindow) { // to an existing SiteInstance. (Bug 1230446) TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - GURL http_url1(server->TestServerPageW(L"files/title1.html")); - GURL http_url2(server->TestServerPageW(L"files/title2.html")); + TestServer server(kDocRoot); + GURL http_url1(server.TestServerPageW(L"files/title1.html")); + GURL http_url2(server.TestServerPageW(L"files/title2.html")); scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); int initial_tab_count; @@ -178,11 +176,9 @@ TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { // already exists. (Bug 1204135) TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - GURL http_url1(server->TestServerPageW(L"files/title1.html")); - GURL http_url2(server->TestServerPageW(L"files/title2.html")); + TestServer server(kDocRoot); + GURL http_url1(server.TestServerPageW(L"files/title1.html")); + GURL http_url2(server.TestServerPageW(L"files/title2.html")); scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); int initial_tab_count; diff --git a/chrome/browser/url_fetcher_unittest.cc b/chrome/browser/url_fetcher_unittest.cc index 308964b..fe73d3f 100644 --- a/chrome/browser/url_fetcher_unittest.cc +++ b/chrome/browser/url_fetcher_unittest.cc @@ -338,19 +338,15 @@ TEST_F(URLFetcherTest, SameThreadsTest) { // Create the fetcher on the main thread. Since IO will happen on the main // thread, this will test URLFetcher's ability to do everything on one // thread. - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); - CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); + CreateFetcher(GURL(server.TestServerPage("defaultresponse"))); MessageLoop::current()->Run(); } TEST_F(URLFetcherTest, DifferentThreadsTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // Create a separate thread that will create the URLFetcher. The current // (main) thread will do the IO, and when the fetch is complete it will // terminate the main thread's message loop; then the other thread's @@ -359,33 +355,27 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) { base::Thread t("URLFetcher test thread"); t.Start(); t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, - GURL(server->TestServerPage("defaultresponse")))); + GURL(server.TestServerPage("defaultresponse")))); MessageLoop::current()->Run(); } TEST_F(URLFetcherPostTest, Basic) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - CreateFetcher(GURL(server->TestServerPage("echo"))); + TestServer server(kDocRoot); + CreateFetcher(GURL(server.TestServerPage("echo"))); MessageLoop::current()->Run(); } TEST_F(URLFetcherHeadersTest, Headers) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); - CreateFetcher(GURL(server->TestServerPage("files/with-headers.html"))); + TestServer server(L"net/data/url_request_unittest"); + CreateFetcher(GURL(server.TestServerPage("files/with-headers.html"))); MessageLoop::current()->Run(); // The actual tests are in the URLFetcherHeadersTest fixture. } TEST_F(URLFetcherProtectTest, Overload) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("defaultresponse")); + TestServer server(kDocRoot); + GURL url = GURL(server.TestServerPage("defaultresponse")); // Registers an entry for test url. It only allows 3 requests to be sent // in 200 milliseconds. @@ -400,10 +390,8 @@ TEST_F(URLFetcherProtectTest, Overload) { } TEST_F(URLFetcherProtectTest, ServerUnavailable) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("files/server-unavailable.html")); + TestServer server(L"chrome/test/data"); + GURL url = GURL(server.TestServerPage("files/server-unavailable.html")); // Registers an entry for test url. The backoff time is calculated by: // new_backoff = 2.0 * old_backoff + 0 @@ -420,21 +408,17 @@ TEST_F(URLFetcherProtectTest, ServerUnavailable) { } TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { - scoped_refptr<HTTPSTestServer> server = - HTTPSTestServer::CreateServer(util_.kHostName, util_.kBadHTTPSPort, + HTTPSTestServer server(util_.kHostName, util_.kBadHTTPSPort, kDocRoot, util_.GetExpiredCertPath().ToWStringHack()); - ASSERT_TRUE(NULL != server.get()); - CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); + CreateFetcher(GURL(server.TestServerPage("defaultresponse"))); MessageLoop::current()->Run(); } TEST_F(URLFetcherCancelTest, ReleasesContext) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("files/server-unavailable.html")); + TestServer server(L"chrome/test/data"); + GURL url = GURL(server.TestServerPage("files/server-unavailable.html")); // Registers an entry for test url. The backoff time is calculated by: // new_backoff = 2.0 * old_backoff + 0 diff --git a/chrome/browser/view_source_uitest.cc b/chrome/browser/view_source_uitest.cc index 73cc875..1aad505 100644 --- a/chrome/browser/view_source_uitest.cc +++ b/chrome/browser/view_source_uitest.cc @@ -38,14 +38,12 @@ class ViewSourceTest : public UITest { // set in the html was set successfully (it shouldn't because we rendered the // page in view source) TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); std::string cookie = "viewsource_cookie"; std::string cookie_data = "foo"; // First we navigate to our view-source test page - GURL url = server->TestServerPageW(test_html_); + GURL url = server.TestServerPageW(test_html_); url = GURL("view-source:" + url.spec()); scoped_ptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(url); @@ -63,12 +61,10 @@ TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { // implementation of the view-source: prefix being consumed (removed from the // URL) if the URL was not changed (apart from adding the view-source prefix) TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // First we navigate to google.html - GURL url = server->TestServerPageW(test_html_); + GURL url = server.TestServerPageW(test_html_); NavigateToURL(url); // Then we navigate to the SAME url but with the view-source: prefix @@ -82,12 +78,10 @@ TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { // Make sure that when looking at the actual page, we can select // "View Source" from the Page menu. TEST_F(ViewSourceTest, ViewSourceInPageMenuEnabledOnANormalPage) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // First we navigate to google.html - GURL url = server->TestServerPageW(test_html_); + GURL url = server.TestServerPageW(test_html_); NavigateToURL(url); EXPECT_TRUE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); @@ -96,12 +90,10 @@ TEST_F(ViewSourceTest, ViewSourceInPageMenuEnabledOnANormalPage) { // Make sure that when looking at the page source, we can't select // "View Source" from the Page menu. TEST_F(ViewSourceTest, ViewSourceInPageMenuDisabledWhileViewingSource) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); // First we navigate to google.html - GURL url = server->TestServerPageW(test_html_); + GURL url = server.TestServerPageW(test_html_); GURL url_viewsource = GURL("view-source:" + url.spec()); NavigateToURL(url_viewsource); diff --git a/chrome/browser/views/find_bar_win_interactive_uitest.cc b/chrome/browser/views/find_bar_win_interactive_uitest.cc index c036b7c..383a64a 100644 --- a/chrome/browser/views/find_bar_win_interactive_uitest.cc +++ b/chrome/browser/views/find_bar_win_interactive_uitest.cc @@ -52,9 +52,7 @@ bool ActivateTabByClick(AutomationProxy* automation, } // namespace TEST_F(FindInPageTest, CrashEscHandlers) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); ASSERT_TRUE(browser.get() != NULL); @@ -63,7 +61,7 @@ TEST_F(FindInPageTest, CrashEscHandlers) { ASSERT_TRUE(window.get() != NULL); // First we navigate to our test page (tab A). - GURL url = server->TestServerPageW(kSimplePage); + GURL url = server.TestServerPageW(kSimplePage); scoped_ptr<TabProxy> tabA(GetActiveTab()); EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tabA->NavigateToURL(url)); diff --git a/chrome/browser/views/find_bar_win_uitest.cc b/chrome/browser/views/find_bar_win_uitest.cc index 94906b8..ac534b4 100644 --- a/chrome/browser/views/find_bar_win_uitest.cc +++ b/chrome/browser/views/find_bar_win_uitest.cc @@ -25,12 +25,10 @@ const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; // This test loads a page with frames and starts FindInPage requests TEST_F(FindInPageControllerTest, FindInPageFrames) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); // First we navigate to our frames page. - GURL url = server->TestServerPageW(kFramePage); + GURL url = server.TestServerPageW(kFramePage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -78,12 +76,10 @@ TEST_F(FindInPageControllerTest, FindInPageFrames) { // This test loads a single-frame page and makes sure the ordinal returned makes // sense as we FindNext over all the items. TEST_F(FindInPageControllerTest, FindInPageOrdinal) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); // First we navigate to our frames page. - GURL url = server->TestServerPageW(kFrameData); + GURL url = server.TestServerPageW(kFrameData); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -116,12 +112,10 @@ TEST_F(FindInPageControllerTest, FindInPageOrdinal) { // This test loads a page with frames and makes sure the ordinal returned makes // sense. TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); // First we navigate to our frames page. - GURL url = server->TestServerPageW(kFramePage); + GURL url = server.TestServerPageW(kFramePage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -162,12 +156,10 @@ TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { // We could get ordinals out of whack when restarting search in subframes. // See http://crbug.com/5132 TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); // First we navigate to our frames page. - GURL url = server->TestServerPageW(kFramePage); + GURL url = server.TestServerPageW(kFramePage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -193,11 +185,9 @@ TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { // Load a page with no selectable text and make sure we don't crash. TEST_F(FindInPageControllerTest, FindUnSelectableText) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); - GURL url = server->TestServerPageW(kUserSelectPage); + GURL url = server.TestServerPageW(kUserSelectPage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -209,11 +199,9 @@ TEST_F(FindInPageControllerTest, FindUnSelectableText) { // Try to reproduce the crash seen in issue 1341577. TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); - GURL url = server->TestServerPageW(kCrashPage); + GURL url = server.TestServerPageW(kCrashPage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -241,11 +229,9 @@ TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { // ms) to find one or more of those matches (so Find times out and has to try // again from where it left off). TEST_F(FindInPageControllerTest, FindEnoughMatches_Issue1155639) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); - GURL url = server->TestServerPageW(kTooFewMatchesPage); + GURL url = server.TestServerPageW(kTooFewMatchesPage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -258,11 +244,9 @@ TEST_F(FindInPageControllerTest, FindEnoughMatches_Issue1155639) { // The find window should not change its location just because we open and close // a new tab. TEST_F(FindInPageControllerTest, FindMovesOnTabClose_Issue1343052) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); - GURL url = server->TestServerPageW(kFramePage); + GURL url = server.TestServerPageW(kFramePage); scoped_ptr<TabProxy> tabA(GetActiveTab()); ASSERT_TRUE(tabA->NavigateToURL(url)); WaitUntilTabCount(1); @@ -319,11 +303,9 @@ TEST_F(FindInPageControllerTest, FindMovesOnTabClose_Issue1343052) { // Make sure Find box disappears on Navigate but not on Refresh. TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"chrome/test/data"); - GURL url = server->TestServerPageW(kUserSelectPage); + GURL url = server.TestServerPageW(kUserSelectPage); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); diff --git a/chrome/common/chrome_plugin_unittest.cc b/chrome/common/chrome_plugin_unittest.cc index 096989f..1465f1a 100644 --- a/chrome/common/chrome_plugin_unittest.cc +++ b/chrome/common/chrome_plugin_unittest.cc @@ -258,11 +258,8 @@ TEST_F(ChromePluginTest, CanMakeGETRequestAsync) { // Tests that the plugin can issue a POST request. TEST_F(ChromePluginTest, CanMakePOSTRequest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - - GURL url = server->TestServerPage("echo"); + TestServer server(kDocRoot); + GURL url = server.TestServerPage("echo"); EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request("POST", url)); diff --git a/chrome/common/net/cache_uitest.cc b/chrome/common/net/cache_uitest.cc index 19ecc01..69b5892 100644 --- a/chrome/common/net/cache_uitest.cc +++ b/chrome/common/net/cache_uitest.cc @@ -54,10 +54,8 @@ class CacheTest : public UITest { void CacheTest::RunCacheTest(const std::wstring &url, bool expect_new_tab_cached, bool expect_delayed_reload) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); - GURL test_page(server->TestServerPageW(url)); + TestServer server(L"chrome/test/data"); + GURL test_page(server.TestServerPageW(url)); NavigateToURL(test_page); std::wstring original_time = GetActiveTabTitle(); diff --git a/chrome/test/ui/inspector_controller_uitest.cc b/chrome/test/ui/inspector_controller_uitest.cc index 29b1489..885eb69 100644 --- a/chrome/test/ui/inspector_controller_uitest.cc +++ b/chrome/test/ui/inspector_controller_uitest.cc @@ -37,20 +37,14 @@ TEST_F(InspectorControllerTest, DISABLED_InspectElement) { if (CommandLine().HasSwitch(switches::kSingleProcess)) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(L"chrome/test/data"); ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); // We don't track resources until we've opened the inspector. - NavigateTab(tab.get(), server->TestServerPageW( - L"files/inspector/test1.html")); + NavigateTab(tab.get(), server.TestServerPageW(L"files/inspector/test1.html")); tab->InspectElement(0, 0); - NavigateTab(tab.get(), server->TestServerPageW( - L"files/inspector/test1.html")); + NavigateTab(tab.get(), server.TestServerPageW(L"files/inspector/test1.html")); EXPECT_EQ(1, tab->InspectElement(0, 0)); - NavigateTab(tab.get(), server->TestServerPageW( - L"files/inspector/test2.html")); + NavigateTab(tab.get(), server.TestServerPageW(L"files/inspector/test2.html")); EXPECT_EQ(2, tab->InspectElement(0, 0)); } diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc index 2139b6c..8507a86 100644 --- a/net/proxy/proxy_script_fetcher_unittest.cc +++ b/net/proxy/proxy_script_fetcher_unittest.cc @@ -181,25 +181,23 @@ TEST_F(ProxyScriptFetcherTest, FileUrl) { // Note that all mime types are allowed for PAC file, to be consistent // with other browsers. TEST_F(ProxyScriptFetcherTest, HttpMimeType) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); SynchFetcher pac_fetcher; { // Fetch a PAC with mime type "text/plain" - GURL url = server->TestServerPage("files/pac.txt"); + GURL url = server.TestServerPage("files/pac.txt"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::OK, result.code); EXPECT_EQ("-pac.txt-\n", result.bytes); } { // Fetch a PAC with mime type "text/html" - GURL url = server->TestServerPage("files/pac.html"); + GURL url = server.TestServerPage("files/pac.html"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::OK, result.code); EXPECT_EQ("-pac.html-\n", result.bytes); } { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" - GURL url = server->TestServerPage("files/pac.nsproxy"); + GURL url = server.TestServerPage("files/pac.nsproxy"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::OK, result.code); EXPECT_EQ("-pac.nsproxy-\n", result.bytes); @@ -207,19 +205,17 @@ TEST_F(ProxyScriptFetcherTest, HttpMimeType) { } TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); SynchFetcher pac_fetcher; { // Fetch a PAC which gives a 500 -- FAIL - GURL url = server->TestServerPage("files/500.pac"); + GURL url = server.TestServerPage("files/500.pac"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code); EXPECT_TRUE(result.bytes.empty()); } { // Fetch a PAC which gives a 404 -- FAIL - GURL url = server->TestServerPage("files/404.pac"); + GURL url = server.TestServerPage("files/404.pac"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code); EXPECT_TRUE(result.bytes.empty()); @@ -227,23 +223,19 @@ TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { } TEST_F(ProxyScriptFetcherTest, ContentDisposition) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); SynchFetcher pac_fetcher; // Fetch PAC scripts via HTTP with a Content-Disposition header -- should // have no effect. - GURL url = server->TestServerPage("files/downloadable.pac"); + GURL url = server.TestServerPage("files/downloadable.pac"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::OK, result.code); EXPECT_EQ("-downloadable.pac-\n", result.bytes); } TEST_F(ProxyScriptFetcherTest, TooLarge) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); SynchFetcher pac_fetcher; // Set the maximum response size to 50 bytes. @@ -251,7 +243,7 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) { // These two URLs are the same file, but are http:// vs file:// GURL urls[] = { - server->TestServerPage("files/large-pac.nsproxy"), + server.TestServerPage("files/large-pac.nsproxy"), GetTestFileUrl("large-pac.nsproxy") }; @@ -268,7 +260,7 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) { net::ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size); { // Make sure we can still fetch regular URLs. - GURL url = server->TestServerPage("files/pac.nsproxy"); + GURL url = server.TestServerPage("files/pac.nsproxy"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::OK, result.code); EXPECT_EQ("-pac.nsproxy-\n", result.bytes); @@ -276,9 +268,7 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) { } TEST_F(ProxyScriptFetcherTest, Hang) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + TestServer server(kDocRoot); SynchFetcher pac_fetcher; // Set the timeout period to 0.5 seconds. @@ -287,7 +277,7 @@ TEST_F(ProxyScriptFetcherTest, Hang) { // Try fetching a URL which takes 1.2 seconds. We should abort the request // after 500 ms, and fail with a timeout error. - { GURL url = server->TestServerPage("slow/proxy.pac?1.2"); + { GURL url = server.TestServerPage("slow/proxy.pac?1.2"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::ERR_TIMED_OUT, result.code); EXPECT_TRUE(result.bytes.empty()); @@ -297,7 +287,7 @@ TEST_F(ProxyScriptFetcherTest, Hang) { net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout); { // Make sure we can still fetch regular URLs. - GURL url = server->TestServerPage("files/pac.nsproxy"); + GURL url = server.TestServerPage("files/pac.nsproxy"); FetchResult result = pac_fetcher.Fetch(url); EXPECT_EQ(net::OK, result.code); EXPECT_EQ("-pac.nsproxy-\n", result.bytes); diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 4fe23f6..be26da9 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -83,12 +83,11 @@ class URLRequestTest : public PlatformTest { }; TEST_F(URLRequestTest, GetTest_NoCache) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(server.TestServerPage(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -105,12 +104,11 @@ TEST_F(URLRequestTest, GetTest_NoCache) { } TEST_F(URLRequestTest, GetTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(server.TestServerPage(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -129,7 +127,7 @@ TEST_F(URLRequestTest, GetTest) { class HTTPSRequestTest : public testing::Test { protected: HTTPSRequestTest() : util_() {}; - + SSLTestUtil util_; }; @@ -145,15 +143,14 @@ TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { // a working document root to server the pages / and /hello.html, // so this test doesn't really need to specify a document root. // But if it did, a good one would be net/data/ssl. - scoped_refptr<HTTPSTestServer> server = - HTTPSTestServer::CreateServer(util_.kHostName, util_.kOKHTTPSPort, - L"net/data/ssl", util_.GetOKCertPath().ToWStringHack()); - ASSERT_TRUE(NULL != server.get()); + HTTPSTestServer https_server(util_.kHostName, util_.kOKHTTPSPort, + L"net/data/ssl", + util_.GetOKCertPath().ToWStringHack()); EXPECT_TRUE(util_.CheckCATrusted()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(https_server.TestServerPage(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -193,16 +190,11 @@ TEST_F(URLRequestTest, CancelTest) { } TEST_F(URLRequestTest, CancelTest2) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); - - // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' - // to 'const int' - + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(server.TestServerPage(""), &d); d.set_cancel_in_response_started(true); @@ -222,12 +214,11 @@ TEST_F(URLRequestTest, CancelTest2) { } TEST_F(URLRequestTest, CancelTest3) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(server.TestServerPage(""), &d); d.set_cancel_in_received_data(true); @@ -250,12 +241,11 @@ TEST_F(URLRequestTest, CancelTest3) { } TEST_F(URLRequestTest, CancelTest4) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(server.TestServerPage(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -276,15 +266,14 @@ TEST_F(URLRequestTest, CancelTest4) { } TEST_F(URLRequestTest, CancelTest5) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); // populate cache { TestDelegate d; - URLRequest r(server->TestServerPage("cachetime"), &d); + URLRequest r(server.TestServerPage("cachetime"), &d); r.set_context(context); r.Start(); MessageLoop::current()->Run(); @@ -294,7 +283,7 @@ TEST_F(URLRequestTest, CancelTest5) { // cancel read from cache (see bug 990242) { TestDelegate d; - URLRequest r(server->TestServerPage("cachetime"), &d); + URLRequest r(server.TestServerPage("cachetime"), &d); r.set_context(context); r.Start(); r.Cancel(); @@ -312,9 +301,9 @@ TEST_F(URLRequestTest, CancelTest5) { } TEST_F(URLRequestTest, PostTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data"); + ASSERT_TRUE(server.init_successful()); + const int kMsgSize = 20000; // multiple of 10 const int kIterations = 50; char *uploadBytes = new char[kMsgSize+1]; @@ -338,7 +327,7 @@ TEST_F(URLRequestTest, PostTest) { for (int i = 0; i < kIterations; ++i) { TestDelegate d; - URLRequest r(server->TestServerPage("echo"), &d); + URLRequest r(server.TestServerPage("echo"), &d); r.set_context(context); r.set_method("POST"); @@ -364,12 +353,11 @@ TEST_F(URLRequestTest, PostTest) { } TEST_F(URLRequestTest, PostEmptyTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage("echo"), &d); + TestURLRequest r(server.TestServerPage("echo"), &d); r.set_method("POST"); r.Start(); @@ -389,12 +377,11 @@ TEST_F(URLRequestTest, PostEmptyTest) { } TEST_F(URLRequestTest, PostFileTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { - TestURLRequest r(server->TestServerPage("echo"), &d); + TestURLRequest r(server.TestServerPage("echo"), &d); r.set_method("POST"); std::wstring dir; @@ -422,8 +409,7 @@ TEST_F(URLRequestTest, PostFileTest) { int size = static_cast<int>(longsize); scoped_array<char> buf(new char[size]); - int size_read = static_cast<int>(file_util::ReadFile(path, - buf.get(), size)); + int size_read = static_cast<int>(file_util::ReadFile(path, buf.get(), size)); ASSERT_EQ(size, size_read); ASSERT_EQ(1, d.response_started_count()) << "request failed: " << @@ -520,11 +506,10 @@ TEST_F(URLRequestTest, DISABLED_DnsFailureTest) { } TEST_F(URLRequestTest, ResponseHeadersTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/url_request_unittest"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; - TestURLRequest req(server->TestServerPage("files/with-headers.html"), &d); + TestURLRequest req(server.TestServerPage("files/with-headers.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -545,14 +530,13 @@ TEST_F(URLRequestTest, ResponseHeadersTest) { } TEST_F(URLRequestTest, BZip2ContentTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/filter_unittests"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/filter_unittests"); + ASSERT_TRUE(server.init_successful()); // for localhost domain, we also should support bzip2 encoding // first, get the original file TestDelegate d1; - TestURLRequest req1(server->TestServerPage("realfiles/google.txt"), &d1); + TestURLRequest req1(server.TestServerPage("realfiles/google.txt"), &d1); req1.Start(); MessageLoop::current()->Run(); @@ -560,7 +544,7 @@ TEST_F(URLRequestTest, BZip2ContentTest) { // second, get bzip2 content TestDelegate d2; - TestURLRequest req2(server->TestServerPage("realbz2files/google.txt"), &d2); + TestURLRequest req2(server.TestServerPage("realbz2files/google.txt"), &d2); req2.Start(); MessageLoop::current()->Run(); @@ -571,14 +555,13 @@ TEST_F(URLRequestTest, BZip2ContentTest) { } TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/filter_unittests"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/filter_unittests"); + ASSERT_TRUE(server.init_successful()); // for localhost domain, we also should support bzip2 encoding // first, get the original file TestDelegate d1; - TestURLRequest req1(server->TestServerPage("realfiles/google.txt"), &d1); + TestURLRequest req1(server.TestServerPage("realfiles/google.txt"), &d1); req1.Start(); MessageLoop::current()->Run(); @@ -587,8 +570,7 @@ TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { // second, get bzip2 content. ask the testserver to send the BZ2 header in // two chunks with a delay between them. this tests our fix for bug 867161. TestDelegate d2; - TestURLRequest req2(server->TestServerPage( - "realbz2files/google.txt?incremental-header"), &d2); + TestURLRequest req2(server.TestServerPage("realbz2files/google.txt?incremental-header"), &d2); req2.Start(); MessageLoop::current()->Run(); @@ -672,12 +654,10 @@ TEST_F(URLRequestTest, ResolveShortcutTest) { #endif // defined(OS_WIN) TEST_F(URLRequestTest, ContentTypeNormalizationTest) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(L"net/data/url_request_unittest"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; - TestURLRequest req(server->TestServerPage( + TestURLRequest req(server.TestServerPage( "files/content-type-normalization.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -721,12 +701,10 @@ TEST_F(URLRequestTest, FileDirCancelTest) { } TEST_F(URLRequestTest, RestrictRedirects) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); - + TestServer server(L"net/data/url_request_unittest"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; - TestURLRequest req(server->TestServerPage( + TestURLRequest req(server.TestServerPage( "files/redirect-to-file.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -736,11 +714,10 @@ TEST_F(URLRequestTest, RestrictRedirects) { } TEST_F(URLRequestTest, NoUserPassInReferrer) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/url_request_unittest"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; - TestURLRequest req(server->TestServerPage( + TestURLRequest req(server.TestServerPage( "echoheader?Referer"), &d); req.set_referrer("http://user:pass@foo.com/"); req.Start(); @@ -750,13 +727,12 @@ TEST_F(URLRequestTest, NoUserPassInReferrer) { } TEST_F(URLRequestTest, CancelRedirect) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/url_request_unittest"); + ASSERT_TRUE(server.init_successful()); TestDelegate d; { d.set_cancel_in_received_redirect(true); - TestURLRequest req(server->TestServerPage( + TestURLRequest req(server.TestServerPage( "files/redirect-test.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -769,9 +745,8 @@ TEST_F(URLRequestTest, CancelRedirect) { } TEST_F(URLRequestTest, VaryHeader) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/url_request_unittest"); + ASSERT_TRUE(server.init_successful()); scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); @@ -780,7 +755,7 @@ TEST_F(URLRequestTest, VaryHeader) { // populate the cache { TestDelegate d; - URLRequest req(server->TestServerPage("echoheader?foo"), &d); + URLRequest req(server.TestServerPage("echoheader?foo"), &d); req.set_context(context); req.SetExtraRequestHeaders("foo:1"); req.Start(); @@ -796,7 +771,7 @@ TEST_F(URLRequestTest, VaryHeader) { // expect a cache hit { TestDelegate d; - URLRequest req(server->TestServerPage("echoheader?foo"), &d); + URLRequest req(server.TestServerPage("echoheader?foo"), &d); req.set_context(context); req.SetExtraRequestHeaders("foo:1"); req.Start(); @@ -808,7 +783,7 @@ TEST_F(URLRequestTest, VaryHeader) { // expect a cache miss { TestDelegate d; - URLRequest req(server->TestServerPage("echoheader?foo"), &d); + URLRequest req(server.TestServerPage("echoheader?foo"), &d); req.set_context(context); req.SetExtraRequestHeaders("foo:2"); req.Start(); @@ -820,9 +795,8 @@ TEST_F(URLRequestTest, VaryHeader) { TEST_F(URLRequestTest, BasicAuth) { scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L""); + ASSERT_TRUE(server.init_successful()); Time response_time; @@ -832,7 +806,7 @@ TEST_F(URLRequestTest, BasicAuth) { d.set_username(L"user"); d.set_password(L"secret"); - URLRequest r(server->TestServerPage("auth-basic"), &d); + URLRequest r(server.TestServerPage("auth-basic"), &d); r.set_context(context); r.Start(); @@ -855,7 +829,7 @@ TEST_F(URLRequestTest, BasicAuth) { d.set_username(L"user"); d.set_password(L"secret"); - URLRequest r(server->TestServerPage("auth-basic"), &d); + URLRequest r(server.TestServerPage("auth-basic"), &d); r.set_context(context); r.set_load_flags(net::LOAD_VALIDATE_CACHE); r.Start(); @@ -875,20 +849,16 @@ TEST_F(URLRequestTest, BasicAuth) { // Content-Type header. // http://code.google.com/p/chromium/issues/detail?id=843 TEST_F(URLRequestTest, Post302RedirectGet) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/url_request_unittest"); TestDelegate d; - TestURLRequest req(server->TestServerPage("files/redirect-to-echoall"), &d); + TestURLRequest req(server.TestServerPage("files/redirect-to-echoall"), &d); req.set_method("POST"); // Set headers (some of which are specific to the POST). // ("Content-Length: 10" is just a junk value to make sure it gets stripped). req.SetExtraRequestHeaders( - "Content-Type: multipart/form-data; " - "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" - "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," - "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" + "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n" "Accept-Language: en-US,en\r\n" "Accept-Charset: ISO-8859-1,*,utf-8\r\n" "Content-Length: 10\r\n" @@ -915,128 +885,11 @@ TEST_F(URLRequestTest, Post302RedirectGet) { } TEST_F(URLRequestTest, Post307RedirectPost) { - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); + TestServer server(L"net/data/url_request_unittest"); TestDelegate d; - TestURLRequest req(server->TestServerPage("files/redirect307-to-echoall"), - &d); + TestURLRequest req(server.TestServerPage("files/redirect307-to-echoall"), &d); req.set_method("POST"); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ(req.method(), "POST"); } - -// TODO(ibrar) It appears that these tests are hanging or not shutting down -// correctly. Disable them for now. -#if 1 // !defined(OS_WIN) - #define MAYBE_FTPGetTestAnonymous DISABLED_FTPGetTestAnonymous - #define MAYBE_FTPCheckWrongPassword DISABLED_FTPCheckWrongPassword - #define MAYBE_FTPCheckWrongUser DISABLED_FTPCheckWrongUser - #define MAYBE_FTPGetTest DISABLED_FTPGetTest -#else - #define MAYBE_FTPGetTestAnonymous FTPGetTestAnonymous - #define MAYBE_FTPCheckWrongPassword FTPCheckWrongPassword - #define MAYBE_FTPCheckWrongUser FTPCheckWrongUser - #define MAYBE_FTPGetTest FTPGetTest -#endif - -TEST_F(URLRequestTest, MAYBE_FTPGetTestAnonymous) { - scoped_refptr<FTPTestServer> server = FTPTestServer::CreateServer(L""); - ASSERT_TRUE(NULL != server.get()); - std::wstring app_path; - PathService::Get(base::DIR_SOURCE_ROOT, &app_path); - app_path.append(L"\\LICENSE"); - TestDelegate d; - { - TestURLRequest r(server->TestServerPage("/LICENSE"), &d); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_TRUE(!r.is_pending()); - EXPECT_EQ(1, d.response_started_count()); - EXPECT_FALSE(d.received_data_before_response()); - EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); - } -} - -TEST_F(URLRequestTest, MAYBE_FTPGetTest) { - scoped_refptr<FTPTestServer> server = - FTPTestServer::CreateServer(L"", "chrome", "chrome"); - ASSERT_TRUE(NULL != server.get()); - std::wstring app_path; - PathService::Get(base::DIR_SOURCE_ROOT, &app_path); - app_path.append(L"\\LICENSE"); - TestDelegate d; - { - TestURLRequest r(server->TestServerPage("/LICENSE"), &d); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_TRUE(!r.is_pending()); - EXPECT_EQ(1, d.response_started_count()); - EXPECT_FALSE(d.received_data_before_response()); - EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); - } -} - -TEST_F(URLRequestTest, MAYBE_FTPCheckWrongPassword) { - scoped_refptr<FTPTestServer> server = - FTPTestServer::CreateServer(L"", "chrome", "wrong_password"); - ASSERT_TRUE(NULL != server.get()); - std::wstring app_path; - PathService::Get(base::DIR_SOURCE_ROOT, &app_path); - app_path.append(L"\\LICENSE"); - TestDelegate d; - { - TestURLRequest r(server->TestServerPage("/LICENSE"), &d); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_TRUE(!r.is_pending()); - EXPECT_EQ(1, d.response_started_count()); - EXPECT_FALSE(d.received_data_before_response()); - EXPECT_EQ(d.bytes_received(), 0); - } -} - -TEST_F(URLRequestTest, MAYBE_FTPCheckWrongUser) { - scoped_refptr<FTPTestServer> server = - FTPTestServer::CreateServer(L"", "wrong_user", "chrome"); - ASSERT_TRUE(NULL != server.get()); - std::wstring app_path; - PathService::Get(base::DIR_SOURCE_ROOT, &app_path); - app_path.append(L"\\LICENSE"); - TestDelegate d; - { - TestURLRequest r(server->TestServerPage("/LICENSE"), &d); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_TRUE(!r.is_pending()); - EXPECT_EQ(1, d.response_started_count()); - EXPECT_FALSE(d.received_data_before_response()); - EXPECT_EQ(d.bytes_received(), 0); - } -} - diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 75ef7b7..a33be39 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -9,7 +9,6 @@ #include <sstream> #include <string> -#include <vector> #include "base/file_path.h" #include "base/file_util.h" @@ -28,9 +27,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "googleurl/src/url_util.h" -const int kHTTPDefaultPort = 1337; -const int kFTPDefaultPort = 1338; - +const int kDefaultPort = 1337; const std::string kDefaultHostName("localhost"); // This URLRequestContext does not use a local cache. @@ -193,37 +190,29 @@ class TestDelegate : public URLRequest::Delegate { char buf_[4096]; }; -// This object bounds the lifetime of an external python-based HTTP/FTP server +// This object bounds the lifetime of an external python-based HTTP server // that can provide various responses useful for testing. -class BaseTestServer : public base::ProcessFilter, - public base::RefCounted<BaseTestServer> { - protected: - BaseTestServer() - : process_handle_(NULL) { +class TestServer : public base::ProcessFilter { + public: + TestServer(const std::wstring& document_root) + : process_handle_(NULL), + is_shutdown_(true) { + Init(kDefaultHostName, kDefaultPort, document_root, std::wstring()); } - public: - virtual ~BaseTestServer() { - if (process_handle_) { -#if defined(OS_WIN) - CloseHandle(process_handle_); -#endif - process_handle_ = NULL; - } - // Make sure we don't leave any stray testserver processes laying around. - std::wstring testserver_name = - file_util::GetFilenameFromPath(python_runtime_); - base::CleanupProcesses(testserver_name, 10000, 1, this); - EXPECT_EQ(0, base::GetProcessCount(testserver_name, this)); + virtual ~TestServer() { + Shutdown(); } // Implementation of ProcessFilter virtual bool Includes(uint32 pid, uint32 parent_pid) const { - // Since no process handle is set, it can't be included in the filter. + // This function may be called after Shutdown(), in which process_handle_ is + // set to NULL. Since no process handle is set, it can't be included in the + // filter. if (!process_handle_) return false; // TODO(port): rationalize return value of GetProcId - return pid == static_cast<uint32>(base::GetProcId(process_handle_)); + return pid == (uint32)base::GetProcId(process_handle_); } GURL TestServerPage(const std::string& path) { @@ -234,46 +223,101 @@ class BaseTestServer : public base::ProcessFilter, return GURL(base_address_ + WideToUTF8(path)); } - void SetPythonPaths() { + // A subclass may wish to send the request in a different manner + virtual bool MakeGETRequest(const std::string& page_name) { + const GURL& url = TestServerPage(page_name); + + // Spin up a background thread for this request so that we have access to + // an IO message loop, and in cases where this thread already has an IO + // message loop, we also want to avoid spinning a nested message loop. + + SyncTestDelegate d; + { + base::Thread io_thread("MakeGETRequest"); + base::Thread::Options options; + options.message_loop_type = MessageLoop::TYPE_IO; + io_thread.StartWithOptions(options); + io_thread.message_loop()->PostTask(FROM_HERE, NewRunnableFunction( + &TestServer::StartGETRequest, url, &d)); + d.Wait(); + } + return d.did_succeed(); + } + + bool init_successful() const { return init_successful_; } + + protected: + struct ManualInit {}; + + // Used by subclasses that need to defer initialization until they are fully + // constructed. The subclass should call Init once it is ready (usually in + // its constructor). + TestServer(ManualInit) + : process_handle_(NULL), + init_successful_(false), + is_shutdown_(true) { + } + + virtual std::string scheme() { return std::string("http"); } + + // This is in a separate function so that we can have assertions and so that + // subclasses can call this later. + void Init(const std::string& host_name, int port, + const std::wstring& document_root, + const std::wstring& cert_path) { + std::stringstream ss; + std::string port_str; + ss << (port ? port : kDefaultPort); + ss >> port_str; + base_address_ = scheme() + "://" + host_name + ":" + port_str + "/"; + + std::wstring testserver_path; + ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)); + file_util::AppendToPath(&testserver_path, L"net"); + file_util::AppendToPath(&testserver_path, L"tools"); + file_util::AppendToPath(&testserver_path, L"testserver"); + file_util::AppendToPath(&testserver_path, L"testserver.py"); + + ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &python_runtime_)); + file_util::AppendToPath(&python_runtime_, L"third_party"); + file_util::AppendToPath(&python_runtime_, L"python_24"); + file_util::AppendToPath(&python_runtime_, L"python.exe"); + + std::wstring test_data_directory; + PathService::Get(base::DIR_SOURCE_ROOT, &test_data_directory); + std::wstring normalized_document_root = document_root; #if defined(OS_WIN) - // Set up PYTHONPATH so that Python is able to find the in-tree copy of - // pyftpdlib. - static bool set_python_path = false; - if (!set_python_path) { - FilePath pyftpdlib_path; - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &pyftpdlib_path)); - pyftpdlib_path = pyftpdlib_path.Append(L"third_party"); - pyftpdlib_path = pyftpdlib_path.Append(L"pyftpdlib"); - - const wchar_t kPythonPath[] = L"PYTHONPATH"; - wchar_t python_path_c[1024]; - if (GetEnvironmentVariable(kPythonPath, python_path_c, 1023) > 0) { - // PYTHONPATH is already set, append to it. - std::wstring python_path(python_path_c); - python_path.append(L":"); - python_path.append(pyftpdlib_path.value()); - SetEnvironmentVariableW(kPythonPath, python_path.c_str()); - } else { - SetEnvironmentVariableW(kPythonPath, pyftpdlib_path.value().c_str()); - } + std::replace(normalized_document_root.begin(), + normalized_document_root.end(), + L'/', FilePath::kSeparators[0]); +#endif + file_util::AppendToPath(&test_data_directory, normalized_document_root); - set_python_path = true; +#if defined(OS_WIN) + std::wstring command_line = + L"\"" + python_runtime_ + L"\" " + L"\"" + testserver_path + + L"\" --port=" + UTF8ToWide(port_str) + L" --data-dir=\"" + + test_data_directory + L"\""; + if (!cert_path.empty()) { + command_line.append(L" --https=\""); + command_line.append(cert_path); + command_line.append(L"\""); } + + ASSERT_TRUE( + base::LaunchApp(command_line, false, true, &process_handle_)) << + "Failed to launch " << command_line; #elif defined(OS_POSIX) // Set up PYTHONPATH so that Python is able to find the in-tree copy of - // tlslite and pyftpdlib. + // tlslite. + static bool set_python_path = false; if (!set_python_path) { FilePath tlslite_path; - FilePath pyftpdlib_path; ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &tlslite_path)); tlslite_path = tlslite_path.Append("third_party"); tlslite_path = tlslite_path.Append("tlslite"); - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &pyftpdlib_path)); - pyftpdlib_path = pyftpdlib_path.Append("third_party"); - pyftpdlib_path = pyftpdlib_path.Append("pyftpdlib"); - const char kPythonPath[] = "PYTHONPATH"; char* python_path_c = getenv(kPythonPath); if (python_path_c) { @@ -281,89 +325,81 @@ class BaseTestServer : public base::ProcessFilter, std::string python_path(python_path_c); python_path.append(":"); python_path.append(tlslite_path.value()); - python_path.append(":"); - python_path.append(pyftpdlib_path.value()); setenv(kPythonPath, python_path.c_str(), 1); } else { - std::string python_path = tlslite_path.value().c_str(); - python_path.append(":"); - python_path.append(pyftpdlib_path.value()); - setenv(kPythonPath, python_path.c_str(), 1); + setenv(kPythonPath, tlslite_path.value().c_str(), 1); } + set_python_path = true; } + + std::vector<std::string> command_line; + command_line.push_back("python"); + command_line.push_back(WideToUTF8(testserver_path)); + command_line.push_back("--port=" + port_str); + command_line.push_back("--data-dir=" + WideToUTF8(test_data_directory)); + if (!cert_path.empty()) + command_line.push_back("--https=" + WideToUTF8(cert_path)); + + base::file_handle_mapping_vector no_mappings; + ASSERT_TRUE( + base::LaunchApp(command_line, no_mappings, false, &process_handle_)) << + "Failed to launch " << command_line[0] << " ..."; #endif - } - void SetAppPath(const std::string& host_name, int port, - const std::wstring& document_root, const std::string& scheme, - std::wstring* testserver_path, std::wstring* test_data_directory) { - port_str_ = IntToString(port); - if (url_user_.empty()) { - base_address_ = scheme + "://" + host_name + ":" + port_str_ + "/"; - } else { - if (url_password_.empty()) - base_address_ = scheme + "://" + url_user_ + "@" + - host_name + ":" + port_str_ + "/"; - else - base_address_ = scheme + "://" + url_user_ + ":" + url_password_ + - "@" + host_name + ":" + port_str_ + "/"; + // Verify that the webserver is actually started. + // Otherwise tests can fail if they run faster than Python can start. + int retries = 10; + bool success; + while ((success = MakeGETRequest("hello.html")) == false && retries > 0) { + retries--; + PlatformThread::Sleep(500); } + ASSERT_TRUE(success) << "Webserver not starting properly."; - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, testserver_path)); - file_util::AppendToPath(testserver_path, L"net"); - file_util::AppendToPath(testserver_path, L"tools"); - file_util::AppendToPath(testserver_path, L"testserver"); - file_util::AppendToPath(testserver_path, L"testserver.py"); - - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &python_runtime_)); - file_util::AppendToPath(&python_runtime_, L"third_party"); - file_util::AppendToPath(&python_runtime_, L"python_24"); - file_util::AppendToPath(&python_runtime_, L"python.exe"); + init_successful_ = true; + is_shutdown_ = false; + } - PathService::Get(base::DIR_SOURCE_ROOT, test_data_directory); - std::wstring normalized_document_root = document_root; + void Shutdown() { + if (is_shutdown_) + return; -#if defined(OS_WIN) - // It is just for windows only and have no effect on other OS - std::replace(normalized_document_root.begin(), - normalized_document_root.end(), - L'/', FilePath::kSeparators[0]); -#endif - if (!normalized_document_root.empty()) - file_util::AppendToPath(test_data_directory, normalized_document_root); - - } + // here we append the time to avoid problems where the kill page + // is being cached rather than being executed on the server + std::ostringstream page_name; + page_name << "kill?" << (unsigned int)(base::Time::Now().ToInternalValue()); + int retry_count = 5; + while (retry_count > 0) { + bool r = MakeGETRequest(page_name.str()); + // BUG #1048625 causes the kill GET to fail. For now we just retry. + // Once the bug is fixed, we should remove the while loop and put back + // the following DCHECK. + // DCHECK(r); + if (r) + break; + retry_count--; + } + // Make sure we were successfull in stopping the testserver. + DCHECK(retry_count > 0); + if (process_handle_) { #if defined(OS_WIN) - void LaunchApp(const std::wstring& command_line) { - ASSERT_TRUE(base::LaunchApp(command_line, false, true, &process_handle_)) << - "Failed to launch " << command_line; - } -#elif defined(OS_POSIX) - void LaunchApp(const std::vector<std::string>& command_line) { - ASSERT_TRUE(base::LaunchApp(command_line, false, true, &process_handle_)) << - "Failed to launch " << command_line[0] << " ..."; - } + CloseHandle(process_handle_); #endif + process_handle_ = NULL; + } - virtual bool MakeGETRequest(const std::string& page_name) = 0; + // Make sure we don't leave any stray testserver processes laying around. + std::wstring testserver_name = + file_util::GetFilenameFromPath(python_runtime_); + base::CleanupProcesses(testserver_name, 10000, 1, this); + EXPECT_EQ(0, base::GetProcessCount(testserver_name, this)); - // Verify that the Server is actually started. - // Otherwise tests can fail if they run faster than Python can start. - bool VerifyLaunchApp(const std::string& page_name) { - int retries = 10; - bool success; - while ((success = MakeGETRequest(page_name)) == false && retries > 0) { - retries--; - PlatformThread::Sleep(500); - } - if (!success) - return false; - return true; + is_shutdown_ = true; } - protected: + private: // Used by MakeGETRequest to implement sync load behavior. class SyncTestDelegate : public TestDelegate { public: @@ -381,73 +417,6 @@ class BaseTestServer : public base::ProcessFilter, bool success_; DISALLOW_COPY_AND_ASSIGN(SyncTestDelegate); }; - - std::string base_address_; - std::string url_user_; - std::string url_password_; - std::wstring python_runtime_; - base::ProcessHandle process_handle_; - std::string port_str_; -}; - -class HTTPTestServer : public BaseTestServer { - protected: - HTTPTestServer() { - } - - public: - static HTTPTestServer* CreateServer(const std::wstring& document_root) { - HTTPTestServer* test_server = new HTTPTestServer(); - if (!test_server->Init(kDefaultHostName, kHTTPDefaultPort, document_root)) { - delete test_server; - return NULL; - } - return test_server; - } - - bool Init(const std::string& host_name, int port, - const std::wstring& document_root) { - std::wstring testserver_path; - std::wstring test_data_directory; -#if defined(OS_WIN) - std::wstring command_line; -#elif defined(OS_POSIX) - std::vector<std::string> command_line; -#endif - - // Set PYTHONPATH for tlslite and pyftpdlib - SetPythonPaths(); - SetAppPath(kDefaultHostName, port, document_root, scheme(), - &testserver_path, &test_data_directory); - SetCommandLineOption(testserver_path, test_data_directory, &command_line); - LaunchApp(command_line); - if (!VerifyLaunchApp("hello.html")) { - LOG(ERROR) << "Webserver not starting properly"; - return false; - } - return true; - } - - // A subclass may wish to send the request in a different manner - virtual bool MakeGETRequest(const std::string& page_name) { - const GURL& url = TestServerPage(page_name); - - // Spin up a background thread for this request so that we have access to - // an IO message loop, and in cases where this thread already has an IO - // message loop, we also want to avoid spinning a nested message loop. - SyncTestDelegate d; - { - base::Thread io_thread("MakeGETRequest"); - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread.StartWithOptions(options); - io_thread.message_loop()->PostTask(FROM_HERE, NewRunnableFunction( - &HTTPTestServer::StartGETRequest, url, &d)); - d.Wait(); - } - return d.did_succeed(); - } - static void StartGETRequest(const GURL& url, URLRequest::Delegate* delegate) { URLRequest* request = new URLRequest(url, delegate); request->set_context(new TestURLRequestContext()); @@ -456,212 +425,23 @@ class HTTPTestServer : public BaseTestServer { EXPECT_TRUE(request->is_pending()); } - virtual ~HTTPTestServer() { - // here we append the time to avoid problems where the kill page - // is being cached rather than being executed on the server - std::string page_name = StringPrintf("kill?%u", - static_cast<int>(base::Time::Now().ToInternalValue())); - int retry_count = 5; - while (retry_count > 0) { - bool r = MakeGETRequest(page_name); - // BUG #1048625 causes the kill GET to fail. For now we just retry. - // Once the bug is fixed, we should remove the while loop and put back - // the following DCHECK. - // DCHECK(r); - if (r) - break; - retry_count--; - } - // Make sure we were successfull in stopping the testserver. - DCHECK(retry_count > 0); - } - - virtual std::string scheme() { return "http"; } - -#if defined(OS_WIN) - virtual void SetCommandLineOption(const std::wstring& testserver_path, - const std::wstring& test_data_directory, - std::wstring* command_line ) { - command_line->append(L"\"" + python_runtime_ + L"\" " + L"\"" + - testserver_path + L"\" --port=" + UTF8ToWide(port_str_) + - L" --data-dir=\"" + test_data_directory + L"\""); - } -#elif defined(OS_POSIX) - virtual void SetCommandLineOption(const std::wstring& testserver_path, - const std::wstring& test_data_directory, - std::vector<std::string>* command_line) { - command_line->push_back("python"); - command_line->push_back(WideToUTF8(testserver_path)); - command_line->push_back("--port=" + port_str_); - command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory)); - } -#endif -}; - -class HTTPSTestServer : public HTTPTestServer { - protected: - explicit HTTPSTestServer(const std::wstring& cert_path) - : cert_path_(cert_path) { - } - - public: - static HTTPSTestServer* CreateServer(const std::string& host_name, int port, - const std::wstring& document_root, - const std::wstring& cert_path) { - HTTPSTestServer* test_server = new HTTPSTestServer(cert_path); - if (!test_server->Init(host_name, port, document_root)) { - delete test_server; - return NULL; - } - return test_server; - } - -#if defined(OS_WIN) - virtual void SetCommandLineOption(const std::wstring& testserver_path, - const std::wstring& test_data_directory, - std::wstring* command_line ) { - command_line->append(L"\"" + python_runtime_ + L"\" " + L"\"" + - testserver_path + L"\"" + L" --port=" + - UTF8ToWide(port_str_) + L" --data-dir=\"" + - test_data_directory + L"\""); - if (!cert_path_.empty()) { - command_line->append(L" --https=\""); - command_line->append(cert_path_); - command_line->append(L"\""); - } - } -#elif defined(OS_POSIX) - virtual void SetCommandLineOption(const std::wstring& testserver_path, - const std::wstring& test_data_directory, - std::vector<std::string>* command_line) { - command_line->push_back("python"); - command_line->push_back(WideToUTF8(testserver_path)); - command_line->push_back("--port=" + port_str_); - command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory)); - if (!cert_path_.empty()) - command_line->push_back("--https=" + WideToUTF8(cert_path_)); -} -#endif - - virtual std::string scheme() { return "https"; } - - virtual ~HTTPSTestServer() { - } - - protected: - std::wstring cert_path_; + std::string base_address_; + std::wstring python_runtime_; + base::ProcessHandle process_handle_; + bool init_successful_; + bool is_shutdown_; }; - -class FTPTestServer : public BaseTestServer { - protected: - FTPTestServer() { - } - +class HTTPSTestServer : public TestServer { public: - FTPTestServer(const std::string& url_user, const std::string& url_password) { - url_user_ = url_user; - url_password_ = url_password; + HTTPSTestServer(const std::string& host_name, int port, + const std::wstring& document_root, + const std::wstring& cert_path) : TestServer(ManualInit()) { + Init(host_name, port, document_root, cert_path); } - static FTPTestServer* CreateServer(const std::wstring& document_root) { - FTPTestServer* test_server = new FTPTestServer(); - if (!test_server->Init(kDefaultHostName, kFTPDefaultPort, document_root)) { - delete test_server; - return NULL; - } - return test_server; - } - - static FTPTestServer* CreateServer(const std::wstring& document_root, - const std::string& url_user, - const std::string& url_password) { - FTPTestServer* test_server = new FTPTestServer(url_user, url_password); - if (!test_server->Init(kDefaultHostName, kFTPDefaultPort, document_root)) { - delete test_server; - return NULL; - } - return test_server; - } - - bool Init(const std::string& host_name, int port, - const std::wstring& document_root) { - std::wstring testserver_path; - std::wstring test_data_directory; - -#if defined(OS_WIN) - std::wstring command_line; -#elif defined(OS_POSIX) - std::vector<std::string> command_line; -#endif - - // Set PYTHONPATH for tlslite and pyftpdlib - SetPythonPaths(); - SetAppPath(kDefaultHostName, port, document_root, scheme(), - &testserver_path, &test_data_directory); - SetCommandLineOption(testserver_path, test_data_directory, &command_line); - LaunchApp(command_line); - if (!VerifyLaunchApp("/LICENSE")) { - LOG(ERROR) << "FTPServer not starting properly."; - return false; - } - return true; - } - - virtual ~FTPTestServer() { - int retry_count = 5; - while (retry_count > 0) { - bool r = MakeGETRequest("kill"); - // For some reason, this is failing some of the time on the bots. - // It appears to be a different reason than BUG #1048625 (see above), - // which is a Vista + WinHTTP issue. This failure is on XP and our FTP - // code curerntly uses WinInet. - if (r) - break; - retry_count--; - } - // Make sure we were successfull in stopping the testserver. - DCHECK(retry_count > 0); - } - - virtual std::string scheme() { return "ftp"; } - - virtual bool MakeGETRequest(const std::string& page_name) { - const GURL& url = TestServerPage(page_name); - TestDelegate d; - URLRequest request(url, &d); - request.set_context(new TestURLRequestContext()); - request.set_method("GET"); - request.Start(); - EXPECT_TRUE(request.is_pending()); - - MessageLoop::current()->Run(); - if (request.is_pending()) - return false; - - return true; - } - -#if defined(OS_WIN) - virtual void SetCommandLineOption(const std::wstring& testserver_path, - const std::wstring& test_data_directory, - std::wstring* command_line ) { - command_line->append(L"\"" + python_runtime_ + L"\" " + L"\"" + - testserver_path + L"\"" + L" -f " + L" --port=" + - UTF8ToWide(port_str_) + L" --data-dir=\"" + - test_data_directory + L"\""); - } -#elif defined(OS_POSIX) - virtual void SetCommandLineOption(const std::wstring& testserver_path, - const std::wstring& test_data_directory, - std::vector<std::string>* command_line) { - command_line->push_back("python"); - command_line->push_back(" -f "); - command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory)); - command_line->push_back("--port=" + port_str_); - command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory)); - } -#endif + virtual std::string scheme() { return std::string("https"); } }; #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ + diff --git a/webkit/glue/mimetype_unittest.cc b/webkit/glue/mimetype_unittest.cc index a746d96..bbbf0f6 100644 --- a/webkit/glue/mimetype_unittest.cc +++ b/webkit/glue/mimetype_unittest.cc @@ -23,7 +23,7 @@ class MimeTypeTests : public TestShellTest { test_shell_->LoadURL(UTF8ToWide(url.spec()).c_str()); test_shell_->WaitTestFinished(); } - + void CheckMimeType(const char* mimetype, const std::wstring& expected) { std::string path("contenttype?"); GURL url = server_->TestServerPage(path + mimetype); @@ -31,17 +31,16 @@ class MimeTypeTests : public TestShellTest { WebFrame* frame = test_shell_->webView()->GetMainFrame(); EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); } - - scoped_refptr<UnittestTestServer> server_; + + scoped_ptr<UnittestTestServer> server_; }; TEST_F(MimeTypeTests, MimeTypeTests) { - server_ = UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server_.get()); + server_.reset(new UnittestTestServer); std::wstring expected_src(L"<html>\n<body>\n" L"<p>HTML text</p>\n</body>\n</html>\n"); - + // These files should all be displayed as plain text. const char* plain_text[] = { "text/css", @@ -81,6 +80,7 @@ TEST_F(MimeTypeTests, MimeTypeTests) { // TODO(tc): make sure other mime types properly go to download (e.g., // image/foo). + server_.reset(NULL); } } // namespace diff --git a/webkit/glue/resource_fetcher_unittest.cc b/webkit/glue/resource_fetcher_unittest.cc index 81d9646..d996f3b 100644 --- a/webkit/glue/resource_fetcher_unittest.cc +++ b/webkit/glue/resource_fetcher_unittest.cc @@ -153,16 +153,14 @@ FetcherDelegate* FetcherDelegate::instance_ = NULL; // Test a fetch from the test server. TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { - scoped_refptr<UnittestTestServer> server = - UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server.get()); + UnittestTestServer server; WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); // Not safe, but this is a unittest, so whatever. WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); WebCore::Frame* frame = web_frame_impl->frame(); - GURL url = server->TestServerPage("files/test_shell/index.html"); + GURL url = server.TestServerPage("files/test_shell/index.html"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( url, frame, delegate.get())); @@ -175,7 +173,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { EXPECT_TRUE(text.find("What is this page?") != std::string::npos); // Test 404 response. - url = server->TestServerPage("files/thisfiledoesntexist.html"); + url = server.TestServerPage("files/thisfiledoesntexist.html"); delegate.reset(new FetcherDelegate); fetcher.reset(new ResourceFetcher(url, frame, delegate.get())); @@ -187,10 +185,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { } TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { - scoped_refptr<UnittestTestServer> server = - UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server.get()); - + UnittestTestServer server; WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); // Not safe, but this is a unittest, so whatever. WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); @@ -213,9 +208,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { } TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { - scoped_refptr<UnittestTestServer> server = - UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server.get()); + UnittestTestServer server; WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); // Not safe, but this is a unittest, so whatever. @@ -224,7 +217,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { // Grab a page that takes at least 1 sec to respond, but set the fetcher to // timeout in 0 sec. - GURL url = server->TestServerPage("slow?1"); + GURL url = server.TestServerPage("slow?1"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout( url, frame, 0, delegate.get())); diff --git a/webkit/glue/unittest_test_server.h b/webkit/glue/unittest_test_server.h index 3e27b875..d9b4ce2 100644 --- a/webkit/glue/unittest_test_server.h +++ b/webkit/glue/unittest_test_server.h @@ -14,22 +14,14 @@ using webkit_glue::ResourceLoaderBridge; // We need to use ResourceLoaderBridge to communicate with the testserver // instead of using URLRequest directly because URLRequests need to be run on // the test_shell's IO thread. -class UnittestTestServer : public HTTPTestServer { - protected: - UnittestTestServer() { - } - +class UnittestTestServer : public TestServer { public: - static UnittestTestServer* CreateServer() { - UnittestTestServer* test_server = new UnittestTestServer(); - if (!test_server->Init("localhost", 1337, L"webkit/data")) { - delete test_server; - return NULL; - } - return test_server; + UnittestTestServer() : TestServer(TestServer::ManualInit()) { + Init("localhost", 1337, L"webkit/data", std::wstring()); } - virtual ~UnittestTestServer() { + ~UnittestTestServer() { + Shutdown(); } virtual bool MakeGETRequest(const std::string& page_name) { |