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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_side_navigation_browsertest.cc
diff --git a/content/browser/browser_side_navigation_browsertest.cc b/content/browser/browser_side_navigation_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..19587acad834cad8ef7378ba1b0f84f0ef79ea5d
--- /dev/null
+++ b/content/browser/browser_side_navigation_browsertest.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/browser_side_navigation_browsertest.h"
+
+#include "base/command_line.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/content_browser_test_utils.cc"
+#include "content/shell/browser/shell.h"
+#include "net/dns/mock_host_resolver.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "url/gurl.h"
+
+namespace content {
+
+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.
+ public:
+ explicit BrowserSideNavigationWebContentsObserver(WebContents* web_contents)
+ : WebContentsObserver(web_contents), navigation_succeeded_(false) {}
+ ~BrowserSideNavigationWebContentsObserver() override {}
+
+ void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ bool is_error_page,
+ bool is_iframe_srcdoc) override {
+ navigation_succeeded_ = false;
+ }
+
+ void DidFailProvisionalLoad(
+ RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ int error_code,
+ const base::string16& error_description) override {
+ navigation_url_ = validated_url;
+ navigation_succeeded_ = false;
+ }
+
+ void DidCommitProvisionalLoadForFrame(
+ RenderFrameHost* render_frame_host,
+ const GURL& url,
+ ui::PageTransition transition_type) override {
+ navigation_url_ = url;
+ navigation_succeeded_ = true;
+ }
+
+ const GURL& navigation_url() const { return navigation_url_; }
+
+ int navigation_succeeded() const { return navigation_succeeded_; }
+
+ private:
+ GURL navigation_url_;
+ bool navigation_succeeded_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserSideNavigationWebContentsObserver);
+};
+
+//
+// BrowserSideNavigationBrowserTest
+//
+
+BrowserSideNavigationBrowserTest::BrowserSideNavigationBrowserTest(){};
+
+void BrowserSideNavigationBrowserTest::SetUpCommandLine(
+ CommandLine* command_line) {
+ command_line->AppendSwitch(switches::kEnableBrowserSideNavigation);
+};
+
+void BrowserSideNavigationBrowserTest::SetUpOnMainThread() {
+ host_resolver()->AddRule("*", "127.0.0.1");
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+}
+
+// Ensure that browser initiated basic navigations work with browser side
+// navigation.
+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.
+ BrowserInitiatedNavigations) {
+ // Perform a navigation with no live renderer.
+ BrowserSideNavigationWebContentsObserver observer1(shell()->web_contents());
+ GURL main_url1(embedded_test_server()->GetURL("/title1.html"));
+ NavigateToURL(shell(), main_url1);
+ EXPECT_EQ(main_url1, observer1.navigation_url());
+ EXPECT_TRUE(observer1.navigation_succeeded());
+
+ // Perform a same site navigation.
+ BrowserSideNavigationWebContentsObserver observer2(shell()->web_contents());
+ GURL main_url2(embedded_test_server()->GetURL("/title2.html"));
+ NavigateToURL(shell(), main_url2);
+ EXPECT_EQ(main_url2, observer2.navigation_url());
+ EXPECT_TRUE(observer2.navigation_succeeded());
+
+ // 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.
+ BrowserSideNavigationWebContentsObserver observer3(shell()->web_contents());
+ GURL main_url3 = embedded_test_server()->GetURL("foo.com", "/title3.html");
+ NavigateToURL(shell(), main_url3);
+ EXPECT_EQ(main_url3, observer3.navigation_url());
+ EXPECT_TRUE(observer3.navigation_succeeded());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698