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

Unified Diff: chrome/browser/ui/webui/web_ui_unittest.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
Index: chrome/browser/ui/webui/web_ui_unittest.cc
diff --git a/chrome/browser/ui/webui/web_ui_unittest.cc b/chrome/browser/ui/webui/web_ui_unittest.cc
index 0673726f7cb94a65efeb6584fc542ff9dfaf02e4..57073ba6d58f829151dea2dd173e9b6f83e44cd9 100644
--- a/chrome/browser/ui/webui/web_ui_unittest.cc
+++ b/chrome/browser/ui/webui/web_ui_unittest.cc
@@ -8,11 +8,13 @@
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/browser/tab_contents/test_tab_contents.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/site_instance.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/referrer.h"
#include "content/test/test_browser_thread.h"
#include "content/test/test_renderer_host.h"
+#include "content/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
@@ -21,6 +23,7 @@ using content::RenderViewHost;
using content::RenderViewHostTester;
using content::SiteInstance;
using content::WebContents;
+using content::WebContentsTester;
class WebUITest : public TabContentsWrapperTestHarness {
public:
@@ -103,7 +106,8 @@ TEST_F(WebUITest, WebUIToStandard) {
// slightly different than the very-first-navigation case since the
// SiteInstance will be the same (the original TabContents must still be
// alive), which will trigger different behavior in RenderViewHostManager.
- TestTabContents* contents2 = new TestTabContents(profile(), NULL);
+ WebContents* contents2 =
+ WebContentsTester::CreateTestWebContents(profile(), NULL);
TabContentsWrapper wrapper2(contents2);
DoNavigationTest(&wrapper2, 101);
@@ -157,27 +161,15 @@ TEST_F(WebUITest, StandardToWebUI) {
// Committing Web UI is tested above.
}
-class TabContentsForFocusTest : public TestTabContents {
- public:
- TabContentsForFocusTest(content::BrowserContext* browser_context,
- SiteInstance* instance)
- : TestTabContents(browser_context, instance), focus_called_(0) {
- }
-
- virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; }
- int focus_called() const { return focus_called_; }
-
- private:
- int focus_called_;
-};
-
TEST_F(WebUITest, FocusOnNavigate) {
- // Setup. |tc| will be used to track when we try to focus the location bar.
- TabContentsForFocusTest* tc = new TabContentsForFocusTest(
- contents()->GetBrowserContext(),
- SiteInstance::Create(contents()->GetBrowserContext()));
- tc->GetController().CopyStateFrom(controller());
- SetContents(tc);
+ // Setup. |wc| will be used to track when we try to focus the location bar.
+ WebContents* wc =
+ WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar(
+ contents()->GetBrowserContext(),
+ SiteInstance::Create(contents()->GetBrowserContext()));
+ WebContentsTester* wct = WebContentsTester::For(wc);
+ wc->GetController().CopyStateFrom(controller());
+ SetContents(wc);
int page_id = 200;
// Load the NTP.
@@ -200,17 +192,17 @@ TEST_F(WebUITest, FocusOnNavigate) {
RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK();
// Navigate back. Should focus the location bar.
- int focus_called = tc->focus_called();
+ int focus_called = wct->GetNumberOfFocusCalls();
ASSERT_TRUE(controller().CanGoBack());
controller().GoBack();
old_rvh = rvh();
RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true);
RenderViewHostTester::For(pending_rvh())->SendNavigate(page_id, new_tab_url);
RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK();
- EXPECT_LT(focus_called, tc->focus_called());
+ EXPECT_LT(focus_called, wct->GetNumberOfFocusCalls());
// Navigate forward. Shouldn't focus the location bar.
- focus_called = tc->focus_called();
+ focus_called = wct->GetNumberOfFocusCalls();
ASSERT_TRUE(controller().CanGoForward());
controller().GoForward();
old_rvh = rvh();
@@ -218,5 +210,5 @@ TEST_F(WebUITest, FocusOnNavigate) {
RenderViewHostTester::For(
pending_rvh())->SendNavigate(next_page_id, next_url);
RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK();
- EXPECT_EQ(focus_called, tc->focus_called());
+ EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls());
}
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_ui_unittest.cc ('k') | chrome/browser/webdata/web_database_migration_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698