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

Side by Side Diff: chrome/browser/chrome_navigation_browsertest.cc

Issue 1881023003: Do not create pending NavigationEntry when a transient one is present. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on ToT. Created 4 years, 8 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
OLDNEW
(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 https_server_expired_.reset(
27 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
28 https_server_expired_->SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
29 https_server_expired_->AddDefaultHandlers(
30 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
31 ASSERT_TRUE(https_server_expired_->Start());
32 }
33
34 net::EmbeddedTestServer* https_server_expired() {
Charlie Reis 2016/04/13 06:03:37 nit: expired_https_server
nasko 2016/04/13 18:45:30 Done.
35 return https_server_expired_.get();
36 }
37
38 private:
39 std::unique_ptr<net::EmbeddedTestServer> https_server_expired_;
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.
Charlie Reis 2016/04/13 06:03:37 Let's list the bug number here.
nasko 2016/04/13 18:45:30 Done.
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");
Charlie Reis 2016/04/13 06:03:37 Looks like you forgot to add this file, which prob
nasko 2016/04/13 18:45:30 Yeah, noticed later, but didn't have a chance to u
79 GURL initial_url = embedded_test_server()->GetURL("/title1.html");
80 GURL error_url(https_server_expired()->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;
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(new_web_contents->GetLastCommittedURL(), initial_url);
Charlie Reis 2016/04/13 06:03:37 nit: Reverse order (expected, actual), here and be
nasko 2016/04/13 18:45:30 Done.
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(new_web_contents->GetLastCommittedURL(), initial_url);
114 EXPECT_EQ(new_web_contents->GetVisibleURL(), error_url);
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();
Charlie Reis 2016/04/13 06:03:37 Sanity check: We're not depending on this returnin
nasko 2016/04/13 18:45:30 No dependency on any other events. I did also disc
124 }
125
Charlie Reis 2016/04/13 06:03:37 nit: No blank line here (or move the EXPECTs into
nasko 2016/04/13 18:45:30 Done.
126 EXPECT_EQ(new_web_contents->GetVisibleURL(), error_url);
Charlie Reis 2016/04/13 06:03:37 Can you add an EXPECT for new_web_contents->GetCon
nasko 2016/04/13 18:45:29 Done.
127 EXPECT_FALSE(new_web_contents->IsLoading());
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698