login_prompt_browsertest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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) 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/login/login_prompt.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_notification_types.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/dns/mock_host_resolver.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationController; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::OpenURLParams; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::Referrer; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LoginPromptBrowserTest : public InProcessBrowserTest { 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTest() 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : bad_password_("incorrect"), 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bad_username_("nouser"), 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) password_("secret"), 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) username_basic_("basicuser"), 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) username_digest_("digestuser") { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_map_["foo"] = AuthInfo("testuser", "foopassword"); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_map_["bar"] = AuthInfo("testuser", "barpassword"); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_map_["testrealm"] = AuthInfo(username_basic_, password_); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct AuthInfo { 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string username_; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string password_; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthInfo() {} 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthInfo(const std::string username, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string password) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : username_(username), password_(password) {} 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::map<std::string, AuthInfo> AuthMap; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetAuthFor(LoginHandler* handler); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthMap auth_map_; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string bad_password_; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string bad_username_; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string password_; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string username_basic_; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string username_digest_; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const net::AuthChallengeInfo* challenge = handler->auth_info(); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(challenge); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthMap::iterator i = auth_map_.find(challenge->realm); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(auth_map_.end() != i); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (i != auth_map_.end()) { 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const AuthInfo& info = i->second; 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(info.username_), 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(info.password_)); 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Maintains a set of LoginHandlers that are currently active and 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// keeps a count of the notifications that were observed. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LoginPromptBrowserTestObserver : public content::NotificationObserver { 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver() 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : auth_needed_count_(0), 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_count_(0), 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_count_(0) {} 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddHandler(LoginHandler* handler); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveHandler(LoginHandler* handler); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Register(const content::NotificationSource& source); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<LoginHandler*> handlers_; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The exact number of notifications we receive is depedent on the 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // number of requests that were dispatched and is subject to a 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // number of factors that we don't directly control here. The 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // values below should only be used qualitatively. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int auth_needed_count_; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int auth_supplied_count_; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int auth_cancelled_count_; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationRegistrar registrar_; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(LoginPromptBrowserTestObserver); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::Observe( 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int type, 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) { 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type == chrome::NOTIFICATION_AUTH_NEEDED) { 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginNotificationDetails* login_details = 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Details<LoginNotificationDetails>(details).ptr(); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddHandler(login_details->handler()); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_count_++; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) { 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthSuppliedLoginNotificationDetails* login_details = 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RemoveHandler(login_details->handler()); 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_count_++; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (type == chrome::NOTIFICATION_AUTH_CANCELLED) { 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginNotificationDetails* login_details = 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Details<LoginNotificationDetails>(details).ptr(); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RemoveHandler(login_details->handler()); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_count_++; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) { 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.end(), 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler); 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(i == handlers_.end()); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (i == handlers_.end()) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.push_back(handler); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::RemoveHandler(LoginHandler* handler) { 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<LoginHandler*>::iterator i = std::find(handlers_.begin(), 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.end(), 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(i != handlers_.end()); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (i != handlers_.end()) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handlers_.erase(i); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LoginPromptBrowserTestObserver::Register( 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source) { 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) registrar_.Add(this, chrome::NOTIFICATION_AUTH_NEEDED, source); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, source); 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, source); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <int T> 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowedNavigationObserver 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public content::WindowedNotificationObserver { 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit WindowedNavigationObserver(NavigationController* controller) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : content::WindowedNotificationObserver( 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) T, content::Source<NavigationController>(controller)) {} 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LOAD_STOP observer is special since we want to be able to wait for 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// multiple LOAD_STOP events. 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowedLoadStopObserver 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP> { 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver(NavigationController* controller, 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int notification_count) 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP>(controller), 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) remaining_notification_count_(notification_count) {} 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int remaining_notification_count_; // Number of notifications remaining. 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WindowedLoadStopObserver::Observe( 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int type, 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) { 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (--remaining_notification_count_ == 0) 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedNotificationObserver::Observe(type, source, details); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_NEEDED> 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver; 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_CANCELLED> 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver; 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_SUPPLIED> 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver; 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kPrefetchAuthPage = "files/login/prefetch.html"; 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kMultiRealmTestPage = "files/login/multi_realm.html"; 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kMultiRealmTestRealmCount = 2; 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kMultiRealmTestResourceCount = 4; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kSingleRealmTestPage = "files/login/single_realm.html"; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kSingleRealmTestResourceCount = 6; 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kAuthBasicPage = "auth-basic"; 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kAuthDigestPage = "auth-digest"; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)string16 ExpectedTitleFromAuth(const string16& username, 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& password) { 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The TestServer sets the title to username/password on successful login. 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return username + UTF8ToUTF16("/") + password; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Confirm that <link rel="prefetch"> targetting an auth required 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// resource does not provide a login dialog. These types of requests 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// should instead just cancel the auth. 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Unfortunately, this test doesn't assert on anything for its 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// correctness. Instead, it relies on the auth dialog blocking the 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// browser, and triggering a timeout to cause failure when the 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// prefetch resource requires authorization. 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, PrefetchAuthCancels) { 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kPrefetchAuthPage); 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class SetPrefetchForTest { 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit SetPrefetchForTest(bool prefetch) 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : old_prefetch_state_(prerender::PrerenderManager::IsPrefetchEnabled()), 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) old_mode_(prerender::PrerenderManager::GetMode()) { 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::SetIsPrefetchEnabled(prefetch); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Disable prerender so this is just a prefetch of the top-level page. 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::SetMode( 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::PRERENDER_MODE_DISABLED); 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~SetPrefetchForTest() { 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::SetIsPrefetchEnabled(old_prefetch_state_); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::SetMode(old_mode_); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool old_prefetch_state_; 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prerender::PrerenderManager::PrerenderManagerMode old_mode_; 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } set_prefetch_for_test(true); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that "Basic" HTTP authentication works. 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestBasicAuth) { 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kAuthBasicPage); 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_FALSE(observer.handlers_.empty()); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(bad_username_), UTF8ToUTF16(bad_password_)); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request should be retried after the incorrect password is 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied. This should result in a new AUTH_NEEDED notification 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same realm. 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 expected_title = 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExpectedTitleFromAuth(ASCIIToUTF16("basicuser"), ASCIIToUTF16("secret")); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher(contents, expected_title); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that "Digest" HTTP authentication works. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestDigestAuth) { 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kAuthDigestPage); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_FALSE(observer.handlers_.empty()); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(bad_username_), UTF8ToUTF16(bad_password_)); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request should be retried after the incorrect password is 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied. This should result in a new AUTH_NEEDED notification 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same realm. 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 username(UTF8ToUTF16(username_digest_)); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 password(UTF8ToUTF16(password_)); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(username, password); 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 expected_title = ExpectedTitleFromAuth(username, password); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher(contents, expected_title); 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestTwoAuths) { 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents1 = 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller1 = &contents1->GetController(); 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller1)); 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open a new tab. 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("about:blank"), 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEW_FOREGROUND_TAB, 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents2 = 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents1, contents2); 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller2 = &contents2->GetController(); 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller2)); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller1); 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents1->OpenURL(OpenURLParams( 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL(kAuthBasicPage), Referrer(), 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller2); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents2->OpenURL(OpenURLParams( 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL(kAuthDigestPage), Referrer(), 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(2u, observer.handlers_.size()); 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler1 = *observer.handlers_.begin(); 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler2 = *(++(observer.handlers_.begin())); 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 expected_title1 = ExpectedTitleFromAuth( 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_)); 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 expected_title2 = ExpectedTitleFromAuth( 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_)); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher1(contents1, expected_title1); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher2(contents2, expected_title2); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler1->SetAuth(UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_)); 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler2->SetAuth(UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_)); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test login prompt cancellation. 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth) { 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL auth_page = test_server()->GetURL(kAuthBasicPage); 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL no_auth_page_1 = test_server()->GetURL("a"); 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL no_auth_page_2 = test_server()->GetURL("b"); 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL no_auth_page_3 = test_server()->GetURL("c"); 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First navigate to an unauthenticated page so we have something to 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // go back to. 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL(browser(), no_auth_page_1); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigating while auth is requested is the same as cancelling. 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We need to wait for two LOAD_STOP events. One for auth_page and one for 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no_auth_page_2. 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 2); 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) false)); 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) no_auth_page_2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try navigating backwards. 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // As above, we wait for two LOAD_STOP events; one for each navigation. 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 2); 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(chrome::CanGoBack(browser())); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::GoBack(browser(), CURRENT_TAB); 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now add a page and go back, so we have something to go forward to. 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL(browser(), no_auth_page_3); 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::GoBack(browser(), CURRENT_TAB); // Should take us to page 1 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We wait for two LOAD_STOP events; one for each navigation. 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 2); 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(chrome::CanGoForward(browser())); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::GoForward(browser(), CURRENT_TAB); // Should take us to page 3 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now test that cancelling works as expected. 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(observer.handlers_.empty()); 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test handling of resources that require authentication even though 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the page they are included on doesn't. In this case we should only 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// present the minimal number of prompts necessary for successfully 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// displaying the page. First we check whether cancelling works as 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// expected. 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int n_handlers = 0; 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (n_handlers < kMultiRealmTestRealmCount) { 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) n_handlers++; 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (n_handlers < kMultiRealmTestRealmCount) 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_supplied_count_); 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_needed_count_); 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_cancelled_count_); 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Similar to the MultipleRealmCancellation test above, but tests 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// whether supplying credentials work as exepcted. 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) { 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kMultiRealmTestPage); 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int n_handlers = 0; 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (n_handlers < kMultiRealmTestRealmCount) { 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) n_handlers++; 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (n_handlers < kMultiRealmTestRealmCount) 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_needed_count_); 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_supplied_count_); 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Testing for recovery from an incorrect password for the case where 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// there are multiple authenticated resources. 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kSingleRealmTestPage); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(observer.handlers_.empty()); 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!observer.handlers_.empty()) { 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->SetAuth(UTF8ToUTF16(bad_username_), 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(bad_password_)); 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request should be retried after the incorrect password is 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied. This should result in a new AUTH_NEEDED notification 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same realm. 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int n_handlers = 0; 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (n_handlers < 1) { 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) n_handlers++; 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (n_handlers < 1) 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The single realm test has only one realm, and thus only one login 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // prompt. 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, n_handlers); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(0, observer.auth_needed_count_); 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(observer.auth_needed_count_, observer.auth_supplied_count_); 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the favicon is an authenticated resource, we shouldn't prompt 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for credentials. The same URL, if requested elsewhere should 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// prompt for credentials. 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, NoLoginPromptForFavicon) { 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* kFaviconTestPage = "files/login/has_favicon.html"; 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* kFaviconResource = "auth-basic/favicon.gif"; 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First load a page that has a favicon that requires 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // authentication. There should be no login prompt. 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kFaviconTestPage); 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now request the same favicon, but directly as the document. 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should be one login prompt. 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kFaviconResource); 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_supplied_count_); 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_needed_count_); 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_cancelled_count_); 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Block crossdomain subresource login prompting as a phishing defense. 7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Disabled per http://crbug.com/174179. 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISABLED_BlockCrossdomainPrompt) { 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* kTestPage = "files/login/load_img_from_b.html"; 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host_resolver()->AddRule("www.a.com", "127.0.0.1"); 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host_resolver()->AddRule("www.b.com", "127.0.0.1"); 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load a page that has a cross-domain sub-resource authentication. 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should be no login prompt. 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kTestPage); 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ("127.0.0.1", test_page.host()); 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change the host from 127.0.0.1 to www.a.com so that when the 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // page tries to load from b, it will be cross-origin. 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string new_host("www.a.com"); 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL::Replacements replacements; 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) replacements.SetHostStr(new_host); 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page = test_page.ReplaceComponents(replacements); 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedLoadStopObserver load_stop_waiter(controller, 1); 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_stop_waiter.Wait(); 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_needed_count_); 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now request the same page, but from the same origin. 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should be one login prompt. 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL test_page = test_server()->GetURL(kTestPage); 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ("127.0.0.1", test_page.host()); 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change the host from 127.0.0.1 to www.b.com so that when the 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // page tries to load from b, it will be same-origin. 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string new_host("www.b.com"); 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL::Replacements replacements; 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) replacements.SetHostStr(new_host); 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page = test_page.ReplaceComponents(replacements); 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(OpenURLParams( 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, observer.handlers_.size()); 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (!observer.handlers_.empty()) { 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler->CancelAuth(); 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter.Wait(); 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_needed_count_); 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, SupplyRedundantAuths) { 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 1. 8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_1 = 8332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_1 = &contents_1->GetController(); 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open a new tab. 8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("about:blank"), 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEW_FOREGROUND_TAB, 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 2. 8442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_2 = 8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents_1, contents_2); 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_2 = &contents_2->GetController(); 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_1)); 8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_2)); 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open different auth urls in each tab. 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_1(controller_1); 8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_2(controller_2); 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_1->OpenURL(OpenURLParams( 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/1"), 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_2->OpenURL(OpenURLParams( 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/2"), 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_1.Wait(); 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_2.Wait(); 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(2U, observer.handlers_.size()); 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Supply auth in one of the tabs. 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter_1(controller_1); 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter_2(controller_2); 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler_1 = *observer.handlers_.begin(); 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler_1); 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler_1); 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Both tabs should be authenticated. 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter_1.Wait(); 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter_2.Wait(); 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_needed_count_); 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_supplied_count_); 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, CancelRedundantAuths) { 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 1. 8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_1 = 8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_1 = &contents_1->GetController(); 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open a new tab. 9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("about:blank"), 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEW_FOREGROUND_TAB, 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for tab 2. 9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents_2 = 9092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents_1, contents_2); 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_2 = &contents_2->GetController(); 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_1)); 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller_2)); 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open different auth urls in each tab. 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_1(controller_1); 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_2(controller_2); 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_1->OpenURL(OpenURLParams( 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/1"), 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_2->OpenURL(OpenURLParams( 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/2"), 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_1.Wait(); 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_2.Wait(); 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(2U, observer.handlers_.size()); 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancel auth in one of the tabs. 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter_1(controller_1); 9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthCancelledObserver auth_cancelled_waiter_2(controller_2); 9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler_1 = *observer.handlers_.begin(); 9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler_1); 9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) handler_1->CancelAuth(); 9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Both tabs should cancel auth. 9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter_1.Wait(); 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_cancelled_waiter_2.Wait(); 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_needed_count_); 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_supplied_count_); 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, observer.auth_cancelled_count_); 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SupplyRedundantAuthsMultiProfile) { 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for regular tab. 9612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents = 9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller = &contents->GetController(); 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open an incognito window. 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Browser* browser_incognito = CreateIncognitoBrowser(); 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get NavigationController for incognito tab. 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* contents_incognito = 9702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_incognito->tab_strip_model()->GetActiveWebContents(); 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_NE(contents, contents_incognito); 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController* controller_incognito = 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &contents_incognito->GetController(); 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer; 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Register(content::Source<NavigationController>(controller)); 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginPromptBrowserTestObserver observer_incognito; 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_incognito.Register( 9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Source<NavigationController>(controller_incognito)); 9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Open an auth url in each window. 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter(controller); 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthNeededObserver auth_needed_waiter_incognito( 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller_incognito); 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents->OpenURL(OpenURLParams( 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/1"), 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_incognito->OpenURL(OpenURLParams( 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic/2"), 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Referrer(), 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_TAB, 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false)); 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter.Wait(); 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_needed_waiter_incognito.Wait(); 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1U, observer.handlers_.size()); 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1U, observer_incognito.handlers_.size()); 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Supply auth in regular tab. 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowedAuthSuppliedObserver auth_supplied_waiter(controller); 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginHandler* handler = *observer.handlers_.begin(); 10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(handler); 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAuthFor(handler); 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Regular tab should be authenticated. 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auth_supplied_waiter.Wait(); 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There's not really a way to wait for the incognito window to "do 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nothing". Run anything pending in the message loop just to be sure. 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (This shouldn't be necessary since notifications are synchronous, but 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // maybe it will help avoid flake someday in the future..) 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_needed_count_); 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer.auth_supplied_count_); 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer.auth_cancelled_count_); 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_incognito.auth_needed_count_); 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_incognito.auth_supplied_count_); 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_incognito.auth_cancelled_count_); 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(test_server()->Stop()); 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1030