Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <list> | 6 #include <list> |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/prerender/prerender_manager.h" | 12 #include "chrome/browser/prerender/prerender_manager.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_commands.h" | 14 #include "chrome/browser/ui/browser_commands.h" |
| 15 #include "chrome/browser/ui/login/login_prompt.h" | 15 #include "chrome/browser/ui/login/login_prompt.h" |
| 16 #include "chrome/browser/ui/login/login_prompt_test_utils.h" | 16 #include "chrome/browser/ui/login/login_prompt_test_utils.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/browser/interstitial_page.h" | 20 #include "content/public/browser/interstitial_page.h" |
| 21 #include "content/public/browser/navigation_entry.h" | |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/ssl_status.h" | |
| 24 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/test_navigation_observer.h" | 27 #include "content/public/test/test_navigation_observer.h" |
| 26 #include "net/base/auth.h" | 28 #include "net/base/auth.h" |
| 27 #include "net/dns/mock_host_resolver.h" | 29 #include "net/dns/mock_host_resolver.h" |
| 30 #include "net/test/spawned_test_server/spawned_test_server.h" | |
| 28 | 31 |
| 29 using content::NavigationController; | 32 using content::NavigationController; |
| 30 using content::OpenURLParams; | 33 using content::OpenURLParams; |
| 31 using content::Referrer; | 34 using content::Referrer; |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 class LoginPromptBrowserTest : public InProcessBrowserTest { | 38 class LoginPromptBrowserTest : public InProcessBrowserTest { |
| 36 public: | 39 public: |
| 37 LoginPromptBrowserTest() | 40 LoginPromptBrowserTest() |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 52 | 55 |
| 53 AuthInfo() {} | 56 AuthInfo() {} |
| 54 | 57 |
| 55 AuthInfo(const std::string& username, | 58 AuthInfo(const std::string& username, |
| 56 const std::string& password) | 59 const std::string& password) |
| 57 : username_(username), password_(password) {} | 60 : username_(username), password_(password) {} |
| 58 }; | 61 }; |
| 59 | 62 |
| 60 typedef std::map<std::string, AuthInfo> AuthMap; | 63 typedef std::map<std::string, AuthInfo> AuthMap; |
| 61 | 64 |
| 62 void SetAuthFor(LoginHandler* handler); | 65 void CheckSSLState(content::WebContents* contents, bool expect_broken) const; |
| 66 void SetAuthFor(LoginHandler* handler) const; | |
| 63 | 67 |
| 64 AuthMap auth_map_; | 68 AuthMap auth_map_; |
| 65 std::string bad_password_; | 69 std::string bad_password_; |
| 66 std::string bad_username_; | 70 std::string bad_username_; |
| 67 std::string password_; | 71 std::string password_; |
| 68 std::string username_basic_; | 72 std::string username_basic_; |
| 69 std::string username_digest_; | 73 std::string username_digest_; |
| 70 }; | 74 }; |
| 71 | 75 |
| 72 void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { | 76 void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) const { |
| 73 const net::AuthChallengeInfo* challenge = handler->auth_info(); | 77 const net::AuthChallengeInfo* challenge = handler->auth_info(); |
| 74 | 78 |
| 75 ASSERT_TRUE(challenge); | 79 ASSERT_TRUE(challenge); |
| 76 AuthMap::iterator i = auth_map_.find(challenge->realm); | 80 AuthMap::const_iterator i = auth_map_.find(challenge->realm); |
| 77 EXPECT_TRUE(auth_map_.end() != i); | 81 EXPECT_TRUE(auth_map_.end() != i); |
| 78 if (i != auth_map_.end()) { | 82 if (i != auth_map_.end()) { |
| 79 const AuthInfo& info = i->second; | 83 const AuthInfo& info = i->second; |
| 80 handler->SetAuth(base::UTF8ToUTF16(info.username_), | 84 handler->SetAuth(base::UTF8ToUTF16(info.username_), |
| 81 base::UTF8ToUTF16(info.password_)); | 85 base::UTF8ToUTF16(info.password_)); |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 89 void LoginPromptBrowserTest::CheckSSLState( | |
| 90 content::WebContents* contents, | |
| 91 bool expect_broken) const { | |
| 92 NavigationController* controller = &contents->GetController(); | |
| 93 content::NavigationEntry* entry = controller->GetVisibleEntry(); | |
| 94 const content::SSLStatus& ssl_status = entry->GetSSL(); | |
| 95 EXPECT_EQ(content::SSLStatus::NORMAL_CONTENT, ssl_status.content_status); | |
| 96 EXPECT_EQ(128, ssl_status.security_bits); | |
| 97 if (!expect_broken) { | |
| 98 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, ssl_status.security_style); | |
| 99 } else { | |
| 100 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN, | |
| 101 ssl_status.security_style); | |
| 102 } | |
| 103 } | |
| 104 | |
| 85 class InterstitialObserver : public content::WebContentsObserver { | 105 class InterstitialObserver : public content::WebContentsObserver { |
| 86 public: | 106 public: |
| 87 InterstitialObserver(content::WebContents* web_contents, | 107 InterstitialObserver(content::WebContents* web_contents, |
| 88 const base::Closure& attach_callback, | 108 const base::Closure& attach_callback, |
| 89 const base::Closure& detach_callback) | 109 const base::Closure& detach_callback) |
| 90 : WebContentsObserver(web_contents), | 110 : WebContentsObserver(web_contents), |
| 91 attach_callback_(attach_callback), | 111 attach_callback_(attach_callback), |
| 92 detach_callback_(detach_callback) { | 112 detach_callback_(detach_callback) { |
| 93 } | 113 } |
| 94 | 114 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 111 scoped_refptr<content::MessageLoopRunner> interstitial_attach_loop_runner( | 131 scoped_refptr<content::MessageLoopRunner> interstitial_attach_loop_runner( |
| 112 new content::MessageLoopRunner); | 132 new content::MessageLoopRunner); |
| 113 InterstitialObserver observer( | 133 InterstitialObserver observer( |
| 114 web_contents, | 134 web_contents, |
| 115 interstitial_attach_loop_runner->QuitClosure(), | 135 interstitial_attach_loop_runner->QuitClosure(), |
| 116 base::Closure()); | 136 base::Closure()); |
| 117 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) | 137 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) |
| 118 interstitial_attach_loop_runner->Run(); | 138 interstitial_attach_loop_runner->Run(); |
| 119 } | 139 } |
| 120 | 140 |
| 141 void CancelAndWaitForInterstitialDetach(LoginHandler* handler, | |
| 142 content::WebContents* contents) { | |
| 143 scoped_refptr<content::MessageLoopRunner> loop_runner( | |
| 144 new content::MessageLoopRunner); | |
| 145 InterstitialObserver interstitial_observer(contents, | |
| 146 base::Closure(), | |
| 147 loop_runner->QuitClosure()); | |
| 148 handler->CancelAuth(); | |
| 149 if (content::InterstitialPage::GetInterstitialPage(contents)) | |
| 150 loop_runner->Run(); | |
| 151 } | |
| 152 | |
| 121 const char kPrefetchAuthPage[] = "files/login/prefetch.html"; | 153 const char kPrefetchAuthPage[] = "files/login/prefetch.html"; |
| 122 | 154 |
| 123 const char kMultiRealmTestPage[] = "files/login/multi_realm.html"; | 155 const char kMultiRealmTestPage[] = "files/login/multi_realm.html"; |
| 124 const int kMultiRealmTestRealmCount = 2; | 156 const int kMultiRealmTestRealmCount = 2; |
| 125 | 157 |
| 126 const char kSingleRealmTestPage[] = "files/login/single_realm.html"; | 158 const char kSingleRealmTestPage[] = "files/login/single_realm.html"; |
| 127 | 159 |
| 128 const char* kAuthBasicPage = "auth-basic"; | 160 const char* kAuthBasicPage = "auth-basic"; |
| 129 const char* kAuthDigestPage = "auth-digest"; | 161 const char* kAuthDigestPage = "auth-digest"; |
| 130 | 162 |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1204 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); | 1236 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); |
| 1205 auth_needed_waiter.Wait(); | 1237 auth_needed_waiter.Wait(); |
| 1206 ASSERT_EQ(1u, observer.handlers().size()); | 1238 ASSERT_EQ(1u, observer.handlers().size()); |
| 1207 WaitForInterstitialAttach(contents); | 1239 WaitForInterstitialAttach(contents); |
| 1208 | 1240 |
| 1209 // The omnibox should show the correct origin for the new page when the | 1241 // The omnibox should show the correct origin for the new page when the |
| 1210 // login prompt is shown. | 1242 // login prompt is shown. |
| 1211 EXPECT_EQ("www.a.com", contents->GetURL().host()); | 1243 EXPECT_EQ("www.a.com", contents->GetURL().host()); |
| 1212 EXPECT_TRUE(contents->ShowingInterstitialPage()); | 1244 EXPECT_TRUE(contents->ShowingInterstitialPage()); |
| 1213 | 1245 |
| 1214 // Cancel and wait for the interstitial to detach. | 1246 CancelAndWaitForInterstitialDetach(*observer.handlers().begin(), contents); |
| 1215 LoginHandler* handler = *observer.handlers().begin(); | |
| 1216 scoped_refptr<content::MessageLoopRunner> loop_runner( | |
| 1217 new content::MessageLoopRunner); | |
| 1218 InterstitialObserver interstitial_observer(contents, | |
| 1219 base::Closure(), | |
| 1220 loop_runner->QuitClosure()); | |
| 1221 handler->CancelAuth(); | |
| 1222 if (content::InterstitialPage::GetInterstitialPage(contents)) | |
| 1223 loop_runner->Run(); | |
| 1224 EXPECT_EQ("www.a.com", contents->GetURL().host()); | 1247 EXPECT_EQ("www.a.com", contents->GetURL().host()); |
| 1225 EXPECT_FALSE(contents->ShowingInterstitialPage()); | 1248 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 1226 } | 1249 } |
| 1227 } | 1250 } |
| 1228 | 1251 |
| 1252 // Omnibox and connection tab should reflect the correct SSL State when login | |
| 1253 // prompt is displayed in the main frame. | |
| 1254 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, | |
| 1255 ShouldUpdateSSLStateOnMainFrameNavigation) { | |
| 1256 net::SpawnedTestServer https_server( | |
| 1257 net::SpawnedTestServer::TYPE_HTTPS, | |
| 1258 net::SpawnedTestServer::SSLOptions( | |
| 1259 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 1260 base::FilePath() | |
| 1261 ); | |
| 1262 ASSERT_TRUE(https_server.Start()); | |
| 1263 content::WebContents* contents = | |
| 1264 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1265 NavigationController* controller = &contents->GetController(); | |
| 1266 LoginPromptBrowserTestObserver observer; | |
| 1267 | |
| 1268 observer.Register(content::Source<NavigationController>(controller)); | |
| 1269 { | |
| 1270 GURL test_page = https_server.GetURL(kAuthBasicPage); | |
| 1271 ASSERT_EQ("127.0.0.1", test_page.host()); | |
| 1272 | |
| 1273 WindowedAuthNeededObserver auth_needed_waiter(controller); | |
| 1274 browser()->OpenURL(OpenURLParams( | |
| 1275 test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | |
| 1276 false)); | |
| 1277 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); | |
| 1278 auth_needed_waiter.Wait(); | |
| 1279 ASSERT_EQ(1u, observer.handlers().size()); | |
| 1280 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); | |
| 1281 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 1282 CheckSSLState(contents, false); | |
| 1283 | |
| 1284 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); | |
| 1285 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 1286 CheckSSLState(contents, false); | |
| 1287 } | |
| 1288 } | |
| 1289 | |
| 1290 // Omnibox and connection tab should reflect the correct SSL State when login | |
| 1291 // prompt is displayed with a blank login interstitial on cross origin | |
| 1292 // navigations. | |
| 1293 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, | |
| 1294 ShouldUpdateSSLStateOnCrossOriginMainFrameNavigation) { | |
| 1295 host_resolver()->AddRule("www.a.com", "127.0.0.1"); | |
| 1296 net::SpawnedTestServer https_server( | |
| 1297 net::SpawnedTestServer::TYPE_HTTPS, | |
| 1298 net::SpawnedTestServer::SSLOptions( | |
| 1299 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 1300 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")) | |
| 1301 ); | |
| 1302 ASSERT_TRUE(https_server.Start()); | |
| 1303 | |
| 1304 content::WebContents* contents = | |
| 1305 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1306 NavigationController* controller = &contents->GetController(); | |
| 1307 LoginPromptBrowserTestObserver observer; | |
| 1308 | |
| 1309 observer.Register(content::Source<NavigationController>(controller)); | |
| 1310 | |
| 1311 // Load a page which navigates to a cross origin page with a login prompt. | |
| 1312 { | |
| 1313 const char* kTestPage = "files/login/cross_origin.html"; | |
| 1314 GURL test_page = https_server.GetURL(kTestPage); | |
| 1315 ASSERT_EQ("127.0.0.1", test_page.host()); | |
| 1316 | |
| 1317 WindowedAuthNeededObserver auth_needed_waiter(controller); | |
| 1318 browser()->OpenURL(OpenURLParams( | |
| 1319 test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | |
| 1320 false)); | |
| 1321 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); | |
| 1322 // Wait for the broken SSL interstitial for https://www.a.com and proceed | |
| 1323 // through it. | |
| 1324 WaitForInterstitialAttach(contents); | |
| 1325 contents->GetInterstitialPage()->Proceed(); | |
| 1326 // The auth prompt should show with the blank login interstitial, and the | |
| 1327 // SSL status should be broken. | |
| 1328 auth_needed_waiter.Wait(); | |
| 1329 ASSERT_EQ(1u, observer.handlers().size()); | |
| 1330 WaitForInterstitialAttach(contents); | |
| 1331 CheckSSLState(contents, true); | |
| 1332 // The omnibox should show the correct origin for the new page when the | |
| 1333 // login prompt is shown. | |
| 1334 EXPECT_EQ("www.a.com", contents->GetURL().host()); | |
|
nasko
2014/07/24 09:32:34
nit: GetVisibleURL
Also, at this point we either
meacer
2014/07/24 17:32:32
Done.
| |
| 1335 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 1336 // Cancel and wait for the interstitial to detach. | |
| 1337 CancelAndWaitForInterstitialDetach(*observer.handlers().begin(), contents); | |
| 1338 EXPECT_EQ("www.a.com", contents->GetURL().host()); | |
|
nasko
2014/07/24 09:32:33
nit: GetVisibleURL
Here we should have the LastCo
meacer
2014/07/24 17:32:32
Done.
| |
| 1339 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 1340 CheckSSLState(contents, true); | |
| 1341 } | |
| 1342 } | |
| 1343 | |
| 1229 } // namespace | 1344 } // namespace |
| OLD | NEW |