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

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

Issue 938713003: Login interstitial should always replace existing interstitials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: creis comment Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/login/login_prompt.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ssl/ssl_blocking_page.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/login/login_interstitial_delegate.h" 16 #include "chrome/browser/ui/login/login_interstitial_delegate.h"
16 #include "chrome/browser/ui/login/login_prompt.h" 17 #include "chrome/browser/ui/login/login_prompt.h"
17 #include "chrome/browser/ui/login/login_prompt_test_utils.h" 18 #include "chrome/browser/ui/login/login_prompt_test_utils.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/interstitial_page.h" 22 #include "content/public/browser/interstitial_page.h"
22 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 1206 host_resolver()->AddRule("www.a.com", "127.0.0.1");
1206 ASSERT_TRUE(test_server()->Start()); 1207 ASSERT_TRUE(test_server()->Start());
1207 1208
1208 const char* kTestPage = "files/login/cross_origin.html"; 1209 const char* kTestPage = "files/login/cross_origin.html";
1209 GURL test_page = test_server()->GetURL(kTestPage); 1210 GURL test_page = test_server()->GetURL(kTestPage);
1210 ASSERT_EQ("127.0.0.1", test_page.host()); 1211 ASSERT_EQ("127.0.0.1", test_page.host());
1211 std::string auth_host("www.a.com"); 1212 std::string auth_host("www.a.com");
1212 TestCrossOriginPrompt(test_page, auth_host); 1213 TestCrossOriginPrompt(test_page, auth_host);
1213 } 1214 }
1214 1215
1216 // Test the scenario where proceeding through a different type of interstitial
1217 // that ends up with an auth URL works fine. This can happen if a URL that
1218 // triggers the auth dialog can also trigger an SSL interstitial (or any other
1219 // type of interstitial).
1215 IN_PROC_BROWSER_TEST_F( 1220 IN_PROC_BROWSER_TEST_F(
1216 LoginPromptBrowserTest, 1221 LoginPromptBrowserTest,
1217 DISABLED_LoginInterstitialShouldReplaceExistingInterstitial) { 1222 DISABLED_LoginInterstitialShouldReplaceExistingInterstitial) {
1218 net::SpawnedTestServer https_server( 1223 net::SpawnedTestServer https_server(
1219 net::SpawnedTestServer::TYPE_HTTPS, 1224 net::SpawnedTestServer::TYPE_HTTPS,
1220 net::SpawnedTestServer::SSLOptions( 1225 net::SpawnedTestServer::SSLOptions(
1221 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED), 1226 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED),
1222 base::FilePath()); 1227 base::FilePath());
1223 ASSERT_TRUE(https_server.Start()); 1228 ASSERT_TRUE(https_server.Start());
1224 1229
(...skipping 10 matching lines...) Expand all
1235 GURL test_page = https_server.GetURL(kAuthBasicPage); 1240 GURL test_page = https_server.GetURL(kAuthBasicPage);
1236 ASSERT_EQ("127.0.0.1", test_page.host()); 1241 ASSERT_EQ("127.0.0.1", test_page.host());
1237 1242
1238 WindowedAuthNeededObserver auth_needed_waiter(controller); 1243 WindowedAuthNeededObserver auth_needed_waiter(controller);
1239 browser()->OpenURL(OpenURLParams( 1244 browser()->OpenURL(OpenURLParams(
1240 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 1245 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
1241 false)); 1246 false));
1242 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); 1247 ASSERT_EQ("127.0.0.1", contents->GetURL().host());
1243 content::WaitForInterstitialAttach(contents); 1248 content::WaitForInterstitialAttach(contents);
1244 1249
1250 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage()
1251 ->GetDelegateForTesting()
1252 ->GetTypeForTesting());
1245 // An overrideable SSL interstitial is now being displayed. Proceed through 1253 // An overrideable SSL interstitial is now being displayed. Proceed through
1246 // the interstitial to see the login prompt. 1254 // the interstitial to see the login prompt.
1247 contents->GetInterstitialPage()->Proceed(); 1255 contents->GetInterstitialPage()->Proceed();
1248 auth_needed_waiter.Wait(); 1256 auth_needed_waiter.Wait();
1249 ASSERT_EQ(1u, observer.handlers().size()); 1257 ASSERT_EQ(1u, observer.handlers().size());
1250 content::WaitForInterstitialAttach(contents); 1258 content::WaitForInterstitialAttach(contents);
1251 1259
1252 // The omnibox should show the correct origin while the login prompt is 1260 // The omnibox should show the correct origin while the login prompt is
1253 // being displayed. 1261 // being displayed.
1254 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); 1262 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host());
1255 EXPECT_TRUE(contents->ShowingInterstitialPage()); 1263 EXPECT_TRUE(contents->ShowingInterstitialPage());
1256 EXPECT_EQ(LoginInterstitialDelegate::kTypeForTesting, 1264 EXPECT_EQ(LoginInterstitialDelegate::kTypeForTesting,
1257 contents->GetInterstitialPage() 1265 contents->GetInterstitialPage()
1258 ->GetDelegateForTesting() 1266 ->GetDelegateForTesting()
1259 ->GetTypeForTesting()); 1267 ->GetTypeForTesting());
1260 1268
1261 // Cancelling the login prompt should detach the interstitial while keeping 1269 // Cancelling the login prompt should detach the interstitial while keeping
1262 // the correct origin. 1270 // the correct origin.
1263 LoginHandler* handler = *observer.handlers().begin(); 1271 LoginHandler* handler = *observer.handlers().begin();
1264 content::RunTaskAndWaitForInterstitialDetach( 1272 content::RunTaskAndWaitForInterstitialDetach(
1265 contents, base::Bind(&LoginHandler::CancelAuth, handler)); 1273 contents, base::Bind(&LoginHandler::CancelAuth, handler));
1266 1274
1267 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); 1275 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host());
1268 EXPECT_FALSE(contents->ShowingInterstitialPage()); 1276 EXPECT_FALSE(contents->ShowingInterstitialPage());
1269 } 1277 }
1270 } 1278 }
1271 1279
1280 // Test the scenario where an auth interstitial should replace a different type
1281 // of interstitial (e.g. SSL) even though the navigation isn't cross origin.
1282 // This is different than the above scenario in that the last
1283 // committed url is the same as the auth url. This can happen when:
1284 //
1285 // 1. Tab is navigated to the auth URL and the auth prompt is cancelled.
1286 // 2. Tab is then navigated to an SSL interstitial.
1287 // 3. Tab is again navigated to the same auth URL in (1).
1288 //
1289 // In this case, the last committed url is the same as the auth URL since the
1290 // navigation at (1) is committed (user clicked cancel and the page loaded), but
1291 // the navigation at (2) isn't (navigations ending up in interstitials don't
1292 // immediately commit). So just checking for cross origin navigation before
1293 // prompting the auth interstitial is not sufficient, must also check if there
1294 // is any other interstitial being displayed.
1295 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
1296 ShouldReplaceExistingInterstitialWhenNavigated) {
1297 ASSERT_TRUE(test_server()->Start());
1298 net::SpawnedTestServer https_server(
1299 net::SpawnedTestServer::TYPE_HTTPS,
1300 net::SpawnedTestServer::SSLOptions(
1301 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED),
1302 base::FilePath());
1303 ASSERT_TRUE(https_server.Start());
1304
1305 content::WebContents* contents =
1306 browser()->tab_strip_model()->GetActiveWebContents();
1307 NavigationController* controller = &contents->GetController();
1308 LoginPromptBrowserTestObserver observer;
1309
1310 observer.Register(content::Source<NavigationController>(controller));
1311
1312 GURL auth_url = test_server()->GetURL(kAuthBasicPage);
1313 GURL broken_ssl_page = https_server.GetURL("/");
1314
1315 // Navigate to an auth url and wait for the login prompt.
1316 {
1317 WindowedAuthNeededObserver auth_needed_waiter(controller);
1318 browser()->OpenURL(OpenURLParams(auth_url, Referrer(), CURRENT_TAB,
1319 ui::PAGE_TRANSITION_TYPED, false));
1320 ASSERT_EQ("127.0.0.1", contents->GetURL().host());
1321 ASSERT_TRUE(contents->GetURL().SchemeIs("http"));
1322 auth_needed_waiter.Wait();
1323 ASSERT_EQ(1u, observer.handlers().size());
1324 content::WaitForInterstitialAttach(contents);
1325 ASSERT_TRUE(contents->ShowingInterstitialPage());
1326 EXPECT_EQ(LoginInterstitialDelegate::kTypeForTesting,
1327 contents->GetInterstitialPage()
1328 ->GetDelegateForTesting()
1329 ->GetTypeForTesting());
1330 // Cancel the auth prompt. This commits the navigation.
1331 LoginHandler* handler = *observer.handlers().begin();
1332 content::RunTaskAndWaitForInterstitialDetach(
1333 contents, base::Bind(&LoginHandler::CancelAuth, handler));
1334 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host());
1335 EXPECT_FALSE(contents->ShowingInterstitialPage());
1336 EXPECT_EQ(auth_url, contents->GetLastCommittedURL());
1337 }
1338
1339 // Navigate to a broken SSL page. This is a cross origin navigation since
1340 // schemes don't match (http vs https).
1341 {
1342 ASSERT_EQ("127.0.0.1", broken_ssl_page.host());
1343 browser()->OpenURL(OpenURLParams(broken_ssl_page, Referrer(), CURRENT_TAB,
1344 ui::PAGE_TRANSITION_TYPED, false));
1345 ASSERT_EQ("127.0.0.1", contents->GetURL().host());
1346 ASSERT_TRUE(contents->GetURL().SchemeIs("https"));
1347 content::WaitForInterstitialAttach(contents);
1348 EXPECT_TRUE(contents->ShowingInterstitialPage());
1349 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage()
1350 ->GetDelegateForTesting()
1351 ->GetTypeForTesting());
1352 EXPECT_EQ(auth_url, contents->GetLastCommittedURL());
1353 }
1354
1355 // An overrideable SSL interstitial is now being displayed. Navigate to the
1356 // auth URL again. This is again a cross origin navigation, but last committed
1357 // URL is the same as the auth URL (since SSL navigation never committed).
1358 // Should still replace SSL interstitial with an auth interstitial even though
1359 // last committed URL and the new URL is the same.
1360 {
1361 WindowedAuthNeededObserver auth_needed_waiter(controller);
1362 browser()->OpenURL(OpenURLParams(auth_url, Referrer(), CURRENT_TAB,
1363 ui::PAGE_TRANSITION_TYPED, false));
1364 ASSERT_EQ("127.0.0.1", contents->GetURL().host());
1365 ASSERT_TRUE(contents->GetURL().SchemeIs("http"));
1366 ASSERT_TRUE(contents->ShowingInterstitialPage());
1367
1368 auth_needed_waiter.Wait();
1369 ASSERT_EQ(1u, observer.handlers().size());
1370 content::WaitForInterstitialAttach(contents);
1371 EXPECT_EQ(LoginInterstitialDelegate::kTypeForTesting,
1372 contents->GetInterstitialPage()
1373 ->GetDelegateForTesting()
1374 ->GetTypeForTesting());
1375 }
1376 }
1377
1272 } // namespace 1378 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/login/login_prompt.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698