| OLD | NEW |
| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/task/cancelable_task_tracker.h" |
| 18 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
| 19 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
| 20 #include "chrome/browser/history/history_service.h" | 21 #include "chrome/browser/history/history_service.h" |
| 21 #include "chrome/browser/history/history_service_factory.h" | 22 #include "chrome/browser/history/history_service_factory.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/browser/ui/view_ids.h" | 26 #include "chrome/browser/ui/view_ids.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 std::vector<GURL> GetRedirects(const GURL& url) { | 40 std::vector<GURL> GetRedirects(const GURL& url) { |
| 40 HistoryService* history_service = | 41 HistoryService* history_service = |
| 41 HistoryServiceFactory::GetForProfile(browser()->profile(), | 42 HistoryServiceFactory::GetForProfile(browser()->profile(), |
| 42 Profile::EXPLICIT_ACCESS); | 43 Profile::EXPLICIT_ACCESS); |
| 43 | 44 |
| 44 // Schedule a history query for redirects. The response will be sent | 45 // Schedule a history query for redirects. The response will be sent |
| 45 // asynchronously from the callback the history system uses to notify us | 46 // asynchronously from the callback the history system uses to notify us |
| 46 // that it's done: OnRedirectQueryComplete. | 47 // that it's done: OnRedirectQueryComplete. |
| 47 std::vector<GURL> rv; | 48 std::vector<GURL> rv; |
| 48 history_service->QueryRedirectsFrom( | 49 history_service->QueryRedirectsFrom( |
| 49 url, &consumer_, | 50 url, |
| 50 base::Bind(&RedirectTest::OnRedirectQueryComplete, | 51 base::Bind(&RedirectTest::OnRedirectQueryComplete, |
| 51 base::Unretained(this), &rv)); | 52 base::Unretained(this), |
| 53 &rv), |
| 54 &tracker_); |
| 52 content::RunMessageLoop(); | 55 content::RunMessageLoop(); |
| 53 return rv; | 56 return rv; |
| 54 } | 57 } |
| 55 | 58 |
| 56 protected: | 59 protected: |
| 57 void OnRedirectQueryComplete( | 60 void OnRedirectQueryComplete(std::vector<GURL>* rv, |
| 58 std::vector<GURL>* rv, | 61 const history::RedirectList* redirects) { |
| 59 HistoryService::Handle request_handle, | 62 rv->insert(rv->end(), redirects->begin(), redirects->end()); |
| 60 GURL from_url, | |
| 61 bool success, | |
| 62 history::RedirectList* redirects) { | |
| 63 for (size_t i = 0; i < redirects->size(); ++i) | |
| 64 rv->push_back(redirects->at(i)); | |
| 65 base::MessageLoop::current()->PostTask(FROM_HERE, | 63 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 66 base::MessageLoop::QuitClosure()); | 64 base::MessageLoop::QuitClosure()); |
| 67 } | 65 } |
| 68 | 66 |
| 69 // Consumer for asynchronous history queries. | 67 // Tracker for asynchronous history queries. |
| 70 CancelableRequestConsumer consumer_; | 68 base::CancelableTaskTracker tracker_; |
| 71 }; | 69 }; |
| 72 | 70 |
| 73 // Tests a single server redirect | 71 // Tests a single server redirect |
| 74 IN_PROC_BROWSER_TEST_F(RedirectTest, Server) { | 72 IN_PROC_BROWSER_TEST_F(RedirectTest, Server) { |
| 75 ASSERT_TRUE(test_server()->Start()); | 73 ASSERT_TRUE(test_server()->Start()); |
| 76 GURL final_url = test_server()->GetURL(std::string()); | 74 GURL final_url = test_server()->GetURL(std::string()); |
| 77 GURL first_url = test_server()->GetURL( | 75 GURL first_url = test_server()->GetURL( |
| 78 "server-redirect?" + final_url.spec()); | 76 "server-redirect?" + final_url.spec()); |
| 79 | 77 |
| 80 ui_test_utils::NavigateToURL(browser(), first_url); | 78 ui_test_utils::NavigateToURL(browser(), first_url); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // as a client redirect from the first (/client-redirect?) page. | 298 // as a client redirect from the first (/client-redirect?) page. |
| 301 for (std::vector<GURL>::iterator it = redirects.begin(); | 299 for (std::vector<GURL>::iterator it = redirects.begin(); |
| 302 it != redirects.end(); ++it) { | 300 it != redirects.end(); ++it) { |
| 303 if (final_url.spec() == it->spec()) { | 301 if (final_url.spec() == it->spec()) { |
| 304 final_navigation_not_redirect = false; | 302 final_navigation_not_redirect = false; |
| 305 break; | 303 break; |
| 306 } | 304 } |
| 307 } | 305 } |
| 308 EXPECT_TRUE(final_navigation_not_redirect); | 306 EXPECT_TRUE(final_navigation_not_redirect); |
| 309 } | 307 } |
| OLD | NEW |