summaryrefslogtreecommitdiffstats
path: root/content/test/web_contents_tester.cc
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-22 13:04:48 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-22 13:04:48 +0000
commit46a32b92e76b665e79bc3ee3b309766a47dbcf9d (patch)
treeef7bab9dc47d5a2473ac07f3998357b08106fd73 /content/test/web_contents_tester.cc
parent2e0a8e5d4e235bac3a687e289de5bdfb6399a1e9 (diff)
downloadchromium_src-46a32b92e76b665e79bc3ee3b309766a47dbcf9d.zip
chromium_src-46a32b92e76b665e79bc3ee3b309766a47dbcf9d.tar.gz
chromium_src-46a32b92e76b665e79bc3ee3b309766a47dbcf9d.tar.bz2
Add abstractions that let embedders drive tests of WebContents, without exposing the internals of content/.
A separate WebContentsTester interface is used. For reasons this approach was chosen, see comments on the interface. As part of this work, removed a bunch of references to TabContents from Chrome, some of which were true usages (leaked to Chrome via the test_tab_contents.h header), others of which were just forward declarations and never used. Also removed a chunk of code from autofill_manager.cc that isn't called from anywhere that referenced TabContents. TBR=ben@chromium.org BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9706012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/test/web_contents_tester.cc')
-rw-r--r--content/test/web_contents_tester.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/content/test/web_contents_tester.cc b/content/test/web_contents_tester.cc
new file mode 100644
index 0000000..afe2802
--- /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