15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list> 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)#include "base/metrics/field_trial.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/login/login_prompt.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/dns/mock_host_resolver.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationController; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::OpenURLParams; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::Referrer; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LoginPromptBrowserTest : public InProcessBrowserTest { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTest() 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : bad_password_("incorrect"), 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bad_username_("nouser"), 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) password_("secret"), 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) username_basic_("basicuser"), 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) username_digest_("digestuser") { 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_map_["foo"] = AuthInfo("testuser", "foopassword"); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_map_["bar"] = AuthInfo("testuser", "barpassword"); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_map_["testrealm"] = AuthInfo(username_basic_, password_); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct AuthInfo { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string username_; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string password_; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthInfo() {} 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) AuthInfo(const std::string& username, 533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& password) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : username_(username), password_(password) {} 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::map<std::string, AuthInfo> AuthMap; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetAuthFor(LoginHandler* handler); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthMap auth_map_; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string bad_password_; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string bad_username_; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string password_; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string username_basic_; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string username_digest_; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const net::AuthChallengeInfo* challenge = handler->auth_info(); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(challenge); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthMap::iterator i = auth_map_.find(challenge->realm); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(auth_map_.end() != i); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (i != auth_map_.end()) { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const AuthInfo& info = i->second; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(info.username_), 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(info.password_)); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Maintains a set of LoginHandlers that are currently active and 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// keeps a count of the notifications that were observed. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LoginPromptBrowserTestObserver : public content::NotificationObserver { 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver() 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : auth_needed_count_(0), 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_count_(0), 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_count_(0) {} 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddHandler(LoginHandler* handler); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveHandler(LoginHandler* handler); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Register(const content::NotificationSource& source); 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<LoginHandler*> handlers_; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The exact number of notifications we receive is depedent on the 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // number of requests that were dispatched and is subject to a 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // number of factors that we don't directly control here. The 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // values below should only be used qualitatively. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int auth_needed_count_; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int auth_supplied_count_; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int auth_cancelled_count_; 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationRegistrar registrar_; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(LoginPromptBrowserTestObserver); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::Observe( 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int type, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) { 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type == chrome::NOTIFICATION_AUTH_NEEDED) { 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginNotificationDetails* login_details = 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Details<LoginNotificationDetails>(details).ptr(); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddHandler(login_details->handler()); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_count_++; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) { 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthSuppliedLoginNotificationDetails* login_details = 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RemoveHandler(login_details->handler()); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_count_++; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (type == chrome::NOTIFICATION_AUTH_CANCELLED) { 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginNotificationDetails* login_details = 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Details<LoginNotificationDetails>(details).ptr(); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RemoveHandler(login_details->handler()); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_count_++; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) { 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.end(), 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(i == handlers_.end()); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (i == handlers_.end()) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.push_back(handler); 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::RemoveHandler(LoginHandler* handler) { 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.end(), 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(i != handlers_.end()); 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (i != handlers_.end()) 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.erase(i); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::Register( 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source) { 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) registrar_.Add(this, chrome::NOTIFICATION_AUTH_NEEDED, source); 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, source); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, source); 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <int T> 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowedNavigationObserver 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public content::WindowedNotificationObserver { 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit WindowedNavigationObserver(NavigationController* controller) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : content::WindowedNotificationObserver( 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) T, content::Source<NavigationController>(controller)) {} 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LOAD_STOP observer is special since we want to be able to wait for 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// multiple LOAD_STOP events. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowedLoadStopObserver 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP> { 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver(NavigationController* controller, 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int notification_count) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP>(controller), 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) remaining_notification_count_(notification_count) {} 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int remaining_notification_count_; // Number of notifications remaining. 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WindowedLoadStopObserver::Observe( 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int type, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) { 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (--remaining_notification_count_ == 0) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedNotificationObserver::Observe(type, source, details); 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_NEEDED> 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver; 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_CANCELLED> 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver; 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_SUPPLIED> 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 20768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kPrefetchAuthPage[] = "files/login/prefetch.html"; 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 20968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kMultiRealmTestPage[] = "files/login/multi_realm.html"; 21068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const int kMultiRealmTestRealmCount = 2; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kSingleRealmTestPage[] = "files/login/single_realm.html"; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kAuthBasicPage = "auth-basic"; 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kAuthDigestPage = "auth-digest"; 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 217d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)base::string16 ExpectedTitleFromAuth(const base::string16& username, 218d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) const base::string16& password) { 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The TestServer sets the title to username/password on successful login. 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return username + UTF8ToUTF16("/") + password; 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Confirm that <link rel="prefetch"> targetting an auth required 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// resource does not provide a login dialog. These types of requests 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// should instead just cancel the auth. 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Unfortunately, this test doesn't assert on anything for its 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// correctness. Instead, it relies on the auth dialog blocking the 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// browser, and triggering a timeout to cause failure when the 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// prefetch resource requires authorization. 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) { 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kPrefetchAuthPage); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class SetPrefetchForTest { 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit SetPrefetchForTest(bool prefetch) 239d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) : old_prerender_mode_(prerender::PrerenderManager::GetMode()) { 240d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) std::string exp_group = prefetch ? "ExperimentYes" : "ExperimentNo"; 241d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) base::FieldTrialList::CreateFieldTrial("Prefetch", exp_group); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Disable prerender so this is just a prefetch of the top-level page. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::SetMode( 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::PRERENDER_MODE_DISABLED); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~SetPrefetchForTest() { 248d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) prerender::PrerenderManager::SetMode(old_prerender_mode_); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 250d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 252d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) prerender::PrerenderManager::PrerenderManagerMode old_prerender_mode_; 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } set_prefetch_for_test(true); 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that "Basic" HTTP authentication works. 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestBasicAuth) { 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kAuthBasicPage); 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_FALSE(observer.handlers_.empty()); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(bad_username_), UTF8ToUTF16(bad_password_)); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request should be retried after the incorrect password is 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied. This should result in a new AUTH_NEEDED notification 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same realm. 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 314a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_title = 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExpectedTitleFromAuth(ASCIIToUTF16("basicuser"), ASCIIToUTF16("secret")); 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher(contents, expected_title); 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that "Digest" HTTP authentication works. 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestDigestAuth) { 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kAuthDigestPage); 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_FALSE(observer.handlers_.empty()); 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(bad_username_), UTF8ToUTF16(bad_password_)); 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request should be retried after the incorrect password is 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied. This should result in a new AUTH_NEEDED notification 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same realm. 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 username(UTF8ToUTF16(username_digest_)); 361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 password(UTF8ToUTF16(password_)); 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(username, password); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_title = ExpectedTitleFromAuth(username, password); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher(contents, expected_title); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestTwoAuths) { 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents1 = 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller1 = &contents1->GetController(); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller1)); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open a new tab. 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("about:blank"), 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEW_FOREGROUND_TAB, 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents2 = 3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents1, contents2); 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller2 = &contents2->GetController(); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller2)); 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller1); 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents1->OpenURL(OpenURLParams( 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL(kAuthBasicPage), Referrer(), 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller2); 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents2->OpenURL(OpenURLParams( 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL(kAuthDigestPage), Referrer(), 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(2u, observer.handlers_.size()); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler1 = *observer.handlers_.begin(); 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler2 = *(++(observer.handlers_.begin())); 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 414a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_title1 = ExpectedTitleFromAuth( 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_)); 416a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_title2 = ExpectedTitleFromAuth( 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_)); 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher1(contents1, expected_title1); 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher2(contents2, expected_title2); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler1->SetAuth(UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_)); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler2->SetAuth(UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_)); 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test login prompt cancellation. 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth) { 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL auth_page = test_server()->GetURL(kAuthBasicPage); 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL no_auth_page_1 = test_server()->GetURL("a"); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL no_auth_page_2 = test_server()->GetURL("b"); 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL no_auth_page_3 = test_server()->GetURL("c"); 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First navigate to an unauthenticated page so we have something to 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // go back to. 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL(browser(), no_auth_page_1); 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigating while auth is requested is the same as cancelling. 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We need to wait for two LOAD_STOP events. One for auth_page and one for 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no_auth_page_2. 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 2); 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) false)); 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) no_auth_page_2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try navigating backwards. 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // As above, we wait for two LOAD_STOP events; one for each navigation. 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 2); 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(chrome::CanGoBack(browser())); 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::GoBack(browser(), CURRENT_TAB); 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now add a page and go back, so we have something to go forward to. 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL(browser(), no_auth_page_3); 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::GoBack(browser(), CURRENT_TAB); // Should take us to page 1 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We wait for two LOAD_STOP events; one for each navigation. 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 2); 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(chrome::CanGoForward(browser())); 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::GoForward(browser(), CURRENT_TAB); // Should take us to page 3 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now test that cancelling works as expected. 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test handling of resources that require authentication even though 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the page they are included on doesn't. In this case we should only 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// present the minimal number of prompts necessary for successfully 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// displaying the page. First we check whether cancelling works as 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// expected. 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int n_handlers = 0; 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (n_handlers < kMultiRealmTestRealmCount) { 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) n_handlers++; 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (n_handlers < kMultiRealmTestRealmCount) 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_supplied_count_); 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_needed_count_); 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_cancelled_count_); 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Similar to the MultipleRealmCancellation test above, but tests 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// whether supplying credentials work as exepcted. 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) { 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int n_handlers = 0; 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (n_handlers < kMultiRealmTestRealmCount) { 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) n_handlers++; 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (n_handlers < kMultiRealmTestRealmCount) 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_needed_count_); 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_supplied_count_); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Testing for recovery from an incorrect password for the case where 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// there are multiple authenticated resources. 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kSingleRealmTestPage); 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(observer.handlers_.empty()); 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!observer.handlers_.empty()) { 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(bad_username_), 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(bad_password_)); 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request should be retried after the incorrect password is 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied. This should result in a new AUTH_NEEDED notification 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same realm. 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int n_handlers = 0; 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (n_handlers < 1) { 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) n_handlers++; 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (n_handlers < 1) 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The single realm test has only one realm, and thus only one login 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // prompt. 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, n_handlers); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_needed_count_); 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the favicon is an authenticated resource, we shouldn't prompt 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for credentials. The same URL, if requested elsewhere should 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// prompt for credentials. 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, NoLoginPromptForFavicon) { 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* kFaviconTestPage = "files/login/has_favicon.html"; 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* kFaviconResource = "auth-basic/favicon.gif"; 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First load a page that has a favicon that requires 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // authentication. There should be no login prompt. 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kFaviconTestPage); 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now request the same favicon, but directly as the document. 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should be one login prompt. 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kFaviconResource); 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_supplied_count_); 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_needed_count_); 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_cancelled_count_); 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 754eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Block crossdomain image login prompting as a phishing defense. 7552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 756eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch BlockCrossdomainPrompt) { 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* kTestPage = "files/login/load_img_from_b.html"; 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host_resolver()->AddRule("www.a.com", "127.0.0.1"); 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host_resolver()->AddRule("www.b.com", "127.0.0.1"); 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load a page that has a cross-domain sub-resource authentication. 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should be no login prompt. 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kTestPage); 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ("127.0.0.1", test_page.host()); 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change the host from 127.0.0.1 to www.a.com so that when the 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // page tries to load from b, it will be cross-origin. 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string new_host("www.a.com"); 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL::Replacements replacements; 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) replacements.SetHostStr(new_host); 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page = test_page.ReplaceComponents(replacements); 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_needed_count_); 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now request the same page, but from the same origin. 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should be one login prompt. 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kTestPage); 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ("127.0.0.1", test_page.host()); 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change the host from 127.0.0.1 to www.b.com so that when the 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // page tries to load from b, it will be same-origin. 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string new_host("www.b.com"); 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL::Replacements replacements; 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) replacements.SetHostStr(new_host); 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page = test_page.ReplaceComponents(replacements); 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_needed_count_); 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Allow crossdomain iframe login prompting despite the above. 826eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochIN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 827eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AllowCrossdomainPrompt) { 828eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const char* kTestPage = "files/login/load_iframe_from_b.html"; 829eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 830eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch host_resolver()->AddRule("www.a.com", "127.0.0.1"); 831eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch host_resolver()->AddRule("www.b.com", "127.0.0.1"); 832eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(test_server()->Start()); 833eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 834eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content::WebContents* contents = 835eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch browser()->tab_strip_model()->GetActiveWebContents(); 836eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch NavigationController* controller = &contents->GetController(); 837eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LoginPromptBrowserTestObserver observer; 838eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.Register(content::Source<NavigationController>(controller)); 839eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 840eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Load a page that has a cross-domain iframe authentication. 841eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch { 842eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL test_page = test_server()->GetURL(kTestPage); 843eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_EQ("127.0.0.1", test_page.host()); 844eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 845eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Change the host from 127.0.0.1 to www.a.com so that when the 846eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // page tries to load from b, it will be cross-origin. 847eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string new_host("www.a.com"); 848eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL::Replacements replacements; 849eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch replacements.SetHostStr(new_host); 850eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test_page = test_page.ReplaceComponents(replacements); 851eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 852eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WindowedAuthNeededObserver auth_needed_waiter(controller); 853eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch browser()->OpenURL(OpenURLParams( 854eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 855eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch false)); 856eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch auth_needed_waiter.Wait(); 857eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_EQ(1u, observer.handlers_.size()); 858eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 859eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch while (!observer.handlers_.empty()) { 860eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 861eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LoginHandler* handler = *observer.handlers_.begin(); 862eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 863eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(handler); 864eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch handler->CancelAuth(); 865eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch auth_cancelled_waiter.Wait(); 866eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 867eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 868eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 869eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(1, observer.auth_needed_count_); 870eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(test_server()->Stop()); 871eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 872eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, SupplyRedundantAuths) { 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 1. 8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_1 = 8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_1 = &contents_1->GetController(); 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open a new tab. 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("about:blank"), 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEW_FOREGROUND_TAB, 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 2. 8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_2 = 8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents_1, contents_2); 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_2 = &contents_2->GetController(); 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_1)); 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_2)); 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open different auth urls in each tab. 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_1(controller_1); 9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_2(controller_2); 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_1->OpenURL(OpenURLParams( 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/1"), 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_2->OpenURL(OpenURLParams( 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/2"), 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_1.Wait(); 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_2.Wait(); 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(2U, observer.handlers_.size()); 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Supply auth in one of the tabs. 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter_1(controller_1); 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter_2(controller_2); 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler_1 = *observer.handlers_.begin(); 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler_1); 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler_1); 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Both tabs should be authenticated. 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter_1.Wait(); 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter_2.Wait(); 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_needed_count_); 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_supplied_count_); 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, CancelRedundantAuths) { 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 1. 9412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_1 = 9422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_1 = &contents_1->GetController(); 9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open a new tab. 9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("about:blank"), 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEW_FOREGROUND_TAB, 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 2. 9532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_2 = 9542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents_1, contents_2); 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_2 = &contents_2->GetController(); 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_1)); 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_2)); 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open different auth urls in each tab. 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_1(controller_1); 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_2(controller_2); 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_1->OpenURL(OpenURLParams( 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/1"), 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_2->OpenURL(OpenURLParams( 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/2"), 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_1.Wait(); 9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_2.Wait(); 9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(2U, observer.handlers_.size()); 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancel auth in one of the tabs. 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter_1(controller_1); 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter_2(controller_2); 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler_1 = *observer.handlers_.begin(); 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler_1); 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler_1->CancelAuth(); 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Both tabs should cancel auth. 9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter_1.Wait(); 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter_2.Wait(); 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_needed_count_); 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_supplied_count_); 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_cancelled_count_); 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SupplyRedundantAuthsMultiProfile) { 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for regular tab. 10062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 10072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open an incognito window. 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Browser* browser_incognito = CreateIncognitoBrowser(); 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for incognito tab. 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* contents_incognito = 10152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_incognito->tab_strip_model()->GetActiveWebContents(); 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents, contents_incognito); 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_incognito = 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &contents_incognito->GetController(); 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer_incognito; 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_incognito.Register( 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Source<NavigationController>(controller_incognito)); 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open an auth url in each window. 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_incognito( 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller_incognito); 10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents->OpenURL(OpenURLParams( 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/1"), 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_incognito->OpenURL(OpenURLParams( 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/2"), 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_incognito.Wait(); 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1U, observer.handlers_.size()); 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1U, observer_incognito.handlers_.size()); 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Supply auth in regular tab. 10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Regular tab should be authenticated. 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There's not really a way to wait for the incognito window to "do 10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nothing". Run anything pending in the message loop just to be sure. 10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (This shouldn't be necessary since notifications are synchronous, but 10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // maybe it will help avoid flake someday in the future..) 10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_needed_count_); 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_supplied_count_); 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_incognito.auth_needed_count_); 10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_incognito.auth_supplied_count_); 10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_incognito.auth_cancelled_count_); 10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1075