OLD | NEW |
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 "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 11 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/login/login_prompt.h" | 13 #include "chrome/browser/ui/login/login_prompt.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
15 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
16 #include "chrome/test/ui_test_utils.h" | 17 #include "chrome/test/ui_test_utils.h" |
17 #include "net/base/auth.h" | 18 #include "net/base/auth.h" |
18 | 19 |
(...skipping 30 matching lines...) Expand all Loading... |
49 | 50 |
50 void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { | 51 void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { |
51 const net::AuthChallengeInfo* challenge = handler->auth_info(); | 52 const net::AuthChallengeInfo* challenge = handler->auth_info(); |
52 | 53 |
53 ASSERT_TRUE(challenge); | 54 ASSERT_TRUE(challenge); |
54 std::map<std::wstring, AuthInfo>::iterator i = | 55 std::map<std::wstring, AuthInfo>::iterator i = |
55 auth_map_.find(challenge->realm); | 56 auth_map_.find(challenge->realm); |
56 EXPECT_TRUE(auth_map_.end() != i); | 57 EXPECT_TRUE(auth_map_.end() != i); |
57 if (i != auth_map_.end()) { | 58 if (i != auth_map_.end()) { |
58 const AuthInfo& info = i->second; | 59 const AuthInfo& info = i->second; |
59 handler->SetAuth(info.username_, info.password_); | 60 handler->SetAuth(WideToUTF16Hack(info.username_), |
| 61 WideToUTF16Hack(info.password_)); |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 // Maintains a set of LoginHandlers that are currently active and | 65 // Maintains a set of LoginHandlers that are currently active and |
64 // keeps a count of the notifications that were observed. | 66 // keeps a count of the notifications that were observed. |
65 class LoginPromptBrowserTestObserver : public NotificationObserver { | 67 class LoginPromptBrowserTestObserver : public NotificationObserver { |
66 public: | 68 public: |
67 LoginPromptBrowserTestObserver() | 69 LoginPromptBrowserTestObserver() |
68 : auth_needed_count_(0), | 70 : auth_needed_count_(0), |
69 auth_supplied_count_(0), | 71 auth_supplied_count_(0), |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 359 } |
358 | 360 |
359 EXPECT_FALSE(observer.handlers_.empty()); | 361 EXPECT_FALSE(observer.handlers_.empty()); |
360 | 362 |
361 if (!observer.handlers_.empty()) { | 363 if (!observer.handlers_.empty()) { |
362 WindowedAuthNeededObserver auth_needed_waiter(controller); | 364 WindowedAuthNeededObserver auth_needed_waiter(controller); |
363 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); | 365 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); |
364 LoginHandler* handler = *observer.handlers_.begin(); | 366 LoginHandler* handler = *observer.handlers_.begin(); |
365 | 367 |
366 ASSERT_TRUE(handler); | 368 ASSERT_TRUE(handler); |
367 handler->SetAuth(bad_username_, bad_password_); | 369 handler->SetAuth(WideToUTF16Hack(bad_username_), |
| 370 WideToUTF16Hack(bad_password_)); |
368 LOG(INFO) << "Waiting for initial AUTH_SUPPLIED"; | 371 LOG(INFO) << "Waiting for initial AUTH_SUPPLIED"; |
369 auth_supplied_waiter.Wait(); | 372 auth_supplied_waiter.Wait(); |
370 | 373 |
371 // The request should be retried after the incorrect password is | 374 // The request should be retried after the incorrect password is |
372 // supplied. This should result in a new AUTH_NEEDED notification | 375 // supplied. This should result in a new AUTH_NEEDED notification |
373 // for the same realm. | 376 // for the same realm. |
374 LOG(INFO) << "Waiting for secondary AUTH_NEEDED"; | 377 LOG(INFO) << "Waiting for secondary AUTH_NEEDED"; |
375 auth_needed_waiter.Wait(); | 378 auth_needed_waiter.Wait(); |
376 } | 379 } |
377 | 380 |
(...skipping 24 matching lines...) Expand all Loading... |
402 EXPECT_EQ(1, n_handlers); | 405 EXPECT_EQ(1, n_handlers); |
403 EXPECT_LT(0, observer.auth_needed_count_); | 406 EXPECT_LT(0, observer.auth_needed_count_); |
404 EXPECT_EQ(0, observer.auth_cancelled_count_); | 407 EXPECT_EQ(0, observer.auth_cancelled_count_); |
405 EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); | 408 EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); |
406 LOG(INFO) << "Waiting for LOAD_STOP"; | 409 LOG(INFO) << "Waiting for LOAD_STOP"; |
407 load_stop_waiter.Wait(); | 410 load_stop_waiter.Wait(); |
408 EXPECT_TRUE(test_server()->Stop()); | 411 EXPECT_TRUE(test_server()->Stop()); |
409 LOG(INFO) << "Done with test"; | 412 LOG(INFO) << "Done with test"; |
410 } | 413 } |
411 } // namespace | 414 } // namespace |
OLD | NEW |