OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_path.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/platform_thread.h" | 12 #include "base/platform_thread.h" |
12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "chrome/test/automation/tab_proxy.h" | 15 #include "chrome/test/automation/tab_proxy.h" |
15 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
16 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
17 #include "net/url_request/url_request_unittest.h" | 18 #include "net/url_request/url_request_unittest.h" |
18 | 19 |
19 namespace { | 20 namespace { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 ASSERT_EQ(1U, redirects.size()); | 75 ASSERT_EQ(1U, redirects.size()); |
75 EXPECT_EQ(final_url.spec(), redirects[0].spec()); | 76 EXPECT_EQ(final_url.spec(), redirects[0].spec()); |
76 } | 77 } |
77 | 78 |
78 TEST_F(RedirectTest, ClientEmptyReferer) { | 79 TEST_F(RedirectTest, ClientEmptyReferer) { |
79 scoped_refptr<HTTPTestServer> server = | 80 scoped_refptr<HTTPTestServer> server = |
80 HTTPTestServer::CreateServer(kDocRoot, NULL); | 81 HTTPTestServer::CreateServer(kDocRoot, NULL); |
81 ASSERT_TRUE(NULL != server.get()); | 82 ASSERT_TRUE(NULL != server.get()); |
82 | 83 |
83 GURL final_url = server->TestServerPageW(std::wstring()); | 84 GURL final_url = server->TestServerPageW(std::wstring()); |
84 std::wstring test_file = test_data_directory_; | 85 FilePath test_file(FilePath::FromWStringHack(test_data_directory_)); |
85 file_util::AppendToPath(&test_file, L"file_client_redirect.html"); | 86 test_file = test_file.AppendASCII("file_client_redirect.html"); |
86 GURL first_url = net::FilePathToFileURL(test_file); | 87 GURL first_url = net::FilePathToFileURL(test_file); |
87 | 88 |
88 NavigateToURL(first_url); | 89 NavigateToURL(first_url); |
89 std::vector<GURL> redirects; | 90 std::vector<GURL> redirects; |
90 // We need the sleeps for the client redirects, because it appears as two | 91 // We need the sleeps for the client redirects, because it appears as two |
91 // page visits in the browser. And note for this test the browser actually | 92 // page visits in the browser. And note for this test the browser actually |
92 // loads the html file on disk, rather than just getting a response from | 93 // loads the html file on disk, rather than just getting a response from |
93 // the TestServer. | 94 // the TestServer. |
94 for (int i = 0; i < 10; ++i) { | 95 for (int i = 0; i < 10; ++i) { |
95 PlatformThread::Sleep(sleep_timeout_ms()); | 96 PlatformThread::Sleep(sleep_timeout_ms()); |
96 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 97 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); |
97 ASSERT_TRUE(tab_proxy.get()); | 98 ASSERT_TRUE(tab_proxy.get()); |
98 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 99 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
99 if (!redirects.empty()) | 100 if (!redirects.empty()) |
100 break; | 101 break; |
101 } | 102 } |
102 | 103 |
103 EXPECT_EQ(1U, redirects.size()); | 104 EXPECT_EQ(1U, redirects.size()); |
104 EXPECT_EQ(final_url.spec(), redirects[0].spec()); | 105 EXPECT_EQ(final_url.spec(), redirects[0].spec()); |
105 } | 106 } |
106 | 107 |
107 // Tests to make sure a location change when a pending redirect exists isn't | 108 // Tests to make sure a location change when a pending redirect exists isn't |
108 // flagged as a redirect. | 109 // flagged as a redirect. |
109 TEST_F(RedirectTest, ClientCancelled) { | 110 TEST_F(RedirectTest, ClientCancelled) { |
110 std::wstring first_path = test_data_directory_; | 111 FilePath first_path(FilePath::FromWStringHack(test_data_directory_)); |
111 file_util::AppendToPath(&first_path, L"cancelled_redirect_test.html"); | 112 first_path = first_path.AppendASCII("cancelled_redirect_test.html"); |
112 ASSERT_TRUE(file_util::AbsolutePath(&first_path)); | 113 ASSERT_TRUE(file_util::AbsolutePath(&first_path)); |
113 GURL first_url = net::FilePathToFileURL(first_path); | 114 GURL first_url = net::FilePathToFileURL(first_path); |
114 | 115 |
115 NavigateToURL(first_url); | 116 NavigateToURL(first_url); |
116 PlatformThread::Sleep(action_timeout_ms()); | 117 PlatformThread::Sleep(action_timeout_ms()); |
117 | 118 |
118 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 119 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); |
119 ASSERT_TRUE(tab_proxy.get()); | 120 ASSERT_TRUE(tab_proxy.get()); |
120 | 121 |
121 std::vector<GURL> redirects; | 122 std::vector<GURL> redirects; |
122 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 123 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
123 | 124 |
124 // There should be no redirects from first_url, because the anchor location | 125 // There should be no redirects from first_url, because the anchor location |
125 // change that occurs should not be flagged as a redirect and the meta-refresh | 126 // change that occurs should not be flagged as a redirect and the meta-refresh |
126 // won't have fired yet. | 127 // won't have fired yet. |
127 ASSERT_EQ(0U, redirects.size()); | 128 ASSERT_EQ(0U, redirects.size()); |
128 GURL current_url; | 129 GURL current_url; |
129 ASSERT_TRUE(tab_proxy->GetCurrentURL(¤t_url)); | 130 ASSERT_TRUE(tab_proxy->GetCurrentURL(¤t_url)); |
130 | 131 |
131 // Need to test final path and ref separately since constructing a file url | 132 // Need to test final path and ref separately since constructing a file url |
132 // containing an anchor using FilePathToFileURL will escape the anchor as | 133 // containing an anchor using FilePathToFileURL will escape the anchor as |
133 // %23, but in current_url the anchor will be '#'. | 134 // %23, but in current_url the anchor will be '#'. |
134 std::string final_ref = "myanchor"; | 135 std::string final_ref = "myanchor"; |
135 std::wstring current_path; | 136 FilePath current_path; |
136 ASSERT_TRUE(net::FileURLToFilePath(current_url, ¤t_path)); | 137 ASSERT_TRUE(net::FileURLToFilePath(current_url, ¤t_path)); |
137 ASSERT_TRUE(file_util::AbsolutePath(¤t_path)); | 138 ASSERT_TRUE(file_util::AbsolutePath(¤t_path)); |
138 // Path should remain unchanged. | 139 // Path should remain unchanged. |
139 EXPECT_EQ(StringToLowerASCII(first_path), StringToLowerASCII(current_path)); | 140 EXPECT_EQ(StringToLowerASCII(first_path.value()), |
| 141 StringToLowerASCII(current_path.value())); |
140 EXPECT_EQ(final_ref, current_url.ref()); | 142 EXPECT_EQ(final_ref, current_url.ref()); |
141 } | 143 } |
142 | 144 |
143 // Tests a client->server->server redirect | 145 // Tests a client->server->server redirect |
144 // TODO(creis): This is disabled temporarily while I figure out why it is | 146 // TODO(creis): This is disabled temporarily while I figure out why it is |
145 // failing. | 147 // failing. |
146 TEST_F(RedirectTest, DISABLED_ClientServerServer) { | 148 TEST_F(RedirectTest, DISABLED_ClientServerServer) { |
147 scoped_refptr<HTTPTestServer> server = | 149 scoped_refptr<HTTPTestServer> server = |
148 HTTPTestServer::CreateServer(kDocRoot, NULL); | 150 HTTPTestServer::CreateServer(kDocRoot, NULL); |
149 ASSERT_TRUE(NULL != server.get()); | 151 ASSERT_TRUE(NULL != server.get()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 EXPECT_EQ(ref, url.ref()); | 197 EXPECT_EQ(ref, url.ref()); |
196 } | 198 } |
197 | 199 |
198 // Test that redirect from http:// to file:// : | 200 // Test that redirect from http:// to file:// : |
199 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 | 201 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 |
200 // B) does not take place. | 202 // B) does not take place. |
201 TEST_F(RedirectTest, NoHttpToFile) { | 203 TEST_F(RedirectTest, NoHttpToFile) { |
202 scoped_refptr<HTTPTestServer> server = | 204 scoped_refptr<HTTPTestServer> server = |
203 HTTPTestServer::CreateServer(kDocRoot, NULL); | 205 HTTPTestServer::CreateServer(kDocRoot, NULL); |
204 ASSERT_TRUE(NULL != server.get()); | 206 ASSERT_TRUE(NULL != server.get()); |
205 std::wstring test_file = test_data_directory_; | 207 FilePath test_file(FilePath::FromWStringHack(test_data_directory_)); |
206 file_util::AppendToPath(&test_file, L"http_to_file.html"); | 208 test_file = test_file.AppendASCII("http_to_file.html"); |
207 GURL file_url = net::FilePathToFileURL(test_file); | 209 GURL file_url = net::FilePathToFileURL(test_file); |
208 | 210 |
209 GURL initial_url = server->TestServerPageW( | 211 GURL initial_url = server->TestServerPageW( |
210 std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec())); | 212 std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec())); |
211 | 213 |
212 NavigateToURL(initial_url); | 214 NavigateToURL(initial_url); |
213 // UITest will check for crashes. We make sure the title doesn't match the | 215 // UITest will check for crashes. We make sure the title doesn't match the |
214 // title from the file, because the nav should not have taken place. | 216 // title from the file, because the nav should not have taken place. |
215 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 217 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); |
216 ASSERT_TRUE(tab_proxy.get()); | 218 ASSERT_TRUE(tab_proxy.get()); |
217 std::wstring actual_title; | 219 std::wstring actual_title; |
218 tab_proxy->GetTabTitle(&actual_title); | 220 tab_proxy->GetTabTitle(&actual_title); |
219 EXPECT_NE(L"File!", actual_title); | 221 EXPECT_NE(L"File!", actual_title); |
220 } | 222 } |
221 | 223 |
222 // Ensures that non-user initiated location changes (within page) are | 224 // Ensures that non-user initiated location changes (within page) are |
223 // flagged as client redirects. See bug 1139823. | 225 // flagged as client redirects. See bug 1139823. |
224 TEST_F(RedirectTest, ClientFragments) { | 226 TEST_F(RedirectTest, ClientFragments) { |
225 scoped_refptr<HTTPTestServer> server = | 227 scoped_refptr<HTTPTestServer> server = |
226 HTTPTestServer::CreateServer(kDocRoot, NULL); | 228 HTTPTestServer::CreateServer(kDocRoot, NULL); |
227 ASSERT_TRUE(NULL != server.get()); | 229 ASSERT_TRUE(NULL != server.get()); |
228 | 230 |
229 std::wstring test_file = test_data_directory_; | 231 FilePath test_file(FilePath::FromWStringHack(test_data_directory_)); |
230 file_util::AppendToPath(&test_file, L"ref_redirect.html"); | 232 test_file = test_file.AppendASCII("ref_redirect.html"); |
231 GURL first_url = net::FilePathToFileURL(test_file); | 233 GURL first_url = net::FilePathToFileURL(test_file); |
232 std::vector<GURL> redirects; | 234 std::vector<GURL> redirects; |
233 | 235 |
234 NavigateToURL(first_url); | 236 NavigateToURL(first_url); |
235 for (int i = 0; i < 10; ++i) { | 237 for (int i = 0; i < 10; ++i) { |
236 PlatformThread::Sleep(sleep_timeout_ms()); | 238 PlatformThread::Sleep(sleep_timeout_ms()); |
237 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 239 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); |
238 ASSERT_TRUE(tab_proxy.get()); | 240 ASSERT_TRUE(tab_proxy.get()); |
239 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); | 241 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); |
240 if (!redirects.empty()) | 242 if (!redirects.empty()) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // as a client redirect from the first (/client-redirect?) page. | 302 // as a client redirect from the first (/client-redirect?) page. |
301 for (std::vector<GURL>::iterator it = redirects.begin(); | 303 for (std::vector<GURL>::iterator it = redirects.begin(); |
302 it != redirects.end(); ++it) { | 304 it != redirects.end(); ++it) { |
303 if (final_url.spec() == it->spec()) { | 305 if (final_url.spec() == it->spec()) { |
304 final_navigation_not_redirect = false; | 306 final_navigation_not_redirect = false; |
305 break; | 307 break; |
306 } | 308 } |
307 } | 309 } |
308 EXPECT_TRUE(final_navigation_not_redirect); | 310 EXPECT_TRUE(final_navigation_not_redirect); |
309 } | 311 } |
OLD | NEW |