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

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

Issue 6321013: Stop login prompt from showing for prefetches (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 11 months 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 | Annotate | Revision Log
OLDNEW
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
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) {
cbentzel 2011/01/20 17:59:45 Should this test also add a LoginPromptBrowserTest
asanka (google) 2011/01/20 18:16:29 An alternative would be to wait for both AUTH_NEED
cbentzel 2011/01/20 18:19:20 In this case we do not expect an AUTH_NEEDED, so t
gavinp 2011/01/20 18:36:15 Added the assertion for the obvserver handlers bei
184 ASSERT_TRUE(test_server()->Start());
185
186 GURL test_page = test_server()->GetURL(kPrefetchAuthPage);
187
188 const bool was_prefetch_enabled =
cbentzel 2011/01/20 17:59:45 Would it make sense to add a simple RAII class to
gavinp 2011/01/20 18:36:15 Done.
189 ResourceDispatcherHost::is_prefetch_enabled();
190 ResourceDispatcherHost::set_is_prefetch_enabled(true);
191
192 TabContentsWrapper* contents =
193 browser()->GetSelectedTabContentsWrapper();
194 ASSERT_TRUE(contents);
195 NavigationController* controller = &contents->controller();
196
197 WindowedLoadStopObserver load_stop_waiter(controller);
198 browser()->OpenURL(test_page, GURL(), CURRENT_TAB, PageTransition::TYPED);
199
200 load_stop_waiter.Wait();
201
202 ResourceDispatcherHost::set_is_prefetch_enabled(was_prefetch_enabled);
203 EXPECT_TRUE(test_server()->Stop());
204 }
205
172 // Test handling of resources that require authentication even though 206 // Test handling of resources that require authentication even though
173 // the page they are included on doesn't. In this case we should only 207 // the page they are included on doesn't. In this case we should only
174 // present the minimal number of prompts necessary for successfully 208 // present the minimal number of prompts necessary for successfully
175 // displaying the page. First we check whether cancelling works as 209 // displaying the page. First we check whether cancelling works as
176 // expected. 210 // expected.
177 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { 211 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) {
178 ASSERT_TRUE(test_server()->Start()); 212 ASSERT_TRUE(test_server()->Start());
179 GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 213 GURL test_page = test_server()->GetURL(kMultiRealmTestPage);
180 214
181 TabContentsWrapper* contents = 215 TabContentsWrapper* contents =
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 EXPECT_EQ(1, n_handlers); 383 EXPECT_EQ(1, n_handlers);
350 EXPECT_LT(0, observer.auth_needed_count_); 384 EXPECT_LT(0, observer.auth_needed_count_);
351 EXPECT_EQ(0, observer.auth_cancelled_count_); 385 EXPECT_EQ(0, observer.auth_cancelled_count_);
352 EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); 386 EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_);
353 LOG(INFO) << "Waiting for LOAD_STOP"; 387 LOG(INFO) << "Waiting for LOAD_STOP";
354 load_stop_waiter.Wait(); 388 load_stop_waiter.Wait();
355 EXPECT_TRUE(test_server()->Stop()); 389 EXPECT_TRUE(test_server()->Stop());
356 LOG(INFO) << "Done with test"; 390 LOG(INFO) << "Done with test";
357 } 391 }
358 } // namespace 392 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698