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

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

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 10 #include "base/bind.h"
(...skipping 15 matching lines...) Expand all
26 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/view_ids.h" 28 #include "chrome/browser/ui/view_ids.h"
29 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
30 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
31 #include "components/history/core/browser/history_service.h" 31 #include "components/history/core/browser/history_service.h"
32 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
33 #include "content/public/test/browser_test_utils.h" 33 #include "content/public/test/browser_test_utils.h"
34 #include "content/public/test/test_navigation_observer.h" 34 #include "content/public/test/test_navigation_observer.h"
35 #include "net/base/filename_util.h" 35 #include "net/base/filename_util.h"
36 #include "net/test/spawned_test_server/spawned_test_server.h" 36 #include "net/test/embedded_test_server/embedded_test_server.h"
37 #include "ui/events/event_constants.h" 37 #include "ui/events/event_constants.h"
38 38
39 class RedirectTest : public InProcessBrowserTest { 39 class RedirectTest : public InProcessBrowserTest {
40 public: 40 public:
41 RedirectTest() {} 41 RedirectTest() {}
42 42
43 std::vector<GURL> GetRedirects(const GURL& url) { 43 std::vector<GURL> GetRedirects(const GURL& url) {
44 history::HistoryService* history_service = 44 history::HistoryService* history_service =
45 HistoryServiceFactory::GetForProfile( 45 HistoryServiceFactory::GetForProfile(
46 browser()->profile(), ServiceAccessType::EXPLICIT_ACCESS); 46 browser()->profile(), ServiceAccessType::EXPLICIT_ACCESS);
(...skipping 19 matching lines...) Expand all
66 base::ThreadTaskRunnerHandle::Get()->PostTask( 66 base::ThreadTaskRunnerHandle::Get()->PostTask(
67 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 67 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
68 } 68 }
69 69
70 // Tracker for asynchronous history queries. 70 // Tracker for asynchronous history queries.
71 base::CancelableTaskTracker tracker_; 71 base::CancelableTaskTracker tracker_;
72 }; 72 };
73 73
74 // Tests a single server redirect 74 // Tests a single server redirect
75 IN_PROC_BROWSER_TEST_F(RedirectTest, Server) { 75 IN_PROC_BROWSER_TEST_F(RedirectTest, Server) {
76 ASSERT_TRUE(test_server()->Start()); 76 ASSERT_TRUE(embedded_test_server()->Start());
77 GURL final_url = test_server()->GetURL(std::string()); 77 GURL final_url = embedded_test_server()->GetURL("/defaultresponse");
78 GURL first_url = test_server()->GetURL( 78 GURL first_url =
79 "server-redirect?" + final_url.spec()); 79 embedded_test_server()->GetURL("/server-redirect?" + final_url.spec());
80 80
81 ui_test_utils::NavigateToURL(browser(), first_url); 81 ui_test_utils::NavigateToURL(browser(), first_url);
82 82
83 std::vector<GURL> redirects = GetRedirects(first_url); 83 std::vector<GURL> redirects = GetRedirects(first_url);
84 84
85 ASSERT_EQ(1U, redirects.size()); 85 ASSERT_EQ(1U, redirects.size());
86 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 86 EXPECT_EQ(final_url.spec(), redirects[0].spec());
87 } 87 }
88 88
89 // Tests a single client redirect. 89 // Tests a single client redirect.
90 IN_PROC_BROWSER_TEST_F(RedirectTest, Client) { 90 IN_PROC_BROWSER_TEST_F(RedirectTest, Client) {
91 ASSERT_TRUE(test_server()->Start()); 91 ASSERT_TRUE(embedded_test_server()->Start());
92 92
93 GURL final_url = test_server()->GetURL(std::string()); 93 GURL final_url = embedded_test_server()->GetURL("/defaultresponse");
94 GURL first_url = test_server()->GetURL( 94 GURL first_url =
95 "client-redirect?" + final_url.spec()); 95 embedded_test_server()->GetURL("/client-redirect?" + final_url.spec());
96 96
97 // The client redirect appears as two page visits in the browser. 97 // The client redirect appears as two page visits in the browser.
98 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 98 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
99 browser(), first_url, 2); 99 browser(), first_url, 2);
100 100
101 std::vector<GURL> redirects = GetRedirects(first_url); 101 std::vector<GURL> redirects = GetRedirects(first_url);
102 102
103 ASSERT_EQ(1U, redirects.size()); 103 ASSERT_EQ(1U, redirects.size());
104 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 104 EXPECT_EQ(final_url.spec(), redirects[0].spec());
105 105
106 // The address bar should display the final URL. 106 // The address bar should display the final URL.
107 EXPECT_EQ(final_url, 107 EXPECT_EQ(final_url,
108 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 108 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
109 109
110 // Navigate one more time. 110 // Navigate one more time.
111 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 111 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
112 browser(), first_url, 2); 112 browser(), first_url, 2);
113 113
114 // The address bar should still display the final URL. 114 // The address bar should still display the final URL.
115 EXPECT_EQ(final_url, 115 EXPECT_EQ(final_url,
116 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 116 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
117 } 117 }
118 118
119 // http://code.google.com/p/chromium/issues/detail?id=62772 119 // http://code.google.com/p/chromium/issues/detail?id=62772
120 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientEmptyReferer) { 120 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientEmptyReferer) {
121 ASSERT_TRUE(test_server()->Start()); 121 ASSERT_TRUE(embedded_test_server()->Start());
122 122
123 // Create the file contents, which will do a redirect to the 123 // Create the file contents, which will do a redirect to the
124 // test server. 124 // test server.
125 GURL final_url = test_server()->GetURL(std::string()); 125 GURL final_url = embedded_test_server()->GetURL("/defaultresponse");
126 ASSERT_TRUE(final_url.is_valid()); 126 ASSERT_TRUE(final_url.is_valid());
127 std::string file_redirect_contents = base::StringPrintf( 127 std::string file_redirect_contents = base::StringPrintf(
128 "<html>" 128 "<html>"
129 "<head></head>" 129 "<head></head>"
130 "<body onload=\"document.location='%s'\"></body>" 130 "<body onload=\"document.location='%s'\"></body>"
131 "</html>", 131 "</html>",
132 final_url.spec().c_str()); 132 final_url.spec().c_str());
133 133
134 // Write the contents to a temporary file. 134 // Write the contents to a temporary file.
135 base::ScopedTempDir temp_directory; 135 base::ScopedTempDir temp_directory;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // There should be no redirects from first_url, because the anchor location 178 // There should be no redirects from first_url, because the anchor location
179 // change that occurs should not be flagged as a redirect and the meta-refresh 179 // change that occurs should not be flagged as a redirect and the meta-refresh
180 // won't have fired yet. 180 // won't have fired yet.
181 ASSERT_EQ(0U, redirects.size()); 181 ASSERT_EQ(0U, redirects.size());
182 EXPECT_EQ("myanchor", web_contents->GetURL().ref()); 182 EXPECT_EQ("myanchor", web_contents->GetURL().ref());
183 } 183 }
184 184
185 // Tests a client->server->server redirect 185 // Tests a client->server->server redirect
186 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientServerServer) { 186 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientServerServer) {
187 ASSERT_TRUE(test_server()->Start()); 187 ASSERT_TRUE(embedded_test_server()->Start());
188 188
189 GURL final_url = test_server()->GetURL(std::string()); 189 GURL final_url = embedded_test_server()->GetURL("/defaultresponse");
190 GURL next_to_last = test_server()->GetURL( 190 GURL next_to_last =
191 "server-redirect?" + final_url.spec()); 191 embedded_test_server()->GetURL("/server-redirect?" + final_url.spec());
192 GURL second_url = test_server()->GetURL( 192 GURL second_url =
193 "server-redirect?" + next_to_last.spec()); 193 embedded_test_server()->GetURL("/server-redirect?" + next_to_last.spec());
194 GURL first_url = test_server()->GetURL( 194 GURL first_url =
195 "client-redirect?" + second_url.spec()); 195 embedded_test_server()->GetURL("/client-redirect?" + second_url.spec());
196 196
197 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 197 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
198 browser(), first_url, 2); 198 browser(), first_url, 2);
199 199
200 std::vector<GURL> redirects = GetRedirects(first_url); 200 std::vector<GURL> redirects = GetRedirects(first_url);
201 ASSERT_EQ(3U, redirects.size()); 201 ASSERT_EQ(3U, redirects.size());
202 EXPECT_EQ(second_url.spec(), redirects[0].spec()); 202 EXPECT_EQ(second_url.spec(), redirects[0].spec());
203 EXPECT_EQ(next_to_last.spec(), redirects[1].spec()); 203 EXPECT_EQ(next_to_last.spec(), redirects[1].spec());
204 EXPECT_EQ(final_url.spec(), redirects[2].spec()); 204 EXPECT_EQ(final_url.spec(), redirects[2].spec());
205 } 205 }
206 206
207 // Tests that the "#reference" gets preserved across server redirects. 207 // Tests that the "#reference" gets preserved across server redirects.
208 IN_PROC_BROWSER_TEST_F(RedirectTest, ServerReference) { 208 IN_PROC_BROWSER_TEST_F(RedirectTest, ServerReference) {
209 ASSERT_TRUE(test_server()->Start()); 209 ASSERT_TRUE(embedded_test_server()->Start());
210 210
211 const std::string ref("reference"); 211 const std::string ref("reference");
212 212
213 GURL final_url = test_server()->GetURL(std::string()); 213 GURL final_url = embedded_test_server()->GetURL("/defaultresponse");
214 GURL initial_url = test_server()->GetURL( 214 GURL initial_url = embedded_test_server()->GetURL(
215 "server-redirect?" + final_url.spec() + "#" + ref); 215 "/server-redirect?" + final_url.spec() + "#" + ref);
216 216
217 ui_test_utils::NavigateToURL(browser(), initial_url); 217 ui_test_utils::NavigateToURL(browser(), initial_url);
218 218
219 EXPECT_EQ(ref, 219 EXPECT_EQ(ref,
220 browser()->tab_strip_model()->GetActiveWebContents()-> 220 browser()->tab_strip_model()->GetActiveWebContents()->
221 GetURL().ref()); 221 GetURL().ref());
222 } 222 }
223 223
224 // Test that redirect from http:// to file:// : 224 // Test that redirect from http:// to file:// :
225 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 225 // A) does not crash the browser or confuse the redirect chain, see bug 1080873
226 // B) does not take place. 226 // B) does not take place.
227 // 227 //
228 // Flaky on XP and Vista, http://crbug.com/69390. 228 // Flaky on XP and Vista, http://crbug.com/69390.
229 IN_PROC_BROWSER_TEST_F(RedirectTest, NoHttpToFile) { 229 IN_PROC_BROWSER_TEST_F(RedirectTest, NoHttpToFile) {
230 ASSERT_TRUE(test_server()->Start()); 230 ASSERT_TRUE(embedded_test_server()->Start());
231 GURL file_url = ui_test_utils::GetTestUrl( 231 GURL file_url = ui_test_utils::GetTestUrl(
232 base::FilePath(), base::FilePath().AppendASCII("http_to_file.html")); 232 base::FilePath(), base::FilePath().AppendASCII("http_to_file.html"));
233 233
234 GURL initial_url = test_server()->GetURL( 234 GURL initial_url =
235 "client-redirect?" + file_url.spec()); 235 embedded_test_server()->GetURL("/client-redirect?" + file_url.spec());
236 236
237 ui_test_utils::NavigateToURL(browser(), initial_url); 237 ui_test_utils::NavigateToURL(browser(), initial_url);
238 // We make sure the title doesn't match the title from the file, because the 238 // We make sure the title doesn't match the title from the file, because the
239 // nav should not have taken place. 239 // nav should not have taken place.
240 EXPECT_NE(base::ASCIIToUTF16("File!"), 240 EXPECT_NE(base::ASCIIToUTF16("File!"),
241 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 241 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
242 } 242 }
243 243
244 // Ensures that non-user initiated location changes (within page) are 244 // Ensures that non-user initiated location changes (within page) are
245 // flagged as client redirects. See bug 1139823. 245 // flagged as client redirects. See bug 1139823.
246 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientFragments) { 246 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientFragments) {
247 ASSERT_TRUE(test_server()->Start()); 247 ASSERT_TRUE(embedded_test_server()->Start());
248 GURL first_url = ui_test_utils::GetTestUrl( 248 GURL first_url = ui_test_utils::GetTestUrl(
249 base::FilePath(), base::FilePath().AppendASCII("ref_redirect.html")); 249 base::FilePath(), base::FilePath().AppendASCII("ref_redirect.html"));
250 ui_test_utils::NavigateToURL(browser(), first_url); 250 ui_test_utils::NavigateToURL(browser(), first_url);
251 std::vector<GURL> redirects = GetRedirects(first_url); 251 std::vector<GURL> redirects = GetRedirects(first_url);
252 EXPECT_EQ(1U, redirects.size()); 252 EXPECT_EQ(1U, redirects.size());
253 EXPECT_EQ(first_url.spec() + "#myanchor", redirects[0].spec()); 253 EXPECT_EQ(first_url.spec() + "#myanchor", redirects[0].spec());
254 } 254 }
255 255
256 // TODO(timsteele): This is disabled because our current testserver can't 256 // TODO(timsteele): This is disabled because our current testserver can't
257 // handle multiple requests in parallel, making it hang on the first request 257 // handle multiple requests in parallel, making it hang on the first request
258 // to /slow?60. It's unable to serve our second request for files/title2.html 258 // to /slow?60. It's unable to serve our second request for /title2.html
259 // until /slow? completes, which doesn't give the desired behavior. We could 259 // until /slow? completes, which doesn't give the desired behavior. We could
260 // alternatively load the second page from disk, but we would need to start 260 // alternatively load the second page from disk, but we would need to start
261 // the browser for this testcase with --process-per-tab, and I don't think 261 // the browser for this testcase with --process-per-tab, and I don't think
262 // we can do this at test-case-level granularity at the moment. 262 // we can do this at test-case-level granularity at the moment.
263 // http://crbug.com/45056 263 // http://crbug.com/45056
264 IN_PROC_BROWSER_TEST_F(RedirectTest, 264 IN_PROC_BROWSER_TEST_F(RedirectTest,
265 DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) { 265 DISABLED_ClientCancelledByNewNavigationAfterProvisionalLoad) {
266 // We want to initiate a second navigation after the provisional load for 266 // We want to initiate a second navigation after the provisional load for
267 // the client redirect destination has started, but before this load is 267 // the client redirect destination has started, but before this load is
268 // committed. To achieve this, we tell the browser to load a slow page, 268 // committed. To achieve this, we tell the browser to load a slow page,
269 // which causes it to start a provisional load, and while it is waiting 269 // which causes it to start a provisional load, and while it is waiting
270 // for the response (which means it hasn't committed the load for the client 270 // for the response (which means it hasn't committed the load for the client
271 // redirect destination page yet), we issue a new navigation request. 271 // redirect destination page yet), we issue a new navigation request.
272 ASSERT_TRUE(test_server()->Start()); 272 ASSERT_TRUE(embedded_test_server()->Start());
273 273
274 GURL final_url = test_server()->GetURL("files/title2.html"); 274 GURL final_url = embedded_test_server()->GetURL("/title2.html");
275 GURL slow = test_server()->GetURL("slow?60"); 275 GURL slow = embedded_test_server()->GetURL("/slow?60");
276 GURL first_url = test_server()->GetURL( 276 GURL first_url =
277 "client-redirect?" + slow.spec()); 277 embedded_test_server()->GetURL("/client-redirect?" + slow.spec());
278 278
279 content::WebContents* web_contents = 279 content::WebContents* web_contents =
280 browser()->tab_strip_model()->GetActiveWebContents(); 280 browser()->tab_strip_model()->GetActiveWebContents();
281 content::TestNavigationObserver observer(web_contents, 2); 281 content::TestNavigationObserver observer(web_contents, 2);
282 282
283 ui_test_utils::NavigateToURLWithDisposition( 283 ui_test_utils::NavigateToURLWithDisposition(
284 browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); 284 browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
285 // We don't sleep here - the first navigation won't have been committed yet 285 // We don't sleep here - the first navigation won't have been committed yet
286 // because we told the server to wait a minute. This means the browser has 286 // because we told the server to wait a minute. This means the browser has
287 // started it's provisional load for the client redirect destination page but 287 // started it's provisional load for the client redirect destination page but
288 // hasn't completed. Our time is now! 288 // hasn't completed. Our time is now!
289 ui_test_utils::NavigateToURLWithDisposition( 289 ui_test_utils::NavigateToURLWithDisposition(
290 browser(), final_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); 290 browser(), final_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
291 observer.Wait(); 291 observer.Wait();
292 292
293 // Check to make sure the navigation did in fact take place and we are 293 // Check to make sure the navigation did in fact take place and we are
294 // at the expected page. 294 // at the expected page.
295 EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"), 295 EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"),
296 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 296 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
297 297
298 bool final_navigation_not_redirect = true; 298 bool final_navigation_not_redirect = true;
299 std::vector<GURL> redirects = GetRedirects(first_url); 299 std::vector<GURL> redirects = GetRedirects(first_url);
300 // Check to make sure our request for files/title2.html doesn't get flagged 300 // Check to make sure our request for /title2.html doesn't get flagged
301 // as a client redirect from the first (/client-redirect?) page. 301 // as a client redirect from the first (/client-redirect?) page.
302 for (std::vector<GURL>::iterator it = redirects.begin(); 302 for (std::vector<GURL>::iterator it = redirects.begin();
303 it != redirects.end(); ++it) { 303 it != redirects.end(); ++it) {
304 if (final_url.spec() == it->spec()) { 304 if (final_url.spec() == it->spec()) {
305 final_navigation_not_redirect = false; 305 final_navigation_not_redirect = false;
306 break; 306 break;
307 } 307 }
308 } 308 }
309 EXPECT_TRUE(final_navigation_not_redirect); 309 EXPECT_TRUE(final_navigation_not_redirect);
310 } 310 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_browsertest.cc ('k') | chrome/browser/infobars/infobars_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698