Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: chrome/browser/history/redirect_uitest.cc

Issue 3034038: GTTF: Move more test server code from net/url_request/url_request_unittest.h (Closed)
Patch Set: hopefully final Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/history/multipart_uitest.cc ('k') | chrome/browser/login_prompt_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
11 #include "base/platform_thread.h" 11 #include "base/platform_thread.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "chrome/test/automation/tab_proxy.h" 15 #include "chrome/test/automation/tab_proxy.h"
16 #include "chrome/test/ui/ui_test.h" 16 #include "chrome/test/ui/ui_test.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "net/url_request/url_request_unittest.h" 18 #include "net/test/test_server.h"
19 19
20 namespace { 20 namespace {
21 21
22 const wchar_t kDocRoot[] = L"chrome/test/data"; 22 const wchar_t kDocRoot[] = L"chrome/test/data";
23 23
24 typedef UITest RedirectTest; 24 typedef UITest RedirectTest;
25 25
26 // Tests a single server redirect 26 // Tests a single server redirect
27 TEST_F(RedirectTest, Server) { 27 TEST_F(RedirectTest, Server) {
28 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 28 scoped_refptr<net::HTTPTestServer> server(
29 net::HTTPTestServer::CreateServer(kDocRoot));
29 ASSERT_TRUE(NULL != server.get()); 30 ASSERT_TRUE(NULL != server.get());
30 31
31 GURL final_url = server->TestServerPage(std::string()); 32 GURL final_url = server->TestServerPage(std::string());
32 GURL first_url = server->TestServerPage( 33 GURL first_url = server->TestServerPage(
33 "server-redirect?" + final_url.spec()); 34 "server-redirect?" + final_url.spec());
34 35
35 NavigateToURL(first_url); 36 NavigateToURL(first_url);
36 37
37 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 38 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
38 ASSERT_TRUE(tab_proxy.get()); 39 ASSERT_TRUE(tab_proxy.get());
39 40
40 std::vector<GURL> redirects; 41 std::vector<GURL> redirects;
41 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 42 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
42 43
43 ASSERT_EQ(1U, redirects.size()); 44 ASSERT_EQ(1U, redirects.size());
44 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 45 EXPECT_EQ(final_url.spec(), redirects[0].spec());
45 } 46 }
46 47
47 // Tests a single client redirect. 48 // Tests a single client redirect.
48 TEST_F(RedirectTest, Client) { 49 TEST_F(RedirectTest, Client) {
49 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 50 scoped_refptr<net::HTTPTestServer> server(
51 net::HTTPTestServer::CreateServer(kDocRoot));
50 ASSERT_TRUE(NULL != server.get()); 52 ASSERT_TRUE(NULL != server.get());
51 53
52 GURL final_url = server->TestServerPage(std::string()); 54 GURL final_url = server->TestServerPage(std::string());
53 GURL first_url = server->TestServerPage( 55 GURL first_url = server->TestServerPage(
54 "client-redirect?" + final_url.spec()); 56 "client-redirect?" + final_url.spec());
55 57
56 // The client redirect appears as two page visits in the browser. 58 // The client redirect appears as two page visits in the browser.
57 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); 59 NavigateToURLBlockUntilNavigationsComplete(first_url, 2);
58 60
59 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 61 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
(...skipping 12 matching lines...) Expand all
72 74
73 // Navigate one more time. 75 // Navigate one more time.
74 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); 76 NavigateToURLBlockUntilNavigationsComplete(first_url, 2);
75 77
76 // The address bar should still display the final URL. 78 // The address bar should still display the final URL.
77 EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url)); 79 EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url));
78 EXPECT_TRUE(final_url == tab_url); 80 EXPECT_TRUE(final_url == tab_url);
79 } 81 }
80 82
81 TEST_F(RedirectTest, ClientEmptyReferer) { 83 TEST_F(RedirectTest, ClientEmptyReferer) {
82 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 84 scoped_refptr<net::HTTPTestServer> server(
85 net::HTTPTestServer::CreateServer(kDocRoot));
83 ASSERT_TRUE(NULL != server.get()); 86 ASSERT_TRUE(NULL != server.get());
84 87
85 GURL final_url = server->TestServerPage(std::string()); 88 GURL final_url = server->TestServerPage(std::string());
86 FilePath test_file(test_data_directory_); 89 FilePath test_file(test_data_directory_);
87 test_file = test_file.AppendASCII("file_client_redirect.html"); 90 test_file = test_file.AppendASCII("file_client_redirect.html");
88 GURL first_url = net::FilePathToFileURL(test_file); 91 GURL first_url = net::FilePathToFileURL(test_file);
89 92
90 // The client redirect appears as two page visits in the browser. 93 // The client redirect appears as two page visits in the browser.
91 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); 94 NavigateToURLBlockUntilNavigationsComplete(first_url, 2);
92 95
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ASSERT_TRUE(net::FileURLToFilePath(current_url, &current_path)); 134 ASSERT_TRUE(net::FileURLToFilePath(current_url, &current_path));
132 ASSERT_TRUE(file_util::AbsolutePath(&current_path)); 135 ASSERT_TRUE(file_util::AbsolutePath(&current_path));
133 // Path should remain unchanged. 136 // Path should remain unchanged.
134 EXPECT_EQ(StringToLowerASCII(first_path.value()), 137 EXPECT_EQ(StringToLowerASCII(first_path.value()),
135 StringToLowerASCII(current_path.value())); 138 StringToLowerASCII(current_path.value()));
136 EXPECT_EQ(final_ref, current_url.ref()); 139 EXPECT_EQ(final_ref, current_url.ref());
137 } 140 }
138 141
139 // Tests a client->server->server redirect 142 // Tests a client->server->server redirect
140 TEST_F(RedirectTest, ClientServerServer) { 143 TEST_F(RedirectTest, ClientServerServer) {
141 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 144 scoped_refptr<net::HTTPTestServer> server(
145 net::HTTPTestServer::CreateServer(kDocRoot));
142 ASSERT_TRUE(NULL != server.get()); 146 ASSERT_TRUE(NULL != server.get());
143 147
144 GURL final_url = server->TestServerPage(std::string()); 148 GURL final_url = server->TestServerPage(std::string());
145 GURL next_to_last = server->TestServerPage( 149 GURL next_to_last = server->TestServerPage(
146 "server-redirect?" + final_url.spec()); 150 "server-redirect?" + final_url.spec());
147 GURL second_url = server->TestServerPage( 151 GURL second_url = server->TestServerPage(
148 "server-redirect?" + next_to_last.spec()); 152 "server-redirect?" + next_to_last.spec());
149 GURL first_url = server->TestServerPage( 153 GURL first_url = server->TestServerPage(
150 "client-redirect?" + second_url.spec()); 154 "client-redirect?" + second_url.spec());
151 std::vector<GURL> redirects; 155 std::vector<GURL> redirects;
(...skipping 12 matching lines...) Expand all
164 } 168 }
165 169
166 ASSERT_EQ(3U, redirects.size()); 170 ASSERT_EQ(3U, redirects.size());
167 EXPECT_EQ(second_url.spec(), redirects[0].spec()); 171 EXPECT_EQ(second_url.spec(), redirects[0].spec());
168 EXPECT_EQ(next_to_last.spec(), redirects[1].spec()); 172 EXPECT_EQ(next_to_last.spec(), redirects[1].spec());
169 EXPECT_EQ(final_url.spec(), redirects[2].spec()); 173 EXPECT_EQ(final_url.spec(), redirects[2].spec());
170 } 174 }
171 175
172 // Tests that the "#reference" gets preserved across server redirects. 176 // Tests that the "#reference" gets preserved across server redirects.
173 TEST_F(RedirectTest, ServerReference) { 177 TEST_F(RedirectTest, ServerReference) {
174 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 178 scoped_refptr<net::HTTPTestServer> server(
179 net::HTTPTestServer::CreateServer(kDocRoot));
175 ASSERT_TRUE(NULL != server.get()); 180 ASSERT_TRUE(NULL != server.get());
176 181
177 const std::string ref("reference"); 182 const std::string ref("reference");
178 183
179 GURL final_url = server->TestServerPage(std::string()); 184 GURL final_url = server->TestServerPage(std::string());
180 GURL initial_url = server->TestServerPage( 185 GURL initial_url = server->TestServerPage(
181 "server-redirect?" + final_url.spec() + "#" + ref); 186 "server-redirect?" + final_url.spec() + "#" + ref);
182 187
183 NavigateToURL(initial_url); 188 NavigateToURL(initial_url);
184 189
185 GURL url = GetActiveTabURL(); 190 GURL url = GetActiveTabURL();
186 EXPECT_EQ(ref, url.ref()); 191 EXPECT_EQ(ref, url.ref());
187 } 192 }
188 193
189 // Test that redirect from http:// to file:// : 194 // Test that redirect from http:// to file:// :
190 // 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
191 // B) does not take place. 196 // B) does not take place.
192 TEST_F(RedirectTest, NoHttpToFile) { 197 TEST_F(RedirectTest, NoHttpToFile) {
193 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 198 scoped_refptr<net::HTTPTestServer> server(
199 net::HTTPTestServer::CreateServer(kDocRoot));
194 ASSERT_TRUE(NULL != server.get()); 200 ASSERT_TRUE(NULL != server.get());
195 FilePath test_file(test_data_directory_); 201 FilePath test_file(test_data_directory_);
196 test_file = test_file.AppendASCII("http_to_file.html"); 202 test_file = test_file.AppendASCII("http_to_file.html");
197 GURL file_url = net::FilePathToFileURL(test_file); 203 GURL file_url = net::FilePathToFileURL(test_file);
198 204
199 GURL initial_url = server->TestServerPage( 205 GURL initial_url = server->TestServerPage(
200 "client-redirect?" + file_url.spec()); 206 "client-redirect?" + file_url.spec());
201 207
202 NavigateToURL(initial_url); 208 NavigateToURL(initial_url);
203 // 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
204 // 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.
205 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 211 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
206 ASSERT_TRUE(tab_proxy.get()); 212 ASSERT_TRUE(tab_proxy.get());
207 std::wstring actual_title; 213 std::wstring actual_title;
208 ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title)); 214 ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title));
209 EXPECT_NE("File!", WideToUTF8(actual_title)); 215 EXPECT_NE("File!", WideToUTF8(actual_title));
210 } 216 }
211 217
212 // Ensures that non-user initiated location changes (within page) are 218 // Ensures that non-user initiated location changes (within page) are
213 // flagged as client redirects. See bug 1139823. 219 // flagged as client redirects. See bug 1139823.
214 TEST_F(RedirectTest, ClientFragments) { 220 TEST_F(RedirectTest, ClientFragments) {
215 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 221 scoped_refptr<net::HTTPTestServer> server(
222 net::HTTPTestServer::CreateServer(kDocRoot));
216 ASSERT_TRUE(NULL != server.get()); 223 ASSERT_TRUE(NULL != server.get());
217 224
218 FilePath test_file(test_data_directory_); 225 FilePath test_file(test_data_directory_);
219 test_file = test_file.AppendASCII("ref_redirect.html"); 226 test_file = test_file.AppendASCII("ref_redirect.html");
220 GURL first_url = net::FilePathToFileURL(test_file); 227 GURL first_url = net::FilePathToFileURL(test_file);
221 std::vector<GURL> redirects; 228 std::vector<GURL> redirects;
222 229
223 NavigateToURL(first_url); 230 NavigateToURL(first_url);
224 231
225 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 232 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
(...skipping 12 matching lines...) Expand all
238 // we can do this at test-case-level granularity at the moment. 245 // we can do this at test-case-level granularity at the moment.
239 // http://crbug.com/45056 246 // http://crbug.com/45056
240 TEST_F(RedirectTest, 247 TEST_F(RedirectTest,
241 DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) { 248 DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) {
242 // We want to initiate a second navigation after the provisional load for 249 // We want to initiate a second navigation after the provisional load for
243 // the client redirect destination has started, but before this load is 250 // the client redirect destination has started, but before this load is
244 // committed. To achieve this, we tell the browser to load a slow page, 251 // committed. To achieve this, we tell the browser to load a slow page,
245 // which causes it to start a provisional load, and while it is waiting 252 // which causes it to start a provisional load, and while it is waiting
246 // for the response (which means it hasn't committed the load for the client 253 // for the response (which means it hasn't committed the load for the client
247 // redirect destination page yet), we issue a new navigation request. 254 // redirect destination page yet), we issue a new navigation request.
248 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 255 scoped_refptr<net::HTTPTestServer> server(
256 net::HTTPTestServer::CreateServer(kDocRoot));
249 ASSERT_TRUE(NULL != server.get()); 257 ASSERT_TRUE(NULL != server.get());
250 258
251 GURL final_url = server->TestServerPage("files/title2.html"); 259 GURL final_url = server->TestServerPage("files/title2.html");
252 GURL slow = server->TestServerPage("slow?60"); 260 GURL slow = server->TestServerPage("slow?60");
253 GURL first_url = server->TestServerPage( 261 GURL first_url = server->TestServerPage(
254 "client-redirect?" + slow.spec()); 262 "client-redirect?" + slow.spec());
255 std::vector<GURL> redirects; 263 std::vector<GURL> redirects;
256 264
257 NavigateToURL(first_url); 265 NavigateToURL(first_url);
258 // We don't sleep here - the first navigation won't have been committed yet 266 // We don't sleep here - the first navigation won't have been committed yet
(...skipping 27 matching lines...) Expand all
286 it != redirects.end(); ++it) { 294 it != redirects.end(); ++it) {
287 if (final_url.spec() == it->spec()) { 295 if (final_url.spec() == it->spec()) {
288 final_navigation_not_redirect = false; 296 final_navigation_not_redirect = false;
289 break; 297 break;
290 } 298 }
291 } 299 }
292 EXPECT_TRUE(final_navigation_not_redirect); 300 EXPECT_TRUE(final_navigation_not_redirect);
293 } 301 }
294 302
295 } // namespace 303 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/history/multipart_uitest.cc ('k') | chrome/browser/login_prompt_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698