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

Side by Side Diff: chrome/browser/ui/login/login_prompt_browsertest.cc

Issue 8316022: Move LoginPromptTest.TestCancelAuth to a browsertest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: notification_service moved to content Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/ui/login/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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <algorithm> 5 #include <algorithm>
6 #include <list> 6 #include <list>
7 #include <map> 7 #include <map>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/prerender/prerender_manager.h" 10 #include "chrome/browser/prerender/prerender_manager.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 template <int T> 151 template <int T>
152 class WindowedNavigationObserver 152 class WindowedNavigationObserver
153 : public ui_test_utils::WindowedNotificationObserver { 153 : public ui_test_utils::WindowedNotificationObserver {
154 public: 154 public:
155 explicit WindowedNavigationObserver(NavigationController* controller) 155 explicit WindowedNavigationObserver(NavigationController* controller)
156 : ui_test_utils::WindowedNotificationObserver( 156 : ui_test_utils::WindowedNotificationObserver(
157 T, content::Source<NavigationController>(controller)) {} 157 T, content::Source<NavigationController>(controller)) {}
158 }; 158 };
159 159
160 typedef WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP> 160 // LOAD_STOP observer is special since we want to be able to wait for
161 WindowedLoadStopObserver; 161 // multiple LOAD_STOP events.
162 class WindowedLoadStopObserver
Paweł Hajdan Jr. 2011/10/21 08:49:04 Could you please generalize it to chrome/test?
163 : public WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP> {
164 public:
165 WindowedLoadStopObserver(NavigationController* controller,
166 int notification_count)
167 : WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP>(controller),
168 remaining_notification_count_(notification_count) {}
cbentzel 2011/10/19 19:03:12 Do you need notification count? Is the sequence of
asanka 2011/10/19 19:21:17 In the TestCancelAuth test, when we initiate a nav
169 protected:
170 virtual void Observe(int type,
171 const content::NotificationSource& source,
172 const content::NotificationDetails& details) OVERRIDE;
173 private:
174 int remaining_notification_count_; // Number of notifications remaining.
175 };
176
177 void WindowedLoadStopObserver::Observe(
178 int type,
179 const content::NotificationSource& source,
180 const content::NotificationDetails& details) {
181 if (--remaining_notification_count_ == 0)
182 WindowedNotificationObserver::Observe(type, source, details);
183 }
162 184
163 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_NEEDED> 185 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_NEEDED>
164 WindowedAuthNeededObserver; 186 WindowedAuthNeededObserver;
165 187
166 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_CANCELLED> 188 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_CANCELLED>
167 WindowedAuthCancelledObserver; 189 WindowedAuthCancelledObserver;
168 190
169 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_SUPPLIED> 191 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_SUPPLIED>
170 WindowedAuthSuppliedObserver; 192 WindowedAuthSuppliedObserver;
171 193
172 const char* kPrefetchAuthPage = "files/login/prefetch.html"; 194 const char* kPrefetchAuthPage = "files/login/prefetch.html";
173 195
174 const char* kMultiRealmTestPage = "files/login/multi_realm.html"; 196 const char* kMultiRealmTestPage = "files/login/multi_realm.html";
175 const int kMultiRealmTestRealmCount = 2; 197 const int kMultiRealmTestRealmCount = 2;
176 const int kMultiRealmTestResourceCount = 4; 198 const int kMultiRealmTestResourceCount = 4;
177 199
178 const char* kSingleRealmTestPage = "files/login/single_realm.html"; 200 const char* kSingleRealmTestPage = "files/login/single_realm.html";
179 const int kSingleRealmTestResourceCount = 6; 201 const int kSingleRealmTestResourceCount = 6;
180 202
203 const char* kAuthBasicPage = "auth-basic";
204
181 // Confirm that <link rel="prefetch"> targetting an auth required 205 // Confirm that <link rel="prefetch"> targetting an auth required
182 // resource does not provide a login dialog. These types of requests 206 // resource does not provide a login dialog. These types of requests
183 // should instead just cancel the auth. 207 // should instead just cancel the auth.
184 208
185 // Unfortunately, this test doesn't assert on anything for its 209 // Unfortunately, this test doesn't assert on anything for its
186 // correctness. Instead, it relies on the auth dialog blocking the 210 // correctness. Instead, it relies on the auth dialog blocking the
187 // browser, and triggering a timeout to cause failure when the 211 // browser, and triggering a timeout to cause failure when the
188 // prefetch resource requires authorization. 212 // prefetch resource requires authorization.
189 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) { 213 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) {
190 ASSERT_TRUE(test_server()->Start()); 214 ASSERT_TRUE(test_server()->Start());
(...skipping 21 matching lines...) Expand all
212 } set_prefetch_for_test(true); 236 } set_prefetch_for_test(true);
213 237
214 TabContentsWrapper* contents = 238 TabContentsWrapper* contents =
215 browser()->GetSelectedTabContentsWrapper(); 239 browser()->GetSelectedTabContentsWrapper();
216 ASSERT_TRUE(contents); 240 ASSERT_TRUE(contents);
217 NavigationController* controller = &contents->controller(); 241 NavigationController* controller = &contents->controller();
218 LoginPromptBrowserTestObserver observer; 242 LoginPromptBrowserTestObserver observer;
219 243
220 observer.Register(content::Source<NavigationController>(controller)); 244 observer.Register(content::Source<NavigationController>(controller));
221 245
222 WindowedLoadStopObserver load_stop_waiter(controller); 246 WindowedLoadStopObserver load_stop_waiter(controller, 1);
223 browser()->OpenURL( 247 browser()->OpenURL(
224 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); 248 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
225 249
226 load_stop_waiter.Wait(); 250 load_stop_waiter.Wait();
227 EXPECT_TRUE(observer.handlers_.empty()); 251 EXPECT_TRUE(observer.handlers_.empty());
228 EXPECT_TRUE(test_server()->Stop()); 252 EXPECT_TRUE(test_server()->Stop());
229 } 253 }
230 254
255 // Test login prompt cancellation.
256 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth) {
257 ASSERT_TRUE(test_server()->Start());
258 GURL auth_page = test_server()->GetURL(kAuthBasicPage);
259 GURL no_auth_page_1 = test_server()->GetURL("a");
260 GURL no_auth_page_2 = test_server()->GetURL("b");
261 GURL no_auth_page_3 = test_server()->GetURL("c");
262
263 TabContentsWrapper* contents =
264 browser()->GetSelectedTabContentsWrapper();
265 ASSERT_TRUE(contents);
266
267 NavigationController* controller = &contents->controller();
268
269 LoginPromptBrowserTestObserver observer;
270 observer.Register(content::Source<NavigationController>(controller));
271
272 // First navigate to an unauthenticated page so we have something to
273 // go back to.
274 ui_test_utils::NavigateToURL(browser(), no_auth_page_1);
275
276 // Navigating while auth is requested is the same as cancelling.
277 {
278 // We need to wait for two LOAD_STOP events. One for auth_page and one for
279 // no_auth_page_2.
280 WindowedLoadStopObserver load_stop_waiter(controller, 2);
281 WindowedAuthNeededObserver auth_needed_waiter(controller);
282 browser()->OpenURL(
283 auth_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
284 auth_needed_waiter.Wait();
285 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
286 browser()->OpenURL(
287 no_auth_page_2, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
288 auth_cancelled_waiter.Wait();
289 load_stop_waiter.Wait();
290 EXPECT_TRUE(observer.handlers_.empty());
291 }
292
293 // Try navigating backwards.
294 {
295 // As above, we wait for two LOAD_STOP events; one for each navigation.
296 WindowedLoadStopObserver load_stop_waiter(controller, 2);
297 WindowedAuthNeededObserver auth_needed_waiter(controller);
298 browser()->OpenURL(
299 auth_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
300 auth_needed_waiter.Wait();
301 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
302 ASSERT_TRUE(browser()->CanGoBack());
303 browser()->GoBack(CURRENT_TAB);
304 auth_cancelled_waiter.Wait();
305 load_stop_waiter.Wait();
306 EXPECT_TRUE(observer.handlers_.empty());
307 }
308
309 // Now add a page and go back, so we have something to go forward to.
310 ui_test_utils::NavigateToURL(browser(), no_auth_page_3);
311 {
312 WindowedLoadStopObserver load_stop_waiter(controller, 1);
313 browser()->GoBack(CURRENT_TAB); // Should take us to page 1
314 load_stop_waiter.Wait();
315 }
316
317 {
318 // We wait for two LOAD_STOP events; one for each navigation.
319 WindowedLoadStopObserver load_stop_waiter(controller, 2);
320 WindowedAuthNeededObserver auth_needed_waiter(controller);
321 browser()->OpenURL(
322 auth_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
323 auth_needed_waiter.Wait();
324 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
325 ASSERT_TRUE(browser()->CanGoForward());
326 browser()->GoForward(CURRENT_TAB); // Should take us to page 3
327 auth_cancelled_waiter.Wait();
328 load_stop_waiter.Wait();
329 EXPECT_TRUE(observer.handlers_.empty());
330 }
331
332 // Now test that cancelling works as expected.
333 {
334 WindowedLoadStopObserver load_stop_waiter(controller, 1);
335 WindowedAuthNeededObserver auth_needed_waiter(controller);
336 browser()->OpenURL(
337 auth_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
338 auth_needed_waiter.Wait();
339 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
340 LoginHandler* handler = *observer.handlers_.begin();
341 ASSERT_TRUE(handler);
342 handler->CancelAuth();
343 auth_cancelled_waiter.Wait();
344 load_stop_waiter.Wait();
345 EXPECT_TRUE(observer.handlers_.empty());
346 }
347 }
348
231 // Test handling of resources that require authentication even though 349 // Test handling of resources that require authentication even though
232 // the page they are included on doesn't. In this case we should only 350 // the page they are included on doesn't. In this case we should only
233 // present the minimal number of prompts necessary for successfully 351 // present the minimal number of prompts necessary for successfully
234 // displaying the page. First we check whether cancelling works as 352 // displaying the page. First we check whether cancelling works as
235 // expected. 353 // expected.
236 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { 354 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) {
237 ASSERT_TRUE(test_server()->Start()); 355 ASSERT_TRUE(test_server()->Start());
238 GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 356 GURL test_page = test_server()->GetURL(kMultiRealmTestPage);
239 357
240 TabContentsWrapper* contents = 358 TabContentsWrapper* contents =
241 browser()->GetSelectedTabContentsWrapper(); 359 browser()->GetSelectedTabContentsWrapper();
242 ASSERT_TRUE(contents); 360 ASSERT_TRUE(contents);
243 361
244 NavigationController* controller = &contents->controller(); 362 NavigationController* controller = &contents->controller();
245 LoginPromptBrowserTestObserver observer; 363 LoginPromptBrowserTestObserver observer;
246 364
247 observer.Register(content::Source<NavigationController>(controller)); 365 observer.Register(content::Source<NavigationController>(controller));
248 366
249 WindowedLoadStopObserver load_stop_waiter(controller); 367 WindowedLoadStopObserver load_stop_waiter(controller, 1);
250 368
251 { 369 {
252 WindowedAuthNeededObserver auth_needed_waiter(controller); 370 WindowedAuthNeededObserver auth_needed_waiter(controller);
253 browser()->OpenURL( 371 browser()->OpenURL(
254 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); 372 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
255 auth_needed_waiter.Wait(); 373 auth_needed_waiter.Wait();
256 } 374 }
257 375
258 int n_handlers = 0; 376 int n_handlers = 0;
259 377
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 416
299 TabContentsWrapper* contents = 417 TabContentsWrapper* contents =
300 browser()->GetSelectedTabContentsWrapper(); 418 browser()->GetSelectedTabContentsWrapper();
301 ASSERT_TRUE(contents); 419 ASSERT_TRUE(contents);
302 420
303 NavigationController* controller = &contents->controller(); 421 NavigationController* controller = &contents->controller();
304 LoginPromptBrowserTestObserver observer; 422 LoginPromptBrowserTestObserver observer;
305 423
306 observer.Register(content::Source<NavigationController>(controller)); 424 observer.Register(content::Source<NavigationController>(controller));
307 425
308 WindowedLoadStopObserver load_stop_waiter(controller); 426 WindowedLoadStopObserver load_stop_waiter(controller, 1);
309 int n_handlers = 0; 427 int n_handlers = 0;
310 428
311 { 429 {
312 WindowedAuthNeededObserver auth_needed_waiter(controller); 430 WindowedAuthNeededObserver auth_needed_waiter(controller);
313 431
314 browser()->OpenURL( 432 browser()->OpenURL(
315 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); 433 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
316 auth_needed_waiter.Wait(); 434 auth_needed_waiter.Wait();
317 } 435 }
318 436
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 543
426 NavigationController* controller = &contents->controller(); 544 NavigationController* controller = &contents->controller();
427 LoginPromptBrowserTestObserver observer; 545 LoginPromptBrowserTestObserver observer;
428 546
429 observer.Register(content::Source<NavigationController>(controller)); 547 observer.Register(content::Source<NavigationController>(controller));
430 548
431 // First load a page that has a favicon that requires 549 // First load a page that has a favicon that requires
432 // authentication. There should be no login prompt. 550 // authentication. There should be no login prompt.
433 { 551 {
434 GURL test_page = test_server()->GetURL(kFaviconTestPage); 552 GURL test_page = test_server()->GetURL(kFaviconTestPage);
435 WindowedLoadStopObserver load_stop_waiter(controller); 553 WindowedLoadStopObserver load_stop_waiter(controller, 1);
436 browser()->OpenURL( 554 browser()->OpenURL(
437 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); 555 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
438 load_stop_waiter.Wait(); 556 load_stop_waiter.Wait();
439 } 557 }
440 558
441 // Now request the same favicon, but directly as the document. 559 // Now request the same favicon, but directly as the document.
442 // There should be one login prompt. 560 // There should be one login prompt.
443 { 561 {
444 GURL test_page = test_server()->GetURL(kFaviconResource); 562 GURL test_page = test_server()->GetURL(kFaviconResource);
445 WindowedLoadStopObserver load_stop_waiter(controller); 563 WindowedLoadStopObserver load_stop_waiter(controller, 1);
446 WindowedAuthNeededObserver auth_needed_waiter(controller); 564 WindowedAuthNeededObserver auth_needed_waiter(controller);
447 browser()->OpenURL( 565 browser()->OpenURL(
448 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); 566 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
449 auth_needed_waiter.Wait(); 567 auth_needed_waiter.Wait();
450 ASSERT_EQ(1u, observer.handlers_.size()); 568 ASSERT_EQ(1u, observer.handlers_.size());
451 569
452 while (!observer.handlers_.empty()) { 570 while (!observer.handlers_.empty()) {
453 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 571 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
454 LoginHandler* handler = *observer.handlers_.begin(); 572 LoginHandler* handler = *observer.handlers_.begin();
455 573
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 GURL test_page = test_server()->GetURL(kTestPage); 606 GURL test_page = test_server()->GetURL(kTestPage);
489 ASSERT_EQ("127.0.0.1", test_page.host()); 607 ASSERT_EQ("127.0.0.1", test_page.host());
490 608
491 // Change the host from 127.0.0.1 to www.a.com so that when the 609 // Change the host from 127.0.0.1 to www.a.com so that when the
492 // page tries to load from b, it will be cross-origin. 610 // page tries to load from b, it will be cross-origin.
493 std::string new_host("www.a.com"); 611 std::string new_host("www.a.com");
494 GURL::Replacements replacements; 612 GURL::Replacements replacements;
495 replacements.SetHostStr(new_host); 613 replacements.SetHostStr(new_host);
496 test_page = test_page.ReplaceComponents(replacements); 614 test_page = test_page.ReplaceComponents(replacements);
497 615
498 WindowedLoadStopObserver load_stop_waiter(controller); 616 WindowedLoadStopObserver load_stop_waiter(controller, 1);
499 browser()->OpenURL( 617 browser()->OpenURL(
500 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); 618 test_page, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
501 load_stop_waiter.Wait(); 619 load_stop_waiter.Wait();
502 } 620 }
503 621
504 EXPECT_EQ(0, observer.auth_needed_count_); 622 EXPECT_EQ(0, observer.auth_needed_count_);
505 623
506 // Now request the same page, but from the same origin. 624 // Now request the same page, but from the same origin.
507 // There should be one login prompt. 625 // There should be one login prompt.
508 { 626 {
(...skipping 21 matching lines...) Expand all
530 handler->CancelAuth(); 648 handler->CancelAuth();
531 auth_cancelled_waiter.Wait(); 649 auth_cancelled_waiter.Wait();
532 } 650 }
533 } 651 }
534 652
535 EXPECT_EQ(1, observer.auth_needed_count_); 653 EXPECT_EQ(1, observer.auth_needed_count_);
536 EXPECT_TRUE(test_server()->Stop()); 654 EXPECT_TRUE(test_server()->Stop());
537 } 655 }
538 656
539 } // namespace 657 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/login/login_prompt_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698