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

Unified Diff: content/test/web_contents_tester.cc

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/web_contents_tester.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/web_contents_tester.cc
diff --git a/content/test/web_contents_tester.cc b/content/test/web_contents_tester.cc
new file mode 100644
index 0000000000000000000000000000000000000000..afe28021c7e58266215f4fa9ae9b03e521c0228f
--- /dev/null
+++ b/content/test/web_contents_tester.cc
@@ -0,0 +1,81 @@
+// 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/test/web_contents_tester.h"
+
+#include "content/browser/tab_contents/test_tab_contents.h"
+
+namespace content {
+
+namespace {
+
+// The two subclasses here are instantiated via the deprecated
+// CreateWebContentsFor... factories below.
+
+class TestTabContentsCountFocus : public TestTabContents {
+ public:
+ TestTabContentsCountFocus(content::BrowserContext* browser_context,
+ content::SiteInstance* instance)
+ : TestTabContents(browser_context, instance), focus_called_(0) {
+ }
+
+ virtual int GetNumberOfFocusCalls() OVERRIDE {
+ return focus_called_;
+ }
+
+ virtual void Focus() OVERRIDE {
+ focus_called_++;
+ }
+
+ private:
+ int focus_called_;
+};
+
+class TestTabContentsCountSetFocusToLocationBar : public TestTabContents {
+ public:
+ TestTabContentsCountSetFocusToLocationBar(
+ content::BrowserContext* browser_context,
+ SiteInstance* instance)
+ : TestTabContents(browser_context, instance), focus_called_(0) {
+ }
+
+ virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; }
+ virtual int GetNumberOfFocusCalls() OVERRIDE {
+ return focus_called_;
+ }
+
+ private:
+ int focus_called_;
+};
+
+} // namespace
+
+// static
+WebContentsTester* WebContentsTester::For(WebContents* contents) {
+ return static_cast<TestTabContents*>(contents);
+}
+
+// static
+WebContents* WebContentsTester::CreateTestWebContents(
+ BrowserContext* browser_context,
+ SiteInstance* instance) {
+ return new TestTabContents(browser_context, instance);
+}
+
+// static
+WebContents* WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar(
+ BrowserContext* browser_context,
+ SiteInstance* instance) {
+ return new TestTabContentsCountSetFocusToLocationBar(
+ browser_context, instance);
+}
+
+// static
+WebContents* WebContentsTester::CreateTestWebContentsCountFocus(
+ BrowserContext* browser_context,
+ SiteInstance* instance) {
+ return new TestTabContentsCountFocus(browser_context, instance);
+}
+
+} // namespace content
« no previous file with comments | « content/test/web_contents_tester.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698