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

Unified Diff: content/browser/tab_contents/tab_contents_unittest.cc

Issue 8802024: Move web_contents_unittest.cc to content, where it belongs next to TabContents. Also rename it to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | « chrome/chrome_tests.gypi ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/tab_contents/tab_contents_unittest.cc
===================================================================
--- content/browser/tab_contents/tab_contents_unittest.cc (revision 113050)
+++ content/browser/tab_contents/tab_contents_unittest.cc (working copy)
@@ -4,18 +4,16 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
-#include "chrome/test/base/testing_pref_service.h"
-#include "chrome/test/base/testing_profile.h"
+#include "content/browser/mock_content_browser_client.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
+#include "content/browser/renderer_host/test_render_view_host.h"
#include "content/browser/site_instance.h"
#include "content/browser/tab_contents/interstitial_page.h"
#include "content/browser/tab_contents/navigation_details.h"
#include "content/browser/tab_contents/navigation_entry.h"
#include "content/browser/tab_contents/test_tab_contents.h"
+#include "content/browser/webui/empty_web_ui_factory.h"
#include "content/common/view_messages.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
@@ -31,6 +29,56 @@
using content::BrowserThread;
using webkit_glue::PasswordForm;
+namespace {
+
+class TabContentsTestWebUI : public WebUI {
+ public:
+ explicit TabContentsTestWebUI(TabContents* source)
+ : WebUI(source) {
+ }
+ virtual ~TabContentsTestWebUI() {
+ }
+};
+
+class TabContentsTestWebUIFactory : public content::EmptyWebUIFactory {
+ public:
+ virtual WebUI* CreateWebUIForURL(TabContents* source,
+ const GURL& url) const OVERRIDE {
+ if (!HasWebUIScheme(url))
+ return NULL;
+
+ return new TabContentsTestWebUI(source);
+ }
+
+ virtual bool UseWebUIForURL(content::BrowserContext* browser_context,
+ const GURL& url) const OVERRIDE {
+ return HasWebUIScheme(url);
+ }
+
+ virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE {
+ return url.SchemeIs("tabcontentstest");
+ }
+
+ virtual bool IsURLAcceptableForWebUI(content::BrowserContext* browser_context,
+ const GURL& url) const {
+ return HasWebUIScheme(url);
+ }
+
+};
+
+class TabContentsTestBrowserClient : public content::MockContentBrowserClient {
+ public:
+ TabContentsTestBrowserClient() {
+ }
+
+ virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE {
+ return &factory_;
+ }
+
+ private:
+ TabContentsTestWebUIFactory factory_;
+};
+
class TestInterstitialPage : public InterstitialPage {
public:
enum InterstitialState {
@@ -166,38 +214,32 @@
TestInterstitialPage* interstitial_page_;
};
-class TabContentsTest : public ChromeRenderViewHostTestHarness {
+class TabContentsTest : public RenderViewHostTestHarness {
public:
- TabContentsTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
+ TabContentsTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ old_browser_client_(NULL) {
}
- private:
- // Supply our own profile so we use the correct profile data. The test harness
- // is not supposed to overwrite a profile if it's already created.
virtual void SetUp() {
- ChromeRenderViewHostTestHarness::SetUp();
+ old_browser_client_ = content::GetContentClient()->browser();
+ content::GetContentClient()->set_browser(&browser_client_);
+ RenderViewHostTestHarness::SetUp();
+ }
- // Set some (WebKit) user preferences.
- TestingPrefService* pref_services = profile()->GetTestingPrefService();
-#if defined(TOOLKIT_USES_GTK)
- pref_services->SetUserPref(prefs::kUsesSystemTheme,
- Value::CreateBooleanValue(false));
-#endif
- pref_services->SetUserPref(prefs::kDefaultCharset,
- Value::CreateStringValue("utf8"));
- pref_services->SetUserPref(prefs::kWebKitDefaultFontSize,
- Value::CreateIntegerValue(20));
- pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable,
- Value::CreateBooleanValue(false));
- pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector,
- Value::CreateBooleanValue(true));
- pref_services->SetUserPref("webkit.webprefs.foo",
- Value::CreateStringValue("bar"));
+ virtual void TearDown() {
+ content::GetContentClient()->set_browser(old_browser_client_);
+ RenderViewHostTestHarness::TearDown();
}
+ private:
+ TabContentsTestBrowserClient browser_client_;
content::TestBrowserThread ui_thread_;
+ content::ContentBrowserClient* old_browser_client_;
};
+} // namespace
+
// Test to make sure that title updates get stripped of whitespace.
TEST_F(TabContentsTest, UpdateTitle) {
ViewHostMsg_FrameNavigate_Params params;
@@ -212,9 +254,9 @@
EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle());
}
-// Test view source mode for the new tabs page.
+// Test view source mode for a webui page.
TEST_F(TabContentsTest, NTPViewSource) {
- const char kUrl[] = "view-source:chrome://newtab";
+ const char kUrl[] = "view-source:tabcontentstest://blah";
const GURL kGURL(kUrl);
process()->sink().ClearMessages();
@@ -407,7 +449,7 @@
contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
// Open a new tab with the same SiteInstance, navigated to the same site.
- TestTabContents contents2(profile(), instance1);
+ TestTabContents contents2(browser_context_.get(), instance1);
contents2.transition_cross_site = true;
contents2.controller().LoadURL(url, content::Referrer(),
content::PAGE_TRANSITION_TYPED,
@@ -468,7 +510,7 @@
orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
// Open a related tab to a second site.
- TestTabContents contents2(profile(), instance1);
+ TestTabContents contents2(browser_context_.get(), instance1);
contents2.transition_cross_site = true;
const GURL url2("http://www.yahoo.com");
contents2.controller().LoadURL(url2, content::Referrer(),
@@ -592,8 +634,8 @@
TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) {
contents()->transition_cross_site = true;
- // Start with NTP, which gets a new RVH with WebUI bindings.
- const GURL url1("chrome://newtab");
+ // Start with a web ui page, which gets a new RVH with WebUI bindings.
+ const GURL url1("tabcontentstest://blah");
controller().LoadURL(
url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
TestRenderViewHost* ntp_rvh = rvh();
@@ -722,7 +764,7 @@
contents()->transition_cross_site = true;
// Navigate to NTP URL.
- const GURL url("chrome://newtab");
+ const GURL url("tabcontentstest://blah");
controller().LoadURL(
url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
TestRenderViewHost* orig_rvh = rvh();
@@ -739,7 +781,7 @@
// Suppose the first navigation tries to commit now, with a
// ViewMsg_Stop in flight. This should not cancel the pending navigation,
// but it should act as if the beforeunload ack arrived.
- orig_rvh->SendNavigate(1, GURL("chrome://newtab"));
+ orig_rvh->SendNavigate(1, GURL("tabcontentstest://blah"));
EXPECT_TRUE(contents()->cross_navigation_pending());
EXPECT_EQ(orig_rvh, contents()->render_view_host());
EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack());
@@ -899,29 +941,6 @@
EXPECT_FALSE(entry->content_state().empty());
}
-// Tests to see that webkit preferences are properly loaded and copied over
-// to a WebPreferences object.
-TEST_F(TabContentsTest, WebKitPrefs) {
- WebPreferences webkit_prefs = contents()->TestGetWebkitPrefs();
-
- // These values have been overridden by the profile preferences.
- EXPECT_EQ("UTF-8", webkit_prefs.default_encoding);
- EXPECT_EQ(20, webkit_prefs.default_font_size);
- EXPECT_FALSE(webkit_prefs.text_areas_are_resizable);
- EXPECT_TRUE(webkit_prefs.uses_universal_detector);
-
- // These should still be the default values.
-#if defined(OS_MACOSX)
- const char kDefaultFont[] = "Times";
-#elif defined(OS_CHROMEOS)
- const char kDefaultFont[] = "Tinos";
-#else
- const char kDefaultFont[] = "Times New Roman";
-#endif
- EXPECT_EQ(ASCIIToUTF16(kDefaultFont), webkit_prefs.standard_font_family);
- EXPECT_TRUE(webkit_prefs.javascript_enabled);
-}
-
////////////////////////////////////////////////////////////////////////////////
// Interstitial Tests
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698