| OLD | NEW |
| 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 "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/view_ids.h" | |
| 17 #include "chrome/test/automation/browser_proxy.h" | |
| 18 #include "chrome/test/automation/tab_proxy.h" | 16 #include "chrome/test/automation/tab_proxy.h" |
| 19 #include "chrome/test/automation/window_proxy.h" | |
| 20 #include "chrome/test/ui/ui_test.h" | 17 #include "chrome/test/ui/ui_test.h" |
| 21 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 22 #include "net/test/test_server.h" | 19 #include "net/test/test_server.h" |
| 23 #include "views/event.h" | |
| 24 | 20 |
| 25 namespace { | 21 namespace { |
| 26 | 22 |
| 27 class RedirectTest : public UITest { | 23 class RedirectTest : public UITest { |
| 28 public: | 24 public: |
| 29 RedirectTest() | 25 RedirectTest() |
| 30 : test_server_(net::TestServer::TYPE_HTTP, | 26 : test_server_(net::TestServer::TYPE_HTTP, |
| 31 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { | 27 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { |
| 32 } | 28 } |
| 33 | 29 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 std::vector<GURL> redirects; | 98 std::vector<GURL> redirects; |
| 103 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 99 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 104 ASSERT_TRUE(tab_proxy.get()); | 100 ASSERT_TRUE(tab_proxy.get()); |
| 105 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 101 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
| 106 ASSERT_EQ(1U, redirects.size()); | 102 ASSERT_EQ(1U, redirects.size()); |
| 107 EXPECT_EQ(final_url.spec(), redirects[0].spec()); | 103 EXPECT_EQ(final_url.spec(), redirects[0].spec()); |
| 108 } | 104 } |
| 109 | 105 |
| 110 // Tests to make sure a location change when a pending redirect exists isn't | 106 // Tests to make sure a location change when a pending redirect exists isn't |
| 111 // flagged as a redirect. | 107 // flagged as a redirect. |
| 112 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 113 // SimulateOSClick is broken on the Mac: http://crbug.com/45162 | |
| 114 TEST_F(RedirectTest, ClientCancelled) { | 108 TEST_F(RedirectTest, ClientCancelled) { |
| 115 FilePath first_path(test_data_directory_); | 109 FilePath first_path(test_data_directory_); |
| 116 first_path = first_path.AppendASCII("cancelled_redirect_test.html"); | 110 first_path = first_path.AppendASCII("cancelled_redirect_test.html"); |
| 117 ASSERT_TRUE(file_util::AbsolutePath(&first_path)); | 111 ASSERT_TRUE(file_util::AbsolutePath(&first_path)); |
| 118 GURL first_url = net::FilePathToFileURL(first_path); | 112 GURL first_url = net::FilePathToFileURL(first_path); |
| 119 | 113 |
| 120 NavigateToURLBlockUntilNavigationsComplete(first_url, 1); | 114 NavigateToURLBlockUntilNavigationsComplete(first_url, 1); |
| 121 | 115 |
| 122 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); | 116 NavigateToURL(GURL("javascript:click()")); // User initiated location change. |
| 123 ASSERT_TRUE(browser.get()); | 117 |
| 124 scoped_refptr<WindowProxy> window = browser->GetWindow(); | |
| 125 ASSERT_TRUE(window.get()); | |
| 126 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 118 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 127 ASSERT_TRUE(tab_proxy.get()); | 119 ASSERT_TRUE(tab_proxy.get()); |
| 128 int64 last_nav_time = 0; | |
| 129 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&last_nav_time)); | |
| 130 // Simulate a click to force to make a user-initiated location change; | |
| 131 // otherwise, a non user-initiated in-page location change will be treated | |
| 132 // as client redirect and the redirect will be recoreded, which can cause | |
| 133 // this test failed. | |
| 134 gfx::Rect tab_view_bounds; | |
| 135 ASSERT_TRUE(browser->BringToFront()); | |
| 136 ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &tab_view_bounds, | |
| 137 true)); | |
| 138 ASSERT_TRUE( | |
| 139 window->SimulateOSClick(tab_view_bounds.CenterPoint(), | |
| 140 views::Event::EF_LEFT_BUTTON_DOWN)); | |
| 141 EXPECT_TRUE(tab_proxy->WaitForNavigation(last_nav_time)); | |
| 142 | 120 |
| 143 std::vector<GURL> redirects; | 121 std::vector<GURL> redirects; |
| 144 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 122 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
| 145 | 123 |
| 146 // There should be no redirects from first_url, because the anchor location | 124 // There should be no redirects from first_url, because the anchor location |
| 147 // change that occurs should not be flagged as a redirect and the meta-refresh | 125 // change that occurs should not be flagged as a redirect and the meta-refresh |
| 148 // won't have fired yet. | 126 // won't have fired yet. |
| 149 ASSERT_EQ(0U, redirects.size()); | 127 ASSERT_EQ(0U, redirects.size()); |
| 150 GURL current_url; | 128 GURL current_url; |
| 151 ASSERT_TRUE(tab_proxy->GetCurrentURL(¤t_url)); | 129 ASSERT_TRUE(tab_proxy->GetCurrentURL(¤t_url)); |
| 152 | 130 |
| 153 // Need to test final path and ref separately since constructing a file url | 131 // Need to test final path and ref separately since constructing a file url |
| 154 // containing an anchor using FilePathToFileURL will escape the anchor as | 132 // containing an anchor using FilePathToFileURL will escape the anchor as |
| 155 // %23, but in current_url the anchor will be '#'. | 133 // %23, but in current_url the anchor will be '#'. |
| 156 std::string final_ref = "myanchor"; | 134 std::string final_ref = "myanchor"; |
| 157 FilePath current_path; | 135 FilePath current_path; |
| 158 ASSERT_TRUE(net::FileURLToFilePath(current_url, ¤t_path)); | 136 ASSERT_TRUE(net::FileURLToFilePath(current_url, ¤t_path)); |
| 159 ASSERT_TRUE(file_util::AbsolutePath(¤t_path)); | 137 ASSERT_TRUE(file_util::AbsolutePath(¤t_path)); |
| 160 // Path should remain unchanged. | 138 // Path should remain unchanged. |
| 161 EXPECT_EQ(StringToLowerASCII(first_path.value()), | 139 EXPECT_EQ(StringToLowerASCII(first_path.value()), |
| 162 StringToLowerASCII(current_path.value())); | 140 StringToLowerASCII(current_path.value())); |
| 163 EXPECT_EQ(final_ref, current_url.ref()); | 141 EXPECT_EQ(final_ref, current_url.ref()); |
| 164 } | 142 } |
| 165 #endif | |
| 166 | 143 |
| 167 // Tests a client->server->server redirect | 144 // Tests a client->server->server redirect |
| 168 TEST_F(RedirectTest, ClientServerServer) { | 145 TEST_F(RedirectTest, ClientServerServer) { |
| 169 ASSERT_TRUE(test_server_.Start()); | 146 ASSERT_TRUE(test_server_.Start()); |
| 170 | 147 |
| 171 GURL final_url = test_server_.GetURL(std::string()); | 148 GURL final_url = test_server_.GetURL(std::string()); |
| 172 GURL next_to_last = test_server_.GetURL( | 149 GURL next_to_last = test_server_.GetURL( |
| 173 "server-redirect?" + final_url.spec()); | 150 "server-redirect?" + final_url.spec()); |
| 174 GURL second_url = test_server_.GetURL( | 151 GURL second_url = test_server_.GetURL( |
| 175 "server-redirect?" + next_to_last.spec()); | 152 "server-redirect?" + next_to_last.spec()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 it != redirects.end(); ++it) { | 286 it != redirects.end(); ++it) { |
| 310 if (final_url.spec() == it->spec()) { | 287 if (final_url.spec() == it->spec()) { |
| 311 final_navigation_not_redirect = false; | 288 final_navigation_not_redirect = false; |
| 312 break; | 289 break; |
| 313 } | 290 } |
| 314 } | 291 } |
| 315 EXPECT_TRUE(final_navigation_not_redirect); | 292 EXPECT_TRUE(final_navigation_not_redirect); |
| 316 } | 293 } |
| 317 | 294 |
| 318 } // namespace | 295 } // namespace |
| OLD | NEW |