| 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 <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/task/cancelable_task_tracker.h" | 21 #include "base/task/cancelable_task_tracker.h" |
| 22 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
| 23 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
| 24 #include "base/threading/thread_restrictions.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 29 #include "chrome/browser/ui/view_ids.h" | 30 #include "chrome/browser/ui/view_ids.h" |
| 30 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
| 31 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "components/history/core/browser/history_service.h" | 33 #include "components/history/core/browser/history_service.h" |
| 33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 GURL final_url = embedded_test_server()->GetURL("/defaultresponse"); | 127 GURL final_url = embedded_test_server()->GetURL("/defaultresponse"); |
| 127 ASSERT_TRUE(final_url.is_valid()); | 128 ASSERT_TRUE(final_url.is_valid()); |
| 128 std::string file_redirect_contents = base::StringPrintf( | 129 std::string file_redirect_contents = base::StringPrintf( |
| 129 "<html>" | 130 "<html>" |
| 130 "<head></head>" | 131 "<head></head>" |
| 131 "<body onload=\"document.location='%s'\"></body>" | 132 "<body onload=\"document.location='%s'\"></body>" |
| 132 "</html>", | 133 "</html>", |
| 133 final_url.spec().c_str()); | 134 final_url.spec().c_str()); |
| 134 | 135 |
| 135 // Write the contents to a temporary file. | 136 // Write the contents to a temporary file. |
| 137 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 136 base::ScopedTempDir temp_directory; | 138 base::ScopedTempDir temp_directory; |
| 137 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 139 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 138 base::FilePath temp_file; | 140 base::FilePath temp_file; |
| 139 ASSERT_TRUE( | 141 ASSERT_TRUE( |
| 140 base::CreateTemporaryFileInDir(temp_directory.GetPath(), &temp_file)); | 142 base::CreateTemporaryFileInDir(temp_directory.GetPath(), &temp_file)); |
| 141 ASSERT_EQ(static_cast<int>(file_redirect_contents.size()), | 143 ASSERT_EQ(static_cast<int>(file_redirect_contents.size()), |
| 142 base::WriteFile(temp_file, | 144 base::WriteFile(temp_file, |
| 143 file_redirect_contents.data(), | 145 file_redirect_contents.data(), |
| 144 file_redirect_contents.size())); | 146 file_redirect_contents.size())); |
| 145 | 147 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // as a client redirect from the first (/client-redirect?) page. | 306 // as a client redirect from the first (/client-redirect?) page. |
| 305 for (std::vector<GURL>::iterator it = redirects.begin(); | 307 for (std::vector<GURL>::iterator it = redirects.begin(); |
| 306 it != redirects.end(); ++it) { | 308 it != redirects.end(); ++it) { |
| 307 if (final_url.spec() == it->spec()) { | 309 if (final_url.spec() == it->spec()) { |
| 308 final_navigation_not_redirect = false; | 310 final_navigation_not_redirect = false; |
| 309 break; | 311 break; |
| 310 } | 312 } |
| 311 } | 313 } |
| 312 EXPECT_TRUE(final_navigation_not_redirect); | 314 EXPECT_TRUE(final_navigation_not_redirect); |
| 313 } | 315 } |
| OLD | NEW |