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

Side by Side Diff: content/browser/browser_side_navigation_browsertest.cc

Issue 715203004: PlzNavigate: Add a browser test for basic navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 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 "content/browser/browser_side_navigation_browsertest.h"
6
7 #include "base/command_line.h"
8 #include "content/public/browser/web_contents_observer.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/content_browser_test_utils.cc"
11 #include "content/shell/browser/shell.h"
12 #include "net/dns/mock_host_resolver.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h"
14 #include "url/gurl.h"
15
16 namespace content {
17
18 class BrowserSideNavigationWebContentsObserver : public WebContentsObserver {
clamy 2014/11/19 16:41:04 I was thinking maybe this class could be extracted
nasko 2014/11/19 18:05:56 Sure. I've created content_browser_test_utils_inte
clamy 2014/11/24 16:49:58 Done.
19 public:
20 explicit BrowserSideNavigationWebContentsObserver(WebContents* web_contents)
21 : WebContentsObserver(web_contents), navigation_succeeded_(false) {}
22 ~BrowserSideNavigationWebContentsObserver() override {}
23
24 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
25 const GURL& validated_url,
26 bool is_error_page,
27 bool is_iframe_srcdoc) override {
28 navigation_succeeded_ = false;
29 }
30
31 void DidFailProvisionalLoad(
32 RenderFrameHost* render_frame_host,
33 const GURL& validated_url,
34 int error_code,
35 const base::string16& error_description) override {
36 navigation_url_ = validated_url;
37 navigation_succeeded_ = false;
38 }
39
40 void DidCommitProvisionalLoadForFrame(
41 RenderFrameHost* render_frame_host,
42 const GURL& url,
43 ui::PageTransition transition_type) override {
44 navigation_url_ = url;
45 navigation_succeeded_ = true;
46 }
47
48 const GURL& navigation_url() const { return navigation_url_; }
49
50 int navigation_succeeded() const { return navigation_succeeded_; }
51
52 private:
53 GURL navigation_url_;
54 bool navigation_succeeded_;
55
56 DISALLOW_COPY_AND_ASSIGN(BrowserSideNavigationWebContentsObserver);
57 };
58
59 //
60 // BrowserSideNavigationBrowserTest
61 //
62
63 BrowserSideNavigationBrowserTest::BrowserSideNavigationBrowserTest(){};
64
65 void BrowserSideNavigationBrowserTest::SetUpCommandLine(
66 CommandLine* command_line) {
67 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation);
68 };
69
70 void BrowserSideNavigationBrowserTest::SetUpOnMainThread() {
71 host_resolver()->AddRule("*", "127.0.0.1");
72 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
73 }
74
75 // Ensure that browser initiated basic navigations work with browser side
76 // navigation.
77 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
clamy 2014/11/19 16:41:04 This only test browser initiated navigations. For
nasko 2014/11/19 18:05:56 We have a "framework" for testing this. Look at re
clamy 2014/11/24 16:49:58 Done.
78 BrowserInitiatedNavigations) {
79 // Perform a navigation with no live renderer.
80 BrowserSideNavigationWebContentsObserver observer1(shell()->web_contents());
81 GURL main_url1(embedded_test_server()->GetURL("/title1.html"));
82 NavigateToURL(shell(), main_url1);
83 EXPECT_EQ(main_url1, observer1.navigation_url());
84 EXPECT_TRUE(observer1.navigation_succeeded());
85
86 // Perform a same site navigation.
87 BrowserSideNavigationWebContentsObserver observer2(shell()->web_contents());
88 GURL main_url2(embedded_test_server()->GetURL("/title2.html"));
89 NavigateToURL(shell(), main_url2);
90 EXPECT_EQ(main_url2, observer2.navigation_url());
91 EXPECT_TRUE(observer2.navigation_succeeded());
92
93 // Perform a cross-site navigation.
nasko 2014/11/19 18:05:56 Let's add a check that the previous site instance
clamy 2014/11/24 16:49:58 Done.
94 BrowserSideNavigationWebContentsObserver observer3(shell()->web_contents());
95 GURL main_url3 = embedded_test_server()->GetURL("foo.com", "/title3.html");
96 NavigateToURL(shell(), main_url3);
97 EXPECT_EQ(main_url3, observer3.navigation_url());
98 EXPECT_TRUE(observer3.navigation_succeeded());
99 }
100
101 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698