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 "base/utf_string_conversions.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/login/login_prompt.h" | 12 #include "chrome/browser/ui/login/login_prompt.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 17 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
18 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
20 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
21 #include "net/base/auth.h" | 21 #include "net/base/auth.h" |
22 #include "net/base/mock_host_resolver.h" | 22 #include "net/base/mock_host_resolver.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class LoginPromptBrowserTest : public InProcessBrowserTest { | 26 class LoginPromptBrowserTest : public InProcessBrowserTest { |
27 public: | 27 public: |
28 LoginPromptBrowserTest() | 28 LoginPromptBrowserTest() |
29 : bad_password_(L"incorrect"), bad_username_(L"nouser") { | 29 : bad_password_("incorrect"), bad_username_("nouser") { |
30 set_show_window(true); | 30 set_show_window(true); |
31 | 31 |
32 auth_map_["foo"] = AuthInfo(L"testuser", L"foopassword"); | 32 auth_map_["foo"] = AuthInfo("testuser", "foopassword"); |
33 auth_map_["bar"] = AuthInfo(L"testuser", L"barpassword"); | 33 auth_map_["bar"] = AuthInfo("testuser", "barpassword"); |
34 } | 34 } |
35 | 35 |
36 protected: | 36 protected: |
37 struct AuthInfo { | 37 struct AuthInfo { |
38 std::wstring username_; | 38 std::string username_; |
39 std::wstring password_; | 39 std::string password_; |
40 | 40 |
41 AuthInfo() {} | 41 AuthInfo() {} |
42 | 42 |
43 AuthInfo(const std::wstring username, | 43 AuthInfo(const std::string username, |
44 const std::wstring password) | 44 const std::string password) |
45 : username_(username), password_(password) {} | 45 : username_(username), password_(password) {} |
46 }; | 46 }; |
47 | 47 |
48 typedef std::map<std::string, AuthInfo> AuthMap; | 48 typedef std::map<std::string, AuthInfo> AuthMap; |
49 | 49 |
50 void SetAuthFor(LoginHandler* handler); | 50 void SetAuthFor(LoginHandler* handler); |
51 | 51 |
52 AuthMap auth_map_; | 52 AuthMap auth_map_; |
53 std::wstring bad_password_; | 53 std::string bad_password_; |
54 std::wstring bad_username_; | 54 std::string bad_username_; |
55 }; | 55 }; |
56 | 56 |
57 void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { | 57 void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { |
58 const net::AuthChallengeInfo* challenge = handler->auth_info(); | 58 const net::AuthChallengeInfo* challenge = handler->auth_info(); |
59 | 59 |
60 ASSERT_TRUE(challenge); | 60 ASSERT_TRUE(challenge); |
61 AuthMap::iterator i = auth_map_.find(challenge->realm); | 61 AuthMap::iterator i = auth_map_.find(challenge->realm); |
62 EXPECT_TRUE(auth_map_.end() != i); | 62 EXPECT_TRUE(auth_map_.end() != i); |
63 if (i != auth_map_.end()) { | 63 if (i != auth_map_.end()) { |
64 const AuthInfo& info = i->second; | 64 const AuthInfo& info = i->second; |
65 handler->SetAuth(WideToUTF16Hack(info.username_), | 65 handler->SetAuth(UTF8ToUTF16(info.username_), |
66 WideToUTF16Hack(info.password_)); | 66 UTF8ToUTF16(info.password_)); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 // Maintains a set of LoginHandlers that are currently active and | 70 // Maintains a set of LoginHandlers that are currently active and |
71 // keeps a count of the notifications that were observed. | 71 // keeps a count of the notifications that were observed. |
72 class LoginPromptBrowserTestObserver : public content::NotificationObserver { | 72 class LoginPromptBrowserTestObserver : public content::NotificationObserver { |
73 public: | 73 public: |
74 LoginPromptBrowserTestObserver() | 74 LoginPromptBrowserTestObserver() |
75 : auth_needed_count_(0), | 75 : auth_needed_count_(0), |
76 auth_supplied_count_(0), | 76 auth_supplied_count_(0), |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 484 } |
485 | 485 |
486 EXPECT_FALSE(observer.handlers_.empty()); | 486 EXPECT_FALSE(observer.handlers_.empty()); |
487 | 487 |
488 if (!observer.handlers_.empty()) { | 488 if (!observer.handlers_.empty()) { |
489 WindowedAuthNeededObserver auth_needed_waiter(controller); | 489 WindowedAuthNeededObserver auth_needed_waiter(controller); |
490 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); | 490 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); |
491 LoginHandler* handler = *observer.handlers_.begin(); | 491 LoginHandler* handler = *observer.handlers_.begin(); |
492 | 492 |
493 ASSERT_TRUE(handler); | 493 ASSERT_TRUE(handler); |
494 handler->SetAuth(WideToUTF16Hack(bad_username_), | 494 handler->SetAuth(UTF8ToUTF16(bad_username_), |
495 WideToUTF16Hack(bad_password_)); | 495 UTF8ToUTF16(bad_password_)); |
496 auth_supplied_waiter.Wait(); | 496 auth_supplied_waiter.Wait(); |
497 | 497 |
498 // The request should be retried after the incorrect password is | 498 // The request should be retried after the incorrect password is |
499 // supplied. This should result in a new AUTH_NEEDED notification | 499 // supplied. This should result in a new AUTH_NEEDED notification |
500 // for the same realm. | 500 // for the same realm. |
501 auth_needed_waiter.Wait(); | 501 auth_needed_waiter.Wait(); |
502 } | 502 } |
503 | 503 |
504 int n_handlers = 0; | 504 int n_handlers = 0; |
505 | 505 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 handler->CancelAuth(); | 649 handler->CancelAuth(); |
650 auth_cancelled_waiter.Wait(); | 650 auth_cancelled_waiter.Wait(); |
651 } | 651 } |
652 } | 652 } |
653 | 653 |
654 EXPECT_EQ(1, observer.auth_needed_count_); | 654 EXPECT_EQ(1, observer.auth_needed_count_); |
655 EXPECT_TRUE(test_server()->Stop()); | 655 EXPECT_TRUE(test_server()->Stop()); |
656 } | 656 } |
657 | 657 |
658 } // namespace | 658 } // namespace |
OLD | NEW |