Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chrome_notification_types.h" | |
| 6 #include "chrome/browser/ui/browser.h" | |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 8 #include "chrome/test/base/in_process_browser_test.h" | |
| 9 #include "chrome/test/base/ui_test_utils.h" | |
| 10 #include "content/public/browser/navigation_handle.h" | |
| 11 #include "content/public/browser/notification_service.h" | |
| 12 #include "content/public/browser/web_contents_observer.h" | |
| 13 #include "content/public/test/browser_test_utils.h" | |
| 14 #include "content/public/test/test_navigation_observer.h" | |
| 15 | |
| 16 class ChromeNavigationBrowserTest : public InProcessBrowserTest { | |
| 17 public: | |
| 18 ChromeNavigationBrowserTest() {} | |
| 19 ~ChromeNavigationBrowserTest() override {} | |
| 20 | |
| 21 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 22 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 23 } | |
| 24 | |
| 25 void StartServerWithExpiredCert() { | |
| 26 expired_https_server_.reset( | |
| 27 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | |
| 28 expired_https_server_->SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); | |
| 29 expired_https_server_->AddDefaultHandlers( | |
| 30 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 31 ASSERT_TRUE(expired_https_server_->Start()); | |
| 32 } | |
| 33 | |
| 34 net::EmbeddedTestServer* expired_https_server() { | |
| 35 return expired_https_server_.get(); | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 std::unique_ptr<net::EmbeddedTestServer> expired_https_server_; | |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(ChromeNavigationBrowserTest); | |
| 42 }; | |
| 43 | |
| 44 // Helper class to track and allow waiting for navigation start events. | |
| 45 class DidStartNavigationObserver : public content::WebContentsObserver { | |
| 46 public: | |
| 47 explicit DidStartNavigationObserver(content::WebContents* web_contents) | |
| 48 : content::WebContentsObserver(web_contents), | |
| 49 message_loop_runner_(new content::MessageLoopRunner) {} | |
| 50 ~DidStartNavigationObserver() override {} | |
| 51 | |
| 52 // Runs a nested message loop and blocks until the full load has | |
| 53 // completed. | |
| 54 void Wait() { message_loop_runner_->Run(); } | |
| 55 | |
| 56 private: | |
| 57 // WebContentsObserver | |
| 58 void DidStartNavigation(content::NavigationHandle* handle) override { | |
| 59 if (message_loop_runner_->loop_running()) | |
| 60 message_loop_runner_->Quit(); | |
| 61 } | |
| 62 | |
| 63 // The MessageLoopRunner used to spin the message loop. | |
| 64 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(DidStartNavigationObserver); | |
| 67 }; | |
| 68 | |
| 69 // Test to verify that navigations are not deleting the transient | |
| 70 // NavigationEntry when showing an interstitial page and the old renderer | |
| 71 // process is trying to navigate. See https://crbug.com/600046. | |
| 72 IN_PROC_BROWSER_TEST_F( | |
| 73 ChromeNavigationBrowserTest, | |
| 74 TransientEntryPreservedOnMultipleNavigationsDuringInterstitial) { | |
| 75 StartServerWithExpiredCert(); | |
| 76 | |
| 77 GURL setup_url = | |
| 78 embedded_test_server()->GetURL("/window_open_and_navigate.html"); | |
| 79 GURL initial_url = embedded_test_server()->GetURL("/title1.html"); | |
| 80 GURL error_url(expired_https_server()->GetURL("/ssl/blank_page.html")); | |
| 81 | |
| 82 ui_test_utils::NavigateToURL(browser(), setup_url); | |
| 83 content::WebContents* main_web_contents = | |
| 84 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 85 content::WebContents* new_web_contents = nullptr; | |
|
Lei Zhang
2016/04/15 04:50:38
declare where first used
nasko
2016/04/15 05:14:46
Done.
| |
| 86 | |
| 87 // Call the JavaScript method in the test page, which opens a new window | |
| 88 // and stores a handle to it. | |
| 89 content::WindowedNotificationObserver tab_added_observer( | |
| 90 chrome::NOTIFICATION_TAB_ADDED, | |
| 91 content::NotificationService::AllSources()); | |
| 92 EXPECT_TRUE(content::ExecuteScript(main_web_contents, "openWin();")); | |
| 93 tab_added_observer.Wait(); | |
| 94 new_web_contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 95 | |
| 96 // Navigate the opened window to a page that will successfully commit and | |
| 97 // create a NavigationEntry. | |
| 98 { | |
| 99 content::TestNavigationObserver observer(new_web_contents); | |
| 100 EXPECT_TRUE(content::ExecuteScript( | |
| 101 main_web_contents, "navigate('" + initial_url.spec() + "');")); | |
| 102 observer.Wait(); | |
| 103 EXPECT_EQ(initial_url, new_web_contents->GetLastCommittedURL()); | |
| 104 } | |
| 105 | |
| 106 // Navigate the opened window to a page which will trigger an | |
| 107 // interstitial. | |
| 108 { | |
| 109 content::TestNavigationObserver observer(new_web_contents); | |
| 110 EXPECT_TRUE(content::ExecuteScript( | |
| 111 main_web_contents, "navigate('" + error_url.spec() + "');")); | |
| 112 observer.Wait(); | |
| 113 EXPECT_EQ(initial_url, new_web_contents->GetLastCommittedURL()); | |
| 114 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); | |
| 115 } | |
| 116 | |
| 117 // Navigate again the opened window to the same page. It should not cause | |
| 118 // WebContents::GetVisibleURL to return the last committed one. | |
| 119 { | |
| 120 DidStartNavigationObserver nav_observer(new_web_contents); | |
| 121 EXPECT_TRUE(content::ExecuteScript( | |
| 122 main_web_contents, "navigate('" + error_url.spec() + "');")); | |
| 123 nav_observer.Wait(); | |
| 124 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); | |
| 125 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry()); | |
| 126 EXPECT_FALSE(new_web_contents->IsLoading()); | |
| 127 } | |
| 128 } | |
| OLD | NEW |