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

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

Issue 1378123003: Adding SSL ETS Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ets
Patch Set: Rebase. Created 5 years, 1 month 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
OLDNEW
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 #include <algorithm> 5 #include <algorithm>
6 #include <list> 6 #include <list>
7 #include <map> 7 #include <map>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/prerender/prerender_manager.h" 12 #include "chrome/browser/prerender/prerender_manager.h"
13 #include "chrome/browser/ssl/ssl_blocking_page.h" 13 #include "chrome/browser/ssl/ssl_blocking_page.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/login/login_interstitial_delegate.h" 16 #include "chrome/browser/ui/login/login_interstitial_delegate.h"
17 #include "chrome/browser/ui/login/login_prompt.h" 17 #include "chrome/browser/ui/login/login_prompt.h"
18 #include "chrome/browser/ui/login/login_prompt_test_utils.h" 18 #include "chrome/browser/ui/login/login_prompt_test_utils.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/interstitial_page.h" 22 #include "content/public/browser/interstitial_page.h"
23 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
27 #include "content/public/test/test_navigation_observer.h" 27 #include "content/public/test/test_navigation_observer.h"
28 #include "net/base/auth.h" 28 #include "net/base/auth.h"
29 #include "net/dns/mock_host_resolver.h" 29 #include "net/dns/mock_host_resolver.h"
30 #include "net/test/spawned_test_server/spawned_test_server.h" 30 #include "net/test/embedded_test_server/embedded_test_server.h"
31 31
32 using content::NavigationController; 32 using content::NavigationController;
33 using content::OpenURLParams; 33 using content::OpenURLParams;
34 using content::Referrer; 34 using content::Referrer;
35 35
36 namespace { 36 namespace {
37 37
38 class LoginPromptBrowserTest : public InProcessBrowserTest { 38 class LoginPromptBrowserTest : public InProcessBrowserTest {
39 public: 39 public:
40 LoginPromptBrowserTest() 40 LoginPromptBrowserTest()
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ASSERT_TRUE(challenge); 86 ASSERT_TRUE(challenge);
87 AuthMap::iterator i = auth_map_.find(challenge->realm); 87 AuthMap::iterator i = auth_map_.find(challenge->realm);
88 EXPECT_TRUE(auth_map_.end() != i); 88 EXPECT_TRUE(auth_map_.end() != i);
89 if (i != auth_map_.end()) { 89 if (i != auth_map_.end()) {
90 const AuthInfo& info = i->second; 90 const AuthInfo& info = i->second;
91 handler->SetAuth(base::UTF8ToUTF16(info.username_), 91 handler->SetAuth(base::UTF8ToUTF16(info.username_),
92 base::UTF8ToUTF16(info.password_)); 92 base::UTF8ToUTF16(info.password_));
93 } 93 }
94 } 94 }
95 95
96 const char kPrefetchAuthPage[] = "files/login/prefetch.html"; 96 const char kPrefetchAuthPage[] = "/login/prefetch.html";
97 97
98 const char kMultiRealmTestPage[] = "files/login/multi_realm.html"; 98 const char kMultiRealmTestPage[] = "/login/multi_realm.html";
99 const int kMultiRealmTestRealmCount = 2; 99 const int kMultiRealmTestRealmCount = 2;
100 100
101 const char kSingleRealmTestPage[] = "files/login/single_realm.html"; 101 const char kSingleRealmTestPage[] = "/login/single_realm.html";
102 102
103 const char* kAuthBasicPage = "auth-basic"; 103 const char* kAuthBasicPage = "/auth-basic";
104 const char* kAuthDigestPage = "auth-digest"; 104 const char* kAuthDigestPage = "/auth-digest";
105 105
106 base::string16 ExpectedTitleFromAuth(const base::string16& username, 106 base::string16 ExpectedTitleFromAuth(const base::string16& username,
107 const base::string16& password) { 107 const base::string16& password) {
108 // The TestServer sets the title to username/password on successful login. 108 // The TestServer sets the title to username/password on successful login.
109 return username + base::UTF8ToUTF16("/") + password; 109 return username + base::UTF8ToUTF16("/") + password;
110 } 110 }
111 111
112 // Confirm that <link rel="prefetch"> targetting an auth required 112 // Confirm that <link rel="prefetch"> targetting an auth required
113 // resource does not provide a login dialog. These types of requests 113 // resource does not provide a login dialog. These types of requests
114 // should instead just cancel the auth. 114 // should instead just cancel the auth.
115 115
116 // Unfortunately, this test doesn't assert on anything for its 116 // Unfortunately, this test doesn't assert on anything for its
117 // correctness. Instead, it relies on the auth dialog blocking the 117 // correctness. Instead, it relies on the auth dialog blocking the
118 // browser, and triggering a timeout to cause failure when the 118 // browser, and triggering a timeout to cause failure when the
119 // prefetch resource requires authorization. 119 // prefetch resource requires authorization.
120 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) { 120 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) {
121 ASSERT_TRUE(test_server()->Start()); 121 ASSERT_TRUE(embedded_test_server()->Start());
122 122
123 GURL test_page = test_server()->GetURL(kPrefetchAuthPage); 123 GURL test_page = embedded_test_server()->GetURL(kPrefetchAuthPage);
124 124
125 class SetPrefetchForTest { 125 class SetPrefetchForTest {
126 public: 126 public:
127 explicit SetPrefetchForTest(bool prefetch) 127 explicit SetPrefetchForTest(bool prefetch)
128 : old_prerender_mode_(prerender::PrerenderManager::GetMode()) { 128 : old_prerender_mode_(prerender::PrerenderManager::GetMode()) {
129 std::string exp_group = prefetch ? "ExperimentYes" : "ExperimentNo"; 129 std::string exp_group = prefetch ? "ExperimentYes" : "ExperimentNo";
130 base::FieldTrialList::CreateFieldTrial("Prefetch", exp_group); 130 base::FieldTrialList::CreateFieldTrial("Prefetch", exp_group);
131 // Disable prerender so this is just a prefetch of the top-level page. 131 // Disable prerender so this is just a prefetch of the top-level page.
132 prerender::PrerenderManager::SetMode( 132 prerender::PrerenderManager::SetMode(
133 prerender::PrerenderManager::PRERENDER_MODE_DISABLED); 133 prerender::PrerenderManager::PRERENDER_MODE_DISABLED);
(...skipping 14 matching lines...) Expand all
148 148
149 observer.Register(content::Source<NavigationController>(controller)); 149 observer.Register(content::Source<NavigationController>(controller));
150 150
151 WindowedLoadStopObserver load_stop_waiter(controller, 1); 151 WindowedLoadStopObserver load_stop_waiter(controller, 1);
152 browser()->OpenURL(OpenURLParams( 152 browser()->OpenURL(OpenURLParams(
153 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 153 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
154 false)); 154 false));
155 155
156 load_stop_waiter.Wait(); 156 load_stop_waiter.Wait();
157 EXPECT_TRUE(observer.handlers().empty()); 157 EXPECT_TRUE(observer.handlers().empty());
158 EXPECT_TRUE(test_server()->Stop());
159 } 158 }
160 159
161 // Test that "Basic" HTTP authentication works. 160 // Test that "Basic" HTTP authentication works.
162 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestBasicAuth) { 161 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestBasicAuth) {
163 ASSERT_TRUE(test_server()->Start()); 162 ASSERT_TRUE(embedded_test_server()->Start());
164 GURL test_page = test_server()->GetURL(kAuthBasicPage); 163 GURL test_page = embedded_test_server()->GetURL(kAuthBasicPage);
165 164
166 content::WebContents* contents = 165 content::WebContents* contents =
167 browser()->tab_strip_model()->GetActiveWebContents(); 166 browser()->tab_strip_model()->GetActiveWebContents();
168 NavigationController* controller = &contents->GetController(); 167 NavigationController* controller = &contents->GetController();
169 LoginPromptBrowserTestObserver observer; 168 LoginPromptBrowserTestObserver observer;
170 169
171 observer.Register(content::Source<NavigationController>(controller)); 170 observer.Register(content::Source<NavigationController>(controller));
172 171
173 { 172 {
174 WindowedAuthNeededObserver auth_needed_waiter(controller); 173 WindowedAuthNeededObserver auth_needed_waiter(controller);
(...skipping 28 matching lines...) Expand all
203 202
204 base::string16 expected_title = 203 base::string16 expected_title =
205 ExpectedTitleFromAuth(base::ASCIIToUTF16("basicuser"), 204 ExpectedTitleFromAuth(base::ASCIIToUTF16("basicuser"),
206 base::ASCIIToUTF16("secret")); 205 base::ASCIIToUTF16("secret"));
207 content::TitleWatcher title_watcher(contents, expected_title); 206 content::TitleWatcher title_watcher(contents, expected_title);
208 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 207 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
209 } 208 }
210 209
211 // Test that "Digest" HTTP authentication works. 210 // Test that "Digest" HTTP authentication works.
212 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestDigestAuth) { 211 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestDigestAuth) {
213 ASSERT_TRUE(test_server()->Start()); 212 ASSERT_TRUE(embedded_test_server()->Start());
214 GURL test_page = test_server()->GetURL(kAuthDigestPage); 213 GURL test_page = embedded_test_server()->GetURL(kAuthDigestPage);
215 214
216 content::WebContents* contents = 215 content::WebContents* contents =
217 browser()->tab_strip_model()->GetActiveWebContents(); 216 browser()->tab_strip_model()->GetActiveWebContents();
218 NavigationController* controller = &contents->GetController(); 217 NavigationController* controller = &contents->GetController();
219 LoginPromptBrowserTestObserver observer; 218 LoginPromptBrowserTestObserver observer;
220 219
221 observer.Register(content::Source<NavigationController>(controller)); 220 observer.Register(content::Source<NavigationController>(controller));
222 221
223 { 222 {
224 WindowedAuthNeededObserver auth_needed_waiter(controller); 223 WindowedAuthNeededObserver auth_needed_waiter(controller);
(...skipping 28 matching lines...) Expand all
253 base::string16 password(base::UTF8ToUTF16(password_)); 252 base::string16 password(base::UTF8ToUTF16(password_));
254 handler->SetAuth(username, password); 253 handler->SetAuth(username, password);
255 auth_supplied_waiter.Wait(); 254 auth_supplied_waiter.Wait();
256 255
257 base::string16 expected_title = ExpectedTitleFromAuth(username, password); 256 base::string16 expected_title = ExpectedTitleFromAuth(username, password);
258 content::TitleWatcher title_watcher(contents, expected_title); 257 content::TitleWatcher title_watcher(contents, expected_title);
259 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 258 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
260 } 259 }
261 260
262 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestTwoAuths) { 261 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestTwoAuths) {
263 ASSERT_TRUE(test_server()->Start()); 262 ASSERT_TRUE(embedded_test_server()->Start());
264 263
265 content::WebContents* contents1 = 264 content::WebContents* contents1 =
266 browser()->tab_strip_model()->GetActiveWebContents(); 265 browser()->tab_strip_model()->GetActiveWebContents();
267 NavigationController* controller1 = &contents1->GetController(); 266 NavigationController* controller1 = &contents1->GetController();
268 LoginPromptBrowserTestObserver observer; 267 LoginPromptBrowserTestObserver observer;
269 268
270 observer.Register(content::Source<NavigationController>(controller1)); 269 observer.Register(content::Source<NavigationController>(controller1));
271 270
272 // Open a new tab. 271 // Open a new tab.
273 ui_test_utils::NavigateToURLWithDisposition( 272 ui_test_utils::NavigateToURLWithDisposition(
274 browser(), 273 browser(),
275 GURL("about:blank"), 274 GURL("about:blank"),
276 NEW_FOREGROUND_TAB, 275 NEW_FOREGROUND_TAB,
277 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 276 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
278 277
279 content::WebContents* contents2 = 278 content::WebContents* contents2 =
280 browser()->tab_strip_model()->GetActiveWebContents(); 279 browser()->tab_strip_model()->GetActiveWebContents();
281 ASSERT_NE(contents1, contents2); 280 ASSERT_NE(contents1, contents2);
282 NavigationController* controller2 = &contents2->GetController(); 281 NavigationController* controller2 = &contents2->GetController();
283 observer.Register(content::Source<NavigationController>(controller2)); 282 observer.Register(content::Source<NavigationController>(controller2));
284 283
285 { 284 {
286 WindowedAuthNeededObserver auth_needed_waiter(controller1); 285 WindowedAuthNeededObserver auth_needed_waiter(controller1);
287 contents1->OpenURL(OpenURLParams( 286 contents1->OpenURL(OpenURLParams(
288 test_server()->GetURL(kAuthBasicPage), Referrer(), 287 embedded_test_server()->GetURL(kAuthBasicPage), Referrer(), CURRENT_TAB,
289 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 288 ui::PAGE_TRANSITION_TYPED, false));
290 auth_needed_waiter.Wait(); 289 auth_needed_waiter.Wait();
291 } 290 }
292 291
293 { 292 {
294 WindowedAuthNeededObserver auth_needed_waiter(controller2); 293 WindowedAuthNeededObserver auth_needed_waiter(controller2);
295 contents2->OpenURL(OpenURLParams( 294 contents2->OpenURL(OpenURLParams(
296 test_server()->GetURL(kAuthDigestPage), Referrer(), 295 embedded_test_server()->GetURL(kAuthDigestPage), Referrer(),
297 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 296 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
298 auth_needed_waiter.Wait(); 297 auth_needed_waiter.Wait();
299 } 298 }
300 299
301 ASSERT_EQ(2u, observer.handlers().size()); 300 ASSERT_EQ(2u, observer.handlers().size());
302 301
303 LoginHandler* handler1 = *observer.handlers().begin(); 302 LoginHandler* handler1 = *observer.handlers().begin();
304 LoginHandler* handler2 = *(++(observer.handlers().begin())); 303 LoginHandler* handler2 = *(++(observer.handlers().begin()));
305 304
306 base::string16 expected_title1 = ExpectedTitleFromAuth( 305 base::string16 expected_title1 = ExpectedTitleFromAuth(
307 base::UTF8ToUTF16(username_basic_), base::UTF8ToUTF16(password_)); 306 base::UTF8ToUTF16(username_basic_), base::UTF8ToUTF16(password_));
308 base::string16 expected_title2 = ExpectedTitleFromAuth( 307 base::string16 expected_title2 = ExpectedTitleFromAuth(
309 base::UTF8ToUTF16(username_digest_), base::UTF8ToUTF16(password_)); 308 base::UTF8ToUTF16(username_digest_), base::UTF8ToUTF16(password_));
310 content::TitleWatcher title_watcher1(contents1, expected_title1); 309 content::TitleWatcher title_watcher1(contents1, expected_title1);
311 content::TitleWatcher title_watcher2(contents2, expected_title2); 310 content::TitleWatcher title_watcher2(contents2, expected_title2);
312 311
313 handler1->SetAuth(base::UTF8ToUTF16(username_basic_), 312 handler1->SetAuth(base::UTF8ToUTF16(username_basic_),
314 base::UTF8ToUTF16(password_)); 313 base::UTF8ToUTF16(password_));
315 handler2->SetAuth(base::UTF8ToUTF16(username_digest_), 314 handler2->SetAuth(base::UTF8ToUTF16(username_digest_),
316 base::UTF8ToUTF16(password_)); 315 base::UTF8ToUTF16(password_));
317 316
318 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); 317 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
319 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); 318 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
320 } 319 }
321 320
322 // Test login prompt cancellation. 321 // Test login prompt cancellation.
323 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth) { 322 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth) {
324 ASSERT_TRUE(test_server()->Start()); 323 ASSERT_TRUE(embedded_test_server()->Start());
325 GURL auth_page = test_server()->GetURL(kAuthBasicPage); 324 GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage);
326 GURL no_auth_page_1 = test_server()->GetURL("a"); 325 GURL no_auth_page_1 = embedded_test_server()->GetURL("/a");
327 GURL no_auth_page_2 = test_server()->GetURL("b"); 326 GURL no_auth_page_2 = embedded_test_server()->GetURL("/b");
328 GURL no_auth_page_3 = test_server()->GetURL("c"); 327 GURL no_auth_page_3 = embedded_test_server()->GetURL("/c");
329 328
330 content::WebContents* contents = 329 content::WebContents* contents =
331 browser()->tab_strip_model()->GetActiveWebContents(); 330 browser()->tab_strip_model()->GetActiveWebContents();
332 NavigationController* controller = &contents->GetController(); 331 NavigationController* controller = &contents->GetController();
333 332
334 LoginPromptBrowserTestObserver observer; 333 LoginPromptBrowserTestObserver observer;
335 observer.Register(content::Source<NavigationController>(controller)); 334 observer.Register(content::Source<NavigationController>(controller));
336 335
337 // First navigate to an unauthenticated page so we have something to 336 // First navigate to an unauthenticated page so we have something to
338 // go back to. 337 // go back to.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 EXPECT_TRUE(observer.handlers().empty()); 414 EXPECT_TRUE(observer.handlers().empty());
416 } 415 }
417 } 416 }
418 417
419 // Test handling of resources that require authentication even though 418 // Test handling of resources that require authentication even though
420 // the page they are included on doesn't. In this case we should only 419 // the page they are included on doesn't. In this case we should only
421 // present the minimal number of prompts necessary for successfully 420 // present the minimal number of prompts necessary for successfully
422 // displaying the page. First we check whether cancelling works as 421 // displaying the page. First we check whether cancelling works as
423 // expected. 422 // expected.
424 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { 423 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) {
425 ASSERT_TRUE(test_server()->Start()); 424 ASSERT_TRUE(embedded_test_server()->Start());
426 GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 425 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage);
427 426
428 content::WebContents* contents = 427 content::WebContents* contents =
429 browser()->tab_strip_model()->GetActiveWebContents(); 428 browser()->tab_strip_model()->GetActiveWebContents();
430 NavigationController* controller = &contents->GetController(); 429 NavigationController* controller = &contents->GetController();
431 LoginPromptBrowserTestObserver observer; 430 LoginPromptBrowserTestObserver observer;
432 431
433 observer.Register(content::Source<NavigationController>(controller)); 432 observer.Register(content::Source<NavigationController>(controller));
434 433
435 WindowedLoadStopObserver load_stop_waiter(controller, 1); 434 WindowedLoadStopObserver load_stop_waiter(controller, 1);
436 435
(...skipping 23 matching lines...) Expand all
460 if (n_handlers < kMultiRealmTestRealmCount) 459 if (n_handlers < kMultiRealmTestRealmCount)
461 auth_needed_waiter.Wait(); 460 auth_needed_waiter.Wait();
462 } 461 }
463 462
464 load_stop_waiter.Wait(); 463 load_stop_waiter.Wait();
465 464
466 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); 465 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers);
467 EXPECT_EQ(0, observer.auth_supplied_count()); 466 EXPECT_EQ(0, observer.auth_supplied_count());
468 EXPECT_LT(0, observer.auth_needed_count()); 467 EXPECT_LT(0, observer.auth_needed_count());
469 EXPECT_LT(0, observer.auth_cancelled_count()); 468 EXPECT_LT(0, observer.auth_cancelled_count());
470 EXPECT_TRUE(test_server()->Stop());
471 } 469 }
472 470
473 // Similar to the MultipleRealmCancellation test above, but tests 471 // Similar to the MultipleRealmCancellation test above, but tests
474 // whether supplying credentials work as exepcted. 472 // whether supplying credentials work as exepcted.
475 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) { 473 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) {
476 ASSERT_TRUE(test_server()->Start()); 474 ASSERT_TRUE(embedded_test_server()->Start());
477 GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 475 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage);
478 476
479 content::WebContents* contents = 477 content::WebContents* contents =
480 browser()->tab_strip_model()->GetActiveWebContents(); 478 browser()->tab_strip_model()->GetActiveWebContents();
481 NavigationController* controller = &contents->GetController(); 479 NavigationController* controller = &contents->GetController();
482 LoginPromptBrowserTestObserver observer; 480 LoginPromptBrowserTestObserver observer;
483 481
484 observer.Register(content::Source<NavigationController>(controller)); 482 observer.Register(content::Source<NavigationController>(controller));
485 483
486 WindowedLoadStopObserver load_stop_waiter(controller, 1); 484 WindowedLoadStopObserver load_stop_waiter(controller, 1);
487 int n_handlers = 0; 485 int n_handlers = 0;
(...skipping 23 matching lines...) Expand all
511 if (n_handlers < kMultiRealmTestRealmCount) 509 if (n_handlers < kMultiRealmTestRealmCount)
512 auth_needed_waiter.Wait(); 510 auth_needed_waiter.Wait();
513 } 511 }
514 512
515 load_stop_waiter.Wait(); 513 load_stop_waiter.Wait();
516 514
517 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); 515 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers);
518 EXPECT_LT(0, observer.auth_needed_count()); 516 EXPECT_LT(0, observer.auth_needed_count());
519 EXPECT_LT(0, observer.auth_supplied_count()); 517 EXPECT_LT(0, observer.auth_supplied_count());
520 EXPECT_EQ(0, observer.auth_cancelled_count()); 518 EXPECT_EQ(0, observer.auth_cancelled_count());
521 EXPECT_TRUE(test_server()->Stop());
522 } 519 }
523 520
524 // Testing for recovery from an incorrect password for the case where 521 // Testing for recovery from an incorrect password for the case where
525 // there are multiple authenticated resources. 522 // there are multiple authenticated resources.
526 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { 523 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) {
527 ASSERT_TRUE(test_server()->Start()); 524 ASSERT_TRUE(embedded_test_server()->Start());
528 GURL test_page = test_server()->GetURL(kSingleRealmTestPage); 525 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage);
529 526
530 content::WebContents* contents = 527 content::WebContents* contents =
531 browser()->tab_strip_model()->GetActiveWebContents(); 528 browser()->tab_strip_model()->GetActiveWebContents();
532 NavigationController* controller = &contents->GetController(); 529 NavigationController* controller = &contents->GetController();
533 LoginPromptBrowserTestObserver observer; 530 LoginPromptBrowserTestObserver observer;
534 531
535 observer.Register(content::Source<NavigationController>(controller)); 532 observer.Register(content::Source<NavigationController>(controller));
536 533
537 { 534 {
538 WindowedAuthNeededObserver auth_needed_waiter(controller); 535 WindowedAuthNeededObserver auth_needed_waiter(controller);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 if (n_handlers < 1) 575 if (n_handlers < 1)
579 auth_needed_waiter.Wait(); 576 auth_needed_waiter.Wait();
580 } 577 }
581 578
582 // The single realm test has only one realm, and thus only one login 579 // The single realm test has only one realm, and thus only one login
583 // prompt. 580 // prompt.
584 EXPECT_EQ(1, n_handlers); 581 EXPECT_EQ(1, n_handlers);
585 EXPECT_LT(0, observer.auth_needed_count()); 582 EXPECT_LT(0, observer.auth_needed_count());
586 EXPECT_EQ(0, observer.auth_cancelled_count()); 583 EXPECT_EQ(0, observer.auth_cancelled_count());
587 EXPECT_EQ(observer.auth_needed_count(), observer.auth_supplied_count()); 584 EXPECT_EQ(observer.auth_needed_count(), observer.auth_supplied_count());
588 EXPECT_TRUE(test_server()->Stop());
589 } 585 }
590 586
591 // If the favicon is an authenticated resource, we shouldn't prompt 587 // If the favicon is an authenticated resource, we shouldn't prompt
592 // for credentials. The same URL, if requested elsewhere should 588 // for credentials. The same URL, if requested elsewhere should
593 // prompt for credentials. 589 // prompt for credentials.
594 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, NoLoginPromptForFavicon) { 590 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, NoLoginPromptForFavicon) {
595 const char* kFaviconTestPage = "files/login/has_favicon.html"; 591 const char* kFaviconTestPage = "/login/has_favicon.html";
596 const char* kFaviconResource = "auth-basic/favicon.gif"; 592 const char* kFaviconResource = "/auth-basic/favicon.gif";
597 593
598 ASSERT_TRUE(test_server()->Start()); 594 ASSERT_TRUE(embedded_test_server()->Start());
599 595
600 content::WebContents* contents = 596 content::WebContents* contents =
601 browser()->tab_strip_model()->GetActiveWebContents(); 597 browser()->tab_strip_model()->GetActiveWebContents();
602 NavigationController* controller = &contents->GetController(); 598 NavigationController* controller = &contents->GetController();
603 LoginPromptBrowserTestObserver observer; 599 LoginPromptBrowserTestObserver observer;
604 600
605 observer.Register(content::Source<NavigationController>(controller)); 601 observer.Register(content::Source<NavigationController>(controller));
606 602
607 // First load a page that has a favicon that requires 603 // First load a page that has a favicon that requires
608 // authentication. There should be no login prompt. 604 // authentication. There should be no login prompt.
609 { 605 {
610 GURL test_page = test_server()->GetURL(kFaviconTestPage); 606 GURL test_page = embedded_test_server()->GetURL(kFaviconTestPage);
611 WindowedLoadStopObserver load_stop_waiter(controller, 1); 607 WindowedLoadStopObserver load_stop_waiter(controller, 1);
612 browser()->OpenURL(OpenURLParams( 608 browser()->OpenURL(OpenURLParams(
613 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 609 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
614 false)); 610 false));
615 load_stop_waiter.Wait(); 611 load_stop_waiter.Wait();
616 } 612 }
617 613
618 // Now request the same favicon, but directly as the document. 614 // Now request the same favicon, but directly as the document.
619 // There should be one login prompt. 615 // There should be one login prompt.
620 { 616 {
621 GURL test_page = test_server()->GetURL(kFaviconResource); 617 GURL test_page = embedded_test_server()->GetURL(kFaviconResource);
622 WindowedLoadStopObserver load_stop_waiter(controller, 1); 618 WindowedLoadStopObserver load_stop_waiter(controller, 1);
623 WindowedAuthNeededObserver auth_needed_waiter(controller); 619 WindowedAuthNeededObserver auth_needed_waiter(controller);
624 browser()->OpenURL(OpenURLParams( 620 browser()->OpenURL(OpenURLParams(
625 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 621 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
626 false)); 622 false));
627 auth_needed_waiter.Wait(); 623 auth_needed_waiter.Wait();
628 ASSERT_EQ(1u, observer.handlers().size()); 624 ASSERT_EQ(1u, observer.handlers().size());
629 625
630 while (!observer.handlers().empty()) { 626 while (!observer.handlers().empty()) {
631 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 627 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
632 LoginHandler* handler = *observer.handlers().begin(); 628 LoginHandler* handler = *observer.handlers().begin();
633 629
634 ASSERT_TRUE(handler); 630 ASSERT_TRUE(handler);
635 handler->CancelAuth(); 631 handler->CancelAuth();
636 auth_cancelled_waiter.Wait(); 632 auth_cancelled_waiter.Wait();
637 } 633 }
638 634
639 load_stop_waiter.Wait(); 635 load_stop_waiter.Wait();
640 } 636 }
641 637
642 EXPECT_EQ(0, observer.auth_supplied_count()); 638 EXPECT_EQ(0, observer.auth_supplied_count());
643 EXPECT_EQ(1, observer.auth_needed_count()); 639 EXPECT_EQ(1, observer.auth_needed_count());
644 EXPECT_EQ(1, observer.auth_cancelled_count()); 640 EXPECT_EQ(1, observer.auth_cancelled_count());
645 EXPECT_TRUE(test_server()->Stop());
646 } 641 }
647 642
648 // Block crossdomain image login prompting as a phishing defense. 643 // Block crossdomain image login prompting as a phishing defense.
649 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 644 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
650 BlockCrossdomainPromptForSubresources) { 645 BlockCrossdomainPromptForSubresources) {
651 const char* kTestPage = "files/login/load_img_from_b.html"; 646 const char* kTestPage = "/login/load_img_from_b.html";
652 647
653 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 648 host_resolver()->AddRule("www.a.com", "127.0.0.1");
654 host_resolver()->AddRule("www.b.com", "127.0.0.1"); 649 host_resolver()->AddRule("www.b.com", "127.0.0.1");
655 ASSERT_TRUE(test_server()->Start()); 650 ASSERT_TRUE(embedded_test_server()->Start());
656 651
657 content::WebContents* contents = 652 content::WebContents* contents =
658 browser()->tab_strip_model()->GetActiveWebContents(); 653 browser()->tab_strip_model()->GetActiveWebContents();
659 NavigationController* controller = &contents->GetController(); 654 NavigationController* controller = &contents->GetController();
660 LoginPromptBrowserTestObserver observer; 655 LoginPromptBrowserTestObserver observer;
661 observer.Register(content::Source<NavigationController>(controller)); 656 observer.Register(content::Source<NavigationController>(controller));
662 657
663 // Load a page that has a cross-domain sub-resource authentication. 658 // Load a page that has a cross-domain sub-resource authentication.
664 // There should be no login prompt. 659 // There should be no login prompt.
665 { 660 {
666 GURL test_page = test_server()->GetURL(kTestPage); 661 GURL test_page = embedded_test_server()->GetURL(kTestPage);
667 ASSERT_EQ("127.0.0.1", test_page.host()); 662 ASSERT_EQ("127.0.0.1", test_page.host());
668 663
669 // Change the host from 127.0.0.1 to www.a.com so that when the 664 // Change the host from 127.0.0.1 to www.a.com so that when the
670 // page tries to load from b, it will be cross-origin. 665 // page tries to load from b, it will be cross-origin.
671 GURL::Replacements replacements; 666 GURL::Replacements replacements;
672 replacements.SetHostStr("www.a.com"); 667 replacements.SetHostStr("www.a.com");
673 test_page = test_page.ReplaceComponents(replacements); 668 test_page = test_page.ReplaceComponents(replacements);
674 669
675 WindowedLoadStopObserver load_stop_waiter(controller, 1); 670 WindowedLoadStopObserver load_stop_waiter(controller, 1);
676 browser()->OpenURL(OpenURLParams( 671 browser()->OpenURL(OpenURLParams(
677 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 672 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
678 false)); 673 false));
679 load_stop_waiter.Wait(); 674 load_stop_waiter.Wait();
680 } 675 }
681 676
682 EXPECT_EQ(0, observer.auth_needed_count()); 677 EXPECT_EQ(0, observer.auth_needed_count());
683 678
684 // Now request the same page, but from the same origin. 679 // Now request the same page, but from the same origin.
685 // There should be one login prompt. 680 // There should be one login prompt.
686 { 681 {
687 GURL test_page = test_server()->GetURL(kTestPage); 682 GURL test_page = embedded_test_server()->GetURL(kTestPage);
688 ASSERT_EQ("127.0.0.1", test_page.host()); 683 ASSERT_EQ("127.0.0.1", test_page.host());
689 684
690 // Change the host from 127.0.0.1 to www.b.com so that when the 685 // Change the host from 127.0.0.1 to www.b.com so that when the
691 // page tries to load from b, it will be same-origin. 686 // page tries to load from b, it will be same-origin.
692 GURL::Replacements replacements; 687 GURL::Replacements replacements;
693 replacements.SetHostStr("www.b.com"); 688 replacements.SetHostStr("www.b.com");
694 test_page = test_page.ReplaceComponents(replacements); 689 test_page = test_page.ReplaceComponents(replacements);
695 690
696 WindowedAuthNeededObserver auth_needed_waiter(controller); 691 WindowedAuthNeededObserver auth_needed_waiter(controller);
697 browser()->OpenURL(OpenURLParams( 692 browser()->OpenURL(OpenURLParams(
698 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 693 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
699 false)); 694 false));
700 auth_needed_waiter.Wait(); 695 auth_needed_waiter.Wait();
701 ASSERT_EQ(1u, observer.handlers().size()); 696 ASSERT_EQ(1u, observer.handlers().size());
702 697
703 while (!observer.handlers().empty()) { 698 while (!observer.handlers().empty()) {
704 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 699 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
705 LoginHandler* handler = *observer.handlers().begin(); 700 LoginHandler* handler = *observer.handlers().begin();
706 701
707 ASSERT_TRUE(handler); 702 ASSERT_TRUE(handler);
708 handler->CancelAuth(); 703 handler->CancelAuth();
709 auth_cancelled_waiter.Wait(); 704 auth_cancelled_waiter.Wait();
710 } 705 }
711 } 706 }
712 707
713 EXPECT_EQ(1, observer.auth_needed_count()); 708 EXPECT_EQ(1, observer.auth_needed_count());
714 EXPECT_TRUE(test_server()->Stop());
715 } 709 }
716 710
717 // Allow crossdomain iframe login prompting despite the above. 711 // Allow crossdomain iframe login prompting despite the above.
718 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 712 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
719 AllowCrossdomainPromptForSubframes) { 713 AllowCrossdomainPromptForSubframes) {
720 const char* kTestPage = "files/login/load_iframe_from_b.html"; 714 const char* kTestPage = "/login/load_iframe_from_b.html";
721 715
722 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 716 host_resolver()->AddRule("www.a.com", "127.0.0.1");
723 host_resolver()->AddRule("www.b.com", "127.0.0.1"); 717 host_resolver()->AddRule("www.b.com", "127.0.0.1");
724 ASSERT_TRUE(test_server()->Start()); 718 ASSERT_TRUE(embedded_test_server()->Start());
725 719
726 content::WebContents* contents = 720 content::WebContents* contents =
727 browser()->tab_strip_model()->GetActiveWebContents(); 721 browser()->tab_strip_model()->GetActiveWebContents();
728 NavigationController* controller = &contents->GetController(); 722 NavigationController* controller = &contents->GetController();
729 LoginPromptBrowserTestObserver observer; 723 LoginPromptBrowserTestObserver observer;
730 observer.Register(content::Source<NavigationController>(controller)); 724 observer.Register(content::Source<NavigationController>(controller));
731 725
732 // Load a page that has a cross-domain iframe authentication. 726 // Load a page that has a cross-domain iframe authentication.
733 { 727 {
734 GURL test_page = test_server()->GetURL(kTestPage); 728 GURL test_page = embedded_test_server()->GetURL(kTestPage);
735 ASSERT_EQ("127.0.0.1", test_page.host()); 729 ASSERT_EQ("127.0.0.1", test_page.host());
736 730
737 // Change the host from 127.0.0.1 to www.a.com so that when the 731 // Change the host from 127.0.0.1 to www.a.com so that when the
738 // page tries to load from b, it will be cross-origin. 732 // page tries to load from b, it will be cross-origin.
739 static const char kNewHost[] = "www.a.com"; 733 static const char kNewHost[] = "www.a.com";
740 GURL::Replacements replacements; 734 GURL::Replacements replacements;
741 replacements.SetHostStr(kNewHost); 735 replacements.SetHostStr(kNewHost);
742 test_page = test_page.ReplaceComponents(replacements); 736 test_page = test_page.ReplaceComponents(replacements);
743 737
744 WindowedAuthNeededObserver auth_needed_waiter(controller); 738 WindowedAuthNeededObserver auth_needed_waiter(controller);
(...skipping 15 matching lines...) Expand all
760 754
761 handler->CancelAuth(); 755 handler->CancelAuth();
762 auth_cancelled_waiter.Wait(); 756 auth_cancelled_waiter.Wait();
763 } 757 }
764 } 758 }
765 759
766 // Should stay on the main frame's url once the prompt the iframe is closed. 760 // Should stay on the main frame's url once the prompt the iframe is closed.
767 EXPECT_EQ("www.a.com", contents->GetVisibleURL().host()); 761 EXPECT_EQ("www.a.com", contents->GetVisibleURL().host());
768 762
769 EXPECT_EQ(1, observer.auth_needed_count()); 763 EXPECT_EQ(1, observer.auth_needed_count());
770 EXPECT_TRUE(test_server()->Stop());
771 } 764 }
772 765
773 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, SupplyRedundantAuths) { 766 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, SupplyRedundantAuths) {
774 ASSERT_TRUE(test_server()->Start()); 767 ASSERT_TRUE(embedded_test_server()->Start());
775 768
776 // Get NavigationController for tab 1. 769 // Get NavigationController for tab 1.
777 content::WebContents* contents_1 = 770 content::WebContents* contents_1 =
778 browser()->tab_strip_model()->GetActiveWebContents(); 771 browser()->tab_strip_model()->GetActiveWebContents();
779 NavigationController* controller_1 = &contents_1->GetController(); 772 NavigationController* controller_1 = &contents_1->GetController();
780 773
781 // Open a new tab. 774 // Open a new tab.
782 ui_test_utils::NavigateToURLWithDisposition( 775 ui_test_utils::NavigateToURLWithDisposition(
783 browser(), 776 browser(),
784 GURL("about:blank"), 777 GURL("about:blank"),
785 NEW_FOREGROUND_TAB, 778 NEW_FOREGROUND_TAB,
786 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 779 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
787 780
788 // Get NavigationController for tab 2. 781 // Get NavigationController for tab 2.
789 content::WebContents* contents_2 = 782 content::WebContents* contents_2 =
790 browser()->tab_strip_model()->GetActiveWebContents(); 783 browser()->tab_strip_model()->GetActiveWebContents();
791 ASSERT_NE(contents_1, contents_2); 784 ASSERT_NE(contents_1, contents_2);
792 NavigationController* controller_2 = &contents_2->GetController(); 785 NavigationController* controller_2 = &contents_2->GetController();
793 786
794 LoginPromptBrowserTestObserver observer; 787 LoginPromptBrowserTestObserver observer;
795 observer.Register(content::Source<NavigationController>(controller_1)); 788 observer.Register(content::Source<NavigationController>(controller_1));
796 observer.Register(content::Source<NavigationController>(controller_2)); 789 observer.Register(content::Source<NavigationController>(controller_2));
797 790
798 { 791 {
799 // Open different auth urls in each tab. 792 // Open different auth urls in each tab.
800 WindowedAuthNeededObserver auth_needed_waiter_1(controller_1); 793 WindowedAuthNeededObserver auth_needed_waiter_1(controller_1);
801 WindowedAuthNeededObserver auth_needed_waiter_2(controller_2); 794 WindowedAuthNeededObserver auth_needed_waiter_2(controller_2);
802 contents_1->OpenURL(OpenURLParams( 795 contents_1->OpenURL(OpenURLParams(
803 test_server()->GetURL("auth-basic/1"), 796 embedded_test_server()->GetURL("/auth-basic/1"), content::Referrer(),
804 content::Referrer(), 797 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
805 CURRENT_TAB,
806 ui::PAGE_TRANSITION_TYPED,
807 false));
808 contents_2->OpenURL(OpenURLParams( 798 contents_2->OpenURL(OpenURLParams(
809 test_server()->GetURL("auth-basic/2"), 799 embedded_test_server()->GetURL("/auth-basic/2"), content::Referrer(),
810 content::Referrer(), 800 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
811 CURRENT_TAB,
812 ui::PAGE_TRANSITION_TYPED,
813 false));
814 auth_needed_waiter_1.Wait(); 801 auth_needed_waiter_1.Wait();
815 auth_needed_waiter_2.Wait(); 802 auth_needed_waiter_2.Wait();
816 803
817 ASSERT_EQ(2U, observer.handlers().size()); 804 ASSERT_EQ(2U, observer.handlers().size());
818 805
819 // Supply auth in one of the tabs. 806 // Supply auth in one of the tabs.
820 WindowedAuthSuppliedObserver auth_supplied_waiter_1(controller_1); 807 WindowedAuthSuppliedObserver auth_supplied_waiter_1(controller_1);
821 WindowedAuthSuppliedObserver auth_supplied_waiter_2(controller_2); 808 WindowedAuthSuppliedObserver auth_supplied_waiter_2(controller_2);
822 LoginHandler* handler_1 = *observer.handlers().begin(); 809 LoginHandler* handler_1 = *observer.handlers().begin();
823 ASSERT_TRUE(handler_1); 810 ASSERT_TRUE(handler_1);
824 SetAuthFor(handler_1); 811 SetAuthFor(handler_1);
825 812
826 // Both tabs should be authenticated. 813 // Both tabs should be authenticated.
827 auth_supplied_waiter_1.Wait(); 814 auth_supplied_waiter_1.Wait();
828 auth_supplied_waiter_2.Wait(); 815 auth_supplied_waiter_2.Wait();
829 } 816 }
830 817
831 EXPECT_EQ(2, observer.auth_needed_count()); 818 EXPECT_EQ(2, observer.auth_needed_count());
832 EXPECT_EQ(2, observer.auth_supplied_count()); 819 EXPECT_EQ(2, observer.auth_supplied_count());
833 EXPECT_EQ(0, observer.auth_cancelled_count()); 820 EXPECT_EQ(0, observer.auth_cancelled_count());
834 EXPECT_TRUE(test_server()->Stop());
835 } 821 }
836 822
837 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, CancelRedundantAuths) { 823 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, CancelRedundantAuths) {
838 ASSERT_TRUE(test_server()->Start()); 824 ASSERT_TRUE(embedded_test_server()->Start());
839 825
840 // Get NavigationController for tab 1. 826 // Get NavigationController for tab 1.
841 content::WebContents* contents_1 = 827 content::WebContents* contents_1 =
842 browser()->tab_strip_model()->GetActiveWebContents(); 828 browser()->tab_strip_model()->GetActiveWebContents();
843 NavigationController* controller_1 = &contents_1->GetController(); 829 NavigationController* controller_1 = &contents_1->GetController();
844 830
845 // Open a new tab. 831 // Open a new tab.
846 ui_test_utils::NavigateToURLWithDisposition( 832 ui_test_utils::NavigateToURLWithDisposition(
847 browser(), 833 browser(),
848 GURL("about:blank"), 834 GURL("about:blank"),
849 NEW_FOREGROUND_TAB, 835 NEW_FOREGROUND_TAB,
850 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 836 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
851 837
852 // Get NavigationController for tab 2. 838 // Get NavigationController for tab 2.
853 content::WebContents* contents_2 = 839 content::WebContents* contents_2 =
854 browser()->tab_strip_model()->GetActiveWebContents(); 840 browser()->tab_strip_model()->GetActiveWebContents();
855 ASSERT_NE(contents_1, contents_2); 841 ASSERT_NE(contents_1, contents_2);
856 NavigationController* controller_2 = &contents_2->GetController(); 842 NavigationController* controller_2 = &contents_2->GetController();
857 843
858 LoginPromptBrowserTestObserver observer; 844 LoginPromptBrowserTestObserver observer;
859 observer.Register(content::Source<NavigationController>(controller_1)); 845 observer.Register(content::Source<NavigationController>(controller_1));
860 observer.Register(content::Source<NavigationController>(controller_2)); 846 observer.Register(content::Source<NavigationController>(controller_2));
861 847
862 { 848 {
863 // Open different auth urls in each tab. 849 // Open different auth urls in each tab.
864 WindowedAuthNeededObserver auth_needed_waiter_1(controller_1); 850 WindowedAuthNeededObserver auth_needed_waiter_1(controller_1);
865 WindowedAuthNeededObserver auth_needed_waiter_2(controller_2); 851 WindowedAuthNeededObserver auth_needed_waiter_2(controller_2);
866 contents_1->OpenURL(OpenURLParams( 852 contents_1->OpenURL(OpenURLParams(
867 test_server()->GetURL("auth-basic/1"), 853 embedded_test_server()->GetURL("/auth-basic/1"), content::Referrer(),
868 content::Referrer(), 854 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
869 CURRENT_TAB,
870 ui::PAGE_TRANSITION_TYPED,
871 false));
872 contents_2->OpenURL(OpenURLParams( 855 contents_2->OpenURL(OpenURLParams(
873 test_server()->GetURL("auth-basic/2"), 856 embedded_test_server()->GetURL("/auth-basic/2"), content::Referrer(),
874 content::Referrer(), 857 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
875 CURRENT_TAB,
876 ui::PAGE_TRANSITION_TYPED,
877 false));
878 auth_needed_waiter_1.Wait(); 858 auth_needed_waiter_1.Wait();
879 auth_needed_waiter_2.Wait(); 859 auth_needed_waiter_2.Wait();
880 860
881 ASSERT_EQ(2U, observer.handlers().size()); 861 ASSERT_EQ(2U, observer.handlers().size());
882 862
883 // Cancel auth in one of the tabs. 863 // Cancel auth in one of the tabs.
884 WindowedAuthCancelledObserver auth_cancelled_waiter_1(controller_1); 864 WindowedAuthCancelledObserver auth_cancelled_waiter_1(controller_1);
885 WindowedAuthCancelledObserver auth_cancelled_waiter_2(controller_2); 865 WindowedAuthCancelledObserver auth_cancelled_waiter_2(controller_2);
886 LoginHandler* handler_1 = *observer.handlers().begin(); 866 LoginHandler* handler_1 = *observer.handlers().begin();
887 ASSERT_TRUE(handler_1); 867 ASSERT_TRUE(handler_1);
888 handler_1->CancelAuth(); 868 handler_1->CancelAuth();
889 869
890 // Both tabs should cancel auth. 870 // Both tabs should cancel auth.
891 auth_cancelled_waiter_1.Wait(); 871 auth_cancelled_waiter_1.Wait();
892 auth_cancelled_waiter_2.Wait(); 872 auth_cancelled_waiter_2.Wait();
893 } 873 }
894 874
895 EXPECT_EQ(2, observer.auth_needed_count()); 875 EXPECT_EQ(2, observer.auth_needed_count());
896 EXPECT_EQ(0, observer.auth_supplied_count()); 876 EXPECT_EQ(0, observer.auth_supplied_count());
897 EXPECT_EQ(2, observer.auth_cancelled_count()); 877 EXPECT_EQ(2, observer.auth_cancelled_count());
898 EXPECT_TRUE(test_server()->Stop());
899 } 878 }
900 879
901 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 880 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
902 SupplyRedundantAuthsMultiProfile) { 881 SupplyRedundantAuthsMultiProfile) {
903 ASSERT_TRUE(test_server()->Start()); 882 ASSERT_TRUE(embedded_test_server()->Start());
904 883
905 // Get NavigationController for regular tab. 884 // Get NavigationController for regular tab.
906 content::WebContents* contents = 885 content::WebContents* contents =
907 browser()->tab_strip_model()->GetActiveWebContents(); 886 browser()->tab_strip_model()->GetActiveWebContents();
908 NavigationController* controller = &contents->GetController(); 887 NavigationController* controller = &contents->GetController();
909 888
910 // Open an incognito window. 889 // Open an incognito window.
911 Browser* browser_incognito = CreateIncognitoBrowser(); 890 Browser* browser_incognito = CreateIncognitoBrowser();
912 891
913 // Get NavigationController for incognito tab. 892 // Get NavigationController for incognito tab.
914 content::WebContents* contents_incognito = 893 content::WebContents* contents_incognito =
915 browser_incognito->tab_strip_model()->GetActiveWebContents(); 894 browser_incognito->tab_strip_model()->GetActiveWebContents();
916 ASSERT_NE(contents, contents_incognito); 895 ASSERT_NE(contents, contents_incognito);
917 NavigationController* controller_incognito = 896 NavigationController* controller_incognito =
918 &contents_incognito->GetController(); 897 &contents_incognito->GetController();
919 898
920 LoginPromptBrowserTestObserver observer; 899 LoginPromptBrowserTestObserver observer;
921 observer.Register(content::Source<NavigationController>(controller)); 900 observer.Register(content::Source<NavigationController>(controller));
922 LoginPromptBrowserTestObserver observer_incognito; 901 LoginPromptBrowserTestObserver observer_incognito;
923 observer_incognito.Register( 902 observer_incognito.Register(
924 content::Source<NavigationController>(controller_incognito)); 903 content::Source<NavigationController>(controller_incognito));
925 904
926 { 905 {
927 // Open an auth url in each window. 906 // Open an auth url in each window.
928 WindowedAuthNeededObserver auth_needed_waiter(controller); 907 WindowedAuthNeededObserver auth_needed_waiter(controller);
929 WindowedAuthNeededObserver auth_needed_waiter_incognito( 908 WindowedAuthNeededObserver auth_needed_waiter_incognito(
930 controller_incognito); 909 controller_incognito);
931 contents->OpenURL(OpenURLParams( 910 contents->OpenURL(OpenURLParams(
932 test_server()->GetURL("auth-basic/1"), 911 embedded_test_server()->GetURL("/auth-basic/1"), content::Referrer(),
933 content::Referrer(), 912 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
934 CURRENT_TAB,
935 ui::PAGE_TRANSITION_TYPED,
936 false));
937 contents_incognito->OpenURL(OpenURLParams( 913 contents_incognito->OpenURL(OpenURLParams(
938 test_server()->GetURL("auth-basic/2"), 914 embedded_test_server()->GetURL("/auth-basic/2"), content::Referrer(),
939 content::Referrer(), 915 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
940 CURRENT_TAB,
941 ui::PAGE_TRANSITION_TYPED,
942 false));
943 auth_needed_waiter.Wait(); 916 auth_needed_waiter.Wait();
944 auth_needed_waiter_incognito.Wait(); 917 auth_needed_waiter_incognito.Wait();
945 918
946 ASSERT_EQ(1U, observer.handlers().size()); 919 ASSERT_EQ(1U, observer.handlers().size());
947 ASSERT_EQ(1U, observer_incognito.handlers().size()); 920 ASSERT_EQ(1U, observer_incognito.handlers().size());
948 921
949 // Supply auth in regular tab. 922 // Supply auth in regular tab.
950 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 923 WindowedAuthSuppliedObserver auth_supplied_waiter(controller);
951 LoginHandler* handler = *observer.handlers().begin(); 924 LoginHandler* handler = *observer.handlers().begin();
952 ASSERT_TRUE(handler); 925 ASSERT_TRUE(handler);
953 SetAuthFor(handler); 926 SetAuthFor(handler);
954 927
955 // Regular tab should be authenticated. 928 // Regular tab should be authenticated.
956 auth_supplied_waiter.Wait(); 929 auth_supplied_waiter.Wait();
957 930
958 // There's not really a way to wait for the incognito window to "do 931 // There's not really a way to wait for the incognito window to "do
959 // nothing". Run anything pending in the message loop just to be sure. 932 // nothing". Run anything pending in the message loop just to be sure.
960 // (This shouldn't be necessary since notifications are synchronous, but 933 // (This shouldn't be necessary since notifications are synchronous, but
961 // maybe it will help avoid flake someday in the future..) 934 // maybe it will help avoid flake someday in the future..)
962 content::RunAllPendingInMessageLoop(); 935 content::RunAllPendingInMessageLoop();
963 } 936 }
964 937
965 EXPECT_EQ(1, observer.auth_needed_count()); 938 EXPECT_EQ(1, observer.auth_needed_count());
966 EXPECT_EQ(1, observer.auth_supplied_count()); 939 EXPECT_EQ(1, observer.auth_supplied_count());
967 EXPECT_EQ(0, observer.auth_cancelled_count()); 940 EXPECT_EQ(0, observer.auth_cancelled_count());
968 EXPECT_EQ(1, observer_incognito.auth_needed_count()); 941 EXPECT_EQ(1, observer_incognito.auth_needed_count());
969 EXPECT_EQ(0, observer_incognito.auth_supplied_count()); 942 EXPECT_EQ(0, observer_incognito.auth_supplied_count());
970 EXPECT_EQ(0, observer_incognito.auth_cancelled_count()); 943 EXPECT_EQ(0, observer_incognito.auth_cancelled_count());
971 EXPECT_TRUE(test_server()->Stop());
972 } 944 }
973 945
974 // If an XMLHttpRequest is made with incorrect credentials, there should be no 946 // If an XMLHttpRequest is made with incorrect credentials, there should be no
975 // login prompt; instead the 401 status should be returned to the script. 947 // login prompt; instead the 401 status should be returned to the script.
976 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 948 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
977 NoLoginPromptForXHRWithBadCredentials) { 949 NoLoginPromptForXHRWithBadCredentials) {
978 const char* kXHRTestPage = "files/login/xhr_with_credentials.html#incorrect"; 950 const char* kXHRTestPage = "/login/xhr_with_credentials.html#incorrect";
979 951
980 ASSERT_TRUE(test_server()->Start()); 952 ASSERT_TRUE(embedded_test_server()->Start());
981 953
982 content::WebContents* contents = 954 content::WebContents* contents =
983 browser()->tab_strip_model()->GetActiveWebContents(); 955 browser()->tab_strip_model()->GetActiveWebContents();
984 NavigationController* controller = &contents->GetController(); 956 NavigationController* controller = &contents->GetController();
985 LoginPromptBrowserTestObserver observer; 957 LoginPromptBrowserTestObserver observer;
986 958
987 observer.Register(content::Source<NavigationController>(controller)); 959 observer.Register(content::Source<NavigationController>(controller));
988 960
989 // Load a page which makes a synchronous XMLHttpRequest for an authenticated 961 // Load a page which makes a synchronous XMLHttpRequest for an authenticated
990 // resource with the wrong credentials. There should be no login prompt. 962 // resource with the wrong credentials. There should be no login prompt.
991 { 963 {
992 GURL test_page = test_server()->GetURL(kXHRTestPage); 964 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage);
993 WindowedLoadStopObserver load_stop_waiter(controller, 1); 965 WindowedLoadStopObserver load_stop_waiter(controller, 1);
994 browser()->OpenURL(OpenURLParams( 966 browser()->OpenURL(OpenURLParams(
995 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 967 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
996 false)); 968 false));
997 load_stop_waiter.Wait(); 969 load_stop_waiter.Wait();
998 } 970 }
999 971
1000 base::string16 expected_title(base::UTF8ToUTF16("status=401")); 972 base::string16 expected_title(base::UTF8ToUTF16("status=401"));
1001 973
1002 EXPECT_EQ(expected_title, contents->GetTitle()); 974 EXPECT_EQ(expected_title, contents->GetTitle());
1003 EXPECT_EQ(0, observer.auth_supplied_count()); 975 EXPECT_EQ(0, observer.auth_supplied_count());
1004 EXPECT_EQ(0, observer.auth_needed_count()); 976 EXPECT_EQ(0, observer.auth_needed_count());
1005 EXPECT_EQ(0, observer.auth_cancelled_count()); 977 EXPECT_EQ(0, observer.auth_cancelled_count());
1006 EXPECT_TRUE(test_server()->Stop());
1007 } 978 }
1008 979
1009 // If an XMLHttpRequest is made with correct credentials, there should be no 980 // If an XMLHttpRequest is made with correct credentials, there should be no
1010 // login prompt either. 981 // login prompt either.
1011 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 982 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1012 NoLoginPromptForXHRWithGoodCredentials) { 983 NoLoginPromptForXHRWithGoodCredentials) {
1013 const char* kXHRTestPage = "files/login/xhr_with_credentials.html#secret"; 984 const char* kXHRTestPage = "/login/xhr_with_credentials.html#secret";
1014 985
1015 ASSERT_TRUE(test_server()->Start()); 986 ASSERT_TRUE(embedded_test_server()->Start());
1016 987
1017 content::WebContents* contents = 988 content::WebContents* contents =
1018 browser()->tab_strip_model()->GetActiveWebContents(); 989 browser()->tab_strip_model()->GetActiveWebContents();
1019 NavigationController* controller = &contents->GetController(); 990 NavigationController* controller = &contents->GetController();
1020 LoginPromptBrowserTestObserver observer; 991 LoginPromptBrowserTestObserver observer;
1021 992
1022 observer.Register(content::Source<NavigationController>(controller)); 993 observer.Register(content::Source<NavigationController>(controller));
1023 994
1024 // Load a page which makes a synchronous XMLHttpRequest for an authenticated 995 // Load a page which makes a synchronous XMLHttpRequest for an authenticated
1025 // resource with the wrong credentials. There should be no login prompt. 996 // resource with the wrong credentials. There should be no login prompt.
1026 { 997 {
1027 GURL test_page = test_server()->GetURL(kXHRTestPage); 998 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage);
1028 WindowedLoadStopObserver load_stop_waiter(controller, 1); 999 WindowedLoadStopObserver load_stop_waiter(controller, 1);
1029 browser()->OpenURL(OpenURLParams( 1000 browser()->OpenURL(OpenURLParams(
1030 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 1001 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
1031 false)); 1002 false));
1032 load_stop_waiter.Wait(); 1003 load_stop_waiter.Wait();
1033 } 1004 }
1034 1005
1035 base::string16 expected_title(base::UTF8ToUTF16("status=200")); 1006 base::string16 expected_title(base::UTF8ToUTF16("status=200"));
1036 1007
1037 EXPECT_EQ(expected_title, contents->GetTitle()); 1008 EXPECT_EQ(expected_title, contents->GetTitle());
1038 EXPECT_EQ(0, observer.auth_supplied_count()); 1009 EXPECT_EQ(0, observer.auth_supplied_count());
1039 EXPECT_EQ(0, observer.auth_needed_count()); 1010 EXPECT_EQ(0, observer.auth_needed_count());
1040 EXPECT_EQ(0, observer.auth_cancelled_count()); 1011 EXPECT_EQ(0, observer.auth_cancelled_count());
1041 EXPECT_TRUE(test_server()->Stop());
1042 } 1012 }
1043 1013
1044 // If an XMLHttpRequest is made without credentials, there should be a login 1014 // If an XMLHttpRequest is made without credentials, there should be a login
1045 // prompt. 1015 // prompt.
1046 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 1016 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1047 LoginPromptForXHRWithoutCredentials) { 1017 LoginPromptForXHRWithoutCredentials) {
1048 const char* kXHRTestPage = "files/login/xhr_without_credentials.html"; 1018 const char* kXHRTestPage = "/login/xhr_without_credentials.html";
1049 1019
1050 ASSERT_TRUE(test_server()->Start()); 1020 ASSERT_TRUE(embedded_test_server()->Start());
1051 1021
1052 content::WebContents* contents = 1022 content::WebContents* contents =
1053 browser()->tab_strip_model()->GetActiveWebContents(); 1023 browser()->tab_strip_model()->GetActiveWebContents();
1054 NavigationController* controller = &contents->GetController(); 1024 NavigationController* controller = &contents->GetController();
1055 LoginPromptBrowserTestObserver observer; 1025 LoginPromptBrowserTestObserver observer;
1056 1026
1057 observer.Register(content::Source<NavigationController>(controller)); 1027 observer.Register(content::Source<NavigationController>(controller));
1058 1028
1059 // Load a page which makes a synchronous XMLHttpRequest for an authenticated 1029 // Load a page which makes a synchronous XMLHttpRequest for an authenticated
1060 // resource with the wrong credentials. There should be no login prompt. 1030 // resource with the wrong credentials. There should be no login prompt.
1061 { 1031 {
1062 GURL test_page = test_server()->GetURL(kXHRTestPage); 1032 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage);
1063 WindowedAuthNeededObserver auth_needed_waiter(controller); 1033 WindowedAuthNeededObserver auth_needed_waiter(controller);
1064 browser()->OpenURL(OpenURLParams( 1034 browser()->OpenURL(OpenURLParams(
1065 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 1035 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
1066 false)); 1036 false));
1067 auth_needed_waiter.Wait(); 1037 auth_needed_waiter.Wait();
1068 } 1038 }
1069 1039
1070 ASSERT_FALSE(observer.handlers().empty()); 1040 ASSERT_FALSE(observer.handlers().empty());
1071 { 1041 {
1072 WindowedAuthNeededObserver auth_needed_waiter(controller); 1042 WindowedAuthNeededObserver auth_needed_waiter(controller);
(...skipping 22 matching lines...) Expand all
1095 1065
1096 WindowedLoadStopObserver load_stop_waiter(controller, 1); 1066 WindowedLoadStopObserver load_stop_waiter(controller, 1);
1097 load_stop_waiter.Wait(); 1067 load_stop_waiter.Wait();
1098 1068
1099 base::string16 expected_title(base::UTF8ToUTF16("status=200")); 1069 base::string16 expected_title(base::UTF8ToUTF16("status=200"));
1100 1070
1101 EXPECT_EQ(expected_title, contents->GetTitle()); 1071 EXPECT_EQ(expected_title, contents->GetTitle());
1102 EXPECT_EQ(2, observer.auth_supplied_count()); 1072 EXPECT_EQ(2, observer.auth_supplied_count());
1103 EXPECT_EQ(2, observer.auth_needed_count()); 1073 EXPECT_EQ(2, observer.auth_needed_count());
1104 EXPECT_EQ(0, observer.auth_cancelled_count()); 1074 EXPECT_EQ(0, observer.auth_cancelled_count());
1105 EXPECT_TRUE(test_server()->Stop());
1106 } 1075 }
1107 1076
1108 // If an XMLHttpRequest is made without credentials, there should be a login 1077 // If an XMLHttpRequest is made without credentials, there should be a login
1109 // prompt. If it's cancelled, the script should get a 401 status. 1078 // prompt. If it's cancelled, the script should get a 401 status.
1110 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 1079 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1111 LoginPromptForXHRWithoutCredentialsCancelled) { 1080 LoginPromptForXHRWithoutCredentialsCancelled) {
1112 const char* kXHRTestPage = "files/login/xhr_without_credentials.html"; 1081 const char* kXHRTestPage = "/login/xhr_without_credentials.html";
1113 1082
1114 ASSERT_TRUE(test_server()->Start()); 1083 ASSERT_TRUE(embedded_test_server()->Start());
1115 1084
1116 content::WebContents* contents = 1085 content::WebContents* contents =
1117 browser()->tab_strip_model()->GetActiveWebContents(); 1086 browser()->tab_strip_model()->GetActiveWebContents();
1118 NavigationController* controller = &contents->GetController(); 1087 NavigationController* controller = &contents->GetController();
1119 LoginPromptBrowserTestObserver observer; 1088 LoginPromptBrowserTestObserver observer;
1120 1089
1121 observer.Register(content::Source<NavigationController>(controller)); 1090 observer.Register(content::Source<NavigationController>(controller));
1122 1091
1123 // Load a page which makes a synchronous XMLHttpRequest for an authenticated 1092 // Load a page which makes a synchronous XMLHttpRequest for an authenticated
1124 // resource with the wrong credentials. There should be no login prompt. 1093 // resource with the wrong credentials. There should be no login prompt.
1125 { 1094 {
1126 GURL test_page = test_server()->GetURL(kXHRTestPage); 1095 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage);
1127 WindowedAuthNeededObserver auth_needed_waiter(controller); 1096 WindowedAuthNeededObserver auth_needed_waiter(controller);
1128 browser()->OpenURL(OpenURLParams( 1097 browser()->OpenURL(OpenURLParams(
1129 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 1098 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
1130 false)); 1099 false));
1131 auth_needed_waiter.Wait(); 1100 auth_needed_waiter.Wait();
1132 } 1101 }
1133 1102
1134 ASSERT_EQ(1u, observer.handlers().size()); 1103 ASSERT_EQ(1u, observer.handlers().size());
1135 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 1104 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
1136 LoginHandler* handler = *observer.handlers().begin(); 1105 LoginHandler* handler = *observer.handlers().begin();
1137 1106
1138 handler->CancelAuth(); 1107 handler->CancelAuth();
1139 auth_cancelled_waiter.Wait(); 1108 auth_cancelled_waiter.Wait();
1140 1109
1141 WindowedLoadStopObserver load_stop_waiter(controller, 1); 1110 WindowedLoadStopObserver load_stop_waiter(controller, 1);
1142 load_stop_waiter.Wait(); 1111 load_stop_waiter.Wait();
1143 1112
1144 base::string16 expected_title(base::UTF8ToUTF16("status=401")); 1113 base::string16 expected_title(base::UTF8ToUTF16("status=401"));
1145 1114
1146 EXPECT_EQ(expected_title, contents->GetTitle()); 1115 EXPECT_EQ(expected_title, contents->GetTitle());
1147 EXPECT_EQ(0, observer.auth_supplied_count()); 1116 EXPECT_EQ(0, observer.auth_supplied_count());
1148 EXPECT_EQ(1, observer.auth_needed_count()); 1117 EXPECT_EQ(1, observer.auth_needed_count());
1149 EXPECT_EQ(1, observer.auth_cancelled_count()); 1118 EXPECT_EQ(1, observer.auth_cancelled_count());
1150 EXPECT_TRUE(test_server()->Stop());
1151 } 1119 }
1152 1120
1153 // If a cross origin navigation triggers a login prompt, the destination URL 1121 // If a cross origin navigation triggers a login prompt, the destination URL
1154 // should be shown in the omnibox. 1122 // should be shown in the omnibox.
1155 void LoginPromptBrowserTest::TestCrossOriginPrompt( 1123 void LoginPromptBrowserTest::TestCrossOriginPrompt(
1156 const GURL& visit_url, 1124 const GURL& visit_url,
1157 const std::string& expected_hostname, 1125 const std::string& expected_hostname,
1158 bool cancel_prompt) const { 1126 bool cancel_prompt) const {
1159 content::WebContents* contents = 1127 content::WebContents* contents =
1160 browser()->tab_strip_model()->GetActiveWebContents(); 1128 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 28 matching lines...) Expand all
1189 1157
1190 EXPECT_EQ(expected_hostname, contents->GetVisibleURL().host()); 1158 EXPECT_EQ(expected_hostname, contents->GetVisibleURL().host());
1191 EXPECT_FALSE(contents->ShowingInterstitialPage()); 1159 EXPECT_FALSE(contents->ShowingInterstitialPage());
1192 } 1160 }
1193 } 1161 }
1194 1162
1195 // If a cross origin direct navigation triggers a login prompt, the login 1163 // If a cross origin direct navigation triggers a login prompt, the login
1196 // interstitial should be shown. 1164 // interstitial should be shown.
1197 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 1165 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1198 ShowCorrectUrlForCrossOriginMainFrameRequests) { 1166 ShowCorrectUrlForCrossOriginMainFrameRequests) {
1199 ASSERT_TRUE(test_server()->Start()); 1167 ASSERT_TRUE(embedded_test_server()->Start());
1200 1168
1201 GURL test_page = test_server()->GetURL(kAuthBasicPage); 1169 GURL test_page = embedded_test_server()->GetURL(kAuthBasicPage);
1202 ASSERT_EQ("127.0.0.1", test_page.host()); 1170 ASSERT_EQ("127.0.0.1", test_page.host());
1203 std::string auth_host("127.0.0.1"); 1171 std::string auth_host("127.0.0.1");
1204 TestCrossOriginPrompt(test_page, auth_host, true); 1172 TestCrossOriginPrompt(test_page, auth_host, true);
1205 } 1173 }
1206 1174
1207 // If a cross origin redirect triggers a login prompt, the destination URL 1175 // If a cross origin redirect triggers a login prompt, the destination URL
1208 // should be shown in the omnibox when the auth dialog is displayed. 1176 // should be shown in the omnibox when the auth dialog is displayed.
1209 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 1177 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1210 ShowCorrectUrlForCrossOriginMainFrameRedirects) { 1178 ShowCorrectUrlForCrossOriginMainFrameRedirects) {
1211 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 1179 host_resolver()->AddRule("www.a.com", "127.0.0.1");
1212 ASSERT_TRUE(test_server()->Start()); 1180 ASSERT_TRUE(embedded_test_server()->Start());
1213 1181
1214 const char* kTestPage = "files/login/cross_origin.html"; 1182 const char* kTestPage = "/login/cross_origin.html";
1215 GURL test_page = test_server()->GetURL(kTestPage); 1183 GURL test_page = embedded_test_server()->GetURL(kTestPage);
1216 ASSERT_EQ("127.0.0.1", test_page.host()); 1184 ASSERT_EQ("127.0.0.1", test_page.host());
1217 std::string auth_host("www.a.com"); 1185 std::string auth_host("www.a.com");
1218 TestCrossOriginPrompt(test_page, auth_host, true); 1186 TestCrossOriginPrompt(test_page, auth_host, true);
1219 } 1187 }
1220 1188
1221 // Same as above, but instead of cancelling the prompt for www.a.com at the end, 1189 // Same as above, but instead of cancelling the prompt for www.a.com at the end,
1222 // the page redirects to another page (www.b.com) that triggers an auth dialog. 1190 // the page redirects to another page (www.b.com) that triggers an auth dialog.
1223 // This should cancel the login interstitial for the first page (www.a.com), 1191 // This should cancel the login interstitial for the first page (www.a.com),
1224 // create a blank interstitial for second page (www.b.com) and show its URL in 1192 // create a blank interstitial for second page (www.b.com) and show its URL in
1225 // the omnibox. 1193 // the omnibox.
1226 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 1194 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1227 CancelLoginInterstitialOnRedirect) { 1195 CancelLoginInterstitialOnRedirect) {
1228 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 1196 host_resolver()->AddRule("www.a.com", "127.0.0.1");
1229 host_resolver()->AddRule("www.b.com", "127.0.0.1"); 1197 host_resolver()->AddRule("www.b.com", "127.0.0.1");
1230 ASSERT_TRUE(test_server()->Start()); 1198 ASSERT_TRUE(embedded_test_server()->Start());
1231 1199
1232 // The test page redirects to www.a.com which triggers an auth dialog. 1200 // The test page redirects to www.a.com which triggers an auth dialog.
1233 const char* kTestPage = "files/login/cross_origin.html"; 1201 const char* kTestPage = "/login/cross_origin.html";
1234 GURL test_page = test_server()->GetURL(kTestPage); 1202 GURL test_page = embedded_test_server()->GetURL(kTestPage);
1235 ASSERT_EQ("127.0.0.1", test_page.host()); 1203 ASSERT_EQ("127.0.0.1", test_page.host());
1236 1204
1237 // The page at b.com simply displays an auth dialog. 1205 // The page at b.com simply displays an auth dialog.
1238 GURL::Replacements replace_host2; 1206 GURL::Replacements replace_host2;
1239 replace_host2.SetHostStr("www.b.com"); 1207 replace_host2.SetHostStr("www.b.com");
1240 GURL page2 = 1208 GURL page2 =
1241 test_server()->GetURL(kAuthBasicPage).ReplaceComponents(replace_host2); 1209 embedded_test_server()->GetURL(kAuthBasicPage).ReplaceComponents(
1210 replace_host2);
1242 1211
1243 content::WebContents* contents = 1212 content::WebContents* contents =
1244 browser()->tab_strip_model()->GetActiveWebContents(); 1213 browser()->tab_strip_model()->GetActiveWebContents();
1245 NavigationController* controller = &contents->GetController(); 1214 NavigationController* controller = &contents->GetController();
1246 LoginPromptBrowserTestObserver observer; 1215 LoginPromptBrowserTestObserver observer;
1247 observer.Register(content::Source<NavigationController>(controller)); 1216 observer.Register(content::Source<NavigationController>(controller));
1248 1217
1249 // Load the test page. It should end up on www.a.com with the auth dialog 1218 // Load the test page. It should end up on www.a.com with the auth dialog
1250 // open. 1219 // open.
1251 TestCrossOriginPrompt(test_page, "www.a.com", false); 1220 TestCrossOriginPrompt(test_page, "www.a.com", false);
(...skipping 29 matching lines...) Expand all
1281 EXPECT_FALSE(contents->ShowingInterstitialPage()); 1250 EXPECT_FALSE(contents->ShowingInterstitialPage());
1282 } 1251 }
1283 1252
1284 // Test the scenario where proceeding through a different type of interstitial 1253 // Test the scenario where proceeding through a different type of interstitial
1285 // that ends up with an auth URL works fine. This can happen if a URL that 1254 // that ends up with an auth URL works fine. This can happen if a URL that
1286 // triggers the auth dialog can also trigger an SSL interstitial (or any other 1255 // triggers the auth dialog can also trigger an SSL interstitial (or any other
1287 // type of interstitial). 1256 // type of interstitial).
1288 IN_PROC_BROWSER_TEST_F( 1257 IN_PROC_BROWSER_TEST_F(
1289 LoginPromptBrowserTest, 1258 LoginPromptBrowserTest,
1290 DISABLED_LoginInterstitialShouldReplaceExistingInterstitial) { 1259 DISABLED_LoginInterstitialShouldReplaceExistingInterstitial) {
1291 net::SpawnedTestServer https_server( 1260 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
1292 net::SpawnedTestServer::TYPE_HTTPS, 1261 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
1293 net::SpawnedTestServer::SSLOptions(
1294 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED),
1295 base::FilePath());
1296 ASSERT_TRUE(https_server.Start()); 1262 ASSERT_TRUE(https_server.Start());
1297 1263
1298 content::WebContents* contents = 1264 content::WebContents* contents =
1299 browser()->tab_strip_model()->GetActiveWebContents(); 1265 browser()->tab_strip_model()->GetActiveWebContents();
1300 NavigationController* controller = &contents->GetController(); 1266 NavigationController* controller = &contents->GetController();
1301 LoginPromptBrowserTestObserver observer; 1267 LoginPromptBrowserTestObserver observer;
1302 1268
1303 observer.Register(content::Source<NavigationController>(controller)); 1269 observer.Register(content::Source<NavigationController>(controller));
1304 1270
1305 // Load a page which triggers an SSL interstitial. Proceeding through it 1271 // Load a page which triggers an SSL interstitial. Proceeding through it
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 // 3. Tab is again navigated to the same auth URL in (1). 1321 // 3. Tab is again navigated to the same auth URL in (1).
1356 // 1322 //
1357 // In this case, the last committed url is the same as the auth URL since the 1323 // In this case, the last committed url is the same as the auth URL since the
1358 // navigation at (1) is committed (user clicked cancel and the page loaded), but 1324 // navigation at (1) is committed (user clicked cancel and the page loaded), but
1359 // the navigation at (2) isn't (navigations ending up in interstitials don't 1325 // the navigation at (2) isn't (navigations ending up in interstitials don't
1360 // immediately commit). So just checking for cross origin navigation before 1326 // immediately commit). So just checking for cross origin navigation before
1361 // prompting the auth interstitial is not sufficient, must also check if there 1327 // prompting the auth interstitial is not sufficient, must also check if there
1362 // is any other interstitial being displayed. 1328 // is any other interstitial being displayed.
1363 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 1329 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1364 ShouldReplaceExistingInterstitialWhenNavigated) { 1330 ShouldReplaceExistingInterstitialWhenNavigated) {
1365 ASSERT_TRUE(test_server()->Start()); 1331 ASSERT_TRUE(embedded_test_server()->Start());
1366 net::SpawnedTestServer https_server( 1332 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
1367 net::SpawnedTestServer::TYPE_HTTPS, 1333 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
1368 net::SpawnedTestServer::SSLOptions(
1369 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED),
1370 base::FilePath());
1371 ASSERT_TRUE(https_server.Start()); 1334 ASSERT_TRUE(https_server.Start());
1372 1335
1373 content::WebContents* contents = 1336 content::WebContents* contents =
1374 browser()->tab_strip_model()->GetActiveWebContents(); 1337 browser()->tab_strip_model()->GetActiveWebContents();
1375 NavigationController* controller = &contents->GetController(); 1338 NavigationController* controller = &contents->GetController();
1376 LoginPromptBrowserTestObserver observer; 1339 LoginPromptBrowserTestObserver observer;
1377 1340
1378 observer.Register(content::Source<NavigationController>(controller)); 1341 observer.Register(content::Source<NavigationController>(controller));
1379 1342
1380 GURL auth_url = test_server()->GetURL(kAuthBasicPage); 1343 GURL auth_url = embedded_test_server()->GetURL(kAuthBasicPage);
1381 GURL broken_ssl_page = https_server.GetURL("/"); 1344 GURL broken_ssl_page = https_server.GetURL("/");
1382 1345
1383 // Navigate to an auth url and wait for the login prompt. 1346 // Navigate to an auth url and wait for the login prompt.
1384 { 1347 {
1385 WindowedAuthNeededObserver auth_needed_waiter(controller); 1348 WindowedAuthNeededObserver auth_needed_waiter(controller);
1386 browser()->OpenURL(OpenURLParams(auth_url, Referrer(), CURRENT_TAB, 1349 browser()->OpenURL(OpenURLParams(auth_url, Referrer(), CURRENT_TAB,
1387 ui::PAGE_TRANSITION_TYPED, false)); 1350 ui::PAGE_TRANSITION_TYPED, false));
1388 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); 1351 ASSERT_EQ("127.0.0.1", contents->GetURL().host());
1389 ASSERT_TRUE(contents->GetURL().SchemeIs("http")); 1352 ASSERT_TRUE(contents->GetURL().SchemeIs("http"));
1390 auth_needed_waiter.Wait(); 1353 auth_needed_waiter.Wait();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 ASSERT_EQ(1u, observer.handlers().size()); 1400 ASSERT_EQ(1u, observer.handlers().size());
1438 content::WaitForInterstitialAttach(contents); 1401 content::WaitForInterstitialAttach(contents);
1439 EXPECT_EQ(LoginInterstitialDelegate::kTypeForTesting, 1402 EXPECT_EQ(LoginInterstitialDelegate::kTypeForTesting,
1440 contents->GetInterstitialPage() 1403 contents->GetInterstitialPage()
1441 ->GetDelegateForTesting() 1404 ->GetDelegateForTesting()
1442 ->GetTypeForTesting()); 1405 ->GetTypeForTesting());
1443 } 1406 }
1444 } 1407 }
1445 1408
1446 } // namespace 1409 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698