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

Unified Diff: content/test/web_contents_tester.h

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/test_renderer_host.cc ('k') | content/test/web_contents_tester.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/web_contents_tester.h
diff --git a/content/test/web_contents_tester.h b/content/test/web_contents_tester.h
new file mode 100644
index 0000000000000000000000000000000000000000..1729404858fe62884eea114fcb2b1df42c591f0c
--- /dev/null
+++ b/content/test/web_contents_tester.h
@@ -0,0 +1,118 @@
+// 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.
+
+#ifndef CONTENT_TEST_WEB_CONTENTS_TESTER_H_
+#define CONTENT_TEST_WEB_CONTENTS_TESTER_H_
+#pragma once
+
+#include "content/public/common/page_transition_types.h"
+
+class GURL;
+struct WebPreferences;
+
+namespace content {
+
+class BrowserContext;
+struct Referrer;
+class RenderViewHost;
+class SiteInstance;
+class WebContents;
+
+// This interface allows embedders of content/ to write tests that
+// depend on a test version of WebContents. This interface can be
+// retrieved from any content::WebContents that was retrieved via a
+// call to RenderViewHostTestHarness::GetWebContents() (directly or
+// indirectly) or constructed explicitly via one of the
+// WebContentsTester::Create... methods.
+//
+// Tests within content/ can directly static_cast WebContents objects
+// retrieved or created as described above to
+// content::TestWebContents.
+//
+// Design note: We considered two alternatives to this separate test
+// interface approach:
+//
+// a) Define a TestWebContents interface that inherits fromn
+// WebContents, and have the concrete TestWebContents inherit from it
+// as well as from content::WebContentsImpl. This approach was
+// discarded as it introduces a diamond inheritance pattern, which
+// means we wouldn't be e.g. able to downcast from WebContents to
+// WebContentsImpl using static_cast.
+//
+// b) Define a TestWebContents interface that inherits from
+// WebContents, and have the concrete TestWebContents implement it,
+// using composition of a content::WebContentsImpl to implement most
+// methods. This approach was discarded as there is a fundamental
+// assumption in content/ that a WebContents* can be downcast to a
+// WebContentsImpl*, and this wouldn't be true for TestWebContents
+// objects.
+class WebContentsTester {
+ public:
+ // Retrieves a WebContentsTester to drive tests of the specified
+ // WebContents. As noted above you need to be sure the 'contents'
+ // object supports testing, i.e. is either created using one of the
+ // Create... functions below, or is retrieved via
+ // RenderViewHostTestHarness::GetWebContents().
+ static WebContentsTester* For(WebContents* contents);
+
+ // Creates a WebContents enabled for testing.
+ static WebContents* CreateTestWebContents(
+ BrowserContext* browser_context,
+ SiteInstance* instance);
+
+ // Deprecated. Creates a WebContents enabled for testing, that
+ // counts the number of times SetFocusToLocationBar is called.
+ static WebContents*
+ CreateTestWebContentsCountSetFocusToLocationBar(
+ BrowserContext* browser_context,
+ SiteInstance* instance);
+
+ // Deprecated. Creates a WebContents enabled for testing, that
+ // counts the number of times Focus is called.
+ static WebContents* CreateTestWebContentsCountFocus(
+ BrowserContext* browser_context,
+ SiteInstance* instance);
+
+ // Simulates the appropriate RenderView (pending if any, current otherwise)
+ // sending a navigate notification for the NavigationController pending entry.
+ virtual void CommitPendingNavigation() = 0;
+
+ // Only implementations retrieved via the deprecated
+ // CreateTestWebContentsFor... methods above will implement this
+ // method. It retrieves the number of times the focus-related calls
+ // in question have been made.
+ virtual int GetNumberOfFocusCalls() = 0;
+
+ // TODO(joi): Rename this and other hacker_style virtual methods.
+ virtual content::RenderViewHost* pending_rvh() const = 0;
+
+ // Creates a pending navigation to the given URL with the default parameters
+ // and then commits the load with a page ID one larger than any seen. This
+ // emulates what happens on a new navigation.
+ virtual void NavigateAndCommit(const GURL& url) = 0;
+
+ // Simulates the current RVH notifying that it has unloaded so that the
+ // pending RVH navigation can proceed.
+ // Does nothing if no cross-navigation is pending.
+ virtual void ProceedWithCrossSiteNavigation() = 0;
+
+ virtual void TestDidNavigate(content::RenderViewHost* render_view_host,
+ int page_id,
+ const GURL& url,
+ content::PageTransition transition) = 0;
+
+ virtual void TestDidNavigateWithReferrer(
+ content::RenderViewHost* render_view_host,
+ int page_id,
+ const GURL& url,
+ const content::Referrer& referrer,
+ content::PageTransition transition) = 0;
+
+ // Promote GetWebkitPrefs to public.
+ virtual WebPreferences TestGetWebkitPrefs() = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_TEST_WEB_CONTENTS_TESTER_H_
« no previous file with comments | « content/test/test_renderer_host.cc ('k') | content/test/web_contents_tester.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698