Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Navigates the browser to server and client redirect pages and makes sure | 5 // Navigates the browser to server and client redirect pages and makes sure |
| 6 // that the correct redirects are reflected in the history database. Errors | 6 // that the correct redirects are reflected in the history database. Errors |
| 7 // here might indicate that WebKit changed the calls our glue layer gets in | 7 // here might indicate that WebKit changed the calls our glue layer gets in |
| 8 // the case of redirects. It may also mean problems with the history system. | 8 // the case of redirects. It may also mean problems with the history system. |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 const wchar_t kDocRoot[] = L"chrome/test/data"; | 21 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 22 | 22 |
| 23 typedef UITest RedirectTest; | 23 typedef UITest RedirectTest; |
| 24 | 24 |
| 25 // Tests a single server redirect | 25 // Tests a single server redirect |
| 26 TEST_F(RedirectTest, Server) { | 26 TEST_F(RedirectTest, Server) { |
| 27 scoped_refptr<HTTPTestServer> server = | 27 scoped_refptr<HTTPTestServer> server = |
| 28 HTTPTestServer::CreateServer(kDocRoot, NULL); | 28 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 29 ASSERT_TRUE(NULL != server.get()); | 29 ASSERT_TRUE(NULL != server.get()); |
| 30 | 30 |
| 31 GURL final_url = server->TestServerPageW(std::wstring()); | 31 GURL final_url = server->TestServerPage(std::string()); |
| 32 GURL first_url = server->TestServerPageW( | 32 GURL first_url = server->TestServerPage( |
| 33 std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec())); | 33 std::string("server-redirect?") + final_url.spec()); |
| 34 | 34 |
| 35 NavigateToURL(first_url); | 35 NavigateToURL(first_url); |
| 36 | 36 |
| 37 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 37 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 38 ASSERT_TRUE(tab_proxy.get()); | 38 ASSERT_TRUE(tab_proxy.get()); |
| 39 | 39 |
| 40 std::vector<GURL> redirects; | 40 std::vector<GURL> redirects; |
| 41 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 41 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
| 42 | 42 |
| 43 ASSERT_EQ(1U, redirects.size()); | 43 ASSERT_EQ(1U, redirects.size()); |
| 44 EXPECT_EQ(final_url.spec(), redirects[0].spec()); | 44 EXPECT_EQ(final_url.spec(), redirects[0].spec()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Tests a single client redirect. | 47 // Tests a single client redirect. |
| 48 TEST_F(RedirectTest, Client) { | 48 TEST_F(RedirectTest, Client) { |
| 49 scoped_refptr<HTTPTestServer> server = | 49 scoped_refptr<HTTPTestServer> server = |
| 50 HTTPTestServer::CreateServer(kDocRoot, NULL); | 50 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 51 ASSERT_TRUE(NULL != server.get()); | 51 ASSERT_TRUE(NULL != server.get()); |
| 52 | 52 |
| 53 GURL final_url = server->TestServerPageW(std::wstring()); | 53 GURL final_url = server->TestServerPage(std::string()); |
| 54 GURL first_url = server->TestServerPageW( | 54 GURL first_url = server->TestServerPage( |
| 55 std::wstring(L"client-redirect?") + UTF8ToWide(final_url.spec())); | 55 std::string("client-redirect?") + final_url.spec()); |
|
eroman
2010/04/29 18:10:47
nit: Can probably omit the std::string() (applies
| |
| 56 | 56 |
| 57 // The client redirect appears as two page visits in the browser. | 57 // The client redirect appears as two page visits in the browser. |
| 58 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); | 58 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); |
| 59 | 59 |
| 60 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 60 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 61 ASSERT_TRUE(tab_proxy.get()); | 61 ASSERT_TRUE(tab_proxy.get()); |
| 62 | 62 |
| 63 std::vector<GURL> redirects; | 63 std::vector<GURL> redirects; |
| 64 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 64 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
| 65 | 65 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 77 // The address bar should still display the final URL. | 77 // The address bar should still display the final URL. |
| 78 EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url)); | 78 EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url)); |
| 79 EXPECT_TRUE(final_url == tab_url); | 79 EXPECT_TRUE(final_url == tab_url); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(RedirectTest, ClientEmptyReferer) { | 82 TEST_F(RedirectTest, ClientEmptyReferer) { |
| 83 scoped_refptr<HTTPTestServer> server = | 83 scoped_refptr<HTTPTestServer> server = |
| 84 HTTPTestServer::CreateServer(kDocRoot, NULL); | 84 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 85 ASSERT_TRUE(NULL != server.get()); | 85 ASSERT_TRUE(NULL != server.get()); |
| 86 | 86 |
| 87 GURL final_url = server->TestServerPageW(std::wstring()); | 87 GURL final_url = server->TestServerPage(std::string()); |
| 88 FilePath test_file(test_data_directory_); | 88 FilePath test_file(test_data_directory_); |
| 89 test_file = test_file.AppendASCII("file_client_redirect.html"); | 89 test_file = test_file.AppendASCII("file_client_redirect.html"); |
| 90 GURL first_url = net::FilePathToFileURL(test_file); | 90 GURL first_url = net::FilePathToFileURL(test_file); |
| 91 | 91 |
| 92 // The client redirect appears as two page visits in the browser. | 92 // The client redirect appears as two page visits in the browser. |
| 93 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); | 93 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); |
| 94 | 94 |
| 95 std::vector<GURL> redirects; | 95 std::vector<GURL> redirects; |
| 96 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 96 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 97 ASSERT_TRUE(tab_proxy.get()); | 97 ASSERT_TRUE(tab_proxy.get()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Tests a client->server->server redirect | 140 // Tests a client->server->server redirect |
| 141 // TODO(creis): This is disabled temporarily while I figure out why it is | 141 // TODO(creis): This is disabled temporarily while I figure out why it is |
| 142 // failing. | 142 // failing. |
| 143 TEST_F(RedirectTest, DISABLED_ClientServerServer) { | 143 TEST_F(RedirectTest, DISABLED_ClientServerServer) { |
| 144 scoped_refptr<HTTPTestServer> server = | 144 scoped_refptr<HTTPTestServer> server = |
| 145 HTTPTestServer::CreateServer(kDocRoot, NULL); | 145 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 146 ASSERT_TRUE(NULL != server.get()); | 146 ASSERT_TRUE(NULL != server.get()); |
| 147 | 147 |
| 148 GURL final_url = server->TestServerPageW(std::wstring()); | 148 GURL final_url = server->TestServerPage(std::string()); |
| 149 GURL next_to_last = server->TestServerPageW( | 149 GURL next_to_last = server->TestServerPage( |
| 150 std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec())); | 150 std::string("server-redirect?") + final_url.spec()); |
| 151 GURL second_url = server->TestServerPageW( | 151 GURL second_url = server->TestServerPage( |
| 152 std::wstring(L"server-redirect?") + UTF8ToWide(next_to_last.spec())); | 152 std::string("server-redirect?") + next_to_last.spec()); |
| 153 GURL first_url = server->TestServerPageW( | 153 GURL first_url = server->TestServerPage( |
| 154 std::wstring(L"client-redirect?") + UTF8ToWide(second_url.spec())); | 154 std::string("client-redirect?") + second_url.spec()); |
| 155 std::vector<GURL> redirects; | 155 std::vector<GURL> redirects; |
| 156 | 156 |
| 157 // We need the sleep for the client redirects, because it appears as two | 157 // We need the sleep for the client redirects, because it appears as two |
| 158 // page visits in the browser. | 158 // page visits in the browser. |
| 159 NavigateToURL(first_url); | 159 NavigateToURL(first_url); |
| 160 | 160 |
| 161 for (int i = 0; i < 10; ++i) { | 161 for (int i = 0; i < 10; ++i) { |
| 162 PlatformThread::Sleep(sleep_timeout_ms()); | 162 PlatformThread::Sleep(sleep_timeout_ms()); |
| 163 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 163 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 164 ASSERT_TRUE(tab_proxy.get()); | 164 ASSERT_TRUE(tab_proxy.get()); |
| 165 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 165 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
| 166 if (!redirects.empty()) | 166 if (!redirects.empty()) |
| 167 break; | 167 break; |
| 168 } | 168 } |
| 169 | 169 |
| 170 ASSERT_EQ(3U, redirects.size()); | 170 ASSERT_EQ(3U, redirects.size()); |
| 171 EXPECT_EQ(second_url.spec(), redirects[0].spec()); | 171 EXPECT_EQ(second_url.spec(), redirects[0].spec()); |
| 172 EXPECT_EQ(next_to_last.spec(), redirects[1].spec()); | 172 EXPECT_EQ(next_to_last.spec(), redirects[1].spec()); |
| 173 EXPECT_EQ(final_url.spec(), redirects[2].spec()); | 173 EXPECT_EQ(final_url.spec(), redirects[2].spec()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Tests that the "#reference" gets preserved across server redirects. | 176 // Tests that the "#reference" gets preserved across server redirects. |
| 177 TEST_F(RedirectTest, ServerReference) { | 177 TEST_F(RedirectTest, ServerReference) { |
| 178 scoped_refptr<HTTPTestServer> server = | 178 scoped_refptr<HTTPTestServer> server = |
| 179 HTTPTestServer::CreateServer(kDocRoot, NULL); | 179 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 180 ASSERT_TRUE(NULL != server.get()); | 180 ASSERT_TRUE(NULL != server.get()); |
| 181 | 181 |
| 182 const std::string ref("reference"); | 182 const std::string ref("reference"); |
| 183 | 183 |
| 184 GURL final_url = server->TestServerPageW(std::wstring()); | 184 GURL final_url = server->TestServerPage(std::string()); |
| 185 GURL initial_url = server->TestServerPageW( | 185 GURL initial_url = server->TestServerPage( |
| 186 std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec()) + | 186 std::string("server-redirect?") + final_url.spec() + "#" + ref); |
| 187 L"#" + UTF8ToWide(ref)); | |
| 188 | 187 |
| 189 NavigateToURL(initial_url); | 188 NavigateToURL(initial_url); |
| 190 | 189 |
| 191 GURL url = GetActiveTabURL(); | 190 GURL url = GetActiveTabURL(); |
| 192 EXPECT_EQ(ref, url.ref()); | 191 EXPECT_EQ(ref, url.ref()); |
| 193 } | 192 } |
| 194 | 193 |
| 195 // Test that redirect from http:// to file:// : | 194 // Test that redirect from http:// to file:// : |
| 196 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 | 195 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 |
| 197 // B) does not take place. | 196 // B) does not take place. |
| 198 TEST_F(RedirectTest, NoHttpToFile) { | 197 TEST_F(RedirectTest, NoHttpToFile) { |
| 199 scoped_refptr<HTTPTestServer> server = | 198 scoped_refptr<HTTPTestServer> server = |
| 200 HTTPTestServer::CreateServer(kDocRoot, NULL); | 199 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 201 ASSERT_TRUE(NULL != server.get()); | 200 ASSERT_TRUE(NULL != server.get()); |
| 202 FilePath test_file(test_data_directory_); | 201 FilePath test_file(test_data_directory_); |
| 203 test_file = test_file.AppendASCII("http_to_file.html"); | 202 test_file = test_file.AppendASCII("http_to_file.html"); |
| 204 GURL file_url = net::FilePathToFileURL(test_file); | 203 GURL file_url = net::FilePathToFileURL(test_file); |
| 205 | 204 |
| 206 GURL initial_url = server->TestServerPageW( | 205 GURL initial_url = server->TestServerPage( |
| 207 std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec())); | 206 std::string("client-redirect?") + file_url.spec()); |
| 208 | 207 |
| 209 NavigateToURL(initial_url); | 208 NavigateToURL(initial_url); |
| 210 // UITest will check for crashes. We make sure the title doesn't match the | 209 // UITest will check for crashes. We make sure the title doesn't match the |
| 211 // title from the file, because the nav should not have taken place. | 210 // title from the file, because the nav should not have taken place. |
| 212 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 211 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 213 ASSERT_TRUE(tab_proxy.get()); | 212 ASSERT_TRUE(tab_proxy.get()); |
| 214 std::wstring actual_title; | 213 std::wstring actual_title; |
| 215 ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title)); | 214 ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title)); |
| 216 EXPECT_NE(L"File!", actual_title); | 215 EXPECT_NE(L"File!", actual_title); |
| 217 } | 216 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 // We want to initiate a second navigation after the provisional load for | 248 // We want to initiate a second navigation after the provisional load for |
| 250 // the client redirect destination has started, but before this load is | 249 // the client redirect destination has started, but before this load is |
| 251 // committed. To achieve this, we tell the browser to load a slow page, | 250 // committed. To achieve this, we tell the browser to load a slow page, |
| 252 // which causes it to start a provisional load, and while it is waiting | 251 // which causes it to start a provisional load, and while it is waiting |
| 253 // for the response (which means it hasn't committed the load for the client | 252 // for the response (which means it hasn't committed the load for the client |
| 254 // redirect destination page yet), we issue a new navigation request. | 253 // redirect destination page yet), we issue a new navigation request. |
| 255 scoped_refptr<HTTPTestServer> server = | 254 scoped_refptr<HTTPTestServer> server = |
| 256 HTTPTestServer::CreateServer(kDocRoot, NULL); | 255 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 257 ASSERT_TRUE(NULL != server.get()); | 256 ASSERT_TRUE(NULL != server.get()); |
| 258 | 257 |
| 259 GURL final_url = server->TestServerPageW(std::wstring(L"files/title2.html")); | 258 GURL final_url = server->TestServerPage(std::string("files/title2.html")); |
|
eroman
2010/04/29 18:10:47
nit: you can omit the std::string
| |
| 260 GURL slow = server->TestServerPageW(std::wstring(L"slow?60")); | 259 GURL slow = server->TestServerPage(std::string("slow?60")); |
|
eroman
2010/04/29 18:10:47
ditto.
| |
| 261 GURL first_url = server->TestServerPageW( | 260 GURL first_url = server->TestServerPage( |
| 262 std::wstring(L"client-redirect?") + UTF8ToWide(slow.spec())); | 261 std::string("client-redirect?") + slow.spec()); |
| 263 std::vector<GURL> redirects; | 262 std::vector<GURL> redirects; |
| 264 | 263 |
| 265 NavigateToURL(first_url); | 264 NavigateToURL(first_url); |
| 266 // We don't sleep here - the first navigation won't have been committed yet | 265 // We don't sleep here - the first navigation won't have been committed yet |
| 267 // because we told the server to wait a minute. This means the browser has | 266 // because we told the server to wait a minute. This means the browser has |
| 268 // started it's provisional load for the client redirect destination page but | 267 // started it's provisional load for the client redirect destination page but |
| 269 // hasn't completed. Our time is now! | 268 // hasn't completed. Our time is now! |
| 270 NavigateToURL(final_url); | 269 NavigateToURL(final_url); |
| 271 | 270 |
| 272 std::wstring tab_title; | 271 std::wstring tab_title; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 294 it != redirects.end(); ++it) { | 293 it != redirects.end(); ++it) { |
| 295 if (final_url.spec() == it->spec()) { | 294 if (final_url.spec() == it->spec()) { |
| 296 final_navigation_not_redirect = false; | 295 final_navigation_not_redirect = false; |
| 297 break; | 296 break; |
| 298 } | 297 } |
| 299 } | 298 } |
| 300 EXPECT_TRUE(final_navigation_not_redirect); | 299 EXPECT_TRUE(final_navigation_not_redirect); |
| 301 } | 300 } |
| 302 | 301 |
| 303 } // namespace | 302 } // namespace |
| OLD | NEW |