diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 21:39:03 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 21:39:03 +0000 |
commit | 826ad711429cb169c4772ffa210d1ef2c952ee43 (patch) | |
tree | 4c384324c9d033021868cd65991b8dc4d08db485 /content | |
parent | cd0cc3b26c9bb9c65e25895135296bfcc6c8d397 (diff) | |
download | chromium_src-826ad711429cb169c4772ffa210d1ef2c952ee43.zip chromium_src-826ad711429cb169c4772ffa210d1ef2c952ee43.tar.gz chromium_src-826ad711429cb169c4772ffa210d1ef2c952ee43.tar.bz2 |
Move more files to content_unittests
and a few related cleanups:
- DCHECK in ctor to fail early
- fix infinite loop in WebUI mock
- ASSERT_TRUE to avoid crashes
BUG=90443
Review URL: http://codereview.chromium.org/7830028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99459 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
9 files changed, 43 insertions, 27 deletions
diff --git a/content/browser/child_process_security_policy.h b/content/browser/child_process_security_policy.h index 2edb81c..1ce1f3d 100644 --- a/content/browser/child_process_security_policy.h +++ b/content/browser/child_process_security_policy.h @@ -172,7 +172,7 @@ class ChildProcessSecurityPolicy { const FilePath& file, int permissions); - // You must acquire this lock before reading or writing any members of this + // You must acquire this lock before reading or writing any members of this // class. You must not block while holding this lock. base::Lock lock_; diff --git a/content/browser/in_process_webkit/session_storage_namespace.cc b/content/browser/in_process_webkit/session_storage_namespace.cc index a0488a6..95456fd 100644 --- a/content/browser/in_process_webkit/session_storage_namespace.cc +++ b/content/browser/in_process_webkit/session_storage_namespace.cc @@ -4,6 +4,7 @@ #include "content/browser/in_process_webkit/session_storage_namespace.h" +#include "base/logging.h" #include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/webkit_context.h" @@ -17,6 +18,7 @@ SessionStorageNamespace::SessionStorageNamespace(WebKitContext* webkit_context, int64 id) : webkit_context_(webkit_context), id_(id) { + DCHECK(webkit_context_); } SessionStorageNamespace::~SessionStorageNamespace() { diff --git a/content/browser/in_process_webkit/webkit_context_unittest.cc b/content/browser/in_process_webkit/webkit_context_unittest.cc index 3e94a9d..89123fa 100644 --- a/content/browser/in_process_webkit/webkit_context_unittest.cc +++ b/content/browser/in_process_webkit/webkit_context_unittest.cc @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" #include "content/browser/browser_thread.h" #include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/webkit_context.h" +#include "content/test/test_browser_context.h" #include "testing/gtest/include/gtest/gtest.h" class MockDOMStorageContext : public DOMStorageContext { @@ -30,18 +29,16 @@ class MockDOMStorageContext : public DOMStorageContext { }; TEST(WebKitContextTest, Basic) { - TestingProfile profile; + TestBrowserContext browser_context; scoped_refptr<WebKitContext> context1(new WebKitContext( - profile.IsOffTheRecord(), profile.GetPath(), - profile.GetSpecialStoragePolicy(), - false, NULL, NULL)); - EXPECT_TRUE(profile.GetPath() == context1->data_path()); - EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito()); + browser_context.IsOffTheRecord(), browser_context.GetPath(), + NULL, false, NULL, NULL)); + EXPECT_TRUE(browser_context.GetPath() == context1->data_path()); + EXPECT_TRUE(browser_context.IsOffTheRecord() == context1->is_incognito()); scoped_refptr<WebKitContext> context2(new WebKitContext( - profile.IsOffTheRecord(), profile.GetPath(), - profile.GetSpecialStoragePolicy(), - false, NULL, NULL)); + browser_context.IsOffTheRecord(), browser_context.GetPath(), + NULL, false, NULL, NULL)); EXPECT_TRUE(context1->data_path() == context2->data_path()); EXPECT_TRUE(context1->is_incognito() == context2->is_incognito()); } @@ -54,13 +51,12 @@ TEST(WebKitContextTest, PurgeMemory) { { // Create the contexts. - TestingProfile profile; + TestBrowserContext browser_context; scoped_refptr<WebKitContext> context(new WebKitContext( - profile.IsOffTheRecord(), profile.GetPath(), - profile.GetSpecialStoragePolicy(), - false, NULL, NULL)); + browser_context.IsOffTheRecord(), browser_context.GetPath(), + NULL, false, NULL, NULL)); MockDOMStorageContext* mock_context = new MockDOMStorageContext( - context.get(), profile.GetSpecialStoragePolicy()); + context.get(), NULL); context->set_dom_storage_context(mock_context); // Takes ownership. // Ensure PurgeMemory() calls our mock object on the right thread. diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index 026c02b..c47f2c5 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -42,7 +42,7 @@ void MockContentBrowserClient::WorkerProcessHostCreated( WebUIFactory* MockContentBrowserClient::GetWebUIFactory() { // Return an empty factory so callsites don't have to check for NULL. - return EmptyWebUIFactory::Get(); + return EmptyWebUIFactory::GetInstance(); } GURL MockContentBrowserClient::GetEffectiveURL( diff --git a/content/browser/tab_contents/render_view_host_manager_unittest.cc b/content/browser/tab_contents/render_view_host_manager_unittest.cc index 104f783..d9d5bd6 100644 --- a/content/browser/tab_contents/render_view_host_manager_unittest.cc +++ b/content/browser/tab_contents/render_view_host_manager_unittest.cc @@ -81,9 +81,10 @@ TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { // The second one is the opposite, creating a cross-site transition and // requiring a beforeunload ack. contents2.controller().LoadURL(kDestUrl, GURL(), PageTransition::LINK); + EXPECT_TRUE(contents2.cross_navigation_pending()); TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( contents2.render_manager()->pending_render_view_host()); - EXPECT_TRUE(contents2.cross_navigation_pending()); + ASSERT_TRUE(dest_rvh2); ntp_rvh2->SendShouldCloseACK(true); dest_rvh2->SendNavigate(101, kDestUrl); ntp_rvh2->OnSwapOutACK(); @@ -240,7 +241,7 @@ TEST_F(RenderViewHostManagerTest, Navigate) { // A new RenderViewHost should be created. EXPECT_TRUE(manager.pending_render_view_host()); - EXPECT_TRUE(host == manager.pending_render_view_host()); + ASSERT_EQ(host, manager.pending_render_view_host()); notifications.Reset(); diff --git a/content/browser/tab_contents/tab_contents_delegate_unittest.cc b/content/browser/tab_contents/tab_contents_delegate_unittest.cc index fab9edb..2181cad 100644 --- a/content/browser/tab_contents/tab_contents_delegate_unittest.cc +++ b/content/browser/tab_contents/tab_contents_delegate_unittest.cc @@ -5,10 +5,9 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_browser_process.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_delegate.h" +#include "content/test/test_browser_context.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -64,15 +63,17 @@ class MockTabContentsDelegate : public TabContentsDelegate { TEST(TabContentsDelegateTest, UnregisterInDestructor) { MessageLoop loop(MessageLoop::TYPE_UI); - scoped_ptr<MockTabContentsDelegate> delegate(new MockTabContentsDelegate()); - scoped_ptr<Profile> profile(new TestingProfile()); + TestBrowserContext browser_context; + scoped_ptr<TabContents> contents_a( - new TabContents(profile.get(), NULL, 0, NULL, NULL)); + new TabContents(&browser_context, NULL, 0, NULL, NULL)); scoped_ptr<TabContents> contents_b( - new TabContents(profile.get(), NULL, 0, NULL, NULL)); + new TabContents(&browser_context, NULL, 0, NULL, NULL)); EXPECT_TRUE(contents_a->delegate() == NULL); EXPECT_TRUE(contents_b->delegate() == NULL); + scoped_ptr<MockTabContentsDelegate> delegate(new MockTabContentsDelegate()); + // Setting a delegate should work correctly. contents_a->set_delegate(delegate.get()); EXPECT_EQ(delegate.get(), contents_a->delegate()); diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 832b2d7..76bc1e2 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -103,6 +103,8 @@ 'browser/geolocation/win7_location_api_unittest_win.cc', 'browser/geolocation/win7_location_provider_unittest_win.cc', 'browser/gpu/gpu_blacklist_unittest.cc', + 'browser/in_process_webkit/webkit_context_unittest.cc', + 'browser/in_process_webkit/webkit_thread_unittest.cc', 'browser/mach_broker_mac_unittest.cc', 'browser/renderer_host/gtk_key_bindings_handler_unittest.cc', 'browser/renderer_host/media/audio_input_device_manager_unittest.cc', @@ -117,6 +119,8 @@ 'browser/speech/speech_recognition_request_unittest.cc', 'browser/speech/speech_recognizer_unittest.cc', 'browser/ssl/ssl_host_state_unittest.cc', + 'browser/tab_contents/navigation_entry_unittest.cc', + 'browser/tab_contents/tab_contents_delegate_unittest.cc', 'browser/trace_subscriber_stdio_unittest.cc', 'common/font_descriptor_mac_unittest.mm', 'common/gpu/gpu_feature_flags_unittest.cc', diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc index 728b98f..42388b8 100644 --- a/content/test/test_browser_context.cc +++ b/content/test/test_browser_context.cc @@ -5,6 +5,7 @@ #include "content/test/test_browser_context.h" #include "base/file_path.h" +#include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/mock_resource_context.h" TestBrowserContext::TestBrowserContext() { @@ -73,7 +74,12 @@ bool TestBrowserContext::DidLastSessionExitCleanly() { } WebKitContext* TestBrowserContext::GetWebKitContext() { - return NULL; + if (webkit_context_ == NULL) { + webkit_context_ = new WebKitContext( + IsOffTheRecord(), GetPath(), + NULL, false, NULL, NULL); + } + return webkit_context_; } ChromeBlobStorageContext* TestBrowserContext::GetBlobStorageContext() { diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h index 1ec01cf..aa24b571 100644 --- a/content/test/test_browser_context.h +++ b/content/test/test_browser_context.h @@ -7,8 +7,11 @@ #pragma once #include "base/compiler_specific.h" +#include "base/memory/ref_counted.h" #include "content/browser/browser_context.h" +class WebKitContext; + class TestBrowserContext : public content::BrowserContext { public: TestBrowserContext(); @@ -34,6 +37,9 @@ class TestBrowserContext : public content::BrowserContext { virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; private: + // WebKitContext, lazily initialized by GetWebKitContext(). + scoped_refptr<WebKitContext> webkit_context_; + DISALLOW_COPY_AND_ASSIGN(TestBrowserContext); }; |