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

Unified Diff: trunk/src/chrome/browser/background/background_contents_service_unittest.cc

Issue 23551005: Revert 219709 "Remove the Extensions URLRequestContext." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 4 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: trunk/src/chrome/browser/background/background_contents_service_unittest.cc
===================================================================
--- trunk/src/chrome/browser/background/background_contents_service_unittest.cc (revision 219785)
+++ trunk/src/chrome/browser/background/background_contents_service_unittest.cc (working copy)
@@ -8,7 +8,6 @@
#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"
@@ -17,41 +16,21 @@
#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 {
- 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_);
+ public:
+ BackgroundContentsServiceTest() {}
+ virtual ~BackgroundContentsServiceTest() {}
+ virtual void SetUp() {
+ command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
}
- virtual ~BackgroundContentsServiceTest() {
- base::RunLoop().RunUntilIdle();
- }
-
- static void SetUpTestCase() {
- message_center::MessageCenter::Initialize();
- }
- static void TearDownTestCase() {
- message_center::MessageCenter::Shutdown();
- }
-
const DictionaryValue* GetPrefs(Profile* profile) {
return profile->GetPrefs()->GetDictionary(
prefs::kRegisteredBackgroundContents);
@@ -68,11 +47,7 @@
return url;
}
- content::TestBrowserThreadBundle thread_bundle;
- CommandLine command_line_;
- TestingProfileManager profile_manager_;
- TestingProfile* profile_; // Not owned.
- scoped_ptr<BackgroundContentsService> service_;
+ scoped_ptr<CommandLine> command_line_;
};
class MockBackgroundContents : public BackgroundContents {
@@ -122,87 +97,104 @@
private:
GURL url_;
- // The ID of our parent application.
+ // The ID of our parent application
string16 appid_;
- // Parent profile. Not owned.
+ // Parent profile
Profile* profile_;
};
TEST_F(BackgroundContentsServiceTest, Create) {
- // Check for creation and leaks when the basic objects in the
- // fixtures are created/destructed.
+ // Check for creation and leaks.
+ TestingProfile profile;
+ BackgroundContentsService service(&profile, command_line_.get());
}
TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
- MockBackgroundContents* contents = new MockBackgroundContents(profile_);
- EXPECT_FALSE(service_->IsTracked(contents));
- contents->SendOpenedNotification(service_.get());
- EXPECT_TRUE(service_->IsTracked(contents));
+ 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));
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_.get());
+ new MockBackgroundContents(&profile));
+ EXPECT_EQ(0U, GetPrefs(&profile)->size());
+ contents->SendOpenedNotification(&service);
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_.get());
+ MockBackgroundContents* contents = new MockBackgroundContents(&profile);
+ EXPECT_EQ(0U, GetPrefs(&profile)->size());
+ contents->SendOpenedNotification(&service);
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_.get());
+ &profile, "appid"));
+ contents->SendOpenedNotification(&service);
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_.get());
+ &profile, "appid"));
+ contents->SendOpenedNotification(&service);
contents->Navigate(url);
- EXPECT_EQ(1U, GetPrefs(profile_)->size());
+ EXPECT_EQ(1U, GetPrefs(&profile)->size());
}
}
@@ -210,29 +202,34 @@
// between a BackgroundContents and its parent extension, including
// unregistering the BC when the extension is uninstalled.
TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) {
- EXPECT_EQ(NULL, service_->GetAppBackgroundContents(ASCIIToUTF16("appid")));
- MockBackgroundContents* contents = new MockBackgroundContents(profile_,
+ TestingProfile profile;
+ BackgroundContentsService service(&profile, command_line_.get());
+ BackgroundContentsServiceFactory::GetInstance()->
+ RegisterUserPrefsOnBrowserContext(&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_.get());
- EXPECT_EQ(contents, service_->GetAppBackgroundContents(contents->appid()));
- contents2->SendOpenedNotification(service_.get());
- EXPECT_EQ(contents2.get(), service_->GetAppBackgroundContents(
+ new MockBackgroundContents(&profile, "appid2"));
+ contents->SendOpenedNotification(&service);
+ EXPECT_EQ(contents, service.GetAppBackgroundContents(contents->appid()));
+ contents2->SendOpenedNotification(&service);
+ 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()));
}

Powered by Google App Engine
This is Rietveld 408576698