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/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/test_navigation_observer.h" | 25 #include "content/public/test/test_navigation_observer.h" |
| 26 #include "net/base/auth.h" | 26 #include "net/base/auth.h" |
| 27 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
| 28 #include "net/test/spawned_test_server/spawned_test_server.h" | |
| 28 | 29 |
| 29 using content::NavigationController; | 30 using content::NavigationController; |
| 30 using content::OpenURLParams; | 31 using content::OpenURLParams; |
| 31 using content::Referrer; | 32 using content::Referrer; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 class LoginPromptBrowserTest : public InProcessBrowserTest { | 36 class LoginPromptBrowserTest : public InProcessBrowserTest { |
| 36 public: | 37 public: |
| 37 LoginPromptBrowserTest() | 38 LoginPromptBrowserTest() |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1242 host_resolver()->AddRule("www.a.com", "127.0.0.1"); | 1243 host_resolver()->AddRule("www.a.com", "127.0.0.1"); |
| 1243 ASSERT_TRUE(test_server()->Start()); | 1244 ASSERT_TRUE(test_server()->Start()); |
| 1244 | 1245 |
| 1245 const char* kTestPage = "files/login/cross_origin.html"; | 1246 const char* kTestPage = "files/login/cross_origin.html"; |
| 1246 GURL test_page = test_server()->GetURL(kTestPage); | 1247 GURL test_page = test_server()->GetURL(kTestPage); |
| 1247 ASSERT_EQ("127.0.0.1", test_page.host()); | 1248 ASSERT_EQ("127.0.0.1", test_page.host()); |
| 1248 std::string auth_host("www.a.com"); | 1249 std::string auth_host("www.a.com"); |
| 1249 TestCrossOriginPrompt(test_page, auth_host); | 1250 TestCrossOriginPrompt(test_page, auth_host); |
| 1250 } | 1251 } |
| 1251 | 1252 |
| 1253 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, | |
| 1254 LoginInterstitialShouldReplaceExistingInterstitial) { | |
| 1255 net::SpawnedTestServer https_server( | |
| 1256 net::SpawnedTestServer::TYPE_HTTPS, | |
|
msw
2014/08/19 01:16:39
nit: indent four spaces for wrapped function argum
meacer
2014/08/20 20:13:45
Done.
| |
| 1257 net::SpawnedTestServer::SSLOptions( | |
| 1258 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED), | |
| 1259 base::FilePath() | |
| 1260 ); | |
|
msw
2014/08/19 01:16:39
nit: move this to the line above.
meacer
2014/08/20 20:13:45
Done.
| |
| 1261 ASSERT_TRUE(https_server.Start()); | |
| 1262 | |
| 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 // Load a page which triggers an SSL interstitial. Proceeding through it | |
| 1271 // should show the login page with the blank interstitial. | |
| 1272 { | |
| 1273 GURL test_page = https_server.GetURL(kAuthBasicPage); | |
| 1274 ASSERT_EQ("127.0.0.1", test_page.host()); | |
| 1275 | |
| 1276 WindowedAuthNeededObserver auth_needed_waiter(controller); | |
| 1277 browser()->OpenURL(OpenURLParams( | |
| 1278 test_page, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | |
| 1279 false)); | |
| 1280 ASSERT_EQ("127.0.0.1", contents->GetURL().host()); | |
| 1281 WaitForInterstitialAttach(contents); | |
| 1282 | |
| 1283 // An overrideable SSL interstitial is now being displayed. Proceed through | |
| 1284 // the interstitial to see the login prompt. | |
| 1285 contents->GetInterstitialPage()->Proceed(); | |
| 1286 auth_needed_waiter.Wait(); | |
| 1287 ASSERT_EQ(1u, observer.handlers().size()); | |
| 1288 WaitForInterstitialAttach(contents); | |
| 1289 | |
| 1290 // The omnibox should show the correct origin while the login prompt is | |
| 1291 // being displayed. | |
| 1292 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); | |
| 1293 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 1294 | |
| 1295 // Cancelling the login prompt should detach the interstitial while keeping | |
| 1296 // the correct origin. | |
| 1297 LoginHandler* handler = *observer.handlers().begin(); | |
| 1298 scoped_refptr<content::MessageLoopRunner> loop_runner( | |
| 1299 new content::MessageLoopRunner); | |
| 1300 InterstitialObserver interstitial_observer(contents, | |
| 1301 base::Closure(), | |
| 1302 loop_runner->QuitClosure()); | |
| 1303 handler->CancelAuth(); | |
| 1304 if (content::InterstitialPage::GetInterstitialPage(contents)) | |
| 1305 loop_runner->Run(); | |
| 1306 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); | |
| 1307 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 1308 } | |
| 1309 } | |
| 1310 | |
| 1252 } // namespace | 1311 } // namespace |
| OLD | NEW |