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 "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/login/login_prompt.h" | 12 #include "chrome/browser/ui/login/login_prompt.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
13 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.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 "net/base/auth.h" | 17 #include "net/base/auth.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 156 |
156 typedef WindowedNavigationObserver<NotificationType::AUTH_NEEDED> | 157 typedef WindowedNavigationObserver<NotificationType::AUTH_NEEDED> |
157 WindowedAuthNeededObserver; | 158 WindowedAuthNeededObserver; |
158 | 159 |
159 typedef WindowedNavigationObserver<NotificationType::AUTH_CANCELLED> | 160 typedef WindowedNavigationObserver<NotificationType::AUTH_CANCELLED> |
160 WindowedAuthCancelledObserver; | 161 WindowedAuthCancelledObserver; |
161 | 162 |
162 typedef WindowedNavigationObserver<NotificationType::AUTH_SUPPLIED> | 163 typedef WindowedNavigationObserver<NotificationType::AUTH_SUPPLIED> |
163 WindowedAuthSuppliedObserver; | 164 WindowedAuthSuppliedObserver; |
164 | 165 |
166 const char* kPrefetchAuthPage = "files/login/prefetch.html"; | |
167 | |
165 const char* kMultiRealmTestPage = "files/login/multi_realm.html"; | 168 const char* kMultiRealmTestPage = "files/login/multi_realm.html"; |
166 const int kMultiRealmTestRealmCount = 2; | 169 const int kMultiRealmTestRealmCount = 2; |
167 const int kMultiRealmTestResourceCount = 4; | 170 const int kMultiRealmTestResourceCount = 4; |
168 | 171 |
169 const char* kSingleRealmTestPage = "files/login/single_realm.html"; | 172 const char* kSingleRealmTestPage = "files/login/single_realm.html"; |
170 const int kSingleRealmTestResourceCount = 6; | 173 const int kSingleRealmTestResourceCount = 6; |
171 | 174 |
175 // Confirm that <link rel="prefetch"> targetting an auth required | |
176 // resource does not provide a login dialog. These types of requests | |
177 // should instead just cancel the auth. | |
178 | |
179 // Unfortunately, this test doesn't assert on anything for its | |
180 // correctness. Instead, it relies on the auth dialog blocking the | |
181 // browser, and triggering a timeout to cause failure when the | |
182 // prefetch resource requires authorization. | |
183 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) { | |
184 ASSERT_TRUE(test_server()->Start()); | |
185 | |
186 GURL test_page = test_server()->GetURL(kPrefetchAuthPage); | |
187 | |
188 class SetPrefetchForTest { | |
cbentzel
2011/01/20 19:26:30
Do you also want to enforce that prerender is not
gavinp
2011/01/21 15:14:36
We should be good no matter the prerender setting.
| |
189 public: | |
190 explicit SetPrefetchForTest(bool prefetch) | |
191 : old_prefetch_state_(ResourceDispatcherHost::is_prefetch_enabled()) { | |
192 ResourceDispatcherHost::set_is_prefetch_enabled(prefetch); | |
193 } | |
194 | |
195 ~SetPrefetchForTest() { | |
196 ResourceDispatcherHost::set_is_prefetch_enabled(old_prefetch_state_); | |
197 } | |
198 private: | |
199 bool old_prefetch_state_; | |
200 } set_prefetch_for_test(true); | |
cbentzel
2011/01/20 19:26:30
I didn't realize you could do this in C++.
| |
201 | |
202 TabContentsWrapper* contents = | |
203 browser()->GetSelectedTabContentsWrapper(); | |
204 ASSERT_TRUE(contents); | |
205 NavigationController* controller = &contents->controller(); | |
206 LoginPromptBrowserTestObserver observer; | |
207 | |
208 observer.Register(Source<NavigationController>(controller)); | |
209 | |
210 WindowedLoadStopObserver load_stop_waiter(controller); | |
211 browser()->OpenURL(test_page, GURL(), CURRENT_TAB, PageTransition::TYPED); | |
212 | |
213 load_stop_waiter.Wait(); | |
214 EXPECT_TRUE(observer.handlers_.empty()); | |
215 EXPECT_TRUE(test_server()->Stop()); | |
216 } | |
217 | |
172 // Test handling of resources that require authentication even though | 218 // Test handling of resources that require authentication even though |
173 // the page they are included on doesn't. In this case we should only | 219 // the page they are included on doesn't. In this case we should only |
174 // present the minimal number of prompts necessary for successfully | 220 // present the minimal number of prompts necessary for successfully |
175 // displaying the page. First we check whether cancelling works as | 221 // displaying the page. First we check whether cancelling works as |
176 // expected. | 222 // expected. |
177 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { | 223 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { |
178 ASSERT_TRUE(test_server()->Start()); | 224 ASSERT_TRUE(test_server()->Start()); |
179 GURL test_page = test_server()->GetURL(kMultiRealmTestPage); | 225 GURL test_page = test_server()->GetURL(kMultiRealmTestPage); |
180 | 226 |
181 TabContentsWrapper* contents = | 227 TabContentsWrapper* contents = |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 EXPECT_EQ(1, n_handlers); | 395 EXPECT_EQ(1, n_handlers); |
350 EXPECT_LT(0, observer.auth_needed_count_); | 396 EXPECT_LT(0, observer.auth_needed_count_); |
351 EXPECT_EQ(0, observer.auth_cancelled_count_); | 397 EXPECT_EQ(0, observer.auth_cancelled_count_); |
352 EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); | 398 EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); |
353 LOG(INFO) << "Waiting for LOAD_STOP"; | 399 LOG(INFO) << "Waiting for LOAD_STOP"; |
354 load_stop_waiter.Wait(); | 400 load_stop_waiter.Wait(); |
355 EXPECT_TRUE(test_server()->Stop()); | 401 EXPECT_TRUE(test_server()->Stop()); |
356 LOG(INFO) << "Done with test"; | 402 LOG(INFO) << "Done with test"; |
357 } | 403 } |
358 } // namespace | 404 } // namespace |
OLD | NEW |