summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 20:45:27 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 20:45:27 +0000
commitdd26501ef315e241911a31a8a98027c9bbb65560 (patch)
tree1c02dfce0035199f0c073ebf793607d6e7934be5 /chrome/browser/history
parent7ecec17feb965bab7cd348ab16a9da8d772f70dc (diff)
downloadchromium_src-dd26501ef315e241911a31a8a98027c9bbb65560.zip
chromium_src-dd26501ef315e241911a31a8a98027c9bbb65560.tar.gz
chromium_src-dd26501ef315e241911a31a8a98027c9bbb65560.tar.bz2
Add FTP unit test in preparation for portable FTP implementation.
Clean up test server code. Originally from issue 12939, written by Ibrar Ahmed (ibrar.ahmed@gmail.com) (take 2) Review URL: http://codereview.chromium.org/17040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/redirect_uitest.cc128
1 files changed, 73 insertions, 55 deletions
diff --git a/chrome/browser/history/redirect_uitest.cc b/chrome/browser/history/redirect_uitest.cc
index 272c59a..4002500 100644
--- a/chrome/browser/history/redirect_uitest.cc
+++ b/chrome/browser/history/redirect_uitest.cc
@@ -30,10 +30,12 @@ class RedirectTest : public UITest {
// Tests a single server redirect
TEST_F(RedirectTest, Server) {
- TestServer server(kDocRoot);
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
- GURL final_url = server.TestServerPageW(std::wstring());
- GURL first_url = server.TestServerPageW(
+ GURL final_url = server->TestServerPageW(std::wstring());
+ GURL first_url = server->TestServerPageW(
std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec()));
NavigateToURL(first_url);
@@ -50,10 +52,12 @@ TEST_F(RedirectTest, Server) {
// Tests a single client redirect.
TEST_F(RedirectTest, Client) {
- TestServer server(kDocRoot);
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
- GURL final_url = server.TestServerPageW(std::wstring());
- GURL first_url = server.TestServerPageW(
+ GURL final_url = server->TestServerPageW(std::wstring());
+ GURL first_url = server->TestServerPageW(
std::wstring(L"client-redirect?") + UTF8ToWide(final_url.spec()));
// We need the sleep for the client redirects, because it appears as two
@@ -72,30 +76,32 @@ TEST_F(RedirectTest, Client) {
}
TEST_F(RedirectTest, ClientEmptyReferer) {
- TestServer server(kDocRoot);
-
- GURL final_url = server.TestServerPageW(std::wstring());
- std::wstring test_file = test_data_directory_;
- file_util::AppendToPath(&test_file, L"file_client_redirect.html");
- GURL first_url = net::FilePathToFileURL(test_file);
-
- NavigateToURL(first_url);
- std::vector<GURL> redirects;
- // We need the sleeps for the client redirects, because it appears as two
- // page visits in the browser. And note for this test the browser actually
- // loads the html file on disk, rather than just getting a response from
- // the TestServer.
- for (int i = 0; i < 10; ++i) {
- Sleep(kWaitForActionMaxMsec / 10);
- scoped_ptr<TabProxy> tab_proxy(GetActiveTab());
- ASSERT_TRUE(tab_proxy.get());
- ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
- if (!redirects.empty())
- break;
- }
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
+
+ GURL final_url = server->TestServerPageW(std::wstring());
+ std::wstring test_file = test_data_directory_;
+ file_util::AppendToPath(&test_file, L"file_client_redirect.html");
+ GURL first_url = net::FilePathToFileURL(test_file);
- EXPECT_EQ(1, redirects.size());
- EXPECT_EQ(final_url.spec(), redirects[0].spec());
+ NavigateToURL(first_url);
+ std::vector<GURL> redirects;
+ // We need the sleeps for the client redirects, because it appears as two
+ // page visits in the browser. And note for this test the browser actually
+ // loads the html file on disk, rather than just getting a response from
+ // the TestServer.
+ for (int i = 0; i < 10; ++i) {
+ Sleep(kWaitForActionMaxMsec / 10);
+ scoped_ptr<TabProxy> tab_proxy(GetActiveTab());
+ ASSERT_TRUE(tab_proxy.get());
+ ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
+ if (!redirects.empty())
+ break;
+ }
+
+ EXPECT_EQ(1, redirects.size());
+ EXPECT_EQ(final_url.spec(), redirects[0].spec());
}
// Tests to make sure a location change when a pending redirect exists isn't
@@ -136,14 +142,16 @@ TEST_F(RedirectTest, ClientCancelled) {
// TODO(creis): This is disabled temporarily while I figure out why it is
// failing.
TEST_F(RedirectTest, DISABLED_ClientServerServer) {
- TestServer server(kDocRoot);
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
- GURL final_url = server.TestServerPageW(std::wstring());
- GURL next_to_last = server.TestServerPageW(
+ GURL final_url = server->TestServerPageW(std::wstring());
+ GURL next_to_last = server->TestServerPageW(
std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec()));
- GURL second_url = server.TestServerPageW(
+ GURL second_url = server->TestServerPageW(
std::wstring(L"server-redirect?") + UTF8ToWide(next_to_last.spec()));
- GURL first_url = server.TestServerPageW(
+ GURL first_url = server->TestServerPageW(
std::wstring(L"client-redirect?") + UTF8ToWide(second_url.spec()));
std::vector<GURL> redirects;
@@ -168,12 +176,14 @@ TEST_F(RedirectTest, DISABLED_ClientServerServer) {
// Tests that the "#reference" gets preserved across server redirects.
TEST_F(RedirectTest, ServerReference) {
- TestServer server(kDocRoot);
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
const std::string ref("reference");
- GURL final_url = server.TestServerPageW(std::wstring());
- GURL initial_url = server.TestServerPageW(
+ GURL final_url = server->TestServerPageW(std::wstring());
+ GURL initial_url = server->TestServerPageW(
std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec()) +
L"#" + UTF8ToWide(ref));
@@ -187,12 +197,14 @@ 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) {
- TestServer server(kDocRoot);
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
std::wstring test_file = test_data_directory_;
file_util::AppendToPath(&test_file, L"http_to_file.html");
GURL file_url = net::FilePathToFileURL(test_file);
- GURL initial_url = server.TestServerPageW(
+ GURL initial_url = server->TestServerPageW(
std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec()));
NavigateToURL(initial_url);
@@ -208,7 +220,10 @@ 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) {
- TestServer server(kDocRoot);
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
+
std::wstring test_file = test_data_directory_;
file_util::AppendToPath(&test_file, L"ref_redirect.html");
GURL first_url = net::FilePathToFileURL(test_file);
@@ -229,24 +244,27 @@ TEST_F(RedirectTest, ClientFragments) {
}
// TODO(timsteele): This is disabled because our current testserver can't
-// handle multiple requests in parallel, making it hang on the first request to
-// /slow?60. It's unable to serve our second request for files/title2.html until
-// /slow? completes, which doesn't give the desired behavior. We could
-// alternatively load the second page from disk, but we would need to start the
-// browser for this testcase with --process-per-tab, and I don't think we can do
-// this at test-case-level granularity at the moment.
-TEST_F(RedirectTest, DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) {
+// handle multiple requests in parallel, making it hang on the first request
+// to /slow?60. It's unable to serve our second request for files/title2.html
+// until /slow? completes, which doesn't give the desired behavior. We could
+// alternatively load the second page from disk, but we would need to start
+// the browser for this testcase with --process-per-tab, and I don't think
+// we can do this at test-case-level granularity at the moment.
+TEST_F(RedirectTest,
+ DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) {
// We want to initiate a second navigation after the provisional load for
// the client redirect destination has started, but before this load is
// committed. To achieve this, we tell the browser to load a slow page,
// which causes it to start a provisional load, and while it is waiting
// for the response (which means it hasn't committed the load for the client
// redirect destination page yet), we issue a new navigation request.
- TestServer server(kDocRoot);
-
- GURL final_url = server.TestServerPageW(std::wstring(L"files/title2.html"));
- GURL slow = server.TestServerPageW(std::wstring(L"slow?60"));
- GURL first_url = server.TestServerPageW(
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot);
+ ASSERT_TRUE(NULL != server.get());
+
+ GURL final_url = server->TestServerPageW(std::wstring(L"files/title2.html"));
+ GURL slow = server->TestServerPageW(std::wstring(L"slow?60"));
+ GURL first_url = server->TestServerPageW(
std::wstring(L"client-redirect?") + UTF8ToWide(slow.spec()));
std::vector<GURL> redirects;
@@ -256,7 +274,7 @@ TEST_F(RedirectTest, DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad
// started it's provisional load for the client redirect destination page but
// hasn't completed. Our time is now!
NavigateToURL(final_url);
-
+
std::wstring tab_title;
std::wstring final_url_title = L"Title Of Awesomeness";
// Wait till the final page has been loaded.
@@ -271,9 +289,9 @@ TEST_F(RedirectTest, DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad
}
}
- // Check to make sure the navigation did in fact take place and we are
+ // Check to make sure the navigation did in fact take place and we are
// at the expected page.
- EXPECT_EQ(final_url_title, tab_title);
+ EXPECT_EQ(final_url_title, tab_title);
bool final_navigation_not_redirect = true;
// Check to make sure our request for files/title2.html doesn't get flagged