diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-27 05:56:17 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-27 05:56:17 +0000 |
commit | 44080e71f9994cfa0c52c470196e7993a4cb9482 (patch) | |
tree | 776f2765d6c45b2a57158e0490b070ce3afb5f55 /chrome/browser/background | |
parent | 50f92668f15f6da453389e6e8705e3aef9ae1a07 (diff) | |
download | chromium_src-44080e71f9994cfa0c52c470196e7993a4cb9482.zip chromium_src-44080e71f9994cfa0c52c470196e7993a4cb9482.tar.gz chromium_src-44080e71f9994cfa0c52c470196e7993a4cb9482.tar.bz2 |
Remove the Extensions URLRequestContext.
Though chrome-extension: scheme URLs support cookies, they do not share
a namespace with http: and https:. In particular, chrome-extension://a and
http://a should not have the same set of cookies.
To enforce this, previously the code created a completely separate
URLRequestContext for servicing chrome-extension: schemes. However,
the code really only used this object as a method for conveying the
correct cookie jar from Profile creation to a few spots where cookies
were accessed; the rest of the URLRequestContext functionality was unused.
This CL removes the Extensions URLRequestContext code and replaces it
with APIs that directly expose the needed net::CookieStore.
Lastly, CookieMonster::EnableFileScheme() is removed and
CookieMonster::Delegate is renamed CookieMonsterDelegate.
EnableFileScheme is an inherently racy API because
CookieMonsters are creatable on all threads and this
function sets an unprotected global flag. CookieMonsterDelegate
is preferable to the nested interface because it can now be
forward declared.
TBRing darin and sky to cover the rest of the mechanical unittest changes.
TBR=darin,sky
BUG=158386,159193,57884
Review URL: https://chromiumcodereview.appspot.com/12546016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219709 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background')
-rw-r--r-- | chrome/browser/background/background_contents_service_unittest.cc | 153 | ||||
-rw-r--r-- | chrome/browser/background/background_mode_manager_unittest.cc | 31 |
2 files changed, 104 insertions, 80 deletions
diff --git a/chrome/browser/background/background_contents_service_unittest.cc b/chrome/browser/background/background_contents_service_unittest.cc index a58cfbc..f739fda 100644 --- a/chrome/browser/background/background_contents_service_unittest.cc +++ b/chrome/browser/background/background_contents_service_unittest.cc @@ -8,6 +8,7 @@ #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/pref_service.h" +#include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/background/background_contents_service.h" #include "chrome/browser/background/background_contents_service_factory.h" @@ -16,19 +17,39 @@ #include "chrome/browser/tab_contents/background_contents.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/pref_names.h" +#include "chrome/test/base/scoped_testing_local_state.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" +#include "chrome/test/base/testing_profile_manager.h" #include "content/public/browser/notification_service.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +#include "ui/message_center/message_center.h" #include "url/gurl.h" class BackgroundContentsServiceTest : public testing::Test { - public: - BackgroundContentsServiceTest() {} - virtual ~BackgroundContentsServiceTest() {} - virtual void SetUp() { - command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); + protected: + BackgroundContentsServiceTest() + : command_line_(CommandLine::NO_PROGRAM), + profile_manager_(TestingBrowserProcess::GetGlobal()), + profile_(NULL) { + CHECK(profile_manager_.SetUp()); + profile_ = profile_manager_.CreateTestingProfile("TestProfile"); + service_.reset(new BackgroundContentsService(profile_, &command_line_)); + BackgroundContentsServiceFactory::GetInstance()-> + RegisterUserPrefsOnBrowserContext(profile_); + } + + virtual ~BackgroundContentsServiceTest() { + base::RunLoop().RunUntilIdle(); + } + + static void SetUpTestCase() { + message_center::MessageCenter::Initialize(); + } + static void TearDownTestCase() { + message_center::MessageCenter::Shutdown(); } const DictionaryValue* GetPrefs(Profile* profile) { @@ -47,7 +68,11 @@ class BackgroundContentsServiceTest : public testing::Test { return url; } - scoped_ptr<CommandLine> command_line_; + content::TestBrowserThreadBundle thread_bundle; + CommandLine command_line_; + TestingProfileManager profile_manager_; + TestingProfile* profile_; // Not owned. + scoped_ptr<BackgroundContentsService> service_; }; class MockBackgroundContents : public BackgroundContents { @@ -97,104 +122,87 @@ class MockBackgroundContents : public BackgroundContents { private: GURL url_; - // The ID of our parent application + // The ID of our parent application. string16 appid_; - // Parent profile + // Parent profile. Not owned. Profile* profile_; }; TEST_F(BackgroundContentsServiceTest, Create) { - // Check for creation and leaks. - TestingProfile profile; - BackgroundContentsService service(&profile, command_line_.get()); + // Check for creation and leaks when the basic objects in the + // fixtures are created/destructed. } TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) { - TestingProfile profile; - BackgroundContentsService service(&profile, command_line_.get()); - MockBackgroundContents* contents = new MockBackgroundContents(&profile); - EXPECT_FALSE(service.IsTracked(contents)); - contents->SendOpenedNotification(&service); - EXPECT_TRUE(service.IsTracked(contents)); + MockBackgroundContents* contents = new MockBackgroundContents(profile_); + EXPECT_FALSE(service_->IsTracked(contents)); + contents->SendOpenedNotification(service_.get()); + EXPECT_TRUE(service_->IsTracked(contents)); delete contents; - EXPECT_FALSE(service.IsTracked(contents)); + EXPECT_FALSE(service_->IsTracked(contents)); } TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) { - TestingProfile profile; - BackgroundContentsService service(&profile, command_line_.get()); - BackgroundContentsServiceFactory::GetInstance()-> - RegisterUserPrefsOnBrowserContext(&profile); GURL orig_url; GURL url("http://a/"); GURL url2("http://a/"); { scoped_ptr<MockBackgroundContents> contents( - new MockBackgroundContents(&profile)); - EXPECT_EQ(0U, GetPrefs(&profile)->size()); - contents->SendOpenedNotification(&service); + new MockBackgroundContents(profile_)); + EXPECT_EQ(0U, GetPrefs(profile_)->size()); + contents->SendOpenedNotification(service_.get()); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); // Navigate the contents to a new url, should not change url. contents->Navigate(url2); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); } // Contents are deleted, url should persist. - EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); } TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) { - TestingProfile profile; - BackgroundContentsService service(&profile, command_line_.get()); - BackgroundContentsServiceFactory::GetInstance()-> - RegisterUserPrefsOnBrowserContext(&profile); - GURL url("http://a/"); - MockBackgroundContents* contents = new MockBackgroundContents(&profile); - EXPECT_EQ(0U, GetPrefs(&profile)->size()); - contents->SendOpenedNotification(&service); + MockBackgroundContents* contents = new MockBackgroundContents(profile_); + EXPECT_EQ(0U, GetPrefs(profile_)->size()); + contents->SendOpenedNotification(service_.get()); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); // Fake a window closed by script. - contents->MockClose(&profile); - EXPECT_EQ(0U, GetPrefs(&profile)->size()); + contents->MockClose(profile_); + EXPECT_EQ(0U, GetPrefs(profile_)->size()); } // Test what happens if a BackgroundContents shuts down (say, due to a renderer // crash) then is restarted. Should not persist URL twice. TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) { - TestingProfile profile; - BackgroundContentsService service(&profile, command_line_.get()); - BackgroundContentsServiceFactory::GetInstance()-> - RegisterUserPrefsOnBrowserContext(&profile); - GURL url("http://a/"); { scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents( - &profile, "appid")); - contents->SendOpenedNotification(&service); + profile_, "appid")); + contents->SendOpenedNotification(service_.get()); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); } // Contents deleted, url should be persisted. - EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); { // Reopen the BackgroundContents to the same URL, we should not register the // URL again. scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents( - &profile, "appid")); - contents->SendOpenedNotification(&service); + profile_, "appid")); + contents->SendOpenedNotification(service_.get()); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); } } @@ -202,34 +210,29 @@ TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) { // between a BackgroundContents and its parent extension, including // unregistering the BC when the extension is uninstalled. TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) { - TestingProfile profile; - BackgroundContentsService service(&profile, command_line_.get()); - BackgroundContentsServiceFactory::GetInstance()-> - RegisterUserPrefsOnBrowserContext(&profile); - - EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); - MockBackgroundContents* contents = new MockBackgroundContents(&profile, + EXPECT_EQ(NULL, service_->GetAppBackgroundContents(ASCIIToUTF16("appid"))); + MockBackgroundContents* contents = new MockBackgroundContents(profile_, "appid"); scoped_ptr<MockBackgroundContents> contents2( - new MockBackgroundContents(&profile, "appid2")); - contents->SendOpenedNotification(&service); - EXPECT_EQ(contents, service.GetAppBackgroundContents(contents->appid())); - contents2->SendOpenedNotification(&service); - EXPECT_EQ(contents2.get(), service.GetAppBackgroundContents( + new MockBackgroundContents(profile_, "appid2")); + contents->SendOpenedNotification(service_.get()); + EXPECT_EQ(contents, service_->GetAppBackgroundContents(contents->appid())); + contents2->SendOpenedNotification(service_.get()); + EXPECT_EQ(contents2.get(), service_->GetAppBackgroundContents( contents2->appid())); - EXPECT_EQ(0U, GetPrefs(&profile)->size()); + EXPECT_EQ(0U, GetPrefs(profile_)->size()); // Navigate the contents, then make sure the one associated with the extension // is unregistered. GURL url("http://a/"); GURL url2("http://b/"); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); contents2->Navigate(url2); - EXPECT_EQ(2U, GetPrefs(&profile)->size()); - service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); - EXPECT_FALSE(service.IsTracked(contents)); - EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); - EXPECT_EQ(1U, GetPrefs(&profile)->size()); - EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); + EXPECT_EQ(2U, GetPrefs(profile_)->size()); + service_->ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); + EXPECT_FALSE(service_->IsTracked(contents)); + EXPECT_EQ(NULL, service_->GetAppBackgroundContents(ASCIIToUTF16("appid"))); + EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(url2.spec(), GetPrefURLForApp(profile_, contents2->appid())); } diff --git a/chrome/browser/background/background_mode_manager_unittest.cc b/chrome/browser/background/background_mode_manager_unittest.cc index 2f222f1..7624532 100644 --- a/chrome/browser/background/background_mode_manager_unittest.cc +++ b/chrome/browser/background/background_mode_manager_unittest.cc @@ -6,26 +6,47 @@ #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/background/background_mode_manager.h" +#include "chrome/browser/browser_shutdown.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_unittest_util.h" +#include "ui/message_center/message_center.h" class BackgroundModeManagerTest : public testing::Test { - public: + protected: BackgroundModeManagerTest() - : profile_manager_(TestingBrowserProcess::GetGlobal()) {} - virtual ~BackgroundModeManagerTest() {} - virtual void SetUp() { + : profile_manager_(TestingBrowserProcess::GetGlobal()) { command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); - ASSERT_TRUE(profile_manager_.SetUp()); + CHECK(profile_manager_.SetUp()); +#if defined(OS_CHROMEOS) + // Because of the http://crbug.com/119175 workaround in the test + // constructor, browser shutdown needs to be reset otherwise + // subsequent test will fail. + browser_shutdown::SetTryingToQuit(false); +#endif // defined(OS_CHROMEOS) + } + + static void SetUpTestCase() { + message_center::MessageCenter::Initialize(); +#if defined(OS_CHROMEOS) + // Needed to handle http://crbug.com/119175. + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisableZeroBrowsersOpenForTests); +#endif // defined(OS_CHROMEOS) } + static void TearDownTestCase() { + message_center::MessageCenter::Shutdown(); + } + scoped_ptr<CommandLine> command_line_; + content::TestBrowserThreadBundle thread_bundle_; TestingProfileManager profile_manager_; }; |