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

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

Issue 113722: Make automation proxy objects to ref_counted. That allows to process async no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_uitest.cc ('k') | chrome/browser/login_prompt_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_util.h" 10 #include "base/file_util.h"
(...skipping 20 matching lines...) Expand all
31 scoped_refptr<HTTPTestServer> server = 31 scoped_refptr<HTTPTestServer> server =
32 HTTPTestServer::CreateServer(kDocRoot, NULL); 32 HTTPTestServer::CreateServer(kDocRoot, NULL);
33 ASSERT_TRUE(NULL != server.get()); 33 ASSERT_TRUE(NULL != server.get());
34 34
35 GURL final_url = server->TestServerPageW(std::wstring()); 35 GURL final_url = server->TestServerPageW(std::wstring());
36 GURL first_url = server->TestServerPageW( 36 GURL first_url = server->TestServerPageW(
37 std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec())); 37 std::wstring(L"server-redirect?") + UTF8ToWide(final_url.spec()));
38 38
39 NavigateToURL(first_url); 39 NavigateToURL(first_url);
40 40
41 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 41 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
42 ASSERT_TRUE(tab_proxy.get()); 42 ASSERT_TRUE(tab_proxy.get());
43 43
44 std::vector<GURL> redirects; 44 std::vector<GURL> redirects;
45 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 45 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
46 46
47 ASSERT_EQ(1U, redirects.size()); 47 ASSERT_EQ(1U, redirects.size());
48 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 48 EXPECT_EQ(final_url.spec(), redirects[0].spec());
49 } 49 }
50 50
51 // Tests a single client redirect. 51 // Tests a single client redirect.
52 TEST_F(RedirectTest, Client) { 52 TEST_F(RedirectTest, Client) {
53 scoped_refptr<HTTPTestServer> server = 53 scoped_refptr<HTTPTestServer> server =
54 HTTPTestServer::CreateServer(kDocRoot, NULL); 54 HTTPTestServer::CreateServer(kDocRoot, NULL);
55 ASSERT_TRUE(NULL != server.get()); 55 ASSERT_TRUE(NULL != server.get());
56 56
57 GURL final_url = server->TestServerPageW(std::wstring()); 57 GURL final_url = server->TestServerPageW(std::wstring());
58 GURL first_url = server->TestServerPageW( 58 GURL first_url = server->TestServerPageW(
59 std::wstring(L"client-redirect?") + UTF8ToWide(final_url.spec())); 59 std::wstring(L"client-redirect?") + UTF8ToWide(final_url.spec()));
60 60
61 // We need the sleep for the client redirects, because it appears as two 61 // We need the sleep for the client redirects, because it appears as two
62 // page visits in the browser. 62 // page visits in the browser.
63 NavigateToURL(first_url); 63 NavigateToURL(first_url);
64 PlatformThread::Sleep(action_timeout_ms()); 64 PlatformThread::Sleep(action_timeout_ms());
65 65
66 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 66 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
67 ASSERT_TRUE(tab_proxy.get()); 67 ASSERT_TRUE(tab_proxy.get());
68 68
69 std::vector<GURL> redirects; 69 std::vector<GURL> redirects;
70 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 70 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
71 71
72 ASSERT_EQ(1U, redirects.size()); 72 ASSERT_EQ(1U, redirects.size());
73 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 73 EXPECT_EQ(final_url.spec(), redirects[0].spec());
74 } 74 }
75 75
76 TEST_F(RedirectTest, ClientEmptyReferer) { 76 TEST_F(RedirectTest, ClientEmptyReferer) {
77 scoped_refptr<HTTPTestServer> server = 77 scoped_refptr<HTTPTestServer> server =
78 HTTPTestServer::CreateServer(kDocRoot, NULL); 78 HTTPTestServer::CreateServer(kDocRoot, NULL);
79 ASSERT_TRUE(NULL != server.get()); 79 ASSERT_TRUE(NULL != server.get());
80 80
81 GURL final_url = server->TestServerPageW(std::wstring()); 81 GURL final_url = server->TestServerPageW(std::wstring());
82 FilePath test_file(test_data_directory_); 82 FilePath test_file(test_data_directory_);
83 test_file = test_file.AppendASCII("file_client_redirect.html"); 83 test_file = test_file.AppendASCII("file_client_redirect.html");
84 GURL first_url = net::FilePathToFileURL(test_file); 84 GURL first_url = net::FilePathToFileURL(test_file);
85 85
86 NavigateToURL(first_url); 86 NavigateToURL(first_url);
87 std::vector<GURL> redirects; 87 std::vector<GURL> redirects;
88 // We need the sleeps for the client redirects, because it appears as two 88 // We need the sleeps for the client redirects, because it appears as two
89 // page visits in the browser. And note for this test the browser actually 89 // page visits in the browser. And note for this test the browser actually
90 // loads the html file on disk, rather than just getting a response from 90 // loads the html file on disk, rather than just getting a response from
91 // the TestServer. 91 // the TestServer.
92 for (int i = 0; i < 10; ++i) { 92 for (int i = 0; i < 10; ++i) {
93 PlatformThread::Sleep(sleep_timeout_ms()); 93 PlatformThread::Sleep(sleep_timeout_ms());
94 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 94 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
95 ASSERT_TRUE(tab_proxy.get()); 95 ASSERT_TRUE(tab_proxy.get());
96 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 96 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
97 if (!redirects.empty()) 97 if (!redirects.empty())
98 break; 98 break;
99 } 99 }
100 100
101 EXPECT_EQ(1U, redirects.size()); 101 EXPECT_EQ(1U, redirects.size());
102 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 102 EXPECT_EQ(final_url.spec(), redirects[0].spec());
103 } 103 }
104 104
105 // Tests to make sure a location change when a pending redirect exists isn't 105 // Tests to make sure a location change when a pending redirect exists isn't
106 // flagged as a redirect. 106 // flagged as a redirect.
107 TEST_F(RedirectTest, ClientCancelled) { 107 TEST_F(RedirectTest, ClientCancelled) {
108 FilePath first_path(test_data_directory_); 108 FilePath first_path(test_data_directory_);
109 first_path = first_path.AppendASCII("cancelled_redirect_test.html"); 109 first_path = first_path.AppendASCII("cancelled_redirect_test.html");
110 ASSERT_TRUE(file_util::AbsolutePath(&first_path)); 110 ASSERT_TRUE(file_util::AbsolutePath(&first_path));
111 GURL first_url = net::FilePathToFileURL(first_path); 111 GURL first_url = net::FilePathToFileURL(first_path);
112 112
113 NavigateToURL(first_url); 113 NavigateToURL(first_url);
114 PlatformThread::Sleep(action_timeout_ms()); 114 PlatformThread::Sleep(action_timeout_ms());
115 115
116 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 116 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
117 ASSERT_TRUE(tab_proxy.get()); 117 ASSERT_TRUE(tab_proxy.get());
118 118
119 std::vector<GURL> redirects; 119 std::vector<GURL> redirects;
120 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 120 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
121 121
122 // There should be no redirects from first_url, because the anchor location 122 // There should be no redirects from first_url, because the anchor location
123 // change that occurs should not be flagged as a redirect and the meta-refresh 123 // change that occurs should not be flagged as a redirect and the meta-refresh
124 // won't have fired yet. 124 // won't have fired yet.
125 ASSERT_EQ(0U, redirects.size()); 125 ASSERT_EQ(0U, redirects.size());
126 GURL current_url; 126 GURL current_url;
(...skipping 28 matching lines...) Expand all
155 GURL first_url = server->TestServerPageW( 155 GURL first_url = server->TestServerPageW(
156 std::wstring(L"client-redirect?") + UTF8ToWide(second_url.spec())); 156 std::wstring(L"client-redirect?") + UTF8ToWide(second_url.spec()));
157 std::vector<GURL> redirects; 157 std::vector<GURL> redirects;
158 158
159 // We need the sleep for the client redirects, because it appears as two 159 // We need the sleep for the client redirects, because it appears as two
160 // page visits in the browser. 160 // page visits in the browser.
161 NavigateToURL(first_url); 161 NavigateToURL(first_url);
162 162
163 for (int i = 0; i < 10; ++i) { 163 for (int i = 0; i < 10; ++i) {
164 PlatformThread::Sleep(sleep_timeout_ms()); 164 PlatformThread::Sleep(sleep_timeout_ms());
165 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 165 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
166 ASSERT_TRUE(tab_proxy.get()); 166 ASSERT_TRUE(tab_proxy.get());
167 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 167 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
168 if (!redirects.empty()) 168 if (!redirects.empty())
169 break; 169 break;
170 } 170 }
171 171
172 ASSERT_EQ(3U, redirects.size()); 172 ASSERT_EQ(3U, redirects.size());
173 EXPECT_EQ(second_url.spec(), redirects[0].spec()); 173 EXPECT_EQ(second_url.spec(), redirects[0].spec());
174 EXPECT_EQ(next_to_last.spec(), redirects[1].spec()); 174 EXPECT_EQ(next_to_last.spec(), redirects[1].spec());
175 EXPECT_EQ(final_url.spec(), redirects[2].spec()); 175 EXPECT_EQ(final_url.spec(), redirects[2].spec());
(...skipping 28 matching lines...) Expand all
204 FilePath test_file(test_data_directory_); 204 FilePath test_file(test_data_directory_);
205 test_file = test_file.AppendASCII("http_to_file.html"); 205 test_file = test_file.AppendASCII("http_to_file.html");
206 GURL file_url = net::FilePathToFileURL(test_file); 206 GURL file_url = net::FilePathToFileURL(test_file);
207 207
208 GURL initial_url = server->TestServerPageW( 208 GURL initial_url = server->TestServerPageW(
209 std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec())); 209 std::wstring(L"client-redirect?") + UTF8ToWide(file_url.spec()));
210 210
211 NavigateToURL(initial_url); 211 NavigateToURL(initial_url);
212 // UITest will check for crashes. We make sure the title doesn't match the 212 // UITest will check for crashes. We make sure the title doesn't match the
213 // title from the file, because the nav should not have taken place. 213 // title from the file, because the nav should not have taken place.
214 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 214 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
215 ASSERT_TRUE(tab_proxy.get()); 215 ASSERT_TRUE(tab_proxy.get());
216 std::wstring actual_title; 216 std::wstring actual_title;
217 tab_proxy->GetTabTitle(&actual_title); 217 tab_proxy->GetTabTitle(&actual_title);
218 EXPECT_NE(L"File!", actual_title); 218 EXPECT_NE(L"File!", actual_title);
219 } 219 }
220 220
221 // Ensures that non-user initiated location changes (within page) are 221 // Ensures that non-user initiated location changes (within page) are
222 // flagged as client redirects. See bug 1139823. 222 // flagged as client redirects. See bug 1139823.
223 TEST_F(RedirectTest, ClientFragments) { 223 TEST_F(RedirectTest, ClientFragments) {
224 scoped_refptr<HTTPTestServer> server = 224 scoped_refptr<HTTPTestServer> server =
225 HTTPTestServer::CreateServer(kDocRoot, NULL); 225 HTTPTestServer::CreateServer(kDocRoot, NULL);
226 ASSERT_TRUE(NULL != server.get()); 226 ASSERT_TRUE(NULL != server.get());
227 227
228 FilePath test_file(test_data_directory_); 228 FilePath test_file(test_data_directory_);
229 test_file = test_file.AppendASCII("ref_redirect.html"); 229 test_file = test_file.AppendASCII("ref_redirect.html");
230 GURL first_url = net::FilePathToFileURL(test_file); 230 GURL first_url = net::FilePathToFileURL(test_file);
231 std::vector<GURL> redirects; 231 std::vector<GURL> redirects;
232 232
233 NavigateToURL(first_url); 233 NavigateToURL(first_url);
234 for (int i = 0; i < 10; ++i) { 234 for (int i = 0; i < 10; ++i) {
235 PlatformThread::Sleep(sleep_timeout_ms()); 235 PlatformThread::Sleep(sleep_timeout_ms());
236 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 236 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
237 ASSERT_TRUE(tab_proxy.get()); 237 ASSERT_TRUE(tab_proxy.get());
238 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 238 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
239 if (!redirects.empty()) 239 if (!redirects.empty())
240 break; 240 break;
241 } 241 }
242 242
243 EXPECT_EQ(1U, redirects.size()); 243 EXPECT_EQ(1U, redirects.size());
244 EXPECT_EQ(first_url.spec() + "#myanchor", redirects[0].spec()); 244 EXPECT_EQ(first_url.spec() + "#myanchor", redirects[0].spec());
245 } 245 }
246 246
(...skipping 27 matching lines...) Expand all
274 // because we told the server to wait a minute. This means the browser has 274 // because we told the server to wait a minute. This means the browser has
275 // started it's provisional load for the client redirect destination page but 275 // started it's provisional load for the client redirect destination page but
276 // hasn't completed. Our time is now! 276 // hasn't completed. Our time is now!
277 NavigateToURL(final_url); 277 NavigateToURL(final_url);
278 278
279 std::wstring tab_title; 279 std::wstring tab_title;
280 std::wstring final_url_title = L"Title Of Awesomeness"; 280 std::wstring final_url_title = L"Title Of Awesomeness";
281 // Wait till the final page has been loaded. 281 // Wait till the final page has been loaded.
282 for (int i = 0; i < 10; ++i) { 282 for (int i = 0; i < 10; ++i) {
283 PlatformThread::Sleep(sleep_timeout_ms()); 283 PlatformThread::Sleep(sleep_timeout_ms());
284 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); 284 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
285 ASSERT_TRUE(tab_proxy.get()); 285 ASSERT_TRUE(tab_proxy.get());
286 ASSERT_TRUE(tab_proxy->GetTabTitle(&tab_title)); 286 ASSERT_TRUE(tab_proxy->GetTabTitle(&tab_title));
287 if (tab_title == final_url_title) { 287 if (tab_title == final_url_title) {
288 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); 288 ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects));
289 break; 289 break;
290 } 290 }
291 } 291 }
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(final_url_title, tab_title); 295 EXPECT_EQ(final_url_title, tab_title);
296 296
297 bool final_navigation_not_redirect = true; 297 bool final_navigation_not_redirect = true;
298 // Check to make sure our request for files/title2.html doesn't get flagged 298 // Check to make sure our request for files/title2.html doesn't get flagged
299 // as a client redirect from the first (/client-redirect?) page. 299 // as a client redirect from the first (/client-redirect?) page.
300 for (std::vector<GURL>::iterator it = redirects.begin(); 300 for (std::vector<GURL>::iterator it = redirects.begin();
301 it != redirects.end(); ++it) { 301 it != redirects.end(); ++it) {
302 if (final_url.spec() == it->spec()) { 302 if (final_url.spec() == it->spec()) {
303 final_navigation_not_redirect = false; 303 final_navigation_not_redirect = false;
304 break; 304 break;
305 } 305 }
306 } 306 }
307 EXPECT_TRUE(final_navigation_not_redirect); 307 EXPECT_TRUE(final_navigation_not_redirect);
308 } 308 }
309 309
310 } // namespace 310 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_uitest.cc ('k') | chrome/browser/login_prompt_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698