Commit 37605ca0 authored by gavinp@chromium.org's avatar gavinp@chromium.org

Stop login prompt from showing for prefetches

BUG=70231
TEST=LoginPromptBrowserTest.PrefetchAuthCancels

Review URL: http://codereview.chromium.org/6321013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72129 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d0f8001
...@@ -1040,6 +1040,10 @@ void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request, ...@@ -1040,6 +1040,10 @@ void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request,
void ResourceDispatcherHost::OnAuthRequired( void ResourceDispatcherHost::OnAuthRequired(
net::URLRequest* request, net::URLRequest* request,
net::AuthChallengeInfo* auth_info) { net::AuthChallengeInfo* auth_info) {
if (request->load_flags() & net::LOAD_PREFETCH) {
request->CancelAuth();
return;
}
// Create a login dialog on the UI thread to get authentication data, // Create a login dialog on the UI thread to get authentication data,
// or pull from cache and continue on the IO thread. // or pull from cache and continue on the IO thread.
// TODO(mpcomplete): We should block the parent tab while waiting for // TODO(mpcomplete): We should block the parent tab while waiting for
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <map> #include <map>
#include "chrome/browser/browser_thread.h" #include "chrome/browser/browser_thread.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/login/login_prompt.h" #include "chrome/browser/ui/login/login_prompt.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
...@@ -162,6 +163,8 @@ typedef WindowedNavigationObserver<NotificationType::AUTH_CANCELLED> ...@@ -162,6 +163,8 @@ typedef WindowedNavigationObserver<NotificationType::AUTH_CANCELLED>
typedef WindowedNavigationObserver<NotificationType::AUTH_SUPPLIED> typedef WindowedNavigationObserver<NotificationType::AUTH_SUPPLIED>
WindowedAuthSuppliedObserver; WindowedAuthSuppliedObserver;
const char* kPrefetchAuthPage = "files/login/prefetch.html";
const char* kMultiRealmTestPage = "files/login/multi_realm.html"; const char* kMultiRealmTestPage = "files/login/multi_realm.html";
const int kMultiRealmTestRealmCount = 2; const int kMultiRealmTestRealmCount = 2;
const int kMultiRealmTestResourceCount = 4; const int kMultiRealmTestResourceCount = 4;
...@@ -169,6 +172,49 @@ const int kMultiRealmTestResourceCount = 4; ...@@ -169,6 +172,49 @@ const int kMultiRealmTestResourceCount = 4;
const char* kSingleRealmTestPage = "files/login/single_realm.html"; const char* kSingleRealmTestPage = "files/login/single_realm.html";
const int kSingleRealmTestResourceCount = 6; const int kSingleRealmTestResourceCount = 6;
// Confirm that <link rel="prefetch"> targetting an auth required
// resource does not provide a login dialog. These types of requests
// should instead just cancel the auth.
// Unfortunately, this test doesn't assert on anything for its
// correctness. Instead, it relies on the auth dialog blocking the
// browser, and triggering a timeout to cause failure when the
// prefetch resource requires authorization.
IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) {
ASSERT_TRUE(test_server()->Start());
GURL test_page = test_server()->GetURL(kPrefetchAuthPage);
class SetPrefetchForTest {
public:
explicit SetPrefetchForTest(bool prefetch)
: old_prefetch_state_(ResourceDispatcherHost::is_prefetch_enabled()) {
ResourceDispatcherHost::set_is_prefetch_enabled(prefetch);
}
~SetPrefetchForTest() {
ResourceDispatcherHost::set_is_prefetch_enabled(old_prefetch_state_);
}
private:
bool old_prefetch_state_;
} set_prefetch_for_test(true);
TabContentsWrapper* contents =
browser()->GetSelectedTabContentsWrapper();
ASSERT_TRUE(contents);
NavigationController* controller = &contents->controller();
LoginPromptBrowserTestObserver observer;
observer.Register(Source<NavigationController>(controller));
WindowedLoadStopObserver load_stop_waiter(controller);
browser()->OpenURL(test_page, GURL(), CURRENT_TAB, PageTransition::TYPED);
load_stop_waiter.Wait();
EXPECT_TRUE(observer.handlers_.empty());
EXPECT_TRUE(test_server()->Stop());
}
// Test handling of resources that require authentication even though // Test handling of resources that require authentication even though
// the page they are included on doesn't. In this case we should only // the page they are included on doesn't. In this case we should only
// present the minimal number of prompts necessary for successfully // present the minimal number of prompts necessary for successfully
......
<html>
<link rel="prefetch" href="/auth-basic/resource.gif">
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment