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/test/in_process_browser_test.h" | 15 #include "chrome/test/in_process_browser_test.h" |
15 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
16 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
17 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 18 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
18 #include "content/common/notification_service.h" | 19 #include "content/common/notification_service.h" |
19 #include "net/base/auth.h" | 20 #include "net/base/auth.h" |
20 #include "net/base/mock_host_resolver.h" | 21 #include "net/base/mock_host_resolver.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 67 |
67 // Maintains a set of LoginHandlers that are currently active and | 68 // Maintains a set of LoginHandlers that are currently active and |
68 // keeps a count of the notifications that were observed. | 69 // keeps a count of the notifications that were observed. |
69 class LoginPromptBrowserTestObserver : public NotificationObserver { | 70 class LoginPromptBrowserTestObserver : public NotificationObserver { |
70 public: | 71 public: |
71 LoginPromptBrowserTestObserver() | 72 LoginPromptBrowserTestObserver() |
72 : auth_needed_count_(0), | 73 : auth_needed_count_(0), |
73 auth_supplied_count_(0), | 74 auth_supplied_count_(0), |
74 auth_cancelled_count_(0) {} | 75 auth_cancelled_count_(0) {} |
75 | 76 |
76 virtual void Observe(NotificationType type, | 77 virtual void Observe(int type, |
77 const NotificationSource& source, | 78 const NotificationSource& source, |
78 const NotificationDetails& details); | 79 const NotificationDetails& details); |
79 | 80 |
80 void AddHandler(LoginHandler* handler); | 81 void AddHandler(LoginHandler* handler); |
81 | 82 |
82 void RemoveHandler(LoginHandler* handler); | 83 void RemoveHandler(LoginHandler* handler); |
83 | 84 |
84 void Register(const NotificationSource& source); | 85 void Register(const NotificationSource& source); |
85 | 86 |
86 std::list<LoginHandler*> handlers_; | 87 std::list<LoginHandler*> handlers_; |
87 | 88 |
88 // The exact number of notifications we receive is depedent on the | 89 // The exact number of notifications we receive is depedent on the |
89 // number of requests that were dispatched and is subject to a | 90 // number of requests that were dispatched and is subject to a |
90 // number of factors that we don't directly control here. The | 91 // number of factors that we don't directly control here. The |
91 // values below should only be used qualitatively. | 92 // values below should only be used qualitatively. |
92 int auth_needed_count_; | 93 int auth_needed_count_; |
93 int auth_supplied_count_; | 94 int auth_supplied_count_; |
94 int auth_cancelled_count_; | 95 int auth_cancelled_count_; |
95 | 96 |
96 private: | 97 private: |
97 NotificationRegistrar registrar_; | 98 NotificationRegistrar registrar_; |
98 | 99 |
99 DISALLOW_COPY_AND_ASSIGN(LoginPromptBrowserTestObserver); | 100 DISALLOW_COPY_AND_ASSIGN(LoginPromptBrowserTestObserver); |
100 }; | 101 }; |
101 | 102 |
102 void LoginPromptBrowserTestObserver::Observe( | 103 void LoginPromptBrowserTestObserver::Observe( |
103 NotificationType type, | 104 int type, |
104 const NotificationSource& source, | 105 const NotificationSource& source, |
105 const NotificationDetails& details) { | 106 const NotificationDetails& details) { |
106 if (type == NotificationType::AUTH_NEEDED) { | 107 if (type == chrome::NOTIFICATION_AUTH_NEEDED) { |
107 LoginNotificationDetails* login_details = | 108 LoginNotificationDetails* login_details = |
108 Details<LoginNotificationDetails>(details).ptr(); | 109 Details<LoginNotificationDetails>(details).ptr(); |
109 AddHandler(login_details->handler()); | 110 AddHandler(login_details->handler()); |
110 auth_needed_count_++; | 111 auth_needed_count_++; |
111 } else if (type == NotificationType::AUTH_SUPPLIED) { | 112 } else if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) { |
112 AuthSuppliedLoginNotificationDetails* login_details = | 113 AuthSuppliedLoginNotificationDetails* login_details = |
113 Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); | 114 Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); |
114 RemoveHandler(login_details->handler()); | 115 RemoveHandler(login_details->handler()); |
115 auth_supplied_count_++; | 116 auth_supplied_count_++; |
116 } else if (type == NotificationType::AUTH_CANCELLED) { | 117 } else if (type == chrome::NOTIFICATION_AUTH_CANCELLED) { |
117 LoginNotificationDetails* login_details = | 118 LoginNotificationDetails* login_details = |
118 Details<LoginNotificationDetails>(details).ptr(); | 119 Details<LoginNotificationDetails>(details).ptr(); |
119 RemoveHandler(login_details->handler()); | 120 RemoveHandler(login_details->handler()); |
120 auth_cancelled_count_++; | 121 auth_cancelled_count_++; |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) { | 125 void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) { |
125 std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), | 126 std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), |
126 handlers_.end(), | 127 handlers_.end(), |
127 handler); | 128 handler); |
128 EXPECT_TRUE(i == handlers_.end()); | 129 EXPECT_TRUE(i == handlers_.end()); |
129 if (i == handlers_.end()) | 130 if (i == handlers_.end()) |
130 handlers_.push_back(handler); | 131 handlers_.push_back(handler); |
131 } | 132 } |
132 | 133 |
133 void LoginPromptBrowserTestObserver::RemoveHandler(LoginHandler* handler) { | 134 void LoginPromptBrowserTestObserver::RemoveHandler(LoginHandler* handler) { |
134 std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), | 135 std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), |
135 handlers_.end(), | 136 handlers_.end(), |
136 handler); | 137 handler); |
137 EXPECT_TRUE(i != handlers_.end()); | 138 EXPECT_TRUE(i != handlers_.end()); |
138 if (i != handlers_.end()) | 139 if (i != handlers_.end()) |
139 handlers_.erase(i); | 140 handlers_.erase(i); |
140 } | 141 } |
141 | 142 |
142 void LoginPromptBrowserTestObserver::Register( | 143 void LoginPromptBrowserTestObserver::Register( |
143 const NotificationSource& source) { | 144 const NotificationSource& source) { |
144 registrar_.Add(this, NotificationType::AUTH_NEEDED, source); | 145 registrar_.Add(this, chrome::NOTIFICATION_AUTH_NEEDED, source); |
145 registrar_.Add(this, NotificationType::AUTH_SUPPLIED, source); | 146 registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, source); |
146 registrar_.Add(this, NotificationType::AUTH_CANCELLED, source); | 147 registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, source); |
147 } | 148 } |
148 | 149 |
149 template <NotificationType::Type T> | 150 template <int T> |
150 class WindowedNavigationObserver | 151 class WindowedNavigationObserver |
151 : public ui_test_utils::WindowedNotificationObserver { | 152 : public ui_test_utils::WindowedNotificationObserver { |
152 public: | 153 public: |
153 explicit WindowedNavigationObserver(NavigationController* controller) | 154 explicit WindowedNavigationObserver(NavigationController* controller) |
154 : ui_test_utils::WindowedNotificationObserver( | 155 : ui_test_utils::WindowedNotificationObserver( |
155 T, Source<NavigationController>(controller)) {} | 156 T, Source<NavigationController>(controller)) {} |
156 }; | 157 }; |
157 | 158 |
158 typedef WindowedNavigationObserver<NotificationType::LOAD_STOP> | 159 typedef WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP> |
159 WindowedLoadStopObserver; | 160 WindowedLoadStopObserver; |
160 | 161 |
161 typedef WindowedNavigationObserver<NotificationType::AUTH_NEEDED> | 162 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_NEEDED> |
162 WindowedAuthNeededObserver; | 163 WindowedAuthNeededObserver; |
163 | 164 |
164 typedef WindowedNavigationObserver<NotificationType::AUTH_CANCELLED> | 165 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_CANCELLED> |
165 WindowedAuthCancelledObserver; | 166 WindowedAuthCancelledObserver; |
166 | 167 |
167 typedef WindowedNavigationObserver<NotificationType::AUTH_SUPPLIED> | 168 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_SUPPLIED> |
168 WindowedAuthSuppliedObserver; | 169 WindowedAuthSuppliedObserver; |
169 | 170 |
170 const char* kPrefetchAuthPage = "files/login/prefetch.html"; | 171 const char* kPrefetchAuthPage = "files/login/prefetch.html"; |
171 | 172 |
172 const char* kMultiRealmTestPage = "files/login/multi_realm.html"; | 173 const char* kMultiRealmTestPage = "files/login/multi_realm.html"; |
173 const int kMultiRealmTestRealmCount = 2; | 174 const int kMultiRealmTestRealmCount = 2; |
174 const int kMultiRealmTestResourceCount = 4; | 175 const int kMultiRealmTestResourceCount = 4; |
175 | 176 |
176 const char* kSingleRealmTestPage = "files/login/single_realm.html"; | 177 const char* kSingleRealmTestPage = "files/login/single_realm.html"; |
177 const int kSingleRealmTestResourceCount = 6; | 178 const int kSingleRealmTestResourceCount = 6; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 handler->CancelAuth(); | 537 handler->CancelAuth(); |
537 auth_cancelled_waiter.Wait(); | 538 auth_cancelled_waiter.Wait(); |
538 } | 539 } |
539 } | 540 } |
540 | 541 |
541 EXPECT_EQ(1, observer.auth_needed_count_); | 542 EXPECT_EQ(1, observer.auth_needed_count_); |
542 EXPECT_TRUE(test_server()->Stop()); | 543 EXPECT_TRUE(test_server()->Stop()); |
543 } | 544 } |
544 | 545 |
545 } // namespace | 546 } // namespace |
OLD | NEW |