diff options
80 files changed, 1563 insertions, 2077 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 19d82d7..dbc3b6e 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -52,7 +52,7 @@ const std::wstring OPEN_NEW_BEFOREUNLOAD_PAGE = const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); // Given a page title, returns the expected window caption string. std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { @@ -102,10 +102,9 @@ class BrowserTest : public ExtensionBrowserTest { // Used by phantom tab tests. Creates two tabs, pins the first and makes it // a phantom tab (by closing it). void PhantomTabTest() { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); host_resolver()->AddRule("www.example.com", "127.0.0.1"); - GURL url(server->TestServerPage("empty.html")); + GURL url(test_server()->GetURL("empty.html")); TabStripModel* model = browser()->tabstrip_model(); ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); @@ -332,10 +331,8 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutFile) { IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutHttp) { CommandUpdater* command_updater = browser()->command_updater(); - scoped_refptr<net::HTTPTestServer> http_server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != http_server.get()); - GURL http_url(http_server->TestServerPage("")); + ASSERT_TRUE(test_server()->Start()); + GURL http_url(test_server()->GetURL("")); ASSERT_TRUE(http_url.SchemeIs(chrome::kHttpScheme)); ui_test_utils::NavigateToURL(browser(), http_url); EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_CREATE_SHORTCUTS)); @@ -344,10 +341,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutHttp) { IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutHttps) { CommandUpdater* command_updater = browser()->command_updater(); - scoped_refptr<net::HTTPSTestServer> https_server( - net::HTTPSTestServer::CreateGoodServer(kDocRoot)); - ASSERT_TRUE(NULL != https_server.get()); - GURL https_url(https_server->TestServerPage("/")); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + GURL https_url(test_server.GetURL("/")); ASSERT_TRUE(https_url.SchemeIs(chrome::kHttpsScheme)); ui_test_utils::NavigateToURL(browser(), https_url); EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_CREATE_SHORTCUTS)); @@ -356,10 +352,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutHttps) { IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutFtp) { CommandUpdater* command_updater = browser()->command_updater(); - scoped_refptr<net::FTPTestServer> ftp_server( - net::FTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != ftp_server.get()); - GURL ftp_url(ftp_server->TestServerPage("")); + net::TestServer test_server(net::TestServer::TYPE_FTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + GURL ftp_url(test_server.GetURL("")); ASSERT_TRUE(ftp_url.SchemeIs(chrome::kFtpScheme)); ui_test_utils::NavigateToURL(browser(), ftp_url); EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_CREATE_SHORTCUTS)); @@ -390,12 +385,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcutInvalid) { // Test RenderView correctly send back favicon url for web page that redirects // to an anchor in javascript body.onload handler. IN_PROC_BROWSER_TEST_F(BrowserTest, FaviconOfOnloadRedirectToAnchorPage) { - static const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL url(server->TestServerPage("files/onload_redirect_to_anchor.html")); - GURL expected_favicon_url(server->TestServerPage("files/test.png")); + ASSERT_TRUE(test_server()->Start()); + GURL url(test_server()->GetURL("files/onload_redirect_to_anchor.html")); + GURL expected_favicon_url(test_server()->GetURL("files/test.png")); ui_test_utils::NavigateToURL(browser(), url); @@ -455,10 +447,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RevivePhantomTab) { // Makes sure TabClosing is sent when uninstalling an extension that is an app // tab. IN_PROC_BROWSER_TEST_F(BrowserTest, TabClosingWhenRemovingExtension) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); host_resolver()->AddRule("www.example.com", "127.0.0.1"); - GURL url(server->TestServerPage("empty.html")); + GURL url(test_server()->GetURL("empty.html")); TabStripModel* model = browser()->tabstrip_model(); ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); @@ -511,10 +502,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, AppTabRemovedWhenExtensionUninstalled) { #endif // Tests that the CLD (Compact Language Detection) works properly. IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { - static const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server()->Start()); TabContents* current_tab = browser()->GetSelectedTabContents(); @@ -524,7 +512,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { en_language_detected_signal(NotificationType::TAB_LANGUAGE_DETERMINED, current_tab); ui_test_utils::NavigateToURL( - browser(), GURL(server->TestServerPage("files/english_page.html"))); + browser(), GURL(test_server()->GetURL("files/english_page.html"))); EXPECT_TRUE(current_tab->language_state().original_language().empty()); en_language_detected_signal.Wait(); std::string lang; @@ -538,7 +526,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { fr_language_detected_signal(NotificationType::TAB_LANGUAGE_DETERMINED, current_tab); ui_test_utils::NavigateToURL( - browser(), GURL(server->TestServerPage("files/french_page.html"))); + browser(), GURL(test_server()->GetURL("files/french_page.html"))); EXPECT_TRUE(current_tab->language_state().original_language().empty()); fr_language_detected_signal.Wait(); lang.clear(); @@ -556,12 +544,11 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { #endif // Makes sure pinned tabs are restored correctly on start. IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // Add an pinned app tab. host_resolver()->AddRule("www.example.com", "127.0.0.1"); - GURL url(server->TestServerPage("empty.html")); + GURL url(test_server()->GetURL("empty.html")); TabStripModel* model = browser()->tabstrip_model(); ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); Extension* extension_app = GetExtension(); @@ -621,9 +608,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { class BrowserAppRefocusTest : public ExtensionBrowserTest { public: - BrowserAppRefocusTest(): server_(NULL), - extension_app_(NULL), - profile_(NULL) {} + BrowserAppRefocusTest() + : extension_app_(NULL), + profile_(NULL) {} protected: // Common setup for all tests. Can't use SetUpInProcessBrowserTestFixture @@ -632,8 +619,7 @@ class BrowserAppRefocusTest : public ExtensionBrowserTest { virtual void SetUpExtensionApp() { // The web URL of the example app we load has a host of // www.example.com . - server_ = StartHTTPServer(); - ASSERT_TRUE(server_); + ASSERT_TRUE(test_server()->Start()); host_resolver()->AddRule("www.example.com", "127.0.0.1"); profile_ = browser()->profile(); @@ -667,7 +653,6 @@ class BrowserAppRefocusTest : public ExtensionBrowserTest { return true; } - net::HTTPTestServer* server_; Extension* extension_app_; Profile* profile_; }; diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index 84a2ba8..6f2e0ad 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -187,11 +187,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); gfx::NativeWindow window = browser()->window()->GetNativeHandle(); @@ -252,11 +251,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) { // Tabs remember focus. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); // Create several tabs. @@ -331,11 +329,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { // Tabs remember focus with find-in-page box. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); browser()->Find(); @@ -374,11 +371,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { // Background window does not steal focus. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); // Open a new browser window. @@ -410,7 +406,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { unfocused_browser = browser(); #endif - GURL steal_focus_url = server->TestServerPage(kStealFocusPage); + GURL steal_focus_url = test_server()->GetURL(kStealFocusPage); ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); // Activate the first browser. @@ -431,11 +427,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { // Page cannot steal focus when focus is on location bar. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // Open the page that steals focus. - GURL url = server->TestServerPage(kStealFocusPage); + GURL url = test_server()->GetURL(kStealFocusPage); ui_test_utils::NavigateToURL(browser(), url); browser()->FocusLocationBar(); @@ -454,11 +449,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { // RenderWidget::didFocus()). IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kTypicalPage); + GURL url = test_server()->GetURL(kTypicalPage); ui_test_utils::NavigateToURL(browser(), url); browser()->FocusLocationBar(); @@ -548,11 +542,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { // Focus traversal while an interstitial is showing. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); // Focus should be on the page. @@ -640,11 +633,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { // Focus stays on page with interstitials. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); // Page should have focus. @@ -677,11 +669,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { // Make sure Find box can request focus, even when it is already open. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // Open some page (any page that doesn't steal focus). - GURL url = server->TestServerPage(kTypicalPage); + GURL url = test_server()->GetURL(kTypicalPage); ui_test_utils::NavigateToURL(browser(), url); gfx::NativeWindow window = browser()->window()->GetNativeHandle(); @@ -779,8 +770,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_TabInitialFocus) { // Tests that focus goes where expected when using reload. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // Open the new tab, reload. browser()->NewTab(); @@ -792,7 +782,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); // Open a regular page, focus the location bar, reload. - ui_test_utils::NavigateToURL(browser(), server->TestServerPage(kSimplePage)); + ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); browser()->FocusLocationBar(); ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); browser()->Reload(CURRENT_TAB); @@ -814,11 +804,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { // Tests that focus goes where expected when using reload on a crashed tab. IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusOnReloadCrashedTab) { BringBrowserWindowToFront(); - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // Open a regular page, crash, reload. - ui_test_utils::NavigateToURL(browser(), server->TestServerPage(kSimplePage)); + ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); browser()->Reload(CURRENT_TAB); ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); diff --git a/chrome/browser/browser_keyevents_browsertest.cc b/chrome/browser/browser_keyevents_browsertest.cc index 0c4bd37db..89f8c08 100644 --- a/chrome/browser/browser_keyevents_browsertest.cc +++ b/chrome/browser/browser_keyevents_browsertest.cc @@ -374,11 +374,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) { "U 65 0 false false false false" } }, }; - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); @@ -460,11 +459,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) { "U 17 0 true false false false" } }; - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); @@ -506,11 +504,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CommandKeyEvents) { "U 91 0 false false false true" } }; - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); @@ -603,11 +600,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { }; #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::RunAllPendingInMessageLoop(); @@ -671,11 +667,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { #endif IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); @@ -829,11 +824,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, EditorKeyBindings) { "U 17 0 true false false false" } }; - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); @@ -867,11 +861,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) { "U 34 0 false false false false" } }; - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); @@ -909,11 +902,10 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { "U 17 0 true false false false" } }; - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); BringBrowserWindowToFront(); - GURL url = server->TestServerPage(kTestingPage); + GURL url = test_server()->GetURL(kTestingPage); ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index 3140ad0..8ec30a2 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -87,9 +87,10 @@ TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { if (in_process_renderer()) return; - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + FilePath test_file(test_data_directory_); scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); @@ -137,10 +138,10 @@ TEST_F(BrowserTest, MAYBE_OtherRedirectsDontForkProcess) { if (in_process_renderer()) return; - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + FilePath test_file(test_data_directory_); scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); diff --git a/chrome/browser/chrome_plugin_unittest.cc b/chrome/browser/chrome_plugin_unittest.cc index 09c73a0..3c5495c 100644 --- a/chrome/browser/chrome_plugin_unittest.cc +++ b/chrome/browser/chrome_plugin_unittest.cc @@ -22,7 +22,7 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); const char kPluginFilename[] = "test_chrome_plugin.dll"; const int kResponseBufferSize = 4096; @@ -279,11 +279,10 @@ TEST_F(ChromePluginTest, CanMakeGETRequestAsync) { // Tests that the plugin can issue a POST request. TEST_F(ChromePluginTest, CanMakePOSTRequest) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); - GURL url = server->TestServerPage("echo"); + GURL url = test_server.GetURL("echo"); EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request("POST", url)); diff --git a/chrome/browser/collected_cookies_uitest.cc b/chrome/browser/collected_cookies_uitest.cc index e59d36d..92b97b0 100644 --- a/chrome/browser/collected_cookies_uitest.cc +++ b/chrome/browser/collected_cookies_uitest.cc @@ -15,7 +15,7 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); } // namespace @@ -23,9 +23,9 @@ typedef UITest CollectedCookiesTest; // Test is flaky. http://crbug.com/49539 TEST_F(CollectedCookiesTest, FLAKY_DoubleDisplay) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -37,7 +37,7 @@ TEST_F(CollectedCookiesTest, FLAKY_DoubleDisplay) { CONTENT_SETTING_BLOCK)); // Load a page with cookies. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/cookie1.html"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/cookie1.html"))); // Click on the info link twice. ASSERT_TRUE(tab->ShowCollectedCookiesDialog()); @@ -46,9 +46,9 @@ TEST_F(CollectedCookiesTest, FLAKY_DoubleDisplay) { // Test is flaky. http://crbug.com/49539 TEST_F(CollectedCookiesTest, FLAKY_NavigateAway) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -60,11 +60,11 @@ TEST_F(CollectedCookiesTest, FLAKY_NavigateAway) { CONTENT_SETTING_BLOCK)); // Load a page with cookies. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/cookie1.html"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/cookie1.html"))); // Click on the info link. ASSERT_TRUE(tab->ShowCollectedCookiesDialog()); // Navigate to another page. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/cookie2.html"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/cookie2.html"))); } diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc index 46ad42f..2b92090 100644 --- a/chrome/browser/debugger/devtools_sanity_unittest.cc +++ b/chrome/browser/debugger/devtools_sanity_unittest.cc @@ -111,8 +111,8 @@ class DevToolsSanityTest : public InProcessBrowserTest { } void OpenDevToolsWindow(const std::string& test_page) { - net::HTTPTestServer* server = StartHTTPServer(); - GURL url = server->TestServerPage(test_page); + ASSERT_TRUE(test_server()->Start()); + GURL url = test_server()->GetURL(test_page); ui_test_utils::NavigateToURL(browser(), url); inspected_rvh_ = GetInspectedTab()->render_view_host(); diff --git a/chrome/browser/errorpage_uitest.cc b/chrome/browser/errorpage_uitest.cc index 705dc14..6446b56 100644 --- a/chrome/browser/errorpage_uitest.cc +++ b/chrome/browser/errorpage_uitest.cc @@ -168,12 +168,10 @@ 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<net::HTTPTestServer> server = - net::HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); - GURL test_url = server->TestServerPage("files/iframe404.html"); - NavigateToURL(test_url); - + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + NavigateToURL(test_server.GetURL("files/iframe404.html")); EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS")); } diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc index af4e967..a75fc50 100644 --- a/chrome/browser/extensions/app_background_page_apitest.cc +++ b/chrome/browser/extensions/app_background_page_apitest.cc @@ -18,7 +18,7 @@ class AppBackgroundPageApiTest : public ExtensionApiTest { IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, Basic) { host_resolver()->AddRule("a.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); LoadExtension(test_data_dir_.AppendASCII( "app_background_page/app_has_permission")); @@ -27,7 +27,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, Basic) { IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, LacksPermission) { host_resolver()->AddRule("a.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); LoadExtension(test_data_dir_.AppendASCII( "app_background_page/app_lacks_permission")); diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc index aa3fad1..4a0014b 100644 --- a/chrome/browser/extensions/app_process_apitest.cc +++ b/chrome/browser/extensions/app_process_apitest.cc @@ -56,7 +56,7 @@ static void NavigateTabHelper(TabContents* contents, const GURL& url) { IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc index 63d205b..82f1320 100644 --- a/chrome/browser/extensions/browser_action_apitest.cc +++ b/chrome/browser/extensions/browser_action_apitest.cc @@ -45,7 +45,7 @@ class BrowserActionApiTest : public ExtensionApiTest { }; IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; Extension* extension = GetSingleLoadedExtension(); ASSERT_TRUE(extension) << message_; @@ -266,7 +266,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) { } IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; Extension* extension = GetSingleLoadedExtension(); diff --git a/chrome/browser/extensions/content_script_all_frames_apitest.cc b/chrome/browser/extensions/content_script_all_frames_apitest.cc index 13be5fd..fac6362 100644 --- a/chrome/browser/extensions/content_script_all_frames_apitest.cc +++ b/chrome/browser/extensions/content_script_all_frames_apitest.cc @@ -5,11 +5,11 @@ #include "chrome/browser/extensions/extension_apitest.h" IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_; } diff --git a/chrome/browser/extensions/content_script_extension_process_apitest.cc b/chrome/browser/extensions/content_script_extension_process_apitest.cc index 16258fa..46729d2 100644 --- a/chrome/browser/extensions/content_script_extension_process_apitest.cc +++ b/chrome/browser/extensions/content_script_extension_process_apitest.cc @@ -10,6 +10,6 @@ #include "chrome/test/ui_test_utils.h" IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("content_scripts/extension_process")) << message_; } diff --git a/chrome/browser/extensions/cross_origin_xhr_apitest.cc b/chrome/browser/extensions/cross_origin_xhr_apitest.cc index a2cf9d8..41474bc 100644 --- a/chrome/browser/extensions/cross_origin_xhr_apitest.cc +++ b/chrome/browser/extensions/cross_origin_xhr_apitest.cc @@ -7,6 +7,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHR) { host_resolver()->AddRule("*.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("cross_origin_xhr")) << message_; } diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc index 07c141c..f6c963b 100644 --- a/chrome/browser/extensions/execute_script_apitest.cc +++ b/chrome/browser/extensions/execute_script_apitest.cc @@ -12,7 +12,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ExecuteScript) { host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500); host_resolver()->AddRule("b.com", "127.0.0.1"); host_resolver()->AddRule("c.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("executescript/basic")) << message_; ASSERT_TRUE(RunExtensionTest("executescript/in_frame")) << message_; @@ -23,7 +23,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ExecuteScript) { // (ExecuteScript) tests are de-flakified, reunite this case with it's brethern. IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ExecuteScriptFileAfterClose) { host_resolver()->AddRule("b.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_; } diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 038d07f..99966df 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -76,7 +76,7 @@ static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, // extension specifies in permissions but not from others. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OriginPrivileges) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension(test_data_dir_ .AppendASCII("origin_privileges").AppendASCII("extension"))); @@ -146,8 +146,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { // Tests that we can load page actions in the Omnibox. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // This page action will not show an icon, since it doesn't specify one but // is included here to test for a crash (http://crbug.com/25562). @@ -161,13 +160,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); // Navigate to the feed page. - GURL feed_url = server->TestServerPage(kFeedPage); + GURL feed_url = test_server()->GetURL(kFeedPage); ui_test_utils::NavigateToURL(browser(), feed_url); // We should now have one page action ready to go in the LocationBar. ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); // Navigate to a page with no feed. - GURL no_feed = server->TestServerPage(kNoFeedPage); + GURL no_feed = test_server()->GetURL(kNoFeedPage); ui_test_utils::NavigateToURL(browser(), no_feed); // Make sure the page action goes away. ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); @@ -175,8 +174,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { // Tests that we don't lose the page action icon on in-page navigations. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); FilePath extension_path(test_data_dir_.AppendASCII("api_test") .AppendASCII("page_action") @@ -184,31 +182,30 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { ASSERT_TRUE(LoadExtension(extension_path)); // Page action should become visible when we navigate here. - GURL feed_url = server->TestServerPage(kHashPageA); + GURL feed_url = test_server()->GetURL(kHashPageA); ui_test_utils::NavigateToURL(browser(), feed_url); ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); // In-page navigation, page action should remain. - feed_url = server->TestServerPage(kHashPageAHash); + feed_url = test_server()->GetURL(kHashPageAHash); ui_test_utils::NavigateToURL(browser(), feed_url); ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); // Not an in-page navigation, page action should go away. - feed_url = server->TestServerPage(kHashPageB); + feed_url = test_server()->GetURL(kHashPageB); ui_test_utils::NavigateToURL(browser(), feed_url); ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); } // Tests that the location bar forgets about unloaded page actions. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); FilePath extension_path(test_data_dir_.AppendASCII("subscribe_page_action")); ASSERT_TRUE(LoadExtension(extension_path)); // Navigation prompts the location bar to load page actions. - GURL feed_url = server->TestServerPage(kFeedPage); + GURL feed_url = test_server()->GetURL(kFeedPage); ui_test_utils::NavigateToURL(browser(), feed_url); ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); @@ -257,8 +254,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) { // Makes sure that the RSS detects RSS feed links, even when rel tag contains // more than just "alternate". IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); @@ -266,7 +262,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) { ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); // Navigate to the feed page. - GURL feed_url = server->TestServerPage(kFeedPageMultiRel); + GURL feed_url = test_server()->GetURL(kFeedPageMultiRel); ui_test_utils::NavigateToURL(browser(), feed_url); // We should now have one page action ready to go in the LocationBar. ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); @@ -296,8 +292,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationBrowserAction) { // Tests that tooltips of a page action icon can be specified using UTF8. // See http://crbug.com/25349. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ExtensionsService* service = browser()->profile()->GetExtensionsService(); const size_t size_before = service->extensions()->size(); @@ -307,7 +302,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { ASSERT_TRUE(LoadExtension(extension_path)); // Any navigation prompts the location bar to load the page action. - GURL url = server->TestServerPage(kLocalization); + GURL url = test_server()->GetURL(kLocalization); ui_test_utils::NavigateToURL(browser(), url); ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); @@ -323,9 +318,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { extension->page_action()->GetTitle(tab_id).c_str()); } -GURL GetFeedUrl(net::HTTPTestServer* server, const std::string& feed_page, +GURL GetFeedUrl(net::TestServer* server, const std::string& feed_page, bool direct_url, std::string extension_id) { - GURL feed_url = server->TestServerPage(feed_page); + GURL feed_url = server->GetURL(feed_page); if (direct_url) { // We navigate directly to the subscribe page for feeds where the feed // sniffing won't work, in other words, as is the case for malformed feeds. @@ -386,7 +381,7 @@ bool ValidatePageElement(TabContents* tab, // extension to kick in, detect the feed and redirect to a feed preview page. // |sniff_xml_type| is generally set to true if the feed is sniffable and false // for invalid feeds. -void NavigateToFeedAndValidate(net::HTTPTestServer* server, +void NavigateToFeedAndValidate(net::TestServer* server, const std::string& url, Browser* browser, bool sniff_xml_type, @@ -425,13 +420,12 @@ void NavigateToFeedAndValidate(net::HTTPTestServer* server, } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); - NavigateToFeedAndValidate(server, kValidFeed1, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), true, "Feed for MyFeedTitle", "Title 1", "Desc", @@ -439,13 +433,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); - NavigateToFeedAndValidate(server, kValidFeed2, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), true, "Feed for MyFeed2", "My item title1", "This is a summary.", @@ -453,13 +446,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); - NavigateToFeedAndValidate(server, kValidFeed3, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), true, "Feed for Google Code buglist rss feed", "My dear title", "My dear content", @@ -467,13 +459,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); - NavigateToFeedAndValidate(server, kValidFeed4, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), true, "Feed for Title chars <script> %23 stop", "Title chars %23 stop", "My dear content %23 stop", @@ -481,15 +472,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Try a feed with a link with an onclick handler (before r27440 this would // trigger a NOTREACHED). - NavigateToFeedAndValidate(server, kValidFeed0, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), true, "Feed for MyFeedTitle", "Title 1", "Desc VIDEO", @@ -497,14 +487,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Feed with valid but mostly empty xml. - NavigateToFeedAndValidate(server, kValidFeed5, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), true, "Feed for Unknown feed name", "element 'anchor_0' not found", "element 'desc_0' not found", @@ -512,14 +501,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Feed that is technically invalid but still parseable. - NavigateToFeedAndValidate(server, kValidFeed6, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), true, "Feed for MyFeedTitle", "Title 1", "Desc", @@ -527,14 +515,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Try an empty feed. - NavigateToFeedAndValidate(server, kInvalidFeed1, browser(), false, + NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), false, "Feed for Unknown feed name", "element 'anchor_0' not found", "element 'desc_0' not found", @@ -542,14 +529,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Try a garbage feed. - NavigateToFeedAndValidate(server, kInvalidFeed2, browser(), false, + NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), false, "Feed for Unknown feed name", "element 'anchor_0' not found", "element 'desc_0' not found", @@ -557,14 +543,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Try a feed that doesn't exist. - NavigateToFeedAndValidate(server, "foo.xml", browser(), false, + NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), false, "Feed for Unknown feed name", "element 'anchor_0' not found", "element 'desc_0' not found", @@ -572,14 +557,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) { } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeedNoLinks) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); // Valid feed but containing no links. - NavigateToFeedAndValidate(server, kValidFeedNoLinks, browser(), true, + NavigateToFeedAndValidate(test_server(), kValidFeedNoLinks, browser(), true, "Feed for MyFeedTitle", "Title with no link", "Desc", diff --git a/chrome/browser/extensions/extension_clipboard_apitest.cc b/chrome/browser/extensions/extension_clipboard_apitest.cc index cfabacf..c159f97 100644 --- a/chrome/browser/extensions/extension_clipboard_apitest.cc +++ b/chrome/browser/extensions/extension_clipboard_apitest.cc @@ -10,6 +10,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Clipboard) { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnableExperimentalExtensionApis); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("clipboard")) << message_; } diff --git a/chrome/browser/extensions/extension_history_apitest.cc b/chrome/browser/extensions/extension_history_apitest.cc index a9a99ef..9815ac8 100644 --- a/chrome/browser/extensions/extension_history_apitest.cc +++ b/chrome/browser/extensions/extension_history_apitest.cc @@ -11,7 +11,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_History) { host_resolver()->AddRule("www.a.com", "127.0.0.1"); host_resolver()->AddRule("www.b.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("history")) << message_; } diff --git a/chrome/browser/extensions/extension_incognito_apitest.cc b/chrome/browser/extensions/extension_incognito_apitest.cc index 2c6dc73..dbc9234c 100644 --- a/chrome/browser/extensions/extension_incognito_apitest.cc +++ b/chrome/browser/extensions/extension_incognito_apitest.cc @@ -18,7 +18,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); // Loads a simple extension which attempts to change the title of every page // that loads to "modified". @@ -44,7 +44,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) { IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoYesScript) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); // Load a dummy extension. This just tests that we don't regress a // crash fix when multiple incognito- and non-incognito-enabled extensions @@ -81,7 +81,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoYesScript) { // Tests that the APIs in an incognito-enabled extension work properly. IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ResultCatcher catcher; @@ -99,7 +99,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { // events or callbacks. IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ResultCatcher catcher; @@ -116,7 +116,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { // Test that opening a popup from an incognito browser window works properly. IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoPopup) { host_resolver()->AddRule("*", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ResultCatcher catcher; diff --git a/chrome/browser/extensions/extension_javascript_url_apitest.cc b/chrome/browser/extensions/extension_javascript_url_apitest.cc index 601a9e4..2b6cf59 100644 --- a/chrome/browser/extensions/extension_javascript_url_apitest.cc +++ b/chrome/browser/extensions/extension_javascript_url_apitest.cc @@ -8,7 +8,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, JavaScriptURLPermissions) { host_resolver()->AddRule("a.com", "127.0.0.1"); host_resolver()->AddRule("b.com", "127.0.0.1"); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("tabs/javascript_url_permissions")) << message_; } diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc index eed3657..9a393c6 100644 --- a/chrome/browser/extensions/extension_messages_apitest.cc +++ b/chrome/browser/extensions/extension_messages_apitest.cc @@ -51,7 +51,7 @@ class MessageSender : public NotificationObserver { // Tests that message passing between extensions and content scripts works. IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Messaging) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("messaging/connect")) << message_; } diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc index 109faf3..1e3abc6 100644 --- a/chrome/browser/extensions/extension_omnibox_apitest.cc +++ b/chrome/browser/extensions/extension_omnibox_apitest.cc @@ -68,7 +68,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnableExperimentalExtensionApis); - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; // The results depend on the TemplateURLModel being loaded. Make sure it is diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc index c0a00f77..0b654f0 100644 --- a/chrome/browser/extensions/extension_tabs_apitest.cc +++ b/chrome/browser/extensions/extension_tabs_apitest.cc @@ -26,7 +26,7 @@ #endif IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); // The test creates a tab and checks that the URL of the new tab // is that of the new tab page. Make sure the pref that controls @@ -38,34 +38,34 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs) { } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabGetCurrent) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabConnect) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabOnRemoved) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTabJpeg) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", "test_jpeg.html")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FAILS_CaptureVisibleTabPng) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", "test_png.html")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsOnUpdated) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_; } diff --git a/chrome/browser/extensions/fragment_navigation_apitest.cc b/chrome/browser/extensions/fragment_navigation_apitest.cc index d44c35a..aa7bc46 100644 --- a/chrome/browser/extensions/fragment_navigation_apitest.cc +++ b/chrome/browser/extensions/fragment_navigation_apitest.cc @@ -6,13 +6,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); const char* extension_name = "content_scripts/fragment"; ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ExecuteScriptFragmentNavigation) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); const char* extension_name = "executescript/fragment"; ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; } diff --git a/chrome/browser/extensions/isolated_world_apitest.cc b/chrome/browser/extensions/isolated_world_apitest.cc index f3ef0eb..4b0761d 100644 --- a/chrome/browser/extensions/isolated_world_apitest.cc +++ b/chrome/browser/extensions/isolated_world_apitest.cc @@ -7,7 +7,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IsolatedWorld1) { // This extension runs various bits of script and tests that they all run in // the same isolated world. - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_; // Now load a different extension, inject into same page, verify worlds aren't diff --git a/chrome/browser/extensions/page_action_apitest.cc b/chrome/browser/extensions/page_action_apitest.cc index 6eb30dd..4ae4b39 100644 --- a/chrome/browser/extensions/page_action_apitest.cc +++ b/chrome/browser/extensions/page_action_apitest.cc @@ -15,7 +15,7 @@ #include "chrome/test/ui_test_utils.h" IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; Extension* extension = GetSingleLoadedExtension(); ASSERT_TRUE(extension) << message_; diff --git a/chrome/browser/extensions/stubs_apitest.cc b/chrome/browser/extensions/stubs_apitest.cc index fe06c6a..72e3a48 100644 --- a/chrome/browser/extensions/stubs_apitest.cc +++ b/chrome/browser/extensions/stubs_apitest.cc @@ -16,14 +16,13 @@ // should be available in content scripts) or update the list of privileged APIs // in renderer_extension_bindings.js. IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Stubs) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("stubs")) << message_; // Navigate to a simple http:// page, which should get the content script // injected and run the rest of the test. - GURL url = server->TestServerPage("file/extensions/test_file.html"); + GURL url(test_server()->GetURL("file/extensions/test_file.html")); ui_test_utils::NavigateToURL(browser(), url); ResultCatcher catcher; diff --git a/chrome/browser/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc index 4c0606c..d68e35d 100644 --- a/chrome/browser/find_bar_host_browsertest.cc +++ b/chrome/browser/find_bar_host_browsertest.cc @@ -116,11 +116,10 @@ int FindInPageWchar(TabContents* tab, // This test loads a page with frames and starts FindInPage requests. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our frames page. - GURL url = server->TestServerPage(kFramePage); + GURL url = test_server()->GetURL(kFramePage); ui_test_utils::NavigateToURL(browser(), url); // Try incremental search (mimicking user typing in). @@ -209,11 +208,10 @@ std::string FocusedOnPage(TabContents* tab_contents) { // close the Find box (ie. if you find within a link the link should be // focused). IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our special focus tracking page. - GURL url = server->TestServerPage(kEndState); + GURL url = test_server()->GetURL(kEndState); ui_test_utils::NavigateToURL(browser(), url); TabContents* tab_contents = browser()->GetSelectedTabContents(); @@ -257,11 +255,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { // This test loads a single-frame page and makes sure the ordinal returned makes // sense as we FindNext over all the items. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kFrameData); + GURL url = test_server()->GetURL(kFrameData); ui_test_utils::NavigateToURL(browser(), url); // Search for 'o', which should make the first item active and return @@ -297,11 +294,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { // This tests that the ordinal is correctly adjusted after a selection IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SelectChangesOrdinal_Issue20883) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test content. - GURL url = server->TestServerPage(kSelectChangesOrdinal); + GURL url = test_server()->GetURL(kSelectChangesOrdinal); ui_test_utils::NavigateToURL(browser(), url); TabContents* tab_contents = browser()->GetSelectedTabContents(); @@ -337,11 +333,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, // This test loads a page with frames and makes sure the ordinal returned makes // sense. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kFramePage); + GURL url = test_server()->GetURL(kFramePage); ui_test_utils::NavigateToURL(browser(), url); // Search for 'a', which should make the first item active and return @@ -389,11 +384,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { // We could get ordinals out of whack when restarting search in subframes. // See http://crbug.com/5132. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kFramePage); + GURL url = test_server()->GetURL(kFramePage); ui_test_utils::NavigateToURL(browser(), url); // Search for 'goa' three times (6 matches on page). @@ -420,11 +414,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { // Load a page with no selectable text and make sure we don't crash. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kUserSelectPage); + GURL url = test_server()->GetURL(kUserSelectPage); ui_test_utils::NavigateToURL(browser(), url); int ordinal = 0; @@ -438,11 +431,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) { // Try to reproduce the crash seen in issue 1341577. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kCrashPage); + GURL url = test_server()->GetURL(kCrashPage); ui_test_utils::NavigateToURL(browser(), url); // This would crash the tab. These must be the first two find requests issued @@ -471,11 +463,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { // Try to reproduce the crash seen in http://crbug.com/14491, where an assert // hits in the BitStack size comparison in WebKit. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kBitstackCrash); + GURL url = test_server()->GetURL(kBitstackCrash); ui_test_utils::NavigateToURL(browser(), url); // This used to crash the tab. @@ -494,11 +485,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { // ms) to find one or more of those matches (so Find times out and has to try // again from where it left off). IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our page. - GURL url = server->TestServerPage(kTooFewMatchesPage); + GURL url = test_server()->GetURL(kTooFewMatchesPage); ui_test_utils::NavigateToURL(browser(), url); // This string appears 5 times at the bottom of a long page. If Find restarts @@ -512,11 +502,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { // This tests bug 11761: FindInPage terminates search prematurely. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FAILS_FindInPagePrematureEnd) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our special focus tracking page. - GURL url = server->TestServerPage(kPrematureEnd); + GURL url = test_server()->GetURL(kPrematureEnd); ui_test_utils::NavigateToURL(browser(), url); TabContents* tab_contents = browser()->GetSelectedTabContents(); @@ -530,12 +519,11 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FAILS_FindInPagePrematureEnd) { } IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our special focus tracking page. - GURL url = server->TestServerPage(kSimplePage); - GURL url2 = server->TestServerPage(kFramePage); + GURL url = test_server()->GetURL(kSimplePage); + GURL url2 = test_server()->GetURL(kFramePage); ui_test_utils::NavigateToURL(browser(), url); browser()->ShowFindBar(); @@ -571,11 +559,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { // when a New Tab is opened. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNewTabAndHistory) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our special focus tracking page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); browser()->ShowFindBar(); @@ -619,10 +606,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, // Make sure Find box moves out of the way if it is obscuring the active match. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FindMovesWhenObscuring) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); - GURL url = server->TestServerPage(kMoveIfOver); + GURL url = test_server()->GetURL(kMoveIfOver); ui_test_utils::NavigateToURL(browser(), url); browser()->ShowFindBar(); @@ -678,11 +664,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FindMovesWhenObscuring) { // Make sure F3 in a new tab works if Find has previous string to search for. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindNextInNewTabUsesPrepopulate) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); // Search for 'no_match'. No matches should be found. @@ -725,11 +710,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, #else IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); views::FocusManager* focus_manager = @@ -764,11 +748,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, // Make sure Find box does not become UI-inactive when no text is in the box as // we switch to a tab contents with an empty find string. See issue 13570. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); browser()->ShowFindBar(); @@ -789,11 +772,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { // Make sure F3 works after you FindNext a couple of times and end the Find // session. See issue http://crbug.com/28306. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to a simple page. - GURL url = server->TestServerPage(kSimple); + GURL url = test_server()->GetURL(kSimple); ui_test_utils::NavigateToURL(browser(), url); // Search for 'page'. Should have 1 match. @@ -821,11 +803,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { // with the last search from the same tab rather than the last overall search. // http://crbug.com/30006 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); // Find "Default". @@ -863,11 +844,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { return; #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimple); + GURL url = test_server()->GetURL(kSimple); ui_test_utils::NavigateToURL(browser(), url); // Search for the word "page". @@ -901,11 +881,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { return; #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimple); + GURL url = test_server()->GetURL(kSimple); ui_test_utils::NavigateToURL(browser(), url); // Search for the word "page". @@ -940,11 +919,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { return; #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimple); + GURL url = test_server()->GetURL(kSimple); ui_test_utils::NavigateToURL(browser(), url); // Search for the word "page". @@ -1019,11 +997,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) { return; #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to the "simple" test page. - GURL url = server->TestServerPage(kSimple); + GURL url = test_server()->GetURL(kSimple); ui_test_utils::NavigateToURL(browser(), url); // Search for the word "page" in the normal browser tab. @@ -1089,11 +1066,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) { // This makes sure that dismissing the find bar with kActivateSelection works. IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_ActivateLinkNavigatesPage) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test content. - GURL url = server->TestServerPage(kLinkPage); + GURL url = test_server()->GetURL(kLinkPage); ui_test_utils::NavigateToURL(browser(), url); TabContents* tab = browser()->GetSelectedTabContents(); diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index a9cee1f..9e975a9 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -205,14 +205,12 @@ class GeolocationBrowserTest : public InProcessBrowserTest { bool Initialize(InitializationOptions options) WARN_UNUSED_RESULT { GeolocationArbitrator::SetProviderFactoryForTest( &NewAutoSuccessMockNetworkLocationProvider); - if (!server_.get()) { - server_ = StartHTTPServer(); - EXPECT_TRUE(server_.get()); - if (!server_.get()) - return false; - } + bool started = test_server()->Start(); + EXPECT_TRUE(started); + if (!started) + return false; - current_url_ = server_->TestServerPage(html_for_tests_); + current_url_ = test_server()->GetURL(html_for_tests_); LOG(WARNING) << "before navigate"; if (options == INITIALIZATION_OFFTHERECORD) { ui_test_utils::OpenURLOffTheRecord(browser()->profile(), current_url_); @@ -330,7 +328,6 @@ class GeolocationBrowserTest : public InProcessBrowserTest { expected, function, current_browser_->GetSelectedTabContents()); } - scoped_refptr<net::HTTPTestServer> server_; InfoBarDelegate* infobar_; Browser* current_browser_; // path element of a URL referencing the html content for this test. diff --git a/chrome/browser/gtk/bookmark_bar_gtk_interactive_uitest.cc b/chrome/browser/gtk/bookmark_bar_gtk_interactive_uitest.cc index 60d6b8f..0d5d030 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk_interactive_uitest.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk_interactive_uitest.cc @@ -13,7 +13,6 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; const char kSimplePage[] = "404_is_enough_for_us.html"; void OnClicked(GtkWidget* widget, bool* clicked_bit) { @@ -28,9 +27,7 @@ class BookmarkBarGtkBrowserTest : public InProcessBrowserTest { // Makes sure that when you switch back to an NTP with an active findbar, // the findbar is above the floating bookmark bar. IN_PROC_BROWSER_TEST_F(BookmarkBarGtkBrowserTest, FindBarTest) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server()->Start()); // Create new tab; open findbar. browser()->NewTab(); @@ -38,7 +35,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkBarGtkBrowserTest, FindBarTest) { // Create new tab with an arbitrary URL. Browser* browser_used = NULL; - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, TabStripModel::ADD_SELECTED, NULL, std::string(), &browser_used); @@ -59,9 +56,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkBarGtkBrowserTest, FindBarTest) { // Makes sure that you can click on the floating bookmark bar. IN_PROC_BROWSER_TEST_F(BookmarkBarGtkBrowserTest, ClickOnFloatingTest) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server()->Start()); GtkWidget* other_bookmarks = ViewIDUtil::GetWidget(GTK_WIDGET(browser()->window()->GetNativeHandle()), diff --git a/chrome/browser/history/multipart_uitest.cc b/chrome/browser/history/multipart_uitest.cc index aabf593..42339bf 100644 --- a/chrome/browser/history/multipart_uitest.cc +++ b/chrome/browser/history/multipart_uitest.cc @@ -30,16 +30,15 @@ class MultipartResponseUITest : public UITest { TEST_F(MultipartResponseUITest, MAYBE_SingleVisit) { // Make sure that visiting a multipart/x-mixed-replace site only // creates one entry in the visits table. - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server = - net::HTTPTestServer::CreateServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); - NavigateToURL(server->TestServerPage("multipart")); + NavigateToURL(test_server.GetURL("multipart")); std::wstring title; EXPECT_TRUE(tab_proxy->GetTabTitle(&title)); EXPECT_EQ(L"page 9", title); diff --git a/chrome/browser/history/redirect_uitest.cc b/chrome/browser/history/redirect_uitest.cc index 6ea84ae..7e3ac11 100644 --- a/chrome/browser/history/redirect_uitest.cc +++ b/chrome/browser/history/redirect_uitest.cc @@ -20,18 +20,23 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +class RedirectTest : public UITest { + public: + RedirectTest() + : test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { + } -typedef UITest RedirectTest; + protected: + net::TestServer test_server_; +}; // Tests a single server redirect TEST_F(RedirectTest, Server) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); - GURL final_url = server->TestServerPage(std::string()); - GURL first_url = server->TestServerPage( + GURL final_url = test_server_.GetURL(std::string()); + GURL first_url = test_server_.GetURL( "server-redirect?" + final_url.spec()); NavigateToURL(first_url); @@ -48,12 +53,10 @@ TEST_F(RedirectTest, Server) { // Tests a single client redirect. TEST_F(RedirectTest, Client) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); - GURL final_url = server->TestServerPage(std::string()); - GURL first_url = server->TestServerPage( + GURL final_url = test_server_.GetURL(std::string()); + GURL first_url = test_server_.GetURL( "client-redirect?" + final_url.spec()); // The client redirect appears as two page visits in the browser. @@ -82,11 +85,9 @@ TEST_F(RedirectTest, Client) { } TEST_F(RedirectTest, ClientEmptyReferer) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); - GURL final_url = server->TestServerPage(std::string()); + GURL final_url = test_server_.GetURL(std::string()); FilePath test_file(test_data_directory_); test_file = test_file.AppendASCII("file_client_redirect.html"); GURL first_url = net::FilePathToFileURL(test_file); @@ -142,16 +143,14 @@ TEST_F(RedirectTest, ClientCancelled) { // Tests a client->server->server redirect TEST_F(RedirectTest, ClientServerServer) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); - GURL final_url = server->TestServerPage(std::string()); - GURL next_to_last = server->TestServerPage( + GURL final_url = test_server_.GetURL(std::string()); + GURL next_to_last = test_server_.GetURL( "server-redirect?" + final_url.spec()); - GURL second_url = server->TestServerPage( + GURL second_url = test_server_.GetURL( "server-redirect?" + next_to_last.spec()); - GURL first_url = server->TestServerPage( + GURL first_url = test_server_.GetURL( "client-redirect?" + second_url.spec()); std::vector<GURL> redirects; @@ -176,14 +175,12 @@ TEST_F(RedirectTest, ClientServerServer) { // Tests that the "#reference" gets preserved across server redirects. TEST_F(RedirectTest, ServerReference) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); const std::string ref("reference"); - GURL final_url = server->TestServerPage(std::string()); - GURL initial_url = server->TestServerPage( + GURL final_url = test_server_.GetURL(std::string()); + GURL initial_url = test_server_.GetURL( "server-redirect?" + final_url.spec() + "#" + ref); NavigateToURL(initial_url); @@ -196,14 +193,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<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); FilePath test_file(test_data_directory_); test_file = test_file.AppendASCII("http_to_file.html"); GURL file_url = net::FilePathToFileURL(test_file); - GURL initial_url = server->TestServerPage( + GURL initial_url = test_server_.GetURL( "client-redirect?" + file_url.spec()); NavigateToURL(initial_url); @@ -219,9 +214,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<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); FilePath test_file(test_data_directory_); test_file = test_file.AppendASCII("ref_redirect.html"); @@ -253,13 +246,11 @@ TEST_F(RedirectTest, // 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<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); - GURL final_url = server->TestServerPage("files/title2.html"); - GURL slow = server->TestServerPage("slow?60"); - GURL first_url = server->TestServerPage( + GURL final_url = test_server_.GetURL("files/title2.html"); + GURL slow = test_server_.GetURL("slow?60"); + GURL first_url = test_server_.GetURL( "client-redirect?" + slow.spec()); std::vector<GURL> redirects; diff --git a/chrome/browser/login_prompt_uitest.cc b/chrome/browser/login_prompt_uitest.cc index 91ee08f..11315ef 100644 --- a/chrome/browser/login_prompt_uitest.cc +++ b/chrome/browser/login_prompt_uitest.cc @@ -16,18 +16,18 @@ using std::wstring; namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); } // namespace class LoginPromptTest : public UITest { protected: LoginPromptTest() - : UITest(), - username_basic_(L"basicuser"), + : username_basic_(L"basicuser"), username_digest_(L"digestuser"), password_(L"secret"), - password_bad_(L"denyme") { + password_bad_(L"denyme"), + test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { } void AppendTab(const GURL& url) { @@ -41,6 +41,8 @@ class LoginPromptTest : public UITest { wstring username_digest_; wstring password_; wstring password_bad_; + + net::TestServer test_server_; }; wstring ExpectedTitleFromAuth(const wstring& username, @@ -51,12 +53,11 @@ wstring ExpectedTitleFromAuth(const wstring& username, // Test that "Basic" HTTP authentication works. TEST_F(LoginPromptTest, TestBasicAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); @@ -64,7 +65,7 @@ TEST_F(LoginPromptTest, TestBasicAuth) { EXPECT_TRUE(tab->CancelAuth()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); @@ -74,19 +75,18 @@ TEST_F(LoginPromptTest, TestBasicAuth) { // Test that "Digest" HTTP authentication works. TEST_F(LoginPromptTest, TestDigestAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("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()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-digest"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); @@ -96,19 +96,17 @@ TEST_F(LoginPromptTest, TestDigestAuth) { // Test that logging in on 2 tabs at once works. TEST_F(LoginPromptTest, TestTwoAuths) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<TabProxy> basic_tab(GetActiveTab()); ASSERT_TRUE(basic_tab.get()); - ASSERT_TRUE(basic_tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(basic_tab->NavigateToURL(test_server_.GetURL("auth-basic"))); AppendTab(GURL(chrome::kAboutBlankURL)); scoped_refptr<TabProxy> digest_tab(GetActiveTab()); ASSERT_TRUE(digest_tab.get()); ASSERT_TRUE( - digest_tab->NavigateToURL(server->TestServerPage("auth-digest"))); + digest_tab->NavigateToURL(test_server_.GetURL("auth-digest"))); EXPECT_TRUE(basic_tab->NeedsAuth()); EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); @@ -125,37 +123,36 @@ TEST_F(LoginPromptTest, TestTwoAuths) { // Test that cancelling authentication works. TEST_F(LoginPromptTest, TestCancelAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); // First navigate to a test server page so we have something to go back to. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("a"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("a"))); // Navigating while auth is requested is the same as cancelling. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("b"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("b"))); EXPECT_FALSE(tab->NeedsAuth()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("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. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("c"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("c"))); EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a' - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("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. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->CancelAuth()); EXPECT_FALSE(tab->NeedsAuth()); @@ -165,21 +162,19 @@ TEST_F(LoginPromptTest, TestCancelAuth) { // If multiple tabs are looking for the same auth, the user should only have to // enter it once (http://crbug.com/8914). TEST_F(LoginPromptTest, SupplyRedundantAuths) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); ASSERT_TRUE(basic_tab1.get()); ASSERT_TRUE( - basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); + basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1"))); EXPECT_TRUE(basic_tab1->NeedsAuth()); AppendTab(GURL(chrome::kAboutBlankURL)); scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); ASSERT_TRUE(basic_tab2.get()); ASSERT_TRUE( - basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2"))); + basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2"))); EXPECT_TRUE(basic_tab2->NeedsAuth()); // Set the auth in only one of the tabs (but wait for the other to load). @@ -200,21 +195,19 @@ TEST_F(LoginPromptTest, SupplyRedundantAuths) { // If multiple tabs are looking for the same auth, and one is cancelled, the // other should be cancelled as well. TEST_F(LoginPromptTest, CancelRedundantAuths) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); ASSERT_TRUE(basic_tab1.get()); ASSERT_TRUE( - basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); + basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1"))); EXPECT_TRUE(basic_tab1->NeedsAuth()); AppendTab(GURL(chrome::kAboutBlankURL)); scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); ASSERT_TRUE(basic_tab2.get()); ASSERT_TRUE( - basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2"))); + basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2"))); EXPECT_TRUE(basic_tab2->NeedsAuth()); // Cancel the auth in only one of the tabs (but wait for the other to load). diff --git a/chrome/browser/net/connection_tester_unittest.cc b/chrome/browser/net/connection_tester_unittest.cc index 01a0345..686c601 100644 --- a/chrome/browser/net/connection_tester_unittest.cc +++ b/chrome/browser/net/connection_tester_unittest.cc @@ -71,7 +71,10 @@ class ConnectionTesterDelegate : public ConnectionTester::Delegate { // (so the test doesn't use any external network dependencies). class ConnectionTesterTest : public PlatformTest { public: - ConnectionTesterTest() : message_loop_(MessageLoop::TYPE_IO) { + ConnectionTesterTest() + : test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))), + message_loop_(MessageLoop::TYPE_IO) { scoped_refptr<net::RuleBasedHostResolverProc> catchall_resolver = new net::RuleBasedHostResolverProc(NULL); @@ -82,20 +85,19 @@ class ConnectionTesterTest : public PlatformTest { protected: net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; + net::TestServer test_server_; ConnectionTesterDelegate test_delegate_; MessageLoop message_loop_; }; TEST_F(ConnectionTesterTest, RunAllTests) { - scoped_refptr<net::HTTPTestServer> server = - net::HTTPTestServer::CreateServer(L"net/data/url_request_unittest/"); + ASSERT_TRUE(test_server_.Start()); ConnectionTester tester(&test_delegate_); // Start the test suite on URL "echoall". // TODO(eroman): Is this URL right? - GURL url = server->TestServerPage("echoall"); - tester.RunAllTests(url); + tester.RunAllTests(test_server_.GetURL("echoall")); // Wait for all the tests to complete. MessageLoop::current()->Run(); @@ -113,15 +115,13 @@ TEST_F(ConnectionTesterTest, RunAllTests) { } TEST_F(ConnectionTesterTest, DeleteWhileInProgress) { - scoped_refptr<net::HTTPTestServer> server = - net::HTTPTestServer::CreateServer(L"net/data/url_request_unittest/"); + ASSERT_TRUE(test_server_.Start()); scoped_ptr<ConnectionTester> tester(new ConnectionTester(&test_delegate_)); // Start the test suite on URL "echoall". // TODO(eroman): Is this URL right? - GURL url = server->TestServerPage("echoall"); - tester->RunAllTests(url); + tester->RunAllTests(test_server_.GetURL("echoall")); MessageLoop::current()->RunAllPending(); diff --git a/chrome/browser/net/cookie_policy_browsertest.cc b/chrome/browser/net/cookie_policy_browsertest.cc index 5b903e2..de87969 100644 --- a/chrome/browser/net/cookie_policy_browsertest.cc +++ b/chrome/browser/net/cookie_policy_browsertest.cc @@ -65,13 +65,12 @@ class CookiePolicyBrowserTest : public InProcessBrowserTest { // Visits a page that sets a first-party cookie. IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server != NULL); + ASSERT_TRUE(test_server()->Start()); browser()->profile()->GetHostContentSettingsMap()-> SetBlockThirdPartyCookies(true); - GURL url = server->TestServerPage("set-cookie?cookie1"); + GURL url(test_server()->GetURL("set-cookie?cookie1")); std::string cookie = GetCookies(url); ASSERT_EQ("", cookie); @@ -86,19 +85,18 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { // a first-party cookie. IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookiesRedirect) { - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server != NULL); + ASSERT_TRUE(test_server()->Start()); browser()->profile()->GetHostContentSettingsMap()-> SetBlockThirdPartyCookies(true); - GURL url = server->TestServerPage("server-redirect?"); + GURL url(test_server()->GetURL("server-redirect?")); + GURL redirected_url(test_server()->GetURL("set-cookie?cookie2")); - GURL redirected_url = server->TestServerPage("set-cookie?cookie2"); - // Change the host name from localhost to www.example.com so it triggers + // Change the host name from 127.0.0.1 to www.example.com so it triggers // third-party cookie blocking if the first party for cookies URL is not // changed when we follow a redirect. - ASSERT_EQ("localhost", redirected_url.host()); + ASSERT_EQ("127.0.0.1", redirected_url.host()); GURL::Replacements replacements; std::string new_host("www.example.com"); replacements.SetHostStr(new_host); diff --git a/chrome/browser/net/ftp_browsertest.cc b/chrome/browser/net/ftp_browsertest.cc index 5033bf9..a639918 100644 --- a/chrome/browser/net/ftp_browsertest.cc +++ b/chrome/browser/net/ftp_browsertest.cc @@ -4,20 +4,21 @@ #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" +#include "googleurl/src/gurl.h" #include "net/test/test_server.h" #include "testing/gtest/include/gtest/gtest.h" class FtpBrowserTest : public InProcessBrowserTest { public: - FtpBrowserTest() : server_(net::FTPTestServer::CreateServer(L"")) { + FtpBrowserTest() : ftp_server_(net::TestServer::TYPE_FTP, FilePath()) { } protected: - scoped_refptr<net::FTPTestServer> server_; + net::TestServer ftp_server_; }; IN_PROC_BROWSER_TEST_F(FtpBrowserTest, DirectoryListing) { - ASSERT_TRUE(NULL != server_.get()); - ui_test_utils::NavigateToURL(browser(), server_->TestServerPage("/")); + ASSERT_TRUE(ftp_server_.Start()); + ui_test_utils::NavigateToURL(browser(), ftp_server_.GetURL("/")); // TODO(phajdan.jr): test more things. } diff --git a/chrome/browser/notifications/notifications_interactive_uitest.cc b/chrome/browser/notifications/notifications_interactive_uitest.cc index 656017a..e9a3efb 100644 --- a/chrome/browser/notifications/notifications_interactive_uitest.cc +++ b/chrome/browser/notifications/notifications_interactive_uitest.cc @@ -19,17 +19,16 @@ class NotificationsPermissionTest : public UITest { }; TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server.get() != NULL); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); scoped_refptr<TabProxy> tab(browser->GetActiveTab()); ASSERT_TRUE(tab.get()); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, - tab->NavigateToURL(server->TestServerPage( + tab->NavigateToURL(test_server.GetURL( "files/notifications/notifications_request_function.html"))); WaitUntilTabCount(1); @@ -46,10 +45,9 @@ TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { } TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server.get() != NULL); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -59,7 +57,7 @@ TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { // Load a page which just does a request; no user gesture should result // in no infobar. ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, - tab->NavigateToURL(server->TestServerPage( + tab->NavigateToURL(test_server.GetURL( "files/notifications/notifications_request_inline.html"))); WaitUntilTabCount(1); diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc index 1d08d42..a87e2397 100644 --- a/chrome/browser/printing/printing_layout_uitest.cc +++ b/chrome/browser/printing/printing_layout_uitest.cc @@ -22,7 +22,7 @@ namespace { using printing::Image; const char kGenerateSwitch[] = "print-layout-generate"; -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); class PrintingLayoutTest : public PrintingTest<UITest> { public: @@ -289,11 +289,10 @@ TEST_F(PrintingLayoutTextTest, FAILS_Complex) { "close_printdlg_thread"); // Print a document, check its output. - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); - NavigateToURL(server->TestServerPage("files/printing/test1.html")); + NavigateToURL(test_server.GetURL("files/printing/test1.html")); close_printdlg_thread.Start(); PrintNowTab(); close_printdlg_thread.Join(); @@ -321,9 +320,9 @@ TEST_F(PrintingLayoutTestHidden, DISABLED_ManyTimes) { if (IsTestCaseDisabled()) return; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + DismissTheWindow dismisser(base::GetProcId(process())); ASSERT_GT(arraysize(kTestPool), 0u); @@ -331,7 +330,7 @@ TEST_F(PrintingLayoutTestHidden, DISABLED_ManyTimes) { if (i) CleanupDumpDirectory(); const TestPool& test = kTestPool[i % arraysize(kTestPool)]; - NavigateToURL(server->TestServerPage(test.source)); + NavigateToURL(test_server.GetURL(test.source)); base::DelegateSimpleThread close_printdlg_thread1(&dismisser, "close_printdlg_thread"); EXPECT_EQ(NULL, FindDialogWindow(dismisser.owner_process())); @@ -372,15 +371,14 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { if (IsTestCaseDisabled()) return; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); { scoped_refptr<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 = test_server.GetURL("files/printing/popup_delayed_print.htm"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); @@ -391,7 +389,7 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { close_printdlg_thread.Join(); // Force a navigation elsewhere to verify that it's fine with it. - url = server->TestServerPage("files/printing/test1.html"); + url = test_server.GetURL("files/printing/test1.html"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); } @@ -407,14 +405,13 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { if (IsTestCaseDisabled()) return; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); { scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); - GURL url = server->TestServerPage("files/printing/iframe.htm"); + GURL url = test_server.GetURL("files/printing/iframe.htm"); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); @@ -425,7 +422,7 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { close_printdlg_thread.Join(); // Force a navigation elsewhere to verify that it's fine with it. - url = server->TestServerPage("files/printing/test1.html"); + url = test_server.GetURL("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 04835ff..6bfff9f 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc @@ -78,17 +78,16 @@ TEST_F(ResourceDispatcherTest, ContentDispositionInline) { // Test for bug #1091358. TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); ASSERT_TRUE(tab.get()); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, - tab->NavigateToURL(server->TestServerPage( + tab->NavigateToURL(test_server.GetURL( "files/sync_xmlhttprequest.html"))); // Let's check the XMLHttpRequest ran successfully. @@ -100,17 +99,16 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { } TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); ASSERT_TRUE(tab.get()); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, - tab->NavigateToURL(server->TestServerPage( + tab->NavigateToURL(test_server.GetURL( "files/sync_xmlhttprequest_disallowed.html"))); // Let's check the XMLHttpRequest ran successfully. @@ -125,10 +123,9 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { // downloadable) would trigger download and hang the renderer process, // if executed while navigating to a new page. TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); @@ -136,7 +133,7 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { ASSERT_TRUE(tab.get()); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, - tab->NavigateToURL(server->TestServerPage( + tab->NavigateToURL(test_server.GetURL( "files/sync_xmlhttprequest_during_unload.html"))); // Confirm that the page has loaded (since it changes its title during load). @@ -147,7 +144,7 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { // Navigate to a new page, to dispatch unload event and trigger xhr. // (the bug would make this step hang the renderer). ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, - tab->NavigateToURL(server->TestServerPage("files/title2.html"))); + tab->NavigateToURL(test_server.GetURL("files/title2.html"))); // Check that the new page got loaded, and that no download was triggered. EXPECT_TRUE(tab->GetTabTitle(&tab_title)); @@ -162,17 +159,16 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { // 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<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); ASSERT_TRUE(tab.get()); - GURL url(server->TestServerPage("files/onunload_cookie.html")); + GURL url(test_server.GetURL("files/onunload_cookie.html")); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); // Confirm that the page has loaded (since it changes its title during load). @@ -255,17 +251,16 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { // doctor page) still runs the onunload handler and can support navigations // away from the link doctor page. (Bug 1235537) TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); ASSERT_TRUE(tab.get()); - GURL url(server->TestServerPage("files/onunload_cookie.html")); + GURL url(test_server.GetURL("files/onunload_cookie.html")); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); // Confirm that the page has loaded (since it changes its title during load). @@ -294,7 +289,7 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { // TabContents 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->TestServerPage("files/title2.html")); + GURL test_url(test_server.GetURL("files/title2.html")); std::string redirect_url = "javascript:window.location='" + test_url.possibly_invalid_spec() + "'"; ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, diff --git a/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc b/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc index 0223cb5..78409dd 100644 --- a/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc +++ b/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc @@ -35,14 +35,14 @@ class RenderViewHostManagerTest : public InProcessBrowserTest { IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, SwapProcessWithRelNoreferrerAndTargetBlank) { // Start two servers with different sites. - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> http_server = - net::HTTPTestServer::CreateServer(kDocRoot); - scoped_refptr<net::HTTPSTestServer> https_server = - net::HTTPSTestServer::CreateGoodServer(kDocRoot); + ASSERT_TRUE(test_server()->Start()); + net::TestServer https_server_( + net::TestServer::TYPE_HTTPS, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(https_server_.Start()); // Load a page with links that open in a new window. - ui_test_utils::NavigateToURL(browser(), http_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), test_server()->GetURL( "files/click-noreferrer-links.html")); // Get the original SiteInstance for later comparison. @@ -78,14 +78,14 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DontSwapProcessWithOnlyTargetBlank) { // Start two servers with different sites. - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> http_server = - net::HTTPTestServer::CreateServer(kDocRoot); - scoped_refptr<net::HTTPSTestServer> https_server = - net::HTTPSTestServer::CreateGoodServer(kDocRoot); + ASSERT_TRUE(test_server()->Start()); + net::TestServer https_server_( + net::TestServer::TYPE_HTTPS, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(https_server_.Start()); // Load a page with links that open in a new window. - ui_test_utils::NavigateToURL(browser(), http_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), test_server()->GetURL( "files/click-noreferrer-links.html")); // Get the original SiteInstance for later comparison. @@ -121,14 +121,14 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DontSwapProcessWithOnlyRelNoreferrer) { // Start two servers with different sites. - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> http_server = - net::HTTPTestServer::CreateServer(kDocRoot); - scoped_refptr<net::HTTPSTestServer> https_server = - net::HTTPSTestServer::CreateGoodServer(kDocRoot); + ASSERT_TRUE(test_server()->Start()); + net::TestServer https_server_( + net::TestServer::TYPE_HTTPS, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(https_server_.Start()); // Load a page with links that open in a new window. - ui_test_utils::NavigateToURL(browser(), http_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), test_server()->GetURL( "files/click-noreferrer-links.html")); // Get the original SiteInstance for later comparison. diff --git a/chrome/browser/repost_form_warning_uitest.cc b/chrome/browser/repost_form_warning_uitest.cc index 8f779c7..c6e9514 100644 --- a/chrome/browser/repost_form_warning_uitest.cc +++ b/chrome/browser/repost_form_warning_uitest.cc @@ -15,7 +15,7 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); } // namespace @@ -29,9 +29,9 @@ typedef UITest RepostFormWarningTest; #endif TEST_F(RepostFormWarningTest, MAYBE_TestDoubleReload) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -39,7 +39,7 @@ TEST_F(RepostFormWarningTest, MAYBE_TestDoubleReload) { ASSERT_TRUE(tab.get()); // Load a form. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/form.html"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/form.html"))); // Submit it. ASSERT_TRUE(tab->NavigateToURL(GURL( "javascript:document.getElementById('form').submit()"))); @@ -49,7 +49,7 @@ TEST_F(RepostFormWarningTest, MAYBE_TestDoubleReload) { tab->ReloadAsync(); // Navigate away from the page (this is when the test usually crashes). - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("bar"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("bar"))); } #if defined(OS_WIN) @@ -60,9 +60,9 @@ TEST_F(RepostFormWarningTest, MAYBE_TestDoubleReload) { #endif TEST_F(RepostFormWarningTest, MAYBE_TestLoginAfterRepost) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -70,7 +70,7 @@ TEST_F(RepostFormWarningTest, MAYBE_TestLoginAfterRepost) { ASSERT_TRUE(tab.get()); // Load a form. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/form.html"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/form.html"))); // Submit it. ASSERT_TRUE(tab->NavigateToURL(GURL( "javascript:document.getElementById('form').submit()"))); @@ -80,11 +80,11 @@ TEST_F(RepostFormWarningTest, MAYBE_TestLoginAfterRepost) { // Navigate to a page that requires authentication, bringing up another // tab-modal sheet. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("auth-basic"))); // Try to reload it again. tab->ReloadAsync(); // Navigate away from the page. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("bar"))); + ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("bar"))); } diff --git a/chrome/browser/session_history_uitest.cc b/chrome/browser/session_history_uitest.cc index 01e16884..ddb0f64 100644 --- a/chrome/browser/session_history_uitest.cc +++ b/chrome/browser/session_history_uitest.cc @@ -15,11 +15,11 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; - class SessionHistoryTest : public UITest { protected: - SessionHistoryTest() : UITest() { + SessionHistoryTest() + : test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { dom_automation_enabled_ = true; } @@ -77,27 +77,27 @@ class SessionHistoryTest : public UITest { protected: scoped_refptr<BrowserProxy> window_; scoped_refptr<TabProxy> tab_; + + net::TestServer test_server_; }; TEST_F(SessionHistoryTest, BasicBackForward) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // 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"))); + test_server_.GetURL("files/session_history/bot1.html"))); EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot2.html"))); + test_server_.GetURL("files/session_history/bot2.html"))); EXPECT_EQ(L"bot2", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + test_server_.GetURL("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, bot2, *bot3] @@ -115,7 +115,7 @@ TEST_F(SessionHistoryTest, BasicBackForward) { EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + test_server_.GetURL("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, *bot3] @@ -147,9 +147,7 @@ TEST_F(SessionHistoryTest, BasicBackForward) { #define MAYBE_FrameBackForward FrameBackForward #endif TEST_F(SessionHistoryTest, MAYBE_FrameBackForward) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // about:blank should be loaded first. GURL home(homepage_); @@ -157,7 +155,7 @@ TEST_F(SessionHistoryTest, MAYBE_FrameBackForward) { EXPECT_EQ(L"", GetTabTitle()); EXPECT_EQ(home, GetTabURL()); - GURL frames(server->TestServerPage("files/session_history/frames.html")); + GURL frames(test_server_.GetURL("files/session_history/frames.html")); ASSERT_TRUE(tab_->NavigateToURL(frames)); EXPECT_EQ(L"bot1", GetTabTitle()); EXPECT_EQ(frames, GetTabURL()); @@ -213,15 +211,13 @@ TEST_F(SessionHistoryTest, MAYBE_FrameBackForward) { // Test that back/forward preserves POST data and document state in subframes. TEST_F(SessionHistoryTest, FrameFormBackForward) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // 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(test_server_.GetURL("files/session_history/frames.html")); ASSERT_TRUE(tab_->NavigateToURL(frames)); EXPECT_EQ(L"bot1", GetTabTitle()); @@ -275,15 +271,13 @@ TEST_F(SessionHistoryTest, FrameFormBackForward) { // across frames (ie, from frame -> nonframe). // Hangs, see http://crbug.com/45058. TEST_F(SessionHistoryTest, DISABLED_CrossFrameFormBackForward) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // 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(test_server_.GetURL("files/session_history/frames.html")); ASSERT_TRUE(tab_->NavigateToURL(frames)); EXPECT_EQ(L"bot1", GetTabTitle()); @@ -321,15 +315,13 @@ TEST_F(SessionHistoryTest, DISABLED_CrossFrameFormBackForward) { // Test that back/forward entries are created for reference fragment // navigations. Bug 730379. TEST_F(SessionHistoryTest, FragmentBackForward) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // 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(test_server_.GetURL("files/session_history/fragment.html")); ASSERT_TRUE(tab_->NavigateToURL(fragment)); EXPECT_EQ(L"fragment", GetTabTitle()); EXPECT_EQ(fragment, GetTabURL()); @@ -368,7 +360,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(test_server_.GetURL("files/session_history/bot3.html")); ASSERT_TRUE(tab_->NavigateToURL(bot3)); EXPECT_EQ(L"bot3", GetTabTitle()); EXPECT_EQ(bot3, GetTabURL()); @@ -394,24 +386,22 @@ TEST_F(SessionHistoryTest, FragmentBackForward) { // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). TEST_F(SessionHistoryTest, FLAKY_JavascriptHistory) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // 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"))); + test_server_.GetURL("files/session_history/bot1.html"))); EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot2.html"))); + test_server_.GetURL("files/session_history/bot2.html"))); EXPECT_EQ(L"bot2", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + test_server_.GetURL("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, bot2, *bot3] @@ -443,7 +433,7 @@ TEST_F(SessionHistoryTest, FLAKY_JavascriptHistory) { EXPECT_EQ(L"bot1", GetTabTitle()); ASSERT_TRUE(tab_->NavigateToURL( - server->TestServerPage("files/session_history/bot3.html"))); + test_server_.GetURL("files/session_history/bot3.html"))); EXPECT_EQ(L"bot3", GetTabTitle()); // history is [blank, bot1, *bot3] @@ -476,13 +466,11 @@ TEST_F(SessionHistoryTest, FLAKY_JavascriptHistory) { // This test is failing consistently. See http://crbug.com/22560 TEST_F(SessionHistoryTest, FAILS_LocationReplace) { + ASSERT_TRUE(test_server_.Start()); + // Test that using location.replace doesn't leave the title of the old page // visible. - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - - ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( + ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL( "files/session_history/replace.html?no-title.html"))); EXPECT_EQ(L"", GetTabTitle()); } @@ -505,11 +493,9 @@ TEST_F(SessionHistoryTest, FLAKY_HistorySearchXSS) { } TEST_F(SessionHistoryTest, LocationChangeInSubframe) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server.get()); + ASSERT_TRUE(test_server_.Start()); - ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( + ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL( "files/session_history/location_redirect.html"))); EXPECT_EQ(L"Default Title", GetTabTitle()); @@ -522,23 +508,21 @@ TEST_F(SessionHistoryTest, LocationChangeInSubframe) { } TEST_F(SessionHistoryTest, HistoryLength) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server.get()); + ASSERT_TRUE(test_server_.Start()); int length; ASSERT_TRUE(tab_->ExecuteAndExtractInt( L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(1, length); - ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage("files/title1.html"))); + ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL("files/title1.html"))); ASSERT_TRUE(tab_->ExecuteAndExtractInt( L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(2, length); // Now test that history.length is updated when the navigation is committed. - ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( + ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL( "files/session_history/record_length.html"))); ASSERT_TRUE(tab_->ExecuteAndExtractInt( L"", L"domAutomationController.send(history.length)", &length)); @@ -551,7 +535,7 @@ TEST_F(SessionHistoryTest, HistoryLength) { ASSERT_TRUE(tab_->GoBack()); // Ensure history.length is properly truncated. - ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage("files/title2.html"))); + ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL("files/title2.html"))); ASSERT_TRUE(tab_->ExecuteAndExtractInt( L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(2, length); diff --git a/chrome/browser/sessions/session_restore_uitest.cc b/chrome/browser/sessions/session_restore_uitest.cc index 068a350..df29c13 100644 --- a/chrome/browser/sessions/session_restore_uitest.cc +++ b/chrome/browser/sessions/session_restore_uitest.cc @@ -144,11 +144,11 @@ TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { // are given appropriate max page IDs, so that going back to a restored // cross-site page and then forward again works. (Bug 1204135) TEST_F(SessionRestoreUITest, RestoresCrossSiteForwardAndBackwardNavs) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL cross_site_url(server->TestServerPage("files/title2.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + + GURL cross_site_url(test_server.GetURL("files/title2.html")); // Visit URLs on different sites. NavigateToURL(url1_); diff --git a/chrome/browser/ssl/ssl_browser_tests.cc b/chrome/browser/ssl/ssl_browser_tests.cc index 284d6ac..54abc50 100644 --- a/chrome/browser/ssl/ssl_browser_tests.cc +++ b/chrome/browser/ssl/ssl_browser_tests.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/time.h" +#include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" @@ -15,26 +16,20 @@ #include "net/base/cert_status_flags.h" #include "net/test/test_server.h" -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); class SSLUITest : public InProcessBrowserTest { public: - SSLUITest() { + SSLUITest() + : https_server_(net::TestServer::TYPE_HTTPS, FilePath(kDocRoot)), + https_server_expired_(net::TestServer::TYPE_HTTPS_EXPIRED_CERTIFICATE, + FilePath(kDocRoot)), + https_server_mismatched_( + net::TestServer::TYPE_HTTPS_MISMATCHED_HOSTNAME, + FilePath(kDocRoot)) { EnableDOMAutomation(); } - scoped_refptr<net::HTTPTestServer> PlainServer() { - return net::HTTPTestServer::CreateServer(kDocRoot); - } - - scoped_refptr<net::HTTPSTestServer> GoodCertServer() { - return net::HTTPSTestServer::CreateGoodServer(kDocRoot); - } - - scoped_refptr<net::HTTPSTestServer> BadCertServer() { - return net::HTTPSTestServer::CreateExpiredServer(kDocRoot); - } - void CheckAuthenticatedState(TabContents* tab, bool displayed_insecure_content) { NavigationEntry* entry = tab->controller().GetActiveEntry(); @@ -116,17 +111,20 @@ class SSLUITest : public InProcessBrowserTest { ui_test_utils::WaitForNavigation(&(tab->controller())); } + net::TestServer https_server_; + net::TestServer https_server_expired_; + net::TestServer https_server_mismatched_; + private: DISALLOW_COPY_AND_ASSIGN(SSLUITest); }; // Visits a regular page over http. IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { - scoped_refptr<net::HTTPTestServer> server = PlainServer(); - ASSERT_TRUE(server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), - server->TestServerPage("files/ssl/google.html")); + test_server()->GetURL("files/ssl/google.html")); CheckUnauthenticatedState(browser()->GetSelectedTabContents()); } @@ -136,35 +134,31 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { // TODO(jcampan): test that bad HTTPS content is blocked (otherwise we'll give // the secure cookies away!). IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/page_with_unsafe_contents.html")); + test_server()->GetURL("files/ssl/page_with_unsafe_contents.html")); CheckUnauthenticatedState(browser()->GetSelectedTabContents()); } // Visits a page over OK https: IN_PROC_BROWSER_TEST_F(SSLUITest, TestOKHTTPS) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); ui_test_utils::NavigateToURL(browser(), - https_server->TestServerPage("files/ssl/google.html")); + https_server_.GetURL("files/ssl/google.html")); CheckAuthenticatedState(browser()->GetSelectedTabContents(), false); } // Visits a page with https error and proceed: IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndProceed) { - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_expired_.Start()); ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/google.html")); + https_server_expired_.GetURL("files/ssl/google.html")); TabContents* tab = browser()->GetSelectedTabContents(); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, @@ -188,23 +182,20 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndProceed) { FLAKY_TestHTTPSExpiredCertAndDontProceed #endif IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSExpiredCertAndDontProceed) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); // First navigate to an OK page. ui_test_utils::NavigateToURL(browser(), - good_https_server->TestServerPage("files/ssl/google.html")); + https_server_.GetURL("files/ssl/google.html")); TabContents* tab = browser()->GetSelectedTabContents(); NavigationEntry* entry = tab->controller().GetActiveEntry(); ASSERT_TRUE(entry); GURL cross_site_url = - bad_https_server->TestServerPage("files/ssl/google.html"); + https_server_expired_.GetURL("files/ssl/google.html"); // Change the host name from 127.0.0.1 to localhost so it triggers a // cross-site navigation so we can test http://crbug.com/5800 is gone. ASSERT_EQ("127.0.0.1", cross_site_url.host()); @@ -230,27 +221,25 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSExpiredCertAndDontProceed) { // Try to navigate to a new page. (to make sure bug 5800 is fixed). ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/google.html")); + test_server()->GetURL("files/ssl/google.html")); CheckUnauthenticatedState(tab); } // Visits a page with https error and then goes back using Browser::GoBack. IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndGoBackViaButton) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); // First navigate to an HTTP page. ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/google.html")); + test_server()->GetURL("files/ssl/google.html")); TabContents* tab = browser()->GetSelectedTabContents(); NavigationEntry* entry = tab->controller().GetActiveEntry(); ASSERT_TRUE(entry); // Now go to a bad HTTPS page that shows an interstitial. ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/google.html")); + https_server_expired_.GetURL("files/ssl/google.html")); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, true); // Interstitial showing @@ -265,21 +254,19 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndGoBackViaButton) { // Visits a page with https error and then goes back using GoToOffset. // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestHTTPSExpiredCertAndGoBackViaMenu) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); // First navigate to an HTTP page. ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/google.html")); + test_server()->GetURL("files/ssl/google.html")); TabContents* tab = browser()->GetSelectedTabContents(); NavigationEntry* entry = tab->controller().GetActiveEntry(); ASSERT_TRUE(entry); // Now go to a bad HTTPS page that shows an interstitial. ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/google.html")); + https_server_expired_.GetURL("files/ssl/google.html")); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, true); // Interstitial showing @@ -294,19 +281,17 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestHTTPSExpiredCertAndGoBackViaMenu) { // Visits a page with https error and then goes forward using GoToOffset. // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestHTTPSExpiredCertAndGoForward) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); // First navigate to two HTTP pages. ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/google.html")); + test_server()->GetURL("files/ssl/google.html")); TabContents* tab = browser()->GetSelectedTabContents(); NavigationEntry* entry1 = tab->controller().GetActiveEntry(); ASSERT_TRUE(entry1); ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/blank_page.html")); + test_server()->GetURL("files/ssl/blank_page.html")); NavigationEntry* entry2 = tab->controller().GetActiveEntry(); ASSERT_TRUE(entry2); @@ -319,7 +304,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestHTTPSExpiredCertAndGoForward) { // Now go to a bad HTTPS page that shows an interstitial. ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/google.html")); + https_server_expired_.GetURL("files/ssl/google.html")); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, true); // Interstitial showing @@ -340,42 +325,22 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestHTTPSExpiredCertAndGoForward) { // does not cause any problems (it was causing a crasher, see // http://crbug.com/19941). IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSErrorWithNoNavEntry) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); - - // Load a page with a link that opens a new window (therefore with no history - // and no navigation entries). - ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/page_with_blank_target.html")); - - bool success = false; + ASSERT_TRUE(https_server_expired_.Start()); ui_test_utils::WindowedNotificationObserver<NavigationController> load_stop_signal(NotificationType::LOAD_STOP, NULL); + Browser* used_browser = NULL; + TabContents* tab_contents = browser()->AddTabWithURL( + https_server_expired_.GetURL("files/ssl/google.htm"), GURL(), + PageTransition::TYPED, -1, TabStripModel::ADD_SELECTED, + NULL, std::string(), &used_browser); + load_stop_signal.WaitFor(&(tab_contents->controller())); - // Simulate clicking the link (and therefore navigating to that new page). - // This will causes a new tab to be created. - EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( - browser()->GetSelectedTabContents()->render_view_host(), std::wstring(), - L"window.domAutomationController.send(navigateInNewTab());", - &success)); - EXPECT_TRUE(success); - - // By the time we got a response, the new tab should have been created and be - // the selected tab. - EXPECT_EQ(2, browser()->tab_count()); - EXPECT_EQ(1, browser()->selected_index()); - - // Since the navigation was initiated by the renderer (when we clicked on the - // link) and since the main page network request failed, we won't get a - // navigation entry committed. So we'll just wait for the load to stop. - load_stop_signal.WaitFor( - &(browser()->GetSelectedTabContents()->controller())); + // Verify our assumption that there was no prior navigation. + EXPECT_FALSE(browser()->command_updater()->IsCommandEnabled(IDC_BACK)); // We should have an interstitial page showing. - ASSERT_TRUE(browser()->GetSelectedTabContents()->interstitial_page()); + ASSERT_TRUE(tab_contents->interstitial_page()); } // @@ -384,13 +349,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSErrorWithNoNavEntry) { // Visits a page that displays insecure content. IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContent) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); // Load a page that displays insecure content. - ui_test_utils::NavigateToURL(browser(), https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_displays_insecure_content.html")); CheckAuthenticatedState(browser()->GetSelectedTabContents(), true); @@ -400,12 +363,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContent) { // content warnings by randomizing location.hash. // Based on http://crbug.com/8706 IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecuredContentRandomizeHash) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); - ui_test_utils::NavigateToURL(browser(), https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_runs_insecure_content.html")); CheckAuthenticationBrokenState(browser()->GetSelectedTabContents(), 0, true, @@ -417,12 +378,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecuredContentRandomizeHash) { // - images and scripts are filtered out entirely // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestUnsafeContents) { - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); - ui_test_utils::NavigateToURL(browser(), good_https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_with_unsafe_contents.html")); TabContents* tab = browser()->GetSelectedTabContents(); @@ -456,12 +415,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestUnsafeContents) { // Visits a page with insecure content loaded by JS (after the initial page // load). IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentLoadedFromJS) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); - ui_test_utils::NavigateToURL(browser(), https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_with_dynamic_insecure_content.html")); TabContents* tab = browser()->GetSelectedTabContents(); @@ -481,13 +438,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentLoadedFromJS) { // one that doesn't. The test checks that we do not propagate the insecure // content state from one to the other. IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); ui_test_utils::NavigateToURL(browser(), - https_server->TestServerPage("files/ssl/blank_page.html")); + https_server_.GetURL("files/ssl/blank_page.html")); TabContents* tab1 = browser()->GetSelectedTabContents(); @@ -495,7 +450,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) { CheckAuthenticatedState(tab1, false); // Create a new tab. - GURL url = https_server->TestServerPage( + GURL url = https_server_.GetURL( "files/ssl/page_displays_insecure_content.html"); TabContents* tab2 = browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, 0, TabStripModel::ADD_SELECTED, @@ -513,13 +468,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) { // that doesn't. The test checks that we propagate the insecure content state // from one to the other. IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); ui_test_utils::NavigateToURL(browser(), - https_server->TestServerPage("files/ssl/blank_page.html")); + https_server_.GetURL("files/ssl/blank_page.html")); TabContents* tab1 = browser()->GetSelectedTabContents(); @@ -528,7 +481,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) { // Create a new tab. GURL url = - https_server->TestServerPage("files/ssl/page_runs_insecure_content.html"); + https_server_.GetURL("files/ssl/page_runs_insecure_content.html"); TabContents* tab2 = browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, 0, TabStripModel::ADD_SELECTED, tab1->GetSiteInstance(), std::string(), NULL); @@ -546,19 +499,17 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) { // referencing that same image over http (hoping it is coming from the webcore // memory cache). IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysCachedInsecureContent) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); - ui_test_utils::NavigateToURL(browser(), http_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), test_server()->GetURL( "files/ssl/page_displays_insecure_content.html")); TabContents* tab = browser()->GetSelectedTabContents(); CheckUnauthenticatedState(tab); // Load again but over SSL. It should be marked as displaying insecure // content (even though the image comes from the WebCore memory cache). - ui_test_utils::NavigateToURL(browser(), https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_displays_insecure_content.html")); CheckAuthenticatedState(tab, true); } @@ -567,19 +518,17 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysCachedInsecureContent) { // referencing that same script over http (hoping it is coming from the webcore // memory cache). IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsCachedInsecureContent) { - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/page_runs_insecure_content.html")); + test_server()->GetURL("files/ssl/page_runs_insecure_content.html")); TabContents* tab = browser()->GetSelectedTabContents(); CheckUnauthenticatedState(tab); // Load again but over SSL. It should be marked as displaying insecure // content (even though the image comes from the WebCore memory cache). - ui_test_utils::NavigateToURL(browser(), https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_runs_insecure_content.html")); CheckAuthenticationBrokenState(tab, 0, true, false); } @@ -594,45 +543,32 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsCachedInsecureContent) { // This test ensures the CN invalid status does not 'stick' to a certificate // (see bug #1044942) and that it depends on the host-name. IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestCNInvalidStickiness) { - const std::string kLocalHost = "localhost"; - scoped_refptr<net::HTTPSTestServer> https_server = - net::HTTPSTestServer::CreateMismatchedServer(kDocRoot); - ASSERT_TRUE(https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_mismatched_.Start()); // First we hit the server with hostname, this generates an invalid policy // error. ui_test_utils::NavigateToURL(browser(), - https_server->TestServerPage("files/ssl/google.html")); + https_server_mismatched_.GetURL("files/ssl/google.html")); // We get an interstitial page as a result. TabContents* tab = browser()->GetSelectedTabContents(); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, false, true); // Interstitial showing. - ProceedThroughInterstitial(tab); - CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, false, false); // No interstitial showing. // Now we try again with the right host name this time. - - // Let's change the host-name in the url. - GURL url = https_server->TestServerPage("files/ssl/google.html"); - std::string::size_type hostname_index = url.spec().find(kLocalHost); - ASSERT_TRUE(hostname_index != std::string::npos); // Test sanity check. - std::string new_url; - new_url.append(url.spec().substr(0, hostname_index)); - new_url.append(net::TestServerLauncher::kHostName); - new_url.append(url.spec().substr(hostname_index + kLocalHost.size())); - - ui_test_utils::NavigateToURL(browser(), GURL(new_url)); + GURL url(https_server_.GetURL("files/ssl/google.html")); + ui_test_utils::NavigateToURL(browser(), url); // Security state should be OK. CheckAuthenticatedState(tab, false); // Now try again the broken one to make sure it is still broken. ui_test_utils::NavigateToURL(browser(), - https_server->TestServerPage("files/ssl/google.html")); + https_server_mismatched_.GetURL("files/ssl/google.html")); // Since we OKed the interstitial last time, we get right to the page. CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, @@ -641,11 +577,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestCNInvalidStickiness) { // Test that navigating to a #ref does not change a bad security state. IN_PROC_BROWSER_TEST_F(SSLUITest, TestRefNavigation) { - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_expired_.Start()); ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/page_with_refs.html")); + https_server_expired_.GetURL("files/ssl/page_with_refs.html")); TabContents* tab = browser()->GetSelectedTabContents(); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, @@ -659,7 +594,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRefNavigation) { // Now navigate to a ref in the page, the security state should not have // changed. ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/page_with_refs.html#jp")); + https_server_expired_.GetURL("files/ssl/page_with_refs.html#jp")); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, false); // No interstitial showing. @@ -670,13 +605,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRefNavigation) { // TODO(jcampan): http://crbug.com/2136 disabled because the popup is not // opened as it is not initiated by a user gesture. IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/page_with_unsafe_popup.html")); + test_server()->GetURL("files/ssl/page_with_unsafe_popup.html")); TabContents* tab1 = browser()->GetSelectedTabContents(); // It is probably overkill to add a notification for a popup-opening, let's @@ -692,8 +625,8 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) { // Let's add another tab to make sure the browser does not exit when we close // the first tab. - GURL url = http_server->TestServerPage("files/ssl/google.html"); Browser* browser_used = NULL; + GURL url = test_server()->GetURL("files/ssl/google.html"); TabContents* tab2 = browser()->AddTabWithURL( url, GURL(), PageTransition::TYPED, 0, TabStripModel::ADD_SELECTED, NULL, std::string(), &browser_used); @@ -709,13 +642,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) { // Visit a page over bad https that is a redirect to a page with good https. // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectBadToGoodHTTPS) { - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); - GURL url1 = bad_https_server->TestServerPage("server-redirect?"); - GURL url2 = good_https_server->TestServerPage("files/ssl/google.html"); + GURL url1 = https_server_expired_.GetURL("server-redirect?"); + GURL url2 = https_server_.GetURL("files/ssl/google.html"); ui_test_utils::NavigateToURL(browser(), GURL(url1.spec() + url2.spec())); @@ -733,13 +664,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectBadToGoodHTTPS) { // Visit a page over good https that is a redirect to a page with bad https. // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectGoodToBadHTTPS) { - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); - GURL url1 = good_https_server->TestServerPage("server-redirect?"); - GURL url2 = bad_https_server->TestServerPage("files/ssl/google.html"); + GURL url1 = https_server_.GetURL("server-redirect?"); + GURL url2 = https_server_expired_.GetURL("files/ssl/google.html"); ui_test_utils::NavigateToURL(browser(), GURL(url1.spec() + url2.spec())); TabContents* tab = browser()->GetSelectedTabContents(); @@ -754,17 +683,15 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectGoodToBadHTTPS) { // Visit a page over http that is a redirect to a page with good HTTPS. IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPToGoodHTTPS) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); TabContents* tab = browser()->GetSelectedTabContents(); // HTTP redirects to good HTTPS. - GURL http_url = http_server->TestServerPage("server-redirect?"); + GURL http_url = test_server()->GetURL("server-redirect?"); GURL good_https_url = - good_https_server->TestServerPage("files/ssl/google.html"); + https_server_.GetURL("files/ssl/google.html"); ui_test_utils::NavigateToURL(browser(), GURL(http_url.spec() + good_https_url.spec())); @@ -773,16 +700,14 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPToGoodHTTPS) { // Visit a page over http that is a redirect to a page with bad HTTPS. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectHTTPToBadHTTPS) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_expired_.Start()); TabContents* tab = browser()->GetSelectedTabContents(); - GURL http_url = http_server->TestServerPage("server-redirect?"); + GURL http_url = test_server()->GetURL("server-redirect?"); GURL bad_https_url = - bad_https_server->TestServerPage("files/ssl/google.html"); + https_server_expired_.GetURL("files/ssl/google.html"); ui_test_utils::NavigateToURL(browser(), GURL(http_url.spec() + bad_https_url.spec())); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, @@ -798,13 +723,11 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectHTTPToBadHTTPS) { // we don't keep the secure state). // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestRedirectHTTPSToHTTP) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> https_server = GoodCertServer(); - ASSERT_TRUE(https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); - GURL https_url = https_server->TestServerPage("server-redirect?"); - GURL http_url = http_server->TestServerPage("files/ssl/google.html"); + GURL https_url = https_server_.GetURL("server-redirect?"); + GURL http_url = test_server()->GetURL("files/ssl/google.html"); ui_test_utils::NavigateToURL(browser(), GURL(https_url.spec() + http_url.spec())); @@ -833,16 +756,13 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestConnectToBadPort) { // - navigate to HTTP (expect insecure content), then back // Disabled, http://crbug.com/18626. IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestGoodFrameNavigation) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); TabContents* tab = browser()->GetSelectedTabContents(); ui_test_utils::NavigateToURL(browser(), - good_https_server->TestServerPage("files/ssl/top_frame.html")); + https_server_.GetURL("files/ssl/top_frame.html")); CheckAuthenticatedState(tab, false); @@ -905,14 +825,12 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestGoodFrameNavigation) { // - navigate to an OK HTTPS frame (expected to be still authentication broken). // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestBadFrameNavigation) { - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); TabContents* tab = browser()->GetSelectedTabContents(); ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/top_frame.html")); + https_server_expired_.GetURL("files/ssl/top_frame.html")); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, true); // Interstitial showing @@ -944,16 +862,13 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestBadFrameNavigation) { FLAKY_TestUnauthenticatedFrameNavigation #endif IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestUnauthenticatedFrameNavigation) { - scoped_refptr<net::HTTPTestServer> http_server = PlainServer(); - ASSERT_TRUE(http_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(test_server()->Start()); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); TabContents* tab = browser()->GetSelectedTabContents(); ui_test_utils::NavigateToURL(browser(), - http_server->TestServerPage("files/ssl/top_frame.html")); + test_server()->GetURL("files/ssl/top_frame.html")); CheckUnauthenticatedState(tab); // Now navigate inside the frame to a secure HTTPS frame. @@ -992,14 +907,12 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestUnauthenticatedFrameNavigation) { // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestUnsafeContentsInWorkerFiltered) { - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); // This page will spawn a Worker which will try to load content from // BadCertServer. - ui_test_utils::NavigateToURL(browser(), good_https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_with_unsafe_worker.html")); TabContents* tab = browser()->GetSelectedTabContents(); // Expect Worker not to load insecure content. @@ -1010,15 +923,13 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestUnsafeContentsInWorkerFiltered) { // Marked as flaky, see bug 40932. IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestUnsafeContentsInWorker) { - scoped_refptr<net::HTTPSTestServer> good_https_server = GoodCertServer(); - ASSERT_TRUE(good_https_server.get() != NULL); - scoped_refptr<net::HTTPSTestServer> bad_https_server = BadCertServer(); - ASSERT_TRUE(bad_https_server.get() != NULL); + ASSERT_TRUE(https_server_.Start()); + ASSERT_TRUE(https_server_expired_.Start()); // Navigate to an unsafe site. Proceed with interstitial page to indicate // the user approves the bad certificate. ui_test_utils::NavigateToURL(browser(), - bad_https_server->TestServerPage("files/ssl/blank_page.html")); + https_server_expired_.GetURL("files/ssl/blank_page.html")); TabContents* tab = browser()->GetSelectedTabContents(); CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, true); // Interstitial showing @@ -1029,7 +940,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, FLAKY_TestUnsafeContentsInWorker) { // Navigate to safe page that has Worker loading unsafe content. // Expect content to load but be marked as auth broken due to running insecure // content. - ui_test_utils::NavigateToURL(browser(), good_https_server->TestServerPage( + ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( "files/ssl/page_with_unsafe_worker.html")); CheckWorkerLoadResult(tab, true); // Worker loads insecure content CheckAuthenticationBrokenState(tab, 0, true, false); diff --git a/chrome/browser/sync/glue/http_bridge_unittest.cc b/chrome/browser/sync/glue/http_bridge_unittest.cc index 4d065f4..db87c81 100644 --- a/chrome/browser/sync/glue/http_bridge_unittest.cc +++ b/chrome/browser/sync/glue/http_bridge_unittest.cc @@ -15,7 +15,7 @@ using browser_sync::HttpBridge; namespace { // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); } // Lazy getter for TestURLRequestContext instances. @@ -39,7 +39,8 @@ class TestURLRequestContextGetter : public URLRequestContextGetter { class HttpBridgeTest : public testing::Test { public: HttpBridgeTest() - : fake_default_request_context_getter_(NULL), + : test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)), + fake_default_request_context_getter_(NULL), io_thread_(ChromeThread::IO) { } @@ -88,6 +89,8 @@ class HttpBridgeTest : public testing::Test { return fake_default_request_context_getter_; } + net::TestServer test_server_; + private: // A make-believe "default" request context, as would be returned by // Profile::GetDefaultRequestContext(). Created lazily by BuildBridge. @@ -175,14 +178,12 @@ TEST_F(HttpBridgeTest, TestMakeSynchronousPostShunted) { // Full round-trip test of the HttpBridge, using default UA string and // no request cookies. TEST_F(HttpBridgeTest, TestMakeSynchronousPostLiveWithPayload) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<HttpBridge> http_bridge(BuildBridge()); std::string payload = "this should be echoed back"; - GURL echo = server->TestServerPage("echo"); + GURL echo = test_server_.GetURL("echo"); http_bridge->SetURL(echo.spec().c_str(), echo.IntPort()); http_bridge->SetPostPayload("application/x-www-form-urlencoded", payload.length() + 1, payload.c_str()); @@ -200,12 +201,11 @@ TEST_F(HttpBridgeTest, TestMakeSynchronousPostLiveWithPayload) { // Full round-trip test of the HttpBridge, using custom UA string TEST_F(HttpBridgeTest, TestMakeSynchronousPostLiveComprehensive) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<HttpBridge> http_bridge(BuildBridge()); - GURL echo_header = server->TestServerPage("echoall"); + GURL echo_header = test_server_.GetURL("echoall"); http_bridge->SetUserAgent("bob"); http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); @@ -228,12 +228,11 @@ TEST_F(HttpBridgeTest, TestMakeSynchronousPostLiveComprehensive) { } TEST_F(HttpBridgeTest, TestExtraRequestHeaders) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<HttpBridge> http_bridge(BuildBridge()); - GURL echo_header = server->TestServerPage("echoall"); + GURL echo_header = test_server_.GetURL("echoall"); http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); http_bridge->SetExtraRequestHeaders("test:fnord"); @@ -257,12 +256,11 @@ TEST_F(HttpBridgeTest, TestExtraRequestHeaders) { } TEST_F(HttpBridgeTest, TestResponseHeader) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<HttpBridge> http_bridge(BuildBridge()); - GURL echo_header = server->TestServerPage("echoall"); + GURL echo_header = test_server_.GetURL("echoall"); http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); std::string test_payload = "###TEST PAYLOAD###"; diff --git a/chrome/browser/tab_contents/view_source_uitest.cc b/chrome/browser/tab_contents/view_source_uitest.cc index 41cd428..654b747 100644 --- a/chrome/browser/tab_contents/view_source_uitest.cc +++ b/chrome/browser/tab_contents/view_source_uitest.cc @@ -11,11 +11,13 @@ namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const char kTestHtml[] = "files/viewsource/test.html"; class ViewSourceTest : public UITest { protected: - ViewSourceTest() : test_html_("files/viewsource/test.html") { + ViewSourceTest() + : test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { } bool IsMenuCommandEnabled(int command) { @@ -30,22 +32,21 @@ class ViewSourceTest : public UITest { } protected: - std::string test_html_; + net::TestServer test_server_; }; // This test renders a page in view-source and then checks to see if a cookie // set in the html was set successfully (it shouldn't because we rendered the // page in view source) TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + std::string cookie = "viewsource_cookie"; std::string cookie_data = "foo"; // First we navigate to our view-source test page. GURL url(chrome::kViewSourceScheme + std::string(":") + - server->TestServerPage(test_html_).spec()); + test_server_.GetURL(kTestHtml).spec()); scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); @@ -62,12 +63,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<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); // First we navigate to google.html. - GURL url(server->TestServerPage(test_html_)); + GURL url(test_server_.GetURL(kTestHtml)); NavigateToURL(url); // Then we navigate to the same url but with the "view-source:" prefix. @@ -82,11 +81,9 @@ TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { // Make sure that when looking at the actual page, we can select "View Source" // from the menu. TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); - GURL url(server->TestServerPage(test_html_)); + GURL url(test_server_.GetURL(kTestHtml)); NavigateToURL(url); EXPECT_TRUE(IsMenuCommandEnabled(IDC_VIEW_SOURCE)); @@ -95,12 +92,10 @@ TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) { // Make sure that when looking at the page source, we can't select "View Source" // from the menu. TEST_F(ViewSourceTest, ViewSourceInMenuDisabledWhileViewingSource) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + - server->TestServerPage(test_html_).spec()); + test_server_.GetURL(kTestHtml).spec()); NavigateToURL(url_viewsource); EXPECT_FALSE(IsMenuCommandEnabled(IDC_VIEW_SOURCE)); diff --git a/chrome/browser/tab_restore_uitest.cc b/chrome/browser/tab_restore_uitest.cc index 7c2c9da..fcd73fb 100644 --- a/chrome/browser/tab_restore_uitest.cc +++ b/chrome/browser/tab_restore_uitest.cc @@ -455,12 +455,12 @@ TEST_F(TabRestoreUITest, FLAKY_RestoreIntoSameWindow) { // Tests that a duplicate history entry is not created when we restore a page // to an existing SiteInstance. (Bug 1230446) TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL http_url1(server->TestServerPage("files/title1.html")); - GURL http_url2(server->TestServerPage("files/title2.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + + GURL http_url1(test_server.GetURL("files/title1.html")); + GURL http_url2(test_server.GetURL("files/title2.html")); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); @@ -502,12 +502,12 @@ TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { // are given appropriate max page IDs, even if the renderer for the entry // already exists. (Bug 1204135) TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL http_url1(server->TestServerPage("files/title1.html")); - GURL http_url2(server->TestServerPage("files/title2.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + + GURL http_url1(test_server.GetURL("files/title1.html")); + GURL http_url2(test_server.GetURL("files/title2.html")); scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser_proxy.get()); @@ -644,11 +644,11 @@ TEST_F(TabRestoreUITest, RestoreTabWithSpecialURL) { // Restore tab with special URL in its navigation history, go back to that // entry and see that it loads properly. See http://crbug.com/31905 TEST_F(TabRestoreUITest, RestoreTabWithSpecialURLOnBack) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server.get()); - const GURL http_url(server->TestServerPage("files/title1.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + + const GURL http_url(test_server.GetURL("files/title1.html")); scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); diff --git a/chrome/browser/views/find_bar_host_interactive_uitest.cc b/chrome/browser/views/find_bar_host_interactive_uitest.cc index 991338c..f866f09 100644 --- a/chrome/browser/views/find_bar_host_interactive_uitest.cc +++ b/chrome/browser/views/find_bar_host_interactive_uitest.cc @@ -24,7 +24,6 @@ namespace { // The delay waited after sending an OS simulated event. static const int kActionDelayMs = 500; -static const wchar_t kDocRoot[] = L"chrome/test/data"; static const char kSimplePage[] = "files/find_in_page/simple.html"; class FindInPageTest : public InProcessBrowserTest { @@ -89,12 +88,10 @@ class FindInPageTest : public InProcessBrowserTest { } // namespace IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page (tab A). - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); browser()->Find(); @@ -130,11 +127,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { } IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server()->Start()); - GURL url = server->TestServerPage("title1.html"); + GURL url = test_server()->GetURL("title1.html"); ui_test_utils::NavigateToURL(browser(), url); // Focus the location bar, open and close the find-in-page, focus should @@ -180,11 +175,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { return; #endif - net::HTTPTestServer* server = StartHTTPServer(); - ASSERT_TRUE(server); + ASSERT_TRUE(test_server()->Start()); // First we navigate to any page. - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server()->GetURL(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); gfx::NativeWindow window = browser()->window()->GetNativeHandle(); diff --git a/chrome/browser/views/find_bar_host_uitest.cc b/chrome/browser/views/find_bar_host_uitest.cc index a8a88ba..df4ea0e 100644 --- a/chrome/browser/views/find_bar_host_uitest.cc +++ b/chrome/browser/views/find_bar_host_uitest.cc @@ -25,11 +25,11 @@ const std::string kSimplePage = "404_is_enough_for_us.html"; // The find window should not change its location just because we open and close // a new tab. TEST_F(FindInPageControllerTest, FindMovesOnTabClose_Issue1343052) { - scoped_refptr<net::HTTPTestServer> server = - net::HTTPTestServer::CreateServer(L"chrome/test/data"); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); - GURL url = server->TestServerPage(kSimplePage); + GURL url = test_server.GetURL(kSimplePage); scoped_refptr<TabProxy> tabA(GetActiveTab()); ASSERT_TRUE(tabA.get()); ASSERT_TRUE(tabA->NavigateToURL(url)); diff --git a/chrome/common/net/url_fetcher_unittest.cc b/chrome/common/net/url_fetcher_unittest.cc index eba4983..a2fa09e 100644 --- a/chrome/common/net/url_fetcher_unittest.cc +++ b/chrome/common/net/url_fetcher_unittest.cc @@ -21,7 +21,7 @@ using base::TimeDelta; namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); class TestURLRequestContextGetter : public URLRequestContextGetter { public: @@ -431,22 +431,20 @@ void URLFetcherCancelTest::CancelRequest() { } TEST_F(URLFetcherTest, SameThreadsTest) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); // 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. - CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); + CreateFetcher(test_server.GetURL("defaultresponse")); MessageLoop::current()->Run(); } TEST_F(URLFetcherTest, DifferentThreadsTest) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); // 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 @@ -456,33 +454,34 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) { base::Thread t("URLFetcher test thread"); ASSERT_TRUE(t.Start()); t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, - GURL(server->TestServerPage("defaultresponse")))); + test_server.GetURL("defaultresponse"))); MessageLoop::current()->Run(); } TEST_F(URLFetcherPostTest, Basic) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - CreateFetcher(GURL(server->TestServerPage("echo"))); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + + CreateFetcher(test_server.GetURL("echo")); MessageLoop::current()->Run(); } TEST_F(URLFetcherHeadersTest, Headers) { - scoped_refptr<net::HTTPTestServer> server = - net::HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); - ASSERT_TRUE(NULL != server.get()); - CreateFetcher(GURL(server->TestServerPage("files/with-headers.html"))); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); + ASSERT_TRUE(test_server.Start()); + + CreateFetcher(test_server.GetURL("files/with-headers.html")); MessageLoop::current()->Run(); // The actual tests are in the URLFetcherHeadersTest fixture. } TEST_F(URLFetcherProtectTest, Overload) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("defaultresponse")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + + GURL url(test_server.GetURL("defaultresponse")); // Registers an entry for test url. It only allows 3 requests to be sent // in 200 milliseconds. @@ -497,10 +496,10 @@ TEST_F(URLFetcherProtectTest, Overload) { } TEST_F(URLFetcherProtectTest, ServerUnavailable) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("files/server-unavailable.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + + GURL url(test_server.GetURL("files/server-unavailable.html")); // Registers an entry for test url. The backoff time is calculated by: // new_backoff = 2.0 * old_backoff + 0 @@ -517,10 +516,10 @@ TEST_F(URLFetcherProtectTest, ServerUnavailable) { } TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("files/server-unavailable.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + + GURL url(test_server.GetURL("files/server-unavailable.html")); // Registers an entry for test url. The backoff time is calculated by: // new_backoff = 2.0 * old_backoff + 0 @@ -540,20 +539,19 @@ TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { - scoped_refptr<net::HTTPSTestServer> server = - net::HTTPSTestServer::CreateExpiredServer(kDocRoot); - ASSERT_TRUE(NULL != server.get()); - - CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_EXPIRED_CERTIFICATE, + FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + CreateFetcher(test_server.GetURL("defaultresponse")); MessageLoop::current()->Run(); } TEST_F(URLFetcherCancelTest, ReleasesContext) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("files/server-unavailable.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + + GURL url(test_server.GetURL("files/server-unavailable.html")); // Registers an entry for test url. The backoff time is calculated by: // new_backoff = 2.0 * old_backoff + 0 @@ -577,10 +575,10 @@ TEST_F(URLFetcherCancelTest, ReleasesContext) { } TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); - GURL url = GURL(server->TestServerPage("files/server-unavailable.html")); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); + + GURL url(test_server.GetURL("files/server-unavailable.html")); // Register an entry for test url. // diff --git a/chrome/renderer/external_extension_uitest.cc b/chrome/renderer/external_extension_uitest.cc index 4cdfe19..064f768 100644 --- a/chrome/renderer/external_extension_uitest.cc +++ b/chrome/renderer/external_extension_uitest.cc @@ -14,49 +14,32 @@ class SearchProviderTest : public UITest { protected: SearchProviderTest(); - virtual ~SearchProviderTest(); void TestIsSearchProviderInstalledForHost( TabProxy* tab, const char* host, const char* expected_result); - scoped_refptr<net::HTTPTestServer> server_; - - private: - DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); + net::TestServer test_server_; }; SearchProviderTest::SearchProviderTest() - : server_(net::HTTPTestServer::CreateServer(L"chrome/test/data")) { - if (!server_) - return; - + : test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { // Enable the search provider additions. launch_arguments_.AppendSwitch(switches::kEnableSearchProviderApiV2); // Map all hosts to our local server. - GURL server_url = server_->TestServerPage(""); - std::string host_rule = "MAP * "; - host_rule.append(server_url.host()); - if (server_url.has_port()) { - host_rule.append(":"); - host_rule.append(server_url.port()); - } + std::string host_rule("MAP * " + test_server_.host_port_pair().ToString()); launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule); } -SearchProviderTest::~SearchProviderTest() { - server_->Stop(); -} - void SearchProviderTest::TestIsSearchProviderInstalledForHost( TabProxy* tab, const char* host, const char* expected_result) { - ASSERT_TRUE(server_); GURL local_url = - server_->TestServerPage("files/is_search_provider_installed.html"); + test_server_.GetURL("files/is_search_provider_installed.html"); GURL test_url(std::string("http://") + host + local_url.path() + "#" + expected_result); EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); @@ -74,9 +57,11 @@ void SearchProviderTest::TestIsSearchProviderInstalledForHost( EXPECT_STREQ("1\n", value.c_str()); } +// Verify the default search provider, other installed search provider, and +// one not installed as well. TEST_F(SearchProviderTest, DISABLED_TestIsSearchProviderInstalled) { - // Verify the default search provider, other installed search provider, and - // one not installed as well. + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); TestIsSearchProviderInstalledForHost(tab, "www.google.com", "2"); diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index 7f530bc..080f96a 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -968,10 +968,10 @@ TEST_F(ExternalTabUITest, FLAKY_TabPostMessage) { } TEST_F(ExternalTabUITest, FLAKY_PostMessageTarget) { - const wchar_t kDocRoot[] = L"chrome/test/data/external_tab"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_THAT(server.get(), testing::NotNull()); + net::TestServer test_server( + net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data/external_tab"))); + ASSERT_TRUE(test_server.Start()); scoped_refptr<TabProxy> tab; TimedMessageLoopRunner loop(MessageLoop::current()); diff --git a/chrome/test/automation/dom_automation_browsertest.cc b/chrome/test/automation/dom_automation_browsertest.cc index dbaa1ef..48192c4 100644 --- a/chrome/test/automation/dom_automation_browsertest.cc +++ b/chrome/test/automation/dom_automation_browsertest.cc @@ -32,7 +32,7 @@ class DOMAutomationTest : public InProcessBrowserTest { typedef DOMElementProxy::By By; IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindByXPath) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("find_elements/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -78,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindByXPath) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindBySelectors) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("find_elements/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -122,7 +122,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindBySelectors) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindByText) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("find_elements/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -170,7 +170,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, FindByText) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitFor1VisibleElement) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -181,7 +181,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitFor1VisibleElement) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitForElementsToDisappear) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -192,7 +192,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, WaitForElementsToDisappear) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, EnsureAttributeEventuallyMatches) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("wait/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -203,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, EnsureAttributeEventuallyMatches) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Frames) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("frames/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -243,7 +243,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Frames) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Events) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("events/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); @@ -271,7 +271,7 @@ IN_PROC_BROWSER_TEST_F(DOMAutomationTest, Events) { } IN_PROC_BROWSER_TEST_F(DOMAutomationTest, StringEscape) { - ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(test_server()->Start()); ui_test_utils::NavigateToURL(browser(), GetTestURL("string_escape/test.html")); DOMElementProxyRef main_doc = ui_test_utils::GetActiveDOMDocument(browser()); diff --git a/chrome/test/data/file_client_redirect.html b/chrome/test/data/file_client_redirect.html index 61dc261..90ec0e8 100644 --- a/chrome/test/data/file_client_redirect.html +++ b/chrome/test/data/file_client_redirect.html @@ -1,8 +1,8 @@ <!-- -Test file for empty referrer client redirects, e.g https>http, file>http. +Test file for empty referrer client redirects, e.g https>http, file>http. See ClientEmptyReferrerRedirectTest in redirect_uitest.cc --> <html> <head></head> -<body onload="document.location='http://localhost:1337'"></body> +<body onload="document.location='http://127.0.0.1:1337'"></body> </html> diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 4761c0a..9fc2544 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -78,6 +78,8 @@ const int kSubsequentTimeoutInMS = 5000; InProcessBrowserTest::InProcessBrowserTest() : browser_(NULL), + test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))), show_window_(false), dom_automation_enabled_(false), tab_closeable_state_watcher_enabled_(false), @@ -237,13 +239,6 @@ void InProcessBrowserTest::TearDown() { RenderProcessHost::set_run_renderer_in_process(original_single_process_); } -net::HTTPTestServer* InProcessBrowserTest::StartHTTPServer() { - DCHECK(!http_server_.get()); - http_server_ = net::HTTPTestServer::CreateServer( - L"chrome/test/data"); - return http_server_.get(); -} - // Creates a browser with a single tab (about:blank), waits for the tab to // finish loading and shows the browser. Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) { @@ -312,9 +307,6 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { QuitBrowsers(); pool.Recycle(); - - // Stop the HTTP server. - http_server_ = NULL; } void InProcessBrowserTest::QuitBrowsers() { diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h index eef6c94..0af1877 100644 --- a/chrome/test/in_process_browser_test.h +++ b/chrome/test/in_process_browser_test.h @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "net/test/test_server.h" #include "testing/gtest/include/gtest/gtest.h" class Browser; @@ -16,7 +17,6 @@ class CommandLine; class Profile; namespace net { -class HTTPTestServer; class RuleBasedHostResolverProc; } @@ -101,8 +101,8 @@ class InProcessBrowserTest : public testing::Test { // Sets Initial Timeout value. void SetInitialTimeoutInMS(int initial_timeout); - // Starts an HTTP server. - net::HTTPTestServer* StartHTTPServer() WARN_UNUSED_RESULT; + // Returns the testing server. Guaranteed to be non-NULL. + net::TestServer* test_server() { return &test_server_; } // Creates a browser with a single tab (about:blank), waits for the tab to // finish loading and shows the browser. @@ -136,8 +136,8 @@ class InProcessBrowserTest : public testing::Test { // Browser created from CreateBrowser. Browser* browser_; - // HTTPServer, created when StartHTTPServer is invoked. - scoped_refptr<net::HTTPTestServer> http_server_; + // Testing server, started on demand. + net::TestServer test_server_; // Whether this test requires the browser windows to be shown (interactive // tests for example need the windows shown). diff --git a/chrome/test/interactive_ui/infobars_uitest.cc b/chrome/test/interactive_ui/infobars_uitest.cc index a57ef58..34d1bda 100644 --- a/chrome/test/interactive_ui/infobars_uitest.cc +++ b/chrome/test/interactive_ui/infobars_uitest.cc @@ -16,17 +16,17 @@ class InfoBarsUITest : public UITest { }; TEST_F(InfoBarsUITest, TestInfoBarsCloseOnNewTheme) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server.get() != NULL); + net::TestServer test_server(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); scoped_refptr<TabProxy> tab_1(browser->GetActiveTab()); ASSERT_TRUE(tab_1.get()); EXPECT_TRUE(tab_1->NavigateToURL( - server->TestServerPage("files/simple.html"))); + test_server.GetURL("files/simple.html"))); scoped_refptr<ExtensionProxy> theme = automation()->InstallExtension( test_data_directory_.AppendASCII("extensions").AppendASCII("theme.crx"), true); @@ -34,7 +34,7 @@ TEST_F(InfoBarsUITest, TestInfoBarsCloseOnNewTheme) { EXPECT_TRUE(tab_1->WaitForInfoBarCount(1, action_max_timeout_ms())); EXPECT_TRUE(browser->AppendTab( - server->TestServerPage("files/simple.html"))); + test_server.GetURL("files/simple.html"))); WaitUntilTabCount(2); scoped_refptr<TabProxy> tab_2(browser->GetActiveTab()); ASSERT_TRUE(tab_2.get()); diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index e09573b..8297006 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -240,22 +240,19 @@ void LiveSyncTest::TearDownInProcessBrowserTestFixture() { } void LiveSyncTest::SetUpLocalTestServer() { - bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, - server_.kHostName, server_.kOKHTTPSPort, - FilePath(), FilePath(), std::wstring()); - ASSERT_TRUE(success); + ASSERT_TRUE(test_server_.Start()); started_local_test_server_ = true; CommandLine* cl = CommandLine::ForCurrentProcess(); cl->AppendSwitchASCII(switches::kSyncServiceURL, - StringPrintf("http://%s:%d/chromiumsync", server_.kHostName, - server_.kOKHTTPSPort)); + StringPrintf("http://%s:%d/chromiumsync", + test_server_.host_port_pair().host().c_str(), + test_server_.host_port_pair().port())); } void LiveSyncTest::TearDownLocalTestServer() { - bool success = server_.Stop(); - ASSERT_TRUE(success); + ASSERT_TRUE(test_server_.Stop()); } @@ -295,8 +292,8 @@ void LiveSyncTest::SetProxyConfig(URLRequestContextGetter* context_getter, bool LiveSyncTest::ConfigureSyncServer(const std::string& name, const std::string& value) { std::string url = StringPrintf("http://%s:%d/chromiumsync/configure", - server_.kHostName, - server_.kOKHTTPSPort); + test_server_.host_port_pair().host().c_str(), + test_server_.host_port_pair().port()); std::string data = EscapePath(name) + "=" + EscapePath(value); ConfigureURLFectcherDelegate delegate; scoped_ptr<URLFetcher> fetcher( diff --git a/chrome/test/live_sync/live_sync_test.h b/chrome/test/live_sync/live_sync_test.h index 0026251..134b200 100644 --- a/chrome/test/live_sync/live_sync_test.h +++ b/chrome/test/live_sync/live_sync_test.h @@ -60,6 +60,7 @@ class LiveSyncTest : public InProcessBrowserTest { explicit LiveSyncTest(TestType test_type) : test_type_(test_type), num_clients_(-1), + test_server_(net::TestServer::TYPE_HTTP, FilePath()), started_local_test_server_(false) { InProcessBrowserTest::set_show_window(true); InProcessBrowserTest::SetInitialTimeoutInMS(kTestTimeoutInMS); @@ -195,7 +196,7 @@ class LiveSyncTest : public InProcessBrowserTest { scoped_ptr<Profile> verifier_; // Local instance of python sync server. - net::TestServerLauncher server_; + net::TestServer test_server_; // Keeps track of whether a local python sync server was used for a test. bool started_local_test_server_; diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc index b190a26..cdad677 100644 --- a/chrome/test/ui/ppapi_uitest.cc +++ b/chrome/test/ui/ppapi_uitest.cc @@ -68,11 +68,11 @@ class PPAPITest : public UITest { } void RunTestViaHTTP(const std::string& test_case) { - const wchar_t kDocRoot[] = L"third_party/ppapi/tests"; - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(server); - RunTestURL(server->TestServerPage("files/test_case.html?" + test_case)); + net::TestServer test_server( + net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("third_party/ppapi/tests"))); + ASSERT_TRUE(test_server.Start()); + RunTestURL(test_server.GetURL("files/test_case.html?" + test_case)); } private: diff --git a/chrome/worker/worker_uitest.cc b/chrome/worker/worker_uitest.cc index f054be4..b4c64da 100644 --- a/chrome/worker/worker_uitest.cc +++ b/chrome/worker/worker_uitest.cc @@ -189,7 +189,8 @@ TEST_F(WorkerTest, IncognitoSharedWorkers) { RunIncognitoTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html"))); } -const wchar_t kDocRoot[] = L"chrome/test/data/workers"; +const FilePath::CharType kDocRoot[] = + FILE_PATH_LITERAL("chrome/test/data/workers"); #if defined(OS_WIN) // http://crbug.com/33344 - NavigateAndWaitForAuth times out on the Windows @@ -198,14 +199,13 @@ const wchar_t kDocRoot[] = L"chrome/test/data/workers"; #endif // Make sure that auth dialog is displayed from worker context. TEST_F(WorkerTest, WorkerHttpAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); - GURL url = server->TestServerPage("files/worker_auth.html"); + GURL url = test_server.GetURL("files/worker_auth.html"); EXPECT_TRUE(NavigateAndWaitForAuth(tab, url)); } @@ -216,14 +216,13 @@ TEST_F(WorkerTest, WorkerHttpAuth) { #endif // Make sure that auth dialog is displayed from shared worker context. TEST_F(WorkerTest, SharedWorkerHttpAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); + ASSERT_TRUE(test_server.Start()); scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); - GURL url = server->TestServerPage("files/shared_worker_auth.html"); + GURL url = test_server.GetURL("files/shared_worker_auth.html"); EXPECT_TRUE(NavigateAndWaitForAuth(tab, url)); // TODO(atwilson): Add support to automation framework to test for auth // dialogs displayed by non-navigating tabs. diff --git a/chrome_frame/test/http_server.cc b/chrome_frame/test/http_server.cc index 48f88e7..c93b01f 100644 --- a/chrome_frame/test/http_server.cc +++ b/chrome_frame/test/http_server.cc @@ -13,10 +13,12 @@ const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; +ChromeFrameHTTPServer::ChromeFrameHTTPServer() + : test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { +} + void ChromeFrameHTTPServer::SetUp() { - std::wstring document_root(kDocRoot); - server_ = net::HTTPTestServer::CreateServer(document_root); - ASSERT_TRUE(server_ != NULL); + ASSERT_TRUE(test_server_.Start()); // copy CFInstance.js into the test directory FilePath cf_source_path; @@ -37,9 +39,7 @@ void ChromeFrameHTTPServer::SetUp() { } void ChromeFrameHTTPServer::TearDown() { - if (server_) { - server_ = NULL; - } + test_server_.Stop(); // clobber CFInstance.js FilePath cfi_path; @@ -64,17 +64,14 @@ void ChromeFrameHTTPServer::TearDown() { } bool ChromeFrameHTTPServer::WaitToFinish(int milliseconds) { - if (!server_) - return true; - - return server_->WaitToFinish(milliseconds); + return test_server_.WaitToFinish(milliseconds); } // TODO(phajdan.jr): Change wchar_t* to std::string& and fix callers. GURL ChromeFrameHTTPServer::Resolve(const wchar_t* relative_url) { - return server_->TestServerPage(WideToUTF8(relative_url)); + return test_server_.GetURL(WideToUTF8(relative_url)); } FilePath ChromeFrameHTTPServer::GetDataDir() { - return server_->GetDataDirectory(); + return test_server_.document_root(); } diff --git a/chrome_frame/test/http_server.h b/chrome_frame/test/http_server.h index 30b3d19..a6dae20 100644 --- a/chrome_frame/test/http_server.h +++ b/chrome_frame/test/http_server.h @@ -17,16 +17,18 @@ class FilePath; // Chrome Frame specilization of http server from net. class ChromeFrameHTTPServer { public: + ChromeFrameHTTPServer(); + void SetUp(); void TearDown(); bool WaitToFinish(int milliseconds); GURL Resolve(const wchar_t* relative_url); FilePath GetDataDir(); - net::HTTPTestServer* server() { return server_; } + net::TestServer* test_server() { return &test_server_; } protected: - scoped_refptr<net::HTTPTestServer> server_; + net::TestServer test_server_; }; #endif // CHROME_FRAME_TEST_HTTP_SERVER_H_ diff --git a/chrome_frame/test/run_all_unittests.cc b/chrome_frame/test/run_all_unittests.cc index a22d4f5..b25b5ae 100644 --- a/chrome_frame/test/run_all_unittests.cc +++ b/chrome_frame/test/run_all_unittests.cc @@ -51,12 +51,12 @@ int main(int argc, char **argv) { if (CommandLine::ForCurrentProcess()->HasSwitch(kRunAsServer)) { ChromeFrameHTTPServer server; server.SetUp(); - GURL server_url(server.server()->TestServerPage("")); + GURL server_url(server.test_server()->GetURL("")); std::cout << std::endl << "Server waiting on " << server_url.spec().c_str() << std::endl << std::endl << "Test output will be written to " - << server.server()->GetDataDirectory().value().c_str() << "\\dump" + << server.test_server()->document_root().value() << "\\dump" << std::endl << std::endl << "Hit Ctrl-C or navigate to " << server_url.spec().c_str() << "kill to shut down the server." diff --git a/chrome_frame/test/test_with_web_server.cc b/chrome_frame/test/test_with_web_server.cc index dead3d2..16ba8b3 100644 --- a/chrome_frame/test/test_with_web_server.cc +++ b/chrome_frame/test/test_with_web_server.cc @@ -85,11 +85,7 @@ void ChromeFrameTestWithWebServer::SetUp() { .Append(FILE_PATH_LITERAL("data")); server_.SetUp(); - EXPECT_TRUE(server_.server() != NULL); - if (server_.server()) { - results_dir_ = server_.GetDataDir(); - results_dir_ = results_dir_.AppendASCII("dump"); - } + results_dir_ = server_.test_server()->document_root().AppendASCII("dump"); } void ChromeFrameTestWithWebServer::TearDown() { @@ -100,7 +96,6 @@ void ChromeFrameTestWithWebServer::TearDown() { bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, const wchar_t* page) { - EXPECT_TRUE(server_.server() != NULL); std::wstring url = page; if (url.find(L"files/") != std::wstring::npos) url = UTF8ToWide(server_.Resolve(page).spec()); @@ -163,7 +158,6 @@ bool ChromeFrameTestWithWebServer::BringBrowserToTop() { } bool ChromeFrameTestWithWebServer::WaitForTestToComplete(int milliseconds) { - EXPECT_TRUE(server_.server() != NULL); return server_.WaitToFinish(milliseconds); } diff --git a/net/net.gyp b/net/net.gyp index abbbc74..7d34f00 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -916,20 +916,6 @@ ], }, { - 'target_name': 'run_testserver', - 'type': 'executable', - 'dependencies': [ - 'net', - 'net_test_support', - '../base/base.gyp:base', - '../testing/gtest.gyp:gtest', - ], - 'msvs_guid': '506F2468-6B1D-48E2-A67C-9D9C6BAC0EC5', - 'sources': [ - 'tools/testserver/run_testserver.cc', - ], - }, - { 'target_name': 'net_test_support', 'type': '<(library)', 'dependencies': [ @@ -947,6 +933,8 @@ 'socket/socket_test_util.cc', 'socket/socket_test_util.h', 'test/test_server.cc', + 'test/test_server_posix.cc', + 'test/test_server_win.cc', 'test/test_server.h', ], 'conditions': [ diff --git a/net/proxy/proxy_resolver_perftest.cc b/net/proxy/proxy_resolver_perftest.cc index 14c4818..dda9587 100644 --- a/net/proxy/proxy_resolver_perftest.cc +++ b/net/proxy/proxy_resolver_perftest.cc @@ -83,10 +83,14 @@ class PacPerfSuiteRunner { // |resolver_name| is the label used when logging the results. PacPerfSuiteRunner(net::ProxyResolver* resolver, const std::string& resolver_name) - : resolver_(resolver), resolver_name_(resolver_name) { + : resolver_(resolver), + resolver_name_(resolver_name), + test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("net/data/proxy_resolver_perftest"))) { } void RunAllTests() { + ASSERT_TRUE(test_server_.Start()); for (size_t i = 0; i < arraysize(kPerfTests); ++i) { const PacPerfTest& test_data = kPerfTests[i]; RunTest(test_data.pac_name, @@ -100,9 +104,8 @@ class PacPerfSuiteRunner { const PacQuery* queries, int queries_len) { if (!resolver_->expects_pac_bytes()) { - InitHttpServer(); GURL pac_url = - server_->TestServerPage(std::string("files/") + script_name); + test_server_.GetURL(std::string("files/") + script_name); int rv = resolver_->SetPacScript( net::ProxyResolverScriptData::FromURL(pac_url), NULL); EXPECT_EQ(net::OK, rv); @@ -145,16 +148,6 @@ class PacPerfSuiteRunner { timer.Done(); } - // Lazily startup an HTTP server (to serve the PAC script). - void InitHttpServer() { - DCHECK(!resolver_->expects_pac_bytes()); - if (!server_) { - server_ = net::HTTPTestServer::CreateServer( - L"net/data/proxy_resolver_perftest"); - } - ASSERT_TRUE(server_.get() != NULL); - } - // Read the PAC script from disk and initialize the proxy resolver with it. void LoadPacScriptIntoResolver(const std::string& script_name) { FilePath path; @@ -180,7 +173,7 @@ class PacPerfSuiteRunner { net::ProxyResolver* resolver_; std::string resolver_name_; - scoped_refptr<net::HTTPTestServer> server_; + net::TestServer test_server_; }; #if defined(OS_WIN) diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc index 28e6895..65a7d4d 100644 --- a/net/proxy/proxy_script_fetcher_unittest.cc +++ b/net/proxy/proxy_script_fetcher_unittest.cc @@ -21,7 +21,8 @@ // - Test canceling an outstanding request. // - Test deleting ProxyScriptFetcher while a request is in progress. -const wchar_t kDocRoot[] = L"net/data/proxy_script_fetcher_unittest"; +const FilePath::CharType kDocRoot[] = + FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); struct FetchResult { int code; @@ -64,7 +65,15 @@ GURL GetTestFileUrl(const std::string& relpath) { return GURL(base_url.spec() + "/" + relpath); } -typedef PlatformTest ProxyScriptFetcherTest; +class ProxyScriptFetcherTest : public PlatformTest { + public: + ProxyScriptFetcherTest() + : test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { + } + + protected: + net::TestServer test_server_; +}; TEST_F(ProxyScriptFetcherTest, FileUrl) { scoped_refptr<URLRequestContext> context = new RequestContext; @@ -94,14 +103,14 @@ 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()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); { // Fetch a PAC with mime type "text/plain" - GURL url = server->TestServerPage("files/pac.txt"); + GURL url(test_server_.GetURL("files/pac.txt")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -110,7 +119,7 @@ TEST_F(ProxyScriptFetcherTest, HttpMimeType) { EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); } { // Fetch a PAC with mime type "text/html" - GURL url = server->TestServerPage("files/pac.html"); + GURL url(test_server_.GetURL("files/pac.html")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -119,7 +128,7 @@ TEST_F(ProxyScriptFetcherTest, HttpMimeType) { EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text); } { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" - GURL url = server->TestServerPage("files/pac.nsproxy"); + GURL url(test_server_.GetURL("files/pac.nsproxy")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -130,14 +139,14 @@ TEST_F(ProxyScriptFetcherTest, HttpMimeType) { } TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); { // Fetch a PAC which gives a 500 -- FAIL - GURL url = server->TestServerPage("files/500.pac"); + GURL url(test_server_.GetURL("files/500.pac")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -146,7 +155,7 @@ TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { EXPECT_TRUE(text.empty()); } { // Fetch a PAC which gives a 404 -- FAIL - GURL url = server->TestServerPage("files/404.pac"); + GURL url(test_server_.GetURL("files/404.pac")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -157,15 +166,15 @@ TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { } TEST_F(ProxyScriptFetcherTest, ContentDisposition) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); // Fetch PAC scripts via HTTP with a Content-Disposition header -- should // have no effect. - GURL url = server->TestServerPage("files/downloadable.pac"); + GURL url(test_server_.GetURL("files/downloadable.pac")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -175,14 +184,14 @@ TEST_F(ProxyScriptFetcherTest, ContentDisposition) { } TEST_F(ProxyScriptFetcherTest, NoCache) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. - GURL url = server->TestServerPage("files/cacheable_1hr.pac"); + GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); { string16 text; TestCompletionCallback callback; @@ -193,8 +202,7 @@ TEST_F(ProxyScriptFetcherTest, NoCache) { } // Now kill the HTTP server. - EXPECT_TRUE(server->Stop()); // Verify it shutdown synchronously. - server = NULL; + ASSERT_TRUE(test_server_.Stop()); // Try to fetch the file again -- if should fail, since the server is not // running anymore. (If it were instead being loaded from cache, we would @@ -209,8 +217,8 @@ TEST_F(ProxyScriptFetcherTest, NoCache) { } TEST_F(ProxyScriptFetcherTest, TooLarge) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); @@ -220,7 +228,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"), + test_server_.GetURL("files/large-pac.nsproxy"), GetTestFileUrl("large-pac.nsproxy") }; @@ -240,7 +248,7 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) { ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size); { // Make sure we can still fetch regular URLs. - GURL url = server->TestServerPage("files/pac.nsproxy"); + GURL url(test_server_.GetURL("files/pac.nsproxy")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -251,8 +259,8 @@ TEST_F(ProxyScriptFetcherTest, TooLarge) { } TEST_F(ProxyScriptFetcherTest, Hang) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); @@ -263,7 +271,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(test_server_.GetURL("slow/proxy.pac?1.2")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -276,7 +284,7 @@ TEST_F(ProxyScriptFetcherTest, Hang) { ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout); { // Make sure we can still fetch regular URLs. - GURL url = server->TestServerPage("files/pac.nsproxy"); + GURL url(test_server_.GetURL("files/pac.nsproxy")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -290,15 +298,15 @@ TEST_F(ProxyScriptFetcherTest, Hang) { // (like gzip, bzip, etc.), and apply any charset conversions to yield // UTF8. TEST_F(ProxyScriptFetcherTest, Encodings) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new RequestContext; scoped_ptr<ProxyScriptFetcher> pac_fetcher( ProxyScriptFetcher::Create(context)); // Test a response that is gzip-encoded -- should get inflated. { - GURL url = server->TestServerPage("files/gzipped_pac"); + GURL url(test_server_.GetURL("files/gzipped_pac")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); @@ -310,7 +318,7 @@ TEST_F(ProxyScriptFetcherTest, Encodings) { // Test a response that was served as UTF-16 (BE). It should // be converted to UTF8. { - GURL url = server->TestServerPage("files/utf16be_pac"); + GURL url(test_server_.GetURL("files/utf16be_pac")); string16 text; TestCompletionCallback callback; int result = pac_fetcher->Fetch(url, &text, &callback); diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index c242db1..6673ec6 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -31,60 +31,31 @@ class SSLClientSocketTest : public PlatformTest { socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { } - void StartOKServer() { - bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, - server_.kHostName, server_.kOKHTTPSPort, - FilePath(), server_.GetOKCertPath(), std::wstring()); - ASSERT_TRUE(success); - } - - void StartClientAuthServer() { - server_.set_ssl_client_auth(true); - StartOKServer(); - } - - void StartMismatchedServer() { - bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, - server_.kMismatchedHostName, server_.kOKHTTPSPort, - FilePath(), server_.GetOKCertPath(), std::wstring()); - ASSERT_TRUE(success); - } - - void StartExpiredServer() { - bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, - server_.kHostName, server_.kBadHTTPSPort, - FilePath(), server_.GetExpiredCertPath(), std::wstring()); - ASSERT_TRUE(success); - } - protected: scoped_refptr<net::HostResolver> resolver_; net::ClientSocketFactory* socket_factory_; - net::TestServerLauncher server_; }; //----------------------------------------------------------------------------- TEST_F(SSLClientSocketTest, Connect) { - StartOKServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); net::ClientSocket* transport = new net::TCPClientSocket(addr, &log); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, kDefaultSSLConfig)); + test_server.host_port_pair().host(), kDefaultSSLConfig)); EXPECT_FALSE(sock->IsConnected()); @@ -110,25 +81,24 @@ TEST_F(SSLClientSocketTest, Connect) { } TEST_F(SSLClientSocketTest, ConnectExpired) { - StartExpiredServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_EXPIRED_CERTIFICATE, + FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort); - int rv = resolver_->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); net::ClientSocket* transport = new net::TCPClientSocket(addr, &log); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, kDefaultSSLConfig)); + test_server.host_port_pair().host(), kDefaultSSLConfig)); EXPECT_FALSE(sock->IsConnected()); @@ -154,26 +124,24 @@ TEST_F(SSLClientSocketTest, ConnectExpired) { } TEST_F(SSLClientSocketTest, ConnectMismatched) { - StartMismatchedServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_MISMATCHED_HOSTNAME, + FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kMismatchedHostName, - server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); net::ClientSocket* transport = new net::TCPClientSocket(addr, &log); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kMismatchedHostName, kDefaultSSLConfig)); + test_server.host_port_pair().host(), kDefaultSSLConfig)); EXPECT_FALSE(sock->IsConnected()); @@ -201,25 +169,24 @@ TEST_F(SSLClientSocketTest, ConnectMismatched) { // TODO(davidben): Also test providing a certificate. TEST_F(SSLClientSocketTest, ConnectClientAuthNoCert) { - StartClientAuthServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_CLIENT_AUTH, + FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); net::ClientSocket* transport = new net::TCPClientSocket(addr, &log); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, kDefaultSSLConfig)); + test_server.host_port_pair().host(), kDefaultSSLConfig)); EXPECT_FALSE(sock->IsConnected()); @@ -250,27 +217,22 @@ TEST_F(SSLClientSocketTest, ConnectClientAuthNoCert) { // - Server sends data unexpectedly. TEST_F(SSLClientSocketTest, Read) { - StartOKServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, &callback, NULL, net::BoundNetLog()); - EXPECT_EQ(net::ERR_IO_PENDING, rv); - - rv = callback.WaitForResult(); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::ClientSocket* transport = new net::TCPClientSocket(addr, NULL); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, + test_server.host_port_pair().host(), kDefaultSSLConfig)); rv = sock->Connect(&callback); @@ -311,28 +273,24 @@ TEST_F(SSLClientSocketTest, Read) { // Test the full duplex mode, with Read and Write pending at the same time. // This test also serves as a regression test for http://crbug.com/29815. TEST_F(SSLClientSocketTest, Read_FullDuplex) { - StartOKServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; // Used for everything except Write. TestCompletionCallback callback2; // Used for Write only. - net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, &callback, NULL, net::BoundNetLog()); - EXPECT_EQ(net::ERR_IO_PENDING, rv); - - rv = callback.WaitForResult(); - EXPECT_EQ(net::OK, rv); - net::ClientSocket* transport = new net::TCPClientSocket(addr, NULL); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, + test_server.host_port_pair().host(), kDefaultSSLConfig)); rv = sock->Connect(&callback); @@ -374,24 +332,22 @@ TEST_F(SSLClientSocketTest, Read_FullDuplex) { } TEST_F(SSLClientSocketTest, Read_SmallChunks) { - StartOKServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::ClientSocket* transport = new net::TCPClientSocket(addr, NULL); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, kDefaultSSLConfig)); + test_server.host_port_pair().host(), kDefaultSSLConfig)); rv = sock->Connect(&callback); if (rv != net::OK) { @@ -428,24 +384,22 @@ TEST_F(SSLClientSocketTest, Read_SmallChunks) { } TEST_F(SSLClientSocketTest, Read_Interrupted) { - StartOKServer(); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); + ASSERT_TRUE(test_server.Start()); net::AddressList addr; - TestCompletionCallback callback; - - net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver_->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); - EXPECT_EQ(net::OK, rv); + ASSERT_TRUE(test_server.GetAddressList(&addr)); + TestCompletionCallback callback; net::ClientSocket* transport = new net::TCPClientSocket(addr, NULL); - rv = transport->Connect(&callback); + int rv = transport->Connect(&callback); if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket(transport, - server_.kHostName, kDefaultSSLConfig)); + test_server.host_port_pair().host(), kDefaultSSLConfig)); rv = sock->Connect(&callback); if (rv != net::OK) { @@ -480,6 +434,9 @@ TEST_F(SSLClientSocketTest, Read_Interrupted) { // Regression test for http://crbug.com/42538 TEST_F(SSLClientSocketTest, PrematureApplicationData) { + net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); + ASSERT_TRUE(test_server.Start()); + net::AddressList addr; TestCompletionCallback callback; @@ -515,7 +472,7 @@ TEST_F(SSLClientSocketTest, PrematureApplicationData) { scoped_ptr<net::SSLClientSocket> sock( socket_factory_->CreateSSLClientSocket( - transport, server_.kHostName, kDefaultSSLConfig)); + transport, test_server.host_port_pair().host(), kDefaultSSLConfig)); rv = sock->Connect(&callback); EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); diff --git a/net/test/test_server.cc b/net/test/test_server.cc index 7a2df0b..e133345 100644 --- a/net/test/test_server.cc +++ b/net/test/test_server.cc @@ -10,10 +10,7 @@ #include "build/build_config.h" -#if defined(OS_WIN) -#include <windows.h> -#include <wincrypt.h> -#elif defined(OS_MACOSX) +#if defined(OS_MACOSX) #include "net/base/x509_certificate.h" #endif @@ -23,17 +20,15 @@ #include "base/path_service.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" +#include "googleurl/src/gurl.h" #include "net/base/cert_test_util.h" +#include "net/base/host_port_pair.h" #include "net/base/host_resolver.h" #include "net/base/test_completion_callback.h" #include "net/socket/tcp_client_socket.h" #include "net/socket/tcp_pinger.h" #include "testing/platform_test.h" -#if defined(OS_WIN) -#pragma comment(lib, "crypt32.lib") -#endif - namespace { // Number of connection attempts for tests. @@ -42,6 +37,33 @@ const int kServerConnectionAttempts = 10; // Connection timeout in milliseconds for tests. const int kServerConnectionTimeoutMs = 1000; +int GetPort(net::TestServer::Type type) { + switch (type) { + case net::TestServer::TYPE_FTP: + return 1338; + case net::TestServer::TYPE_HTTP: + return 1337; + case net::TestServer::TYPE_HTTPS: + case net::TestServer::TYPE_HTTPS_CLIENT_AUTH: + case net::TestServer::TYPE_HTTPS_EXPIRED_CERTIFICATE: + return 9443; + case net::TestServer::TYPE_HTTPS_MISMATCHED_HOSTNAME: + return 9666; + default: + NOTREACHED(); + } + return -1; +} + +std::string GetHostname(net::TestServer::Type type) { + if (type == net::TestServer::TYPE_HTTPS_MISMATCHED_HOSTNAME) { + // Return a different hostname string that resolves to the same hostname. + return "localhost"; + } + + return "127.0.0.1"; +} + } // namespace namespace net { @@ -50,258 +72,192 @@ namespace net { void SetMacTestCertificate(X509Certificate* cert); #endif -// static -const char TestServerLauncher::kHostName[] = "127.0.0.1"; -const char TestServerLauncher::kMismatchedHostName[] = "localhost"; -const int TestServerLauncher::kOKHTTPSPort = 9443; -const int TestServerLauncher::kBadHTTPSPort = 9666; +TestServer::TestServer(Type type, const FilePath& document_root) + : host_port_pair_(GetHostname(type), GetPort(type)), + process_handle_(base::kNullProcessHandle), + type_(type) { + FilePath src_dir; + PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); -// The issuer name of the cert that should be trusted for the test to work. -const wchar_t TestServerLauncher::kCertIssuerName[] = L"Test CA"; - -TestServerLauncher::TestServerLauncher() - : process_handle_(base::kNullProcessHandle), - ssl_client_auth_(false) { - InitCertPath(); -} + document_root_ = src_dir.Append(document_root); -void TestServerLauncher::InitCertPath() { - PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); - cert_dir_ = cert_dir_.Append(FILE_PATH_LITERAL("net")) + certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net")) .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("ssl")) .Append(FILE_PATH_LITERAL("certificates")); } -namespace { - -void AppendToPythonPath(const FilePath& dir) { - // Do nothing if dir already on path. - -#if defined(OS_WIN) - const wchar_t kPythonPath[] = L"PYTHONPATH"; - // TODO(dkegel): handle longer PYTHONPATH variables - wchar_t oldpath[4096]; - if (GetEnvironmentVariable(kPythonPath, oldpath, arraysize(oldpath)) == 0) { - SetEnvironmentVariableW(kPythonPath, dir.value().c_str()); - } else if (!wcsstr(oldpath, dir.value().c_str())) { - std::wstring newpath(oldpath); - newpath.append(L";"); - newpath.append(dir.value()); - SetEnvironmentVariableW(kPythonPath, newpath.c_str()); - } -#elif defined(OS_POSIX) - const char kPythonPath[] = "PYTHONPATH"; - const char* oldpath = getenv(kPythonPath); - // setenv() leaks memory intentionally on Mac - if (!oldpath) { - setenv(kPythonPath, dir.value().c_str(), 1); - } else if (!strstr(oldpath, dir.value().c_str())) { - std::string newpath(oldpath); - newpath.append(":"); - newpath.append(dir.value()); - setenv(kPythonPath, newpath.c_str(), 1); - } +TestServer::~TestServer() { +#if defined(OS_MACOSX) + SetMacTestCertificate(NULL); #endif + Stop(); } -} // end namespace - -void TestServerLauncher::SetPythonPath() { - FilePath third_party_dir; - CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)); - third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); - - AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); - AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); - - // Locate the Python code generated by the protocol buffers compiler. - FilePath generated_code_dir; - CHECK(PathService::Get(base::DIR_EXE, &generated_code_dir)); - generated_code_dir = generated_code_dir.Append(FILE_PATH_LITERAL("pyproto")); - AppendToPythonPath(generated_code_dir); - AppendToPythonPath(generated_code_dir.Append(FILE_PATH_LITERAL("sync_pb"))); -} - -bool TestServerLauncher::Start(Protocol protocol, - const std::string& host_name, int port, - const FilePath& document_root, - const FilePath& cert_path, - const std::wstring& file_root_url) { - if (!cert_path.value().empty()) { +bool TestServer::Start() { + if (GetScheme() == "https") { if (!LoadTestRootCert()) return false; if (!CheckCATrusted()) return false; } - std::string port_str = base::IntToString(port); - // Get path to python server script FilePath testserver_path; - if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) + if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) { + LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; return false; + } testserver_path = testserver_path .Append(FILE_PATH_LITERAL("net")) .Append(FILE_PATH_LITERAL("tools")) .Append(FILE_PATH_LITERAL("testserver")) .Append(FILE_PATH_LITERAL("testserver.py")); - PathService::Get(base::DIR_SOURCE_ROOT, &document_root_dir_); - document_root_dir_ = document_root_dir_.Append(document_root); - - SetPythonPath(); - -#if defined(OS_WIN) - // Get path to python interpreter - FilePath python_exe; - if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_exe)) + if (!SetPythonPath()) return false; - python_exe = python_exe - .Append(FILE_PATH_LITERAL("third_party")) - .Append(FILE_PATH_LITERAL("python_24")) - .Append(FILE_PATH_LITERAL("python.exe")); - - std::wstring command_line = - L"\"" + python_exe.ToWStringHack() + L"\" " + - L"\"" + testserver_path.ToWStringHack() + - L"\" --port=" + UTF8ToWide(port_str) + - L" --data-dir=\"" + document_root_dir_.ToWStringHack() + L"\""; - if (protocol == ProtoFTP) - command_line.append(L" -f"); - if (!cert_path.value().empty()) { - command_line.append(L" --https=\""); - command_line.append(cert_path.ToWStringHack()); - command_line.append(L"\""); - } - if (!file_root_url.empty()) { - command_line.append(L" --file-root-url=\""); - command_line.append(file_root_url); - command_line.append(L"\""); - } - if (ssl_client_auth_) - command_line.append(L" --ssl-client-auth"); - - if (!LaunchTestServerAsJob(command_line, - true, - &process_handle_, - &job_handle_)) { - LOG(ERROR) << "Failed to launch " << command_line; - return false; - } -#elif defined(OS_POSIX) - std::vector<std::string> command_line; - command_line.push_back("python"); - command_line.push_back(testserver_path.value()); - command_line.push_back("--port=" + port_str); - command_line.push_back("--data-dir=" + document_root_dir_.value()); - if (protocol == ProtoFTP) - command_line.push_back("-f"); - if (!cert_path.value().empty()) - command_line.push_back("--https=" + cert_path.value()); - if (ssl_client_auth_) - command_line.push_back("--ssl-client-auth"); - - base::file_handle_mapping_vector no_mappings; - LOG(INFO) << "Trying to launch " << command_line[0] << " ..."; - if (!base::LaunchApp(command_line, no_mappings, false, &process_handle_)) { - LOG(ERROR) << "Failed to launch " << command_line[0] << " ..."; + + if (!LaunchPython(testserver_path)) return false; - } -#endif - // Let the server start, then verify that it's up. - // Our server is Python, and takes about 500ms to start - // up the first time, and about 200ms after that. - if (!WaitToStart(host_name, port)) { - LOG(ERROR) << "Failed to connect to server"; + if (!WaitToStart()) { Stop(); return false; } - LOG(INFO) << "Started on port " << port_str; return true; } -bool TestServerLauncher::WaitToStart(const std::string& host_name, int port) { - // Verify that the webserver is actually started. - // Otherwise tests can fail if they run faster than Python can start. - net::AddressList addr; - scoped_refptr<net::HostResolver> resolver( - net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism)); - net::HostResolver::RequestInfo info(host_name, port); - int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog()); - if (rv != net::OK) - return false; - - net::TCPPinger pinger(addr); - rv = pinger.Ping( - base::TimeDelta::FromMilliseconds(kServerConnectionTimeoutMs), - kServerConnectionAttempts); - return rv == net::OK; -} - -bool TestServerLauncher::WaitToFinish(int timeout_ms) { +bool TestServer::Stop() { if (!process_handle_) return true; - bool ret = base::WaitForSingleProcess(process_handle_, timeout_ms); + // First check if the process has already terminated. + bool ret = base::WaitForSingleProcess(process_handle_, 0); + if (!ret) + ret = base::KillProcess(process_handle_, 1, true); + if (ret) { base::CloseProcessHandle(process_handle_); process_handle_ = base::kNullProcessHandle; - LOG(INFO) << "Finished."; } else { - LOG(INFO) << "Timed out."; + LOG(INFO) << "Kill failed?"; } + return ret; } -bool TestServerLauncher::Stop() { +bool TestServer::WaitToFinish(int timeout_ms) { if (!process_handle_) return true; - // First check if the process has already terminated. - bool ret = base::WaitForSingleProcess(process_handle_, 0); - if (!ret) - ret = base::KillProcess(process_handle_, 1, true); - + bool ret = base::WaitForSingleProcess(process_handle_, timeout_ms); if (ret) { base::CloseProcessHandle(process_handle_); process_handle_ = base::kNullProcessHandle; - LOG(INFO) << "Stopped."; } else { - LOG(INFO) << "Kill failed?"; + LOG(ERROR) << "Timed out."; } - return ret; } -TestServerLauncher::~TestServerLauncher() { -#if defined(OS_MACOSX) - SetMacTestCertificate(NULL); -#endif - Stop(); +std::string TestServer::GetScheme() const { + switch (type_) { + case TYPE_FTP: + return "ftp"; + case TYPE_HTTP: + return "http"; + case TYPE_HTTPS: + case TYPE_HTTPS_CLIENT_AUTH: + case TYPE_HTTPS_MISMATCHED_HOSTNAME: + case TYPE_HTTPS_EXPIRED_CERTIFICATE: + return "https"; + default: + NOTREACHED(); + } + return std::string(); +} + +bool TestServer::GetAddressList(AddressList* address_list) const { + DCHECK(address_list); + + scoped_refptr<HostResolver> resolver( + CreateSystemHostResolver(HostResolver::kDefaultParallelism)); + HostResolver::RequestInfo info(host_port_pair_.host(), + host_port_pair_.port()); + int rv = resolver->Resolve(info, address_list, NULL, NULL, BoundNetLog()); + if (rv != net::OK) { + LOG(ERROR) << "Failed to resolve hostname: " << host_port_pair_.host(); + return false; + } + return true; +} + +GURL TestServer::GetURL(const std::string& path) { + return GURL(GetScheme() + "://" + host_port_pair_.ToString() + + "/" + path); } -FilePath TestServerLauncher::GetRootCertPath() { - FilePath path(cert_dir_); - path = path.AppendASCII("root_ca_cert.crt"); - return path; +GURL TestServer::GetURLWithUser(const std::string& path, + const std::string& user) { + return GURL(GetScheme() + "://" + user + "@" + + host_port_pair_.ToString() + + "/" + path); +} + +GURL TestServer::GetURLWithUserAndPassword(const std::string& path, + const std::string& user, + const std::string& password) { + return GURL(GetScheme() + "://" + user + ":" + password + + "@" + host_port_pair_.ToString() + + "/" + path); +} + +bool TestServer::SetPythonPath() { + FilePath third_party_dir; + if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { + LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; + return false; + } + third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); + + AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); + AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); + + // Locate the Python code generated by the protocol buffers compiler. + FilePath generated_code_dir; + if (!PathService::Get(base::DIR_EXE, &generated_code_dir)) { + LOG(ERROR) << "Failed to get DIR_EXE"; + return false; + } + generated_code_dir = generated_code_dir.Append(FILE_PATH_LITERAL("pyproto")); + AppendToPythonPath(generated_code_dir); + AppendToPythonPath(generated_code_dir.Append(FILE_PATH_LITERAL("sync_pb"))); + + return true; } -FilePath TestServerLauncher::GetOKCertPath() { - FilePath path(cert_dir_); - path = path.AppendASCII("ok_cert.pem"); - return path; +bool TestServer::WaitToStart() { + net::AddressList addr; + if (!GetAddressList(&addr)) + return false; + + net::TCPPinger pinger(addr); + int rv = pinger.Ping( + base::TimeDelta::FromMilliseconds(kServerConnectionTimeoutMs), + kServerConnectionAttempts); + bool result = (rv == net::OK); + if (!result) { + LOG(ERROR) << "Failed to connect to server"; + } + return result; } -FilePath TestServerLauncher::GetExpiredCertPath() { - FilePath path(cert_dir_); - path = path.AppendASCII("expired_cert.pem"); - return path; +FilePath TestServer::GetRootCertificatePath() { + return certificates_dir_.AppendASCII("root_ca_cert.crt"); } -bool TestServerLauncher::LoadTestRootCert() { +bool TestServer::LoadTestRootCert() { #if defined(USE_NSS) if (cert_) return true; @@ -312,11 +268,10 @@ bool TestServerLauncher::LoadTestRootCert() { // TODO(dkegel): fix the leak and remove the entry in // tools/valgrind/memcheck/suppressions.txt ANNOTATE_SCOPED_MEMORY_LEAK; // Tell heap checker about the leak. - cert_ = LoadTemporaryRootCert(GetRootCertPath()); - DCHECK(cert_); + cert_ = LoadTemporaryRootCert(GetRootCertificatePath()); return (cert_ != NULL); #elif defined(OS_MACOSX) - X509Certificate* cert = LoadTemporaryRootCert(GetRootCertPath()); + X509Certificate* cert = LoadTemporaryRootCert(GetRootCertificatePath()); if (!cert) return false; SetMacTestCertificate(cert); @@ -326,88 +281,21 @@ bool TestServerLauncher::LoadTestRootCert() { #endif } -bool TestServerLauncher::CheckCATrusted() { -#if defined(OS_WIN) - HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); - if (!cert_store) { - LOG(ERROR) << " could not open trusted root CA store"; - return false; - } - PCCERT_CONTEXT cert = - CertFindCertificateInStore(cert_store, - X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, - 0, - CERT_FIND_ISSUER_STR, - kCertIssuerName, - NULL); - if (cert) - CertFreeCertificateContext(cert); - CertCloseStore(cert_store, 0); - - if (!cert) { - LOG(ERROR) << " TEST CONFIGURATION ERROR: you need to import the test ca " - "certificate to your trusted roots for this test to work. " - "For more info visit:\n" - "http://dev.chromium.org/developers/testing\n"; - return false; +FilePath TestServer::GetCertificatePath() { + switch (type_) { + case TYPE_FTP: + case TYPE_HTTP: + return FilePath(); + case TYPE_HTTPS: + case TYPE_HTTPS_CLIENT_AUTH: + case TYPE_HTTPS_MISMATCHED_HOSTNAME: + return certificates_dir_.AppendASCII("ok_cert.pem"); + case TYPE_HTTPS_EXPIRED_CERTIFICATE: + return certificates_dir_.AppendASCII("expired_cert.pem"); + default: + NOTREACHED(); } -#endif - return true; -} - -#if defined(OS_WIN) -bool LaunchTestServerAsJob(const std::wstring& cmdline, - bool start_hidden, - base::ProcessHandle* process_handle, - ScopedHandle* job_handle) { - // Launch test server process. - STARTUPINFO startup_info = {0}; - startup_info.cb = sizeof(startup_info); - startup_info.dwFlags = STARTF_USESHOWWINDOW; - startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW; - PROCESS_INFORMATION process_info; - - // If this code is run under a debugger, the test server process is - // automatically associated with a job object created by the debugger. - // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. - if (!CreateProcess(NULL, - const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, - FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, - &startup_info, &process_info)) { - LOG(ERROR) << "Could not create process."; - return false; - } - CloseHandle(process_info.hThread); - - // If the caller wants the process handle, we won't close it. - if (process_handle) { - *process_handle = process_info.hProcess; - } else { - CloseHandle(process_info.hProcess); - } - - // Create a JobObject and associate the test server process with it. - job_handle->Set(CreateJobObject(NULL, NULL)); - if (!job_handle->IsValid()) { - LOG(ERROR) << "Could not create JobObject."; - return false; - } else { - JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; - limit_info.BasicLimitInformation.LimitFlags = - JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; - if (0 == SetInformationJobObject(job_handle->Get(), - JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) { - LOG(ERROR) << "Could not SetInformationJobObject."; - return false; - } - if (0 == AssignProcessToJobObject(job_handle->Get(), - process_info.hProcess)) { - LOG(ERROR) << "Could not AssignProcessToObject."; - return false; - } - } - return true; + return FilePath(); } -#endif } // namespace net diff --git a/net/test/test_server.h b/net/test/test_server.h index 989e38d..5f51571 100644 --- a/net/test/test_server.h +++ b/net/test/test_server.h @@ -13,52 +13,40 @@ #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/process_util.h" -#include "base/ref_counted.h" -#include "base/string_number_conversions.h" -//#include "base/string_util.h" -#include "googleurl/src/gurl.h" +#include "net/base/host_port_pair.h" #if defined(OS_WIN) #include "base/scoped_handle_win.h" #endif #if defined(USE_NSS) +#include "base/ref_counted.h" #include "net/base/x509_certificate.h" #endif -namespace net { +class GURL; -const int kHTTPDefaultPort = 1337; -const int kFTPDefaultPort = 1338; +namespace net { -const char kDefaultHostName[] = "localhost"; +class AddressList; -// This object bounds the lifetime of an external python-based HTTP/HTTPS/FTP -// server that can provide various responses useful for testing. -class TestServerLauncher { +// This object bounds the lifetime of an external python-based HTTP/FTP server +// that can provide various responses useful for testing. +class TestServer { public: - TestServerLauncher(); - virtual ~TestServerLauncher(); - - enum Protocol { - ProtoHTTP, ProtoFTP + enum Type { + TYPE_FTP, + TYPE_HTTP, + TYPE_HTTPS, + TYPE_HTTPS_CLIENT_AUTH, + TYPE_HTTPS_MISMATCHED_HOSTNAME, + TYPE_HTTPS_EXPIRED_CERTIFICATE, }; - // Load the test root cert, if it hasn't been loaded yet. - bool LoadTestRootCert() WARN_UNUSED_RESULT; + TestServer(Type type, const FilePath& document_root); + ~TestServer(); - // Start src/net/tools/testserver/testserver.py and - // ask it to serve the given protocol. - // If protocol is HTTP, and cert_path is not empty, serves HTTPS. - // file_root_url specifies the root url on the server that documents will be - // served out of. This is /files/ by default. - // Returns true on success, false if files not found or root cert - // not trusted. - bool Start(net::TestServerLauncher::Protocol protocol, - const std::string& host_name, int port, - const FilePath& document_root, - const FilePath& cert_path, - const std::wstring& file_root_url) WARN_UNUSED_RESULT; + bool Start() WARN_UNUSED_RESULT; // Stop the server started by Start(). bool Stop(); @@ -69,56 +57,56 @@ class TestServerLauncher { // It returns true if the server exited cleanly. bool WaitToFinish(int milliseconds) WARN_UNUSED_RESULT; - // Paths to a good, an expired, and an invalid server certificate - // (use as arguments to Start()). - FilePath GetOKCertPath(); - FilePath GetExpiredCertPath(); - - FilePath GetDocumentRootPath() { return document_root_dir_; } - - // When Start is called, if protocol is HTTPS and ssl_client_auth_ is true, - // the server will request a client certificate on each connection. Must be - // called before Start to take effect. - void set_ssl_client_auth(bool ssl_client_auth) { - ssl_client_auth_ = ssl_client_auth; - } + const FilePath& document_root() const { return document_root_; } + const HostPortPair& host_port_pair() const { return host_port_pair_; } + std::string GetScheme() const; + bool GetAddressList(AddressList* address_list) const WARN_UNUSED_RESULT; - // Issuer name of the root cert that should be trusted for the test to work. - static const wchar_t kCertIssuerName[]; + GURL GetURL(const std::string& path); - // Hostname to use for test server - static const char kHostName[]; + GURL GetURLWithUser(const std::string& path, + const std::string& user); - // Different hostname to use for test server (that still resolves to same IP) - static const char kMismatchedHostName[]; + GURL GetURLWithUserAndPassword(const std::string& path, + const std::string& user, + const std::string& password); - // Port to use for test server - static const int kOKHTTPSPort; + private: + // Appends |dir| to PYTHONPATH. + static void AppendToPythonPath(const FilePath& dir); - // Port to use for bad test server - static const int kBadHTTPSPort; + // Modify PYTHONPATH to contain libraries we need. + bool SetPythonPath() WARN_UNUSED_RESULT; - private: - // Wait a while for the server to start, return whether - // we were able to make a connection to it. - bool WaitToStart(const std::string& host_name, int port) WARN_UNUSED_RESULT; + // Launches the Python test server. Returns true on success. + bool LaunchPython(const FilePath& testserver_path) WARN_UNUSED_RESULT; - // Append to PYTHONPATH so Python can find pyftpdlib and tlslite. - void SetPythonPath(); + // Waits for the server to start. Returns true on success. + bool WaitToStart() WARN_UNUSED_RESULT; - // Path to our test root certificate. - FilePath GetRootCertPath(); + // Returns path to the root certificate. + FilePath GetRootCertificatePath(); // Returns false if our test root certificate is not trusted. bool CheckCATrusted() WARN_UNUSED_RESULT; - // Initilize the certificate path. - void InitCertPath(); + // Load the test root cert, if it hasn't been loaded yet. + bool LoadTestRootCert() WARN_UNUSED_RESULT; + + // Returns path to the SSL certificate we should use, or empty path + // if not applicable. + FilePath GetCertificatePath(); - FilePath document_root_dir_; + // Document root of the test server. + FilePath document_root_; - FilePath cert_dir_; + // Directory that contains the SSL certificates. + FilePath certificates_dir_; + // Address the test server listens on. + HostPortPair host_port_pair_; + + // Handle of the Python process running the test server. base::ProcessHandle process_handle_; #if defined(OS_WIN) @@ -130,238 +118,11 @@ class TestServerLauncher { scoped_refptr<X509Certificate> cert_; #endif - bool ssl_client_auth_; - - DISALLOW_COPY_AND_ASSIGN(TestServerLauncher); -}; - -#if defined(OS_WIN) -// Launch test server as a job so that it is not orphaned if the test case is -// abnormally terminated. -bool LaunchTestServerAsJob(const std::wstring& cmdline, - bool start_hidden, - base::ProcessHandle* process_handle, - ScopedHandle* job_handle); -#endif - -// This object bounds the lifetime of an external python-based HTTP/FTP server -// that can provide various responses useful for testing. -class BaseTestServer : public base::RefCounted<BaseTestServer> { - protected: - BaseTestServer() {} + Type type_; - public: - bool WaitToFinish(int milliseconds) { - return launcher_.WaitToFinish(milliseconds); - } - - bool Stop() { - return launcher_.Stop(); - } - - GURL TestServerPage(const std::string& base_address, - const std::string& path) { - return GURL(base_address + path); - } - - GURL TestServerPage(const std::string& path) { - // TODO(phajdan.jr): Check for problems with IPv6. - return GURL(scheme_ + "://" + host_name_ + ":" + port_str_ + "/" + path); - } - - GURL TestServerPage(const std::string& path, - const std::string& user, - const std::string& password) { - // TODO(phajdan.jr): Check for problems with IPv6. - - if (password.empty()) - return GURL(scheme_ + "://" + user + "@" + - host_name_ + ":" + port_str_ + "/" + path); - - return GURL(scheme_ + "://" + user + ":" + password + - "@" + host_name_ + ":" + port_str_ + "/" + path); - } - - FilePath GetDataDirectory() { - return launcher_.GetDocumentRootPath(); - } - - protected: - friend class base::RefCounted<BaseTestServer>; - virtual ~BaseTestServer() { } - - bool Start(net::TestServerLauncher::Protocol protocol, - const std::string& host_name, int port, - const FilePath& document_root, - const FilePath& cert_path, - const std::wstring& file_root_url) { - if (!launcher_.Start(protocol, - host_name, port, document_root, cert_path, file_root_url)) - return false; - - if (protocol == net::TestServerLauncher::ProtoFTP) - scheme_ = "ftp"; - else - scheme_ = "http"; - if (!cert_path.empty()) - scheme_.push_back('s'); - - host_name_ = host_name; - port_str_ = base::IntToString(port); - return true; - } - - net::TestServerLauncher launcher_; - std::string scheme_; - std::string host_name_; - std::string port_str_; + DISALLOW_COPY_AND_ASSIGN(TestServer); }; -class HTTPTestServer : public BaseTestServer { - protected: - HTTPTestServer() {} - - public: - // Creates and returns a new HTTPTestServer. - static scoped_refptr<HTTPTestServer> CreateServer( - const std::wstring& document_root) { - return CreateServerWithFileRootURL(document_root, std::wstring()); - } - - static scoped_refptr<HTTPTestServer> CreateServerWithFileRootURL( - const std::wstring& document_root, - const std::wstring& file_root_url) { - scoped_refptr<HTTPTestServer> test_server(new HTTPTestServer()); - FilePath no_cert; - FilePath docroot = FilePath::FromWStringHack(document_root); - if (!StartTestServer(test_server.get(), docroot, no_cert, file_root_url)) - return NULL; - return test_server; - } - - static bool StartTestServer(HTTPTestServer* server, - const FilePath& document_root, - const FilePath& cert_path, - const std::wstring& file_root_url) { - return server->Start(net::TestServerLauncher::ProtoHTTP, kDefaultHostName, - kHTTPDefaultPort, document_root, cert_path, - file_root_url); - } -}; - -class HTTPSTestServer : public HTTPTestServer { - protected: - HTTPSTestServer() {} - - public: - // Create a server with a valid certificate - // TODO(dkegel): HTTPSTestServer should not require an instance to specify - // stock test certificates - static scoped_refptr<HTTPSTestServer> CreateGoodServer( - const std::wstring& document_root) { - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer(); - FilePath docroot = FilePath::FromWStringHack(document_root); - FilePath certpath = test_server->launcher_.GetOKCertPath(); - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP, - net::TestServerLauncher::kHostName, - net::TestServerLauncher::kOKHTTPSPort, - docroot, certpath, std::wstring())) { - return NULL; - } - return test_server; - } - - // Create a server which requests SSL client auth - static scoped_refptr<HTTPSTestServer> CreateClientAuthServer( - const std::wstring& document_root) { - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer(); - FilePath docroot = FilePath::FromWStringHack(document_root); - FilePath certpath = test_server->launcher_.GetOKCertPath(); - test_server->launcher_.set_ssl_client_auth(true); - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP, - net::TestServerLauncher::kHostName, - net::TestServerLauncher::kOKHTTPSPort, - docroot, certpath, std::wstring())) { - return NULL; - } - return test_server; - } - - // Create a server with an up to date certificate for the wrong hostname - // for this host - static scoped_refptr<HTTPSTestServer> CreateMismatchedServer( - const std::wstring& document_root) { - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer(); - FilePath docroot = FilePath::FromWStringHack(document_root); - FilePath certpath = test_server->launcher_.GetOKCertPath(); - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP, - net::TestServerLauncher::kMismatchedHostName, - net::TestServerLauncher::kOKHTTPSPort, - docroot, certpath, std::wstring())) { - return NULL; - } - return test_server; - } - - // Create a server with an expired certificate - static scoped_refptr<HTTPSTestServer> CreateExpiredServer( - const std::wstring& document_root) { - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer(); - FilePath docroot = FilePath::FromWStringHack(document_root); - FilePath certpath = test_server->launcher_.GetExpiredCertPath(); - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP, - net::TestServerLauncher::kHostName, - net::TestServerLauncher::kBadHTTPSPort, - docroot, certpath, std::wstring())) { - return NULL; - } - return test_server; - } - - // Create a server with an arbitrary certificate - static scoped_refptr<HTTPSTestServer> CreateServer( - const std::string& host_name, int port, - const std::wstring& document_root, - const std::wstring& cert_path) { - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer(); - FilePath docroot = FilePath::FromWStringHack(document_root); - FilePath certpath = FilePath::FromWStringHack(cert_path); - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP, - host_name, port, docroot, certpath, std::wstring())) { - return NULL; - } - return test_server; - } - - protected: - std::wstring cert_path_; - - private: - virtual ~HTTPSTestServer() {} -}; - -class FTPTestServer : public BaseTestServer { - public: - FTPTestServer() { - } - - static scoped_refptr<FTPTestServer> CreateServer( - const std::wstring& document_root) { - scoped_refptr<FTPTestServer> test_server = new FTPTestServer(); - FilePath docroot = FilePath::FromWStringHack(document_root); - FilePath no_cert; - if (!test_server->Start(net::TestServerLauncher::ProtoFTP, - kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring())) { - return NULL; - } - return test_server; - } - - private: - ~FTPTestServer() {} -}; - - } // namespace net #endif // NET_TEST_TEST_SERVER_H_ diff --git a/net/test/test_server_posix.cc b/net/test/test_server_posix.cc new file mode 100644 index 0000000..783bdc3 --- /dev/null +++ b/net/test/test_server_posix.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/test/test_server.h" + +#include "base/file_util.h" +#include "base/logging.h" +#include "base/string_number_conversions.h" + +namespace net { + +// static +void TestServer::AppendToPythonPath(const FilePath& dir) { + const char kPythonPath[] = "PYTHONPATH"; + const char* oldpath = getenv(kPythonPath); + // setenv() leaks memory intentionally on Mac + if (!oldpath) { + setenv(kPythonPath, dir.value().c_str(), 1); + } else if (!strstr(oldpath, dir.value().c_str())) { + std::string newpath(oldpath); + newpath.append(":"); + newpath.append(dir.value()); + setenv(kPythonPath, newpath.c_str(), 1); + } +} + +bool TestServer::LaunchPython(const FilePath& testserver_path) { + std::vector<std::string> command_line; + command_line.push_back("python"); + command_line.push_back(testserver_path.value()); + command_line.push_back("--port=" + base::IntToString(host_port_pair_.port())); + command_line.push_back("--data-dir=" + document_root_.value()); + + if (type_ == TYPE_FTP) + command_line.push_back("-f"); + + FilePath certificate_path(GetCertificatePath()); + if (!certificate_path.value().empty()) { + if (!file_util::PathExists(certificate_path)) { + LOG(ERROR) << "Certificate path " << certificate_path.value() + << " doesn't exist. Can't launch https server."; + return false; + } + command_line.push_back("--https=" + certificate_path.value()); + } + + if (type_ == TYPE_HTTPS_CLIENT_AUTH) + command_line.push_back("--ssl-client-auth"); + + base::file_handle_mapping_vector no_mappings; + if (!base::LaunchApp(command_line, no_mappings, false, &process_handle_)) { + LOG(ERROR) << "Failed to launch " << command_line[0] << " ..."; + return false; + } + + return true; +} + +bool TestServer::CheckCATrusted() { + return true; +} + +} // namespace net diff --git a/net/test/test_server_win.cc b/net/test/test_server_win.cc new file mode 100644 index 0000000..b806cba --- /dev/null +++ b/net/test/test_server_win.cc @@ -0,0 +1,165 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/test/test_server.h" + +#include <windows.h> +#include <wincrypt.h> + +#include "base/base_paths.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/string_number_conversions.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" + +#pragma comment(lib, "crypt32.lib") + +namespace { + +bool LaunchTestServerAsJob(const std::wstring& cmdline, + bool start_hidden, + base::ProcessHandle* process_handle, + ScopedHandle* job_handle) { + // Launch test server process. + STARTUPINFO startup_info = {0}; + startup_info.cb = sizeof(startup_info); + startup_info.dwFlags = STARTF_USESHOWWINDOW; + startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW; + PROCESS_INFORMATION process_info; + + // If this code is run under a debugger, the test server process is + // automatically associated with a job object created by the debugger. + // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. + if (!CreateProcess(NULL, + const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, + FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, + &startup_info, &process_info)) { + LOG(ERROR) << "Could not create process."; + return false; + } + CloseHandle(process_info.hThread); + + // If the caller wants the process handle, we won't close it. + if (process_handle) { + *process_handle = process_info.hProcess; + } else { + CloseHandle(process_info.hProcess); + } + + // Create a JobObject and associate the test server process with it. + job_handle->Set(CreateJobObject(NULL, NULL)); + if (!job_handle->IsValid()) { + LOG(ERROR) << "Could not create JobObject."; + return false; + } else { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; + limit_info.BasicLimitInformation.LimitFlags = + JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + if (0 == SetInformationJobObject(job_handle->Get(), + JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) { + LOG(ERROR) << "Could not SetInformationJobObject."; + return false; + } + if (0 == AssignProcessToJobObject(job_handle->Get(), + process_info.hProcess)) { + LOG(ERROR) << "Could not AssignProcessToObject."; + return false; + } + } + return true; +} + +} // namespace + +namespace net { + +// static +void TestServer::AppendToPythonPath(const FilePath& dir) { + const wchar_t kPythonPath[] = L"PYTHONPATH"; + // TODO(dkegel): handle longer PYTHONPATH variables + wchar_t oldpath[4096]; + if (GetEnvironmentVariable(kPythonPath, oldpath, arraysize(oldpath)) == 0) { + SetEnvironmentVariableW(kPythonPath, dir.value().c_str()); + } else if (!wcsstr(oldpath, dir.value().c_str())) { + std::wstring newpath(oldpath); + newpath.append(L";"); + newpath.append(dir.value()); + SetEnvironmentVariableW(kPythonPath, newpath.c_str()); + } +} + +bool TestServer::LaunchPython(const FilePath& testserver_path) { + FilePath python_exe; + if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_exe)) + return false; + python_exe = python_exe + .Append(FILE_PATH_LITERAL("third_party")) + .Append(FILE_PATH_LITERAL("python_24")) + .Append(FILE_PATH_LITERAL("python.exe")); + + std::wstring command_line = + L"\"" + python_exe.value() + L"\" " + + L"\"" + testserver_path.value() + + L"\" --port=" + ASCIIToWide(base::IntToString(host_port_pair_.port())) + + L" --data-dir=\"" + document_root_.value() + L"\""; + + if (type_ == TYPE_FTP) + command_line.append(L" -f"); + + FilePath certificate_path(GetCertificatePath()); + if (!certificate_path.value().empty()) { + if (!file_util::PathExists(certificate_path)) { + LOG(ERROR) << "Certificate path " << certificate_path.value() + << " doesn't exist. Can't launch https server."; + return false; + } + command_line.append(L" --https=\""); + command_line.append(certificate_path.value()); + command_line.append(L"\""); + } + + if (type_ == TYPE_HTTPS_CLIENT_AUTH) + command_line.append(L" --ssl-client-auth"); + + if (!LaunchTestServerAsJob(command_line, + true, + &process_handle_, + &job_handle_)) { + LOG(ERROR) << "Failed to launch " << command_line; + return false; + } + + return true; +} + +bool TestServer::CheckCATrusted() { + HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); + if (!cert_store) { + LOG(ERROR) << " could not open trusted root CA store"; + return false; + } + PCCERT_CONTEXT cert = + CertFindCertificateInStore(cert_store, + X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, + 0, + CERT_FIND_ISSUER_STR, + L"Test CA", + NULL); + if (cert) + CertFreeCertificateContext(cert); + CertCloseStore(cert_store, 0); + + if (!cert) { + LOG(ERROR) << " TEST CONFIGURATION ERROR: you need to import the test ca " + "certificate to your trusted roots for this test to work. " + "For more info visit:\n" + "http://dev.chromium.org/developers/testing\n"; + return false; + } + + return true; +} + +} // namespace net diff --git a/net/tools/testserver/run_testserver.cc b/net/tools/testserver/run_testserver.cc deleted file mode 100644 index 9e0396a..0000000 --- a/net/tools/testserver/run_testserver.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <stdio.h> - -#include "base/at_exit.h" -#include "base/command_line.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "net/test/test_server.h" - -static void PrintUsage() { - printf("run_testserver --doc-root=relpath [--http|--https|--ftp]\n"); - printf("(NOTE: relpath should be relative to the 'src' directory)\n"); -} - -int main(int argc, const char* argv[]) { - base::AtExitManager at_exit_manager; - MessageLoopForIO message_loop; - - // Process command line - CommandLine::Init(argc, argv); - CommandLine* command_line = CommandLine::ForCurrentProcess(); - - if (command_line->GetSwitchCount() == 0 || - command_line->HasSwitch("help")) { - PrintUsage(); - return -1; - } - - std::string protocol; - int port; - if (command_line->HasSwitch("https")) { - protocol = "https"; - port = net::TestServerLauncher::kOKHTTPSPort; - } else if (command_line->HasSwitch("ftp")) { - protocol = "ftp"; - port = net::kFTPDefaultPort; - } else { - protocol = "http"; - port = net::kHTTPDefaultPort; - } - // TODO(phajdan.jr): refactor this. - std::wstring doc_root = - command_line->GetSwitchValuePath("doc-root").ToWStringHack(); - if (doc_root.empty()) { - printf("Error: --doc-root must be specified\n"); - PrintUsage(); - return -1; - } - - // Launch testserver - scoped_refptr<net::BaseTestServer> test_server; - if (protocol == "https") { - test_server = net::HTTPSTestServer::CreateGoodServer(doc_root); - } else if (protocol == "ftp") { - test_server = net::FTPTestServer::CreateServer(doc_root); - } else if (protocol == "http") { - test_server = net::HTTPTestServer::CreateServer(doc_root); - } else { - NOTREACHED(); - } - - printf("testserver running at %s://%s:%d (type ctrl+c to exit)\n", - protocol.c_str(), - net::TestServerLauncher::kHostName, - port); - - message_loop.Run(); - return 0; -} diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py index 849ec17..6c9ef83 100644 --- a/net/tools/testserver/testserver.py +++ b/net/tools/testserver/testserver.py @@ -23,6 +23,10 @@ import SocketServer import sys import time import urllib2 +import warnings + +# Ignore deprecation warnings, they make our output more cluttered. +warnings.filterwarnings("ignore", category=DeprecationWarning) import pyftpdlib.ftpserver import tlslite @@ -79,6 +83,9 @@ class HTTPSServer(tlslite.api.TLSSocketServerMixIn, StoppableHTTPServer): reqCert=self.ssl_client_auth) tlsConnection.ignoreAbruptClose = True return True + except tlslite.api.TLSAbruptCloseError: + # Ignore abrupt close. + return True except tlslite.api.TLSError, error: print "Handshake failure:", str(error) return False @@ -1201,10 +1208,29 @@ def TryKillingOldServer(port): # Common case, indicates no server running. pass +class FileMultiplexer: + def __init__(self, fd1, fd2) : + self.__fd1 = fd1 + self.__fd2 = fd2 + + def __del__(self) : + if self.__fd1 != sys.stdout and self.__fd1 != sys.stderr: + self.__fd1.close() + if self.__fd2 != sys.stdout and self.__fd2 != sys.stderr: + self.__fd2.close() + + def write(self, text) : + self.__fd1.write(text) + self.__fd2.write(text) + + def flush(self) : + self.__fd1.flush() + self.__fd2.flush() + def main(options, args): - # redirect output to a log file so it doesn't spam the unit test output logfile = open('testserver.log', 'w') - sys.stderr = sys.stdout = logfile + sys.stdout = FileMultiplexer(sys.stdout, logfile) + sys.stderr = FileMultiplexer(sys.stderr, logfile) port = options.port diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index eb4a9bb..aabb070 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -49,10 +49,6 @@ #include "testing/platform_test.h" using base::Time; -using net::kHTTPDefaultPort; -using net::FTPTestServer; -using net::HTTPTestServer; -using net::HTTPSTestServer; namespace { @@ -103,17 +99,15 @@ class URLRequestTest : public PlatformTest { }; class URLRequestTestHTTP : public URLRequestTest { - protected: - static void SetUpTestCase() { - server_ = HTTPTestServer::CreateServer(L"net/data/url_request_unittest/"); - } - - static void TearDownTestCase() { - server_ = NULL; + public: + URLRequestTestHTTP() + : test_server_(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL( + "net/data/url_request_unittest"))) { } + protected: void HTTPUploadDataOperationTest(const std::string& method) { - ASSERT_TRUE(NULL != server_.get()); const int kMsgSize = 20000; // multiple of 10 const int kIterations = 50; char *uploadBytes = new char[kMsgSize+1]; @@ -135,7 +129,7 @@ class URLRequestTestHTTP : public URLRequestTest { for (int i = 0; i < kIterations; ++i) { TestDelegate d; - URLRequest r(server_->TestServerPage("echo"), &d); + URLRequest r(test_server_.GetURL("echo"), &d); r.set_context(context); r.set_method(method.c_str()); @@ -157,24 +151,21 @@ class URLRequestTestHTTP : public URLRequestTest { delete[] uploadBytes; } - static scoped_refptr<HTTPTestServer> server_; + net::TestServer test_server_; }; -// static -scoped_refptr<HTTPTestServer> URLRequestTestHTTP::server_; - +// In this unit test, we're using the HTTPTestServer as a proxy server and +// issuing a CONNECT request with the magic host name "www.redirect.com". +// The HTTPTestServer will return a 302 response, which we should not +// follow. TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { - // In this unit test, we're using the HTTPTestServer as a proxy server and - // issuing a CONNECT request with the magic host name "www.redirect.com". - // The HTTPTestServer will return a 302 response, which we should not - // follow. - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { URLRequest r(GURL("https://www.redirect.com/"), &d); - std::string proxy("localhost:"); - proxy.append(base::IntToString(kHTTPDefaultPort)); - r.set_context(new TestURLRequestContext(proxy)); + r.set_context( + new TestURLRequestContext(test_server_.host_port_pair().ToString())); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -189,17 +180,17 @@ TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { } } +// In this unit test, we're using the HTTPTestServer as a proxy server and +// issuing a CONNECT request with the magic host name "www.server-auth.com". +// The HTTPTestServer will return a 401 response, which we should balk at. TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { - // In this unit test, we're using the HTTPTestServer as a proxy server and - // issuing a CONNECT request with the magic host name "www.server-auth.com". - // The HTTPTestServer will return a 401 response, which we should balk at. - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { URLRequest r(GURL("https://www.server-auth.com/"), &d); - std::string proxy("localhost:"); - proxy.append(base::IntToString(kHTTPDefaultPort)); - r.set_context(new TestURLRequestContext(proxy)); + r.set_context( + new TestURLRequestContext(test_server_.host_port_pair().ToString())); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -212,10 +203,11 @@ TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { } TEST_F(URLRequestTestHTTP, GetTest_NoCache) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage(""), &d); + TestURLRequest r(test_server_.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -231,10 +223,11 @@ TEST_F(URLRequestTestHTTP, GetTest_NoCache) { } TEST_F(URLRequestTestHTTP, GetTest) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage(""), &d); + TestURLRequest r(test_server_.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -248,17 +241,18 @@ TEST_F(URLRequestTestHTTP, GetTest) { } TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { - scoped_refptr<HTTPSTestServer> https_server = - HTTPSTestServer::CreateGoodServer(L"net/data/ssl/"); - ASSERT_TRUE(NULL != https_server.get()); - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + + net::TestServer https_test_server( + net::TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl"))); + ASSERT_TRUE(https_test_server.Start()); // An https server is sent a request with an https referer, // and responds with a redirect to an http url. The http // server should not be sent the referer. - GURL http_destination = server_->TestServerPage(""); + GURL http_destination = test_server_.GetURL(""); TestDelegate d; - TestURLRequest req(https_server->TestServerPage( + TestURLRequest req(https_test_server.GetURL( "server-redirect?" + http_destination.spec()), &d); req.set_referrer("https://www.referrer.com/"); req.Start(); @@ -326,15 +320,16 @@ bool MakeGETRequest(const GURL& url) { // the server to exit by itself (rather than letting TestServerLauncher's // destructor kill it). We now unit test this mechanism. TEST_F(URLRequestTest, QuitTest) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + // 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(server->TestServerPage(page_name)); + bool r = MakeGETRequest(test_server.GetURL(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. @@ -345,25 +340,20 @@ TEST_F(URLRequestTest, QuitTest) { } // Make sure we were successful in stopping the testserver. EXPECT_LT(0, retry_count); - EXPECT_TRUE(server->WaitToFinish(20000)); + EXPECT_TRUE(test_server.WaitToFinish(20000)); } class HTTPSRequestTest : public testing::Test { }; - TEST_F(HTTPSRequestTest, HTTPSGetTest) { - // Note: tools/testserver/testserver.py does not need - // 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::CreateGoodServer(L"net/data/ssl"); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTPS, + FilePath(FILE_PATH_LITERAL("net/data/ssl"))); + ASSERT_TRUE(test_server.Start()); TestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(test_server.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -377,16 +367,16 @@ TEST_F(HTTPSRequestTest, HTTPSGetTest) { } TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { - scoped_refptr<HTTPSTestServer> server = - HTTPSTestServer::CreateMismatchedServer(L"net/data/ssl"); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_MISMATCHED_HOSTNAME, + FilePath(FILE_PATH_LITERAL("net/data/ssl"))); + ASSERT_TRUE(test_server.Start()); bool err_allowed = true; for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { TestDelegate d; { d.set_allow_certificate_errors(err_allowed); - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(test_server.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -405,9 +395,9 @@ TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { } TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { - scoped_refptr<HTTPSTestServer> server = - HTTPSTestServer::CreateExpiredServer(L"net/data/ssl"); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_EXPIRED_CERTIFICATE, + FilePath(FILE_PATH_LITERAL("net/data/ssl"))); + ASSERT_TRUE(test_server.Start()); // Iterate from false to true, just so that we do the opposite of the // previous test in order to increase test coverage. @@ -416,7 +406,7 @@ TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { TestDelegate d; { d.set_allow_certificate_errors(err_allowed); - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(test_server.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -461,13 +451,13 @@ class SSLClientAuthTestDelegate : public TestDelegate { // - Getting a certificate request in an SSL renegotiation sending the // HTTP request. TEST_F(HTTPSRequestTest, ClientAuthTest) { - scoped_refptr<HTTPSTestServer> server = - HTTPSTestServer::CreateClientAuthServer(L"net/data/ssl"); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTPS_CLIENT_AUTH, + FilePath(FILE_PATH_LITERAL("net/data/ssl"))); + ASSERT_TRUE(test_server.Start()); SSLClientAuthTestDelegate d; { - TestURLRequest r(server->TestServerPage(""), &d); + TestURLRequest r(test_server.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -501,14 +491,11 @@ TEST_F(URLRequestTestHTTP, CancelTest) { } TEST_F(URLRequestTestHTTP, CancelTest2) { - ASSERT_TRUE(NULL != server_.get()); - - // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' - // to 'const int' + ASSERT_TRUE(test_server_.Start()); TestDelegate d; { - TestURLRequest r(server_->TestServerPage(""), &d); + TestURLRequest r(test_server_.GetURL(""), &d); d.set_cancel_in_response_started(true); @@ -525,10 +512,11 @@ TEST_F(URLRequestTestHTTP, CancelTest2) { } TEST_F(URLRequestTestHTTP, CancelTest3) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage(""), &d); + TestURLRequest r(test_server_.GetURL(""), &d); d.set_cancel_in_received_data(true); @@ -548,10 +536,11 @@ TEST_F(URLRequestTestHTTP, CancelTest3) { } TEST_F(URLRequestTestHTTP, CancelTest4) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage(""), &d); + TestURLRequest r(test_server_.GetURL(""), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -572,13 +561,14 @@ TEST_F(URLRequestTestHTTP, CancelTest4) { } TEST_F(URLRequestTestHTTP, CancelTest5) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); // populate cache { TestDelegate d; - URLRequest r(server_->TestServerPage("cachetime"), &d); + URLRequest r(test_server_.GetURL("cachetime"), &d); r.set_context(context); r.Start(); MessageLoop::current()->Run(); @@ -588,7 +578,7 @@ TEST_F(URLRequestTestHTTP, CancelTest5) { // cancel read from cache (see bug 990242) { TestDelegate d; - URLRequest r(server_->TestServerPage("cachetime"), &d); + URLRequest r(test_server_.GetURL("cachetime"), &d); r.set_context(context); r.Start(); r.Cancel(); @@ -602,18 +592,21 @@ TEST_F(URLRequestTestHTTP, CancelTest5) { } TEST_F(URLRequestTestHTTP, PostTest) { + ASSERT_TRUE(test_server_.Start()); HTTPUploadDataOperationTest("POST"); } TEST_F(URLRequestTestHTTP, PutTest) { + ASSERT_TRUE(test_server_.Start()); HTTPUploadDataOperationTest("PUT"); } TEST_F(URLRequestTestHTTP, PostEmptyTest) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage("echo"), &d); + TestURLRequest r(test_server_.GetURL("echo"), &d); r.set_method("POST"); r.Start(); @@ -630,10 +623,11 @@ TEST_F(URLRequestTestHTTP, PostEmptyTest) { } TEST_F(URLRequestTestHTTP, PostFileTest) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage("echo"), &d); + TestURLRequest r(test_server_.GetURL("echo"), &d); r.set_method("POST"); FilePath dir; @@ -884,9 +878,10 @@ TEST_F(URLRequestTest, InvalidUrlTest) { } TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; - TestURLRequest req(server_->TestServerPage("files/with-headers.html"), &d); + TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -981,10 +976,10 @@ TEST_F(URLRequestTest, ResolveShortcutTest) { #endif // defined(OS_WIN) TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "files/content-type-normalization.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -1059,10 +1054,10 @@ TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { #endif TEST_F(URLRequestTestHTTP, RestrictRedirects) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "files/redirect-to-file.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -1072,10 +1067,10 @@ TEST_F(URLRequestTestHTTP, RestrictRedirects) { } TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "files/redirect-to-invalid-url.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -1085,9 +1080,10 @@ TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { } TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "echoheader?Referer"), &d); req.set_referrer("http://user:pass@foo.com/"); req.Start(); @@ -1097,11 +1093,12 @@ TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { } TEST_F(URLRequestTestHTTP, CancelRedirect) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { d.set_cancel_in_received_redirect(true); - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "files/redirect-test.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -1114,11 +1111,12 @@ TEST_F(URLRequestTestHTTP, CancelRedirect) { } TEST_F(URLRequestTestHTTP, DeferredRedirect) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { d.set_quit_on_redirect(true); - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "files/redirect-test.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -1146,11 +1144,12 @@ TEST_F(URLRequestTestHTTP, DeferredRedirect) { } TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { d.set_quit_on_redirect(true); - TestURLRequest req(server_->TestServerPage( + TestURLRequest req(test_server_.GetURL( "files/redirect-test.html"), &d); req.Start(); MessageLoop::current()->Run(); @@ -1168,14 +1167,14 @@ TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { } TEST_F(URLRequestTestHTTP, VaryHeader) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); // populate the cache { TestDelegate d; - URLRequest req(server_->TestServerPage("echoheader?foo"), &d); + URLRequest req(test_server_.GetURL("echoheader?foo"), &d); req.set_context(context); net::HttpRequestHeaders headers; headers.SetHeader("foo", "1"); @@ -1187,7 +1186,7 @@ TEST_F(URLRequestTestHTTP, VaryHeader) { // expect a cache hit { TestDelegate d; - URLRequest req(server_->TestServerPage("echoheader?foo"), &d); + URLRequest req(test_server_.GetURL("echoheader?foo"), &d); req.set_context(context); net::HttpRequestHeaders headers; headers.SetHeader("foo", "1"); @@ -1201,7 +1200,7 @@ TEST_F(URLRequestTestHTTP, VaryHeader) { // expect a cache miss { TestDelegate d; - URLRequest req(server_->TestServerPage("echoheader?foo"), &d); + URLRequest req(test_server_.GetURL("echoheader?foo"), &d); req.set_context(context); net::HttpRequestHeaders headers; headers.SetHeader("foo", "2"); @@ -1214,8 +1213,9 @@ TEST_F(URLRequestTestHTTP, VaryHeader) { } TEST_F(URLRequestTestHTTP, BasicAuth) { + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); - ASSERT_TRUE(NULL != server_.get()); // populate the cache { @@ -1223,7 +1223,7 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { d.set_username(kUser); d.set_password(kSecret); - URLRequest r(server_->TestServerPage("auth-basic"), &d); + URLRequest r(test_server_.GetURL("auth-basic"), &d); r.set_context(context); r.Start(); @@ -1240,7 +1240,7 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { d.set_username(kUser); d.set_password(kSecret); - URLRequest r(server_->TestServerPage("auth-basic"), &d); + URLRequest r(test_server_.GetURL("auth-basic"), &d); r.set_context(context); r.set_load_flags(net::LOAD_VALIDATE_CACHE); r.Start(); @@ -1257,10 +1257,10 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { // Check that Set-Cookie headers in 401 responses are respected. // http://crbug.com/6450 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); GURL url_requiring_auth = - server_->TestServerPage("auth-basic?set-cookie-if-challenged"); + test_server_.GetURL("auth-basic?set-cookie-if-challenged"); // Request a page that will give a 401 containing a Set-Cookie header. // Verify that when the transaction is restarted, it includes the new cookie. @@ -1311,14 +1311,15 @@ TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { } TEST_F(URLRequestTest, DoNotSendCookies) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); + URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1329,7 +1330,7 @@ TEST_F(URLRequestTest, DoNotSendCookies) { // Verify that the cookie is set. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1343,7 +1344,7 @@ TEST_F(URLRequestTest, DoNotSendCookies) { // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); req.set_context(context); req.Start(); @@ -1359,14 +1360,15 @@ TEST_F(URLRequestTest, DoNotSendCookies) { } TEST_F(URLRequestTest, DoNotSaveCookies) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), + URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); req.set_context(context); req.Start(); @@ -1380,7 +1382,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { // Try to set-up another cookie and update the previous cookie. { TestDelegate d; - URLRequest req(server->TestServerPage( + URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); req.set_context(context); @@ -1397,7 +1399,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { // Verify the cookies weren't saved or updated. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1414,14 +1416,15 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { } TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); + URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1433,7 +1436,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { // Verify that the cookie is set. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1451,7 +1454,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { context->set_cookie_policy(&cookie_policy); TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1467,14 +1470,15 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { } TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), + URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); req.set_context(context); req.Start(); @@ -1490,7 +1494,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { context->set_cookie_policy(&cookie_policy); TestDelegate d; - URLRequest req(server->TestServerPage( + URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); req.set_context(context); req.Start(); @@ -1507,7 +1511,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { // Verify the cookies weren't saved or updated. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1523,14 +1527,15 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { } TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); + URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1542,7 +1547,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { // Verify that the cookie is set. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1561,7 +1566,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { context->set_cookie_policy(&cookie_policy); TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1577,14 +1582,15 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { } TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), + URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); req.set_context(context); req.Start(); @@ -1601,7 +1607,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { context->set_cookie_policy(&cookie_policy); TestDelegate d; - URLRequest req(server->TestServerPage( + URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); req.set_context(context); req.Start(); @@ -1617,7 +1623,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { // Verify the cookies weren't saved or updated. { TestDelegate d; - TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); @@ -1633,8 +1639,9 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { } TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); @@ -1643,7 +1650,7 @@ TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), + URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), &d); req.set_context(context); req.Start(); // Triggers an asynchronous cookie policy check. @@ -1663,8 +1670,9 @@ TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { } TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); @@ -1674,7 +1682,7 @@ TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { { TestDelegate d; d.set_cancel_in_get_cookies_blocked(true); - URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), + URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), &d); req.set_context(context); req.Start(); // Triggers an asynchronous cookie policy check. @@ -1691,8 +1699,9 @@ TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { } TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); @@ -1702,7 +1711,7 @@ TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { { TestDelegate d; d.set_cancel_in_set_cookie_blocked(true); - URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), + URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), &d); req.set_context(context); req.Start(); // Triggers an asynchronous cookie policy check. @@ -1724,8 +1733,9 @@ TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { } TEST_F(URLRequestTest, CookiePolicy_ForceSession) { - scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); - ASSERT_TRUE(NULL != server.get()); + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); + ASSERT_TRUE(test_server.Start()); + scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); @@ -1734,7 +1744,7 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { // Set up a cookie. { TestDelegate d; - URLRequest req(server->TestServerPage( + URLRequest req(test_server.GetURL( "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); req.set_context(context); req.Start(); // Triggers an asynchronous cookie policy check. @@ -1759,10 +1769,12 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { // Content-Type header. // http://code.google.com/p/chromium/issues/detail?id=843 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { + ASSERT_TRUE(test_server_.Start()); + const char kData[] = "hello world"; - ASSERT_TRUE(NULL != server_.get()); + TestDelegate d; - TestURLRequest req(server_->TestServerPage("files/redirect-to-echoall"), &d); + TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); req.set_method("POST"); req.set_upload(CreateSimpleUploadData(kData)); @@ -1799,10 +1811,12 @@ TEST_F(URLRequestTestHTTP, Post302RedirectGet) { } TEST_F(URLRequestTestHTTP, Post307RedirectPost) { + ASSERT_TRUE(test_server_.Start()); + const char kData[] = "hello world"; - ASSERT_TRUE(NULL != server_.get()); + TestDelegate d; - TestURLRequest req(server_->TestServerPage("files/redirect307-to-echo"), + TestURLRequest req(test_server_.GetURL("files/redirect307-to-echo"), &d); req.set_method("POST"); req.set_upload(CreateSimpleUploadData(kData).get()); @@ -2275,27 +2289,21 @@ TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { } class URLRequestTestFTP : public URLRequestTest { - protected: - static void SetUpTestCase() { - server_ = FTPTestServer::CreateServer(L""); - } - - static void TearDownTestCase() { - server_ = NULL; + public: + URLRequestTestFTP() : test_server_(net::TestServer::TYPE_FTP, FilePath()) { } - static scoped_refptr<FTPTestServer> server_; + protected: + net::TestServer test_server_; }; -// static -scoped_refptr<FTPTestServer> URLRequestTestFTP::server_; - // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPDirectoryListing) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; { - TestURLRequest r(server_->TestServerPage("/"), &d); + TestURLRequest r(test_server_.GetURL("/"), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2310,13 +2318,14 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPDirectoryListing) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPGetTestAnonymous) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r(server_->TestServerPage("/LICENSE"), &d); + TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2334,14 +2343,16 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPGetTestAnonymous) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPGetTest) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "chrome"), - &d); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), + &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2359,14 +2370,18 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPGetTest) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPassword) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r(server_->TestServerPage("/LICENSE", - "chrome", "wrong_password"), &d); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", + "chrome", + "wrong_password"), + &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2384,7 +2399,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPassword) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPasswordRestart) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); @@ -2394,8 +2410,11 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPasswordRestart) { d.set_username(kChrome); d.set_password(kChrome); { - TestURLRequest r(server_->TestServerPage("/LICENSE", - "chrome", "wrong_password"), &d); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", + "chrome", + "wrong_password"), + &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2413,14 +2432,18 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPasswordRestart) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUser) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r(server_->TestServerPage("/LICENSE", - "wrong_user", "chrome"), &d); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", + "wrong_user", + "chrome"), + &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2438,7 +2461,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUser) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUserRestart) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); @@ -2448,8 +2472,11 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUserRestart) { d.set_username(kChrome); d.set_password(kChrome); { - TestURLRequest r(server_->TestServerPage("/LICENSE", - "wrong_user", "chrome"), &d); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", + "wrong_user", + "chrome"), + &d); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2467,7 +2494,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUserRestart) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPCacheURLCredentials) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); @@ -2475,9 +2503,11 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheURLCredentials) { scoped_ptr<TestDelegate> d(new TestDelegate); { // Pass correct login identity in the URL. - TestURLRequest r(server_->TestServerPage("/LICENSE", - "chrome", "chrome"), - d.get()); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", + "chrome", + "chrome"), + d.get()); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2495,7 +2525,7 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheURLCredentials) { d.reset(new TestDelegate); { // This request should use cached identity from previous request. - TestURLRequest r(server_->TestServerPage("/LICENSE"), d.get()); + TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2513,7 +2543,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheURLCredentials) { // Flaky, see http://crbug.com/25045. TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + FilePath app_path; PathService::Get(base::DIR_SOURCE_ROOT, &app_path); app_path = app_path.AppendASCII("LICENSE"); @@ -2524,9 +2555,11 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { d->set_username(kChrome); d->set_password(kChrome); { - TestURLRequest r(server_->TestServerPage("/LICENSE", - "chrome", "wrong_password"), - d.get()); + TestURLRequest r( + test_server_.GetURLWithUserAndPassword("/LICENSE", + "chrome", + "wrong_password"), + d.get()); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2547,7 +2580,7 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { { // Don't pass wrong credentials in the URL, they would override valid cached // ones. - TestURLRequest r(server_->TestServerPage("/LICENSE"), d.get()); + TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2565,9 +2598,10 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { // Check that default A-L header is sent. TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; - TestURLRequest req(server_->TestServerPage("echoheader?Accept-Language"), &d); + TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); req.set_context(new TestURLRequestContext()); req.Start(); MessageLoop::current()->Run(); @@ -2577,10 +2611,11 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { // Check that if request overrides the A-L header, the default is not appended. // See http://crbug.com/20894 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; TestURLRequest - req(server_->TestServerPage("echoheaderoverride?Accept-Language"), &d); + req(test_server_.GetURL("echoheaderoverride?Accept-Language"), &d); req.set_context(new TestURLRequestContext()); net::HttpRequestHeaders headers; headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage, "ru"); @@ -2592,9 +2627,10 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { // Check that default A-C header is sent. TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; - TestURLRequest req(server_->TestServerPage("echoheader?Accept-Charset"), &d); + TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); req.set_context(new TestURLRequestContext()); req.Start(); MessageLoop::current()->Run(); @@ -2604,10 +2640,11 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { // Check that if request overrides the A-C header, the default is not appended. // See http://crbug.com/20894 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); + TestDelegate d; TestURLRequest - req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); + req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); req.set_context(new TestURLRequestContext()); net::HttpRequestHeaders headers; headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); diff --git a/webkit/glue/mimetype_unittest.cc b/webkit/glue/mimetype_unittest.cc index 152d20d9..1c2e5f4 100644 --- a/webkit/glue/mimetype_unittest.cc +++ b/webkit/glue/mimetype_unittest.cc @@ -25,18 +25,17 @@ class MimeTypeTests : public TestShellTest { void CheckMimeType(const char* mimetype, const std::wstring& expected) { std::string path("contenttype?"); - GURL url = server_->TestServerPage(path + mimetype); + GURL url(test_server_.GetURL(path + mimetype)); LoadURL(url); WebFrame* frame = test_shell_->webView()->mainFrame(); EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); } - scoped_refptr<UnittestTestServer> server_; + UnittestTestServer test_server_; }; TEST_F(MimeTypeTests, MimeTypeTests) { - server_ = UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server_.get()); + ASSERT_TRUE(test_server_.Start()); std::wstring expected_src(L"<html>\n<body>\n" L"<p>HTML text</p>\n</body>\n</html>\n"); diff --git a/webkit/glue/resource_fetcher_unittest.cc b/webkit/glue/resource_fetcher_unittest.cc index b3f4427..70c316b 100644 --- a/webkit/glue/resource_fetcher_unittest.cc +++ b/webkit/glue/resource_fetcher_unittest.cc @@ -25,13 +25,8 @@ using webkit_glue::ResourceFetcherWithTimeout; namespace { class ResourceFetcherTests : public TestShellTest { - public: - void SetUp() { - TestShellTest::SetUp(); - } - void TearDown() { - TestShellTest::TearDown(); - } + protected: + UnittestTestServer test_server_; }; static const int kMaxWaitTimeMs = 5000; @@ -155,13 +150,11 @@ 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()); + ASSERT_TRUE(test_server_.Start()); WebFrame* frame = test_shell_->webView()->mainFrame(); - GURL url = server->TestServerPage("files/test_shell/index.html"); + GURL url(test_server_.GetURL("files/test_shell/index.html")); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( url, frame, delegate->NewCallback())); @@ -174,7 +167,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 = test_server_.GetURL("files/thisfiledoesntexist.html"); delegate.reset(new FetcherDelegate); fetcher.reset(new ResourceFetcher(url, frame, delegate->NewCallback())); @@ -186,9 +179,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { } TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { - scoped_refptr<UnittestTestServer> server = - UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); WebFrame* frame = test_shell_->webView()->mainFrame(); @@ -209,15 +200,13 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { } TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { - scoped_refptr<UnittestTestServer> server = - UnittestTestServer::CreateServer(); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); WebFrame* frame = test_shell_->webView()->mainFrame(); // 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(test_server_.GetURL("slow?1")); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout( url, frame, 0, delegate->NewCallback())); diff --git a/webkit/glue/unittest_test_server.h b/webkit/glue/unittest_test_server.h index fe282ec..575f0f9 100644 --- a/webkit/glue/unittest_test_server.h +++ b/webkit/glue/unittest_test_server.h @@ -9,58 +9,13 @@ #include "net/test/test_server.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/appcache/appcache_interfaces.h" -#include "webkit/glue/resource_loader_bridge.h" - -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 net::HTTPTestServer { - protected: - UnittestTestServer() { - } +class UnittestTestServer : public net::TestServer { public: - static UnittestTestServer* CreateServer() { - UnittestTestServer* test_server = new UnittestTestServer(); - FilePath no_cert; - FilePath docroot(FILE_PATH_LITERAL("webkit/data")); - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP, - "localhost", 1337, docroot, no_cert, std::wstring())) { - delete test_server; - return NULL; - } - return test_server; + UnittestTestServer() + : net::TestServer(net::TestServer::TYPE_HTTP, + FilePath(FILE_PATH_LITERAL("webkit/data"))) { } - - virtual bool MakeGETRequest(const std::string& page_name) { - GURL url(TestServerPage(page_name)); - webkit_glue::ResourceLoaderBridge::RequestInfo request_info; - request_info.method = "GET"; - request_info.url = url; - request_info.first_party_for_cookies = url; - request_info.referrer = GURL(); // No referrer. - request_info.frame_origin = "null"; - request_info.main_frame_origin = "null"; - request_info.headers = std::string(); // No extra headers. - request_info.load_flags = net::LOAD_NORMAL; - request_info.requestor_pid = 0; - request_info.request_type = ResourceType::SUB_RESOURCE; - request_info.request_context = 0; - request_info.appcache_host_id = appcache::kNoHostId; - request_info.routing_id = 0; - scoped_ptr<ResourceLoaderBridge> loader( - ResourceLoaderBridge::Create(request_info)); - EXPECT_TRUE(loader.get()); - - ResourceLoaderBridge::SyncLoadResponse resp; - loader->SyncLoad(&resp); - return resp.status.is_success(); - } - - private: - virtual ~UnittestTestServer() {} }; #endif // WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc index 8ccc7ef..27f2396 100644 --- a/webkit/tools/test_shell/test_shell_main.cc +++ b/webkit/tools/test_shell/test_shell_main.cc @@ -177,12 +177,6 @@ int main(int argc, char* argv[]) { // Config the network module so it has access to a limited set of resources. net::NetModule::SetResourceProvider(TestShell::NetResourceProvider); - // On Linux and Mac, load the test root certificate. - net::TestServerLauncher ssl_util; - if (!ssl_util.LoadTestRootCert()) { - LOG(ERROR) << "Failed to load test root certificate."; - } - platform.InitializeGUI(); if (parsed_command_line.HasSwitch(test_shell::kEnableLegacyParser)) { |