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

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

Issue 2881028: GTTF: test server cleanup: (Closed)
Patch Set: final Created 10 years, 5 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/url_request/url_request_unittest.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 = 28 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
29 HTTPTestServer::CreateServer(kDocRoot, NULL);
30 ASSERT_TRUE(NULL != server.get()); 29 ASSERT_TRUE(NULL != server.get());
31 30
32 GURL final_url = server->TestServerPage(std::string()); 31 GURL final_url = server->TestServerPage(std::string());
33 GURL first_url = server->TestServerPage( 32 GURL first_url = server->TestServerPage(
34 "server-redirect?" + final_url.spec()); 33 "server-redirect?" + final_url.spec());
35 34
36 NavigateToURL(first_url); 35 NavigateToURL(first_url);
37 36
38 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 37 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
39 ASSERT_TRUE(tab_proxy.get()); 38 ASSERT_TRUE(tab_proxy.get());
40 39
41 std::vector<GURL> redirects; 40 std::vector<GURL> redirects;
42 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 41 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
43 42
44 ASSERT_EQ(1U, redirects.size()); 43 ASSERT_EQ(1U, redirects.size());
45 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 44 EXPECT_EQ(final_url.spec(), redirects[0].spec());
46 } 45 }
47 46
48 // Tests a single client redirect. 47 // Tests a single client redirect.
49 TEST_F(RedirectTest, Client) { 48 TEST_F(RedirectTest, Client) {
50 scoped_refptr<HTTPTestServer> server = 49 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
51 HTTPTestServer::CreateServer(kDocRoot, NULL);
52 ASSERT_TRUE(NULL != server.get()); 50 ASSERT_TRUE(NULL != server.get());
53 51
54 GURL final_url = server->TestServerPage(std::string()); 52 GURL final_url = server->TestServerPage(std::string());
55 GURL first_url = server->TestServerPage( 53 GURL first_url = server->TestServerPage(
56 "client-redirect?" + final_url.spec()); 54 "client-redirect?" + final_url.spec());
57 55
58 // The client redirect appears as two page visits in the browser. 56 // The client redirect appears as two page visits in the browser.
59 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); 57 NavigateToURLBlockUntilNavigationsComplete(first_url, 2);
60 58
61 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 59 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
(...skipping 12 matching lines...) Expand all
74 72
75 // Navigate one more time. 73 // Navigate one more time.
76 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); 74 NavigateToURLBlockUntilNavigationsComplete(first_url, 2);
77 75
78 // The address bar should still display the final URL. 76 // The address bar should still display the final URL.
79 EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url)); 77 EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url));
80 EXPECT_TRUE(final_url == tab_url); 78 EXPECT_TRUE(final_url == tab_url);
81 } 79 }
82 80
83 TEST_F(RedirectTest, ClientEmptyReferer) { 81 TEST_F(RedirectTest, ClientEmptyReferer) {
84 scoped_refptr<HTTPTestServer> server = 82 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
85 HTTPTestServer::CreateServer(kDocRoot, NULL);
86 ASSERT_TRUE(NULL != server.get()); 83 ASSERT_TRUE(NULL != server.get());
87 84
88 GURL final_url = server->TestServerPage(std::string()); 85 GURL final_url = server->TestServerPage(std::string());
89 FilePath test_file(test_data_directory_); 86 FilePath test_file(test_data_directory_);
90 test_file = test_file.AppendASCII("file_client_redirect.html"); 87 test_file = test_file.AppendASCII("file_client_redirect.html");
91 GURL first_url = net::FilePathToFileURL(test_file); 88 GURL first_url = net::FilePathToFileURL(test_file);
92 89
93 // The client redirect appears as two page visits in the browser. 90 // The client redirect appears as two page visits in the browser.
94 NavigateToURLBlockUntilNavigationsComplete(first_url, 2); 91 NavigateToURLBlockUntilNavigationsComplete(first_url, 2);
95 92
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ASSERT_TRUE(net::FileURLToFilePath(current_url, &current_path)); 131 ASSERT_TRUE(net::FileURLToFilePath(current_url, &current_path));
135 ASSERT_TRUE(file_util::AbsolutePath(&current_path)); 132 ASSERT_TRUE(file_util::AbsolutePath(&current_path));
136 // Path should remain unchanged. 133 // Path should remain unchanged.
137 EXPECT_EQ(StringToLowerASCII(first_path.value()), 134 EXPECT_EQ(StringToLowerASCII(first_path.value()),
138 StringToLowerASCII(current_path.value())); 135 StringToLowerASCII(current_path.value()));
139 EXPECT_EQ(final_ref, current_url.ref()); 136 EXPECT_EQ(final_ref, current_url.ref());
140 } 137 }
141 138
142 // Tests a client->server->server redirect 139 // Tests a client->server->server redirect
143 TEST_F(RedirectTest, ClientServerServer) { 140 TEST_F(RedirectTest, ClientServerServer) {
144 scoped_refptr<HTTPTestServer> server = 141 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
145 HTTPTestServer::CreateServer(kDocRoot, NULL);
146 ASSERT_TRUE(NULL != server.get()); 142 ASSERT_TRUE(NULL != server.get());
147 143
148 GURL final_url = server->TestServerPage(std::string()); 144 GURL final_url = server->TestServerPage(std::string());
149 GURL next_to_last = server->TestServerPage( 145 GURL next_to_last = server->TestServerPage(
150 "server-redirect?" + final_url.spec()); 146 "server-redirect?" + final_url.spec());
151 GURL second_url = server->TestServerPage( 147 GURL second_url = server->TestServerPage(
152 "server-redirect?" + next_to_last.spec()); 148 "server-redirect?" + next_to_last.spec());
153 GURL first_url = server->TestServerPage( 149 GURL first_url = server->TestServerPage(
154 "client-redirect?" + second_url.spec()); 150 "client-redirect?" + second_url.spec());
155 std::vector<GURL> redirects; 151 std::vector<GURL> redirects;
(...skipping 12 matching lines...) Expand all
168 } 164 }
169 165
170 ASSERT_EQ(3U, redirects.size()); 166 ASSERT_EQ(3U, redirects.size());
171 EXPECT_EQ(second_url.spec(), redirects[0].spec()); 167 EXPECT_EQ(second_url.spec(), redirects[0].spec());
172 EXPECT_EQ(next_to_last.spec(), redirects[1].spec()); 168 EXPECT_EQ(next_to_last.spec(), redirects[1].spec());
173 EXPECT_EQ(final_url.spec(), redirects[2].spec()); 169 EXPECT_EQ(final_url.spec(), redirects[2].spec());
174 } 170 }
175 171
176 // Tests that the "#reference" gets preserved across server redirects. 172 // Tests that the "#reference" gets preserved across server redirects.
177 TEST_F(RedirectTest, ServerReference) { 173 TEST_F(RedirectTest, ServerReference) {
178 scoped_refptr<HTTPTestServer> server = 174 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
179 HTTPTestServer::CreateServer(kDocRoot, NULL);
180 ASSERT_TRUE(NULL != server.get()); 175 ASSERT_TRUE(NULL != server.get());
181 176
182 const std::string ref("reference"); 177 const std::string ref("reference");
183 178
184 GURL final_url = server->TestServerPage(std::string()); 179 GURL final_url = server->TestServerPage(std::string());
185 GURL initial_url = server->TestServerPage( 180 GURL initial_url = server->TestServerPage(
186 "server-redirect?" + final_url.spec() + "#" + ref); 181 "server-redirect?" + final_url.spec() + "#" + ref);
187 182
188 NavigateToURL(initial_url); 183 NavigateToURL(initial_url);
189 184
190 GURL url = GetActiveTabURL(); 185 GURL url = GetActiveTabURL();
191 EXPECT_EQ(ref, url.ref()); 186 EXPECT_EQ(ref, url.ref());
192 } 187 }
193 188
194 // Test that redirect from http:// to file:// : 189 // Test that redirect from http:// to file:// :
195 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 190 // A) does not crash the browser or confuse the redirect chain, see bug 1080873
196 // B) does not take place. 191 // B) does not take place.
197 TEST_F(RedirectTest, NoHttpToFile) { 192 TEST_F(RedirectTest, NoHttpToFile) {
198 scoped_refptr<HTTPTestServer> server = 193 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
199 HTTPTestServer::CreateServer(kDocRoot, NULL);
200 ASSERT_TRUE(NULL != server.get()); 194 ASSERT_TRUE(NULL != server.get());
201 FilePath test_file(test_data_directory_); 195 FilePath test_file(test_data_directory_);
202 test_file = test_file.AppendASCII("http_to_file.html"); 196 test_file = test_file.AppendASCII("http_to_file.html");
203 GURL file_url = net::FilePathToFileURL(test_file); 197 GURL file_url = net::FilePathToFileURL(test_file);
204 198
205 GURL initial_url = server->TestServerPage( 199 GURL initial_url = server->TestServerPage(
206 "client-redirect?" + file_url.spec()); 200 "client-redirect?" + file_url.spec());
207 201
208 NavigateToURL(initial_url); 202 NavigateToURL(initial_url);
209 // UITest will check for crashes. We make sure the title doesn't match the 203 // UITest will check for crashes. We make sure the title doesn't match the
210 // title from the file, because the nav should not have taken place. 204 // title from the file, because the nav should not have taken place.
211 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 205 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
212 ASSERT_TRUE(tab_proxy.get()); 206 ASSERT_TRUE(tab_proxy.get());
213 std::wstring actual_title; 207 std::wstring actual_title;
214 ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title)); 208 ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title));
215 EXPECT_NE("File!", WideToUTF8(actual_title)); 209 EXPECT_NE("File!", WideToUTF8(actual_title));
216 } 210 }
217 211
218 // Ensures that non-user initiated location changes (within page) are 212 // Ensures that non-user initiated location changes (within page) are
219 // flagged as client redirects. See bug 1139823. 213 // flagged as client redirects. See bug 1139823.
220 TEST_F(RedirectTest, ClientFragments) { 214 TEST_F(RedirectTest, ClientFragments) {
221 scoped_refptr<HTTPTestServer> server = 215 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
222 HTTPTestServer::CreateServer(kDocRoot, NULL);
223 ASSERT_TRUE(NULL != server.get()); 216 ASSERT_TRUE(NULL != server.get());
224 217
225 FilePath test_file(test_data_directory_); 218 FilePath test_file(test_data_directory_);
226 test_file = test_file.AppendASCII("ref_redirect.html"); 219 test_file = test_file.AppendASCII("ref_redirect.html");
227 GURL first_url = net::FilePathToFileURL(test_file); 220 GURL first_url = net::FilePathToFileURL(test_file);
228 std::vector<GURL> redirects; 221 std::vector<GURL> redirects;
229 222
230 NavigateToURL(first_url); 223 NavigateToURL(first_url);
231 224
232 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 225 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
(...skipping 12 matching lines...) Expand all
245 // we can do this at test-case-level granularity at the moment. 238 // we can do this at test-case-level granularity at the moment.
246 // http://crbug.com/45056 239 // http://crbug.com/45056
247 TEST_F(RedirectTest, 240 TEST_F(RedirectTest,
248 DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) { 241 DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) {
249 // We want to initiate a second navigation after the provisional load for 242 // We want to initiate a second navigation after the provisional load for
250 // the client redirect destination has started, but before this load is 243 // 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, 244 // 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 245 // 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 246 // 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. 247 // redirect destination page yet), we issue a new navigation request.
255 scoped_refptr<HTTPTestServer> server = 248 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
256 HTTPTestServer::CreateServer(kDocRoot, NULL);
257 ASSERT_TRUE(NULL != server.get()); 249 ASSERT_TRUE(NULL != server.get());
258 250
259 GURL final_url = server->TestServerPage("files/title2.html"); 251 GURL final_url = server->TestServerPage("files/title2.html");
260 GURL slow = server->TestServerPage("slow?60"); 252 GURL slow = server->TestServerPage("slow?60");
261 GURL first_url = server->TestServerPage( 253 GURL first_url = server->TestServerPage(
262 "client-redirect?" + slow.spec()); 254 "client-redirect?" + slow.spec());
263 std::vector<GURL> redirects; 255 std::vector<GURL> redirects;
264 256
265 NavigateToURL(first_url); 257 NavigateToURL(first_url);
266 // We don't sleep here - the first navigation won't have been committed yet 258 // We don't sleep here - the first navigation won't have been committed yet
(...skipping 27 matching lines...) Expand all
294 it != redirects.end(); ++it) { 286 it != redirects.end(); ++it) {
295 if (final_url.spec() == it->spec()) { 287 if (final_url.spec() == it->spec()) {
296 final_navigation_not_redirect = false; 288 final_navigation_not_redirect = false;
297 break; 289 break;
298 } 290 }
299 } 291 }
300 EXPECT_TRUE(final_navigation_not_redirect); 292 EXPECT_TRUE(final_navigation_not_redirect);
301 } 293 }
302 294
303 } // namespace 295 } // 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