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

Unified Diff: chrome/browser/ui/sync/one_click_signin_helper_unittest.cc

Issue 10443113: Fix memory leak in OneClickSigninHelperTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move UI marking to ctor Created 8 years, 6 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
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
index 15571d8fa28b8d66c1b3f89f942d851195b31f48..99e560987cf2db9df984e1cf71aaa92933128dc5 100644
--- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
+++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc
@@ -5,109 +5,86 @@
#include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_manager_fake.h"
#include "chrome/browser/ui/sync/one_click_signin_helper.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/browser_context.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/test/test_browser_thread.h"
-#include "content/public/test/web_contents_tester.h"
-#include "testing/gmock/include/gmock/gmock-actions.h"
-#include "testing/gmock/include/gmock/gmock.h"
+#include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness {
+class OneClickSigninHelperTest : public content::RenderViewHostTestHarness {
public:
- OneClickSigninHelperTest() : signin_manager_(NULL) {
- }
+ OneClickSigninHelperTest();
- virtual void TearDown() OVERRIDE;
+ virtual void SetUp() OVERRIDE;
protected:
- // Marks the current thread as the UI thread, so that calls that assume
- // they are called on that thread work.
- void MarkCurrentThreadAsUIThread();
-
// Creates a mock WebContents for tests. If |use_incognito| is true then
- // a WebContents for an incognito profile is created.
- content::WebContents* CreateMockWebContents(bool use_incognito);
+ // a WebContents for an incognito profile is created. If |username| is
+ // is not empty, the profile of the mock WebContents will be connected to
+ // the given account.
+ content::WebContents* CreateMockWebContents(bool use_incognito,
+ const std::string& username);
void EnableOneClick(bool enable);
void AllowSigninCookies(bool enable);
- // Marks the profile as connected to the given account. If |username| is the
- // empty string, the profile is not connected.
- void ConnectProfileToAccount(const std::string& username);
-
private:
// Members to fake that we are on the UI thread.
- scoped_ptr<content::TestBrowserThread> ui_thread_;
-
- // Mock objects used during tests. The objects need to be torn down in the
- // correct order, see TearDown().
- scoped_ptr<content::WebContents> web_contents_;
- scoped_ptr<TestingProfile> profile_;
- SigninManager* signin_manager_;
+ content::TestBrowserThread ui_thread_;
DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest);
};
-void OneClickSigninHelperTest::TearDown() {
- // Destroy things in proper order.
- web_contents_.reset();
- profile_.reset();
- ui_thread_.reset();
- MessageLoop::current()->RunAllPending();
- ChromeRenderViewHostTestHarness::TearDown();
+OneClickSigninHelperTest::OneClickSigninHelperTest()
+ : ui_thread_(content::BrowserThread::UI, &message_loop_) {
}
-void OneClickSigninHelperTest::MarkCurrentThreadAsUIThread() {
- ui_thread_.reset(new content::TestBrowserThread(
- content::BrowserThread::UI, &message_loop_));
+void OneClickSigninHelperTest::SetUp() {
+ // Don't call base class so that default browser context and test WebContents
+ // are not created now. They will be created in CreateMockWebContents()
+ // as needed.
}
content::WebContents* OneClickSigninHelperTest::CreateMockWebContents(
- bool use_incognito) {
- EXPECT_TRUE(web_contents_.get() == NULL);
+ bool use_incognito,
+ const std::string& username) {
+ TestingProfile* testing_profile = new TestingProfile();
+ browser_context_.reset(testing_profile);
- profile_.reset(new TestingProfile());
- signin_manager_ = static_cast<SigninManager*>(
+ testing_profile->set_incognito(use_incognito);
+ SigninManager* signin_manager = static_cast<SigninManager*>(
SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
- profile_.get(), FakeSigninManager::Build));
+ testing_profile, FakeSigninManager::Build));
+ if (!username.empty()) {
+ signin_manager->StartSignIn(username, std::string(), std::string(),
+ std::string());
+ }
- profile_->set_incognito(use_incognito);
- web_contents_.reset(content::WebContentsTester::CreateTestWebContents(
- profile_.get(), NULL));
- return web_contents_.get();
+ return CreateTestWebContents();
}
void OneClickSigninHelperTest::EnableOneClick(bool enable) {
- PrefService* pref_service = profile_->GetPrefs();
+ PrefService* pref_service = Profile::FromBrowserContext(
+ browser_context_.get())->GetPrefs();
pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable);
}
void OneClickSigninHelperTest::AllowSigninCookies(bool enable) {
CookieSettings* cookie_settings =
- CookieSettings::Factory::GetForProfile(profile_.get());
+ CookieSettings::Factory::GetForProfile(
+ Profile::FromBrowserContext(browser_context_.get()));
cookie_settings->SetDefaultCookieSetting(
enable ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
}
-void OneClickSigninHelperTest::ConnectProfileToAccount(
- const std::string& username) {
- signin_manager_->StartSignIn(username, std::string(), std::string(),
- std::string());
-}
-
} // namespace
TEST_F(OneClickSigninHelperTest, CanOfferNoContents) {
@@ -116,8 +93,7 @@ TEST_F(OneClickSigninHelperTest, CanOfferNoContents) {
}
TEST_F(OneClickSigninHelperTest, CanOffer) {
- MarkCurrentThreadAsUIThread();
- content::WebContents* web_contents = CreateMockWebContents(false);
+ content::WebContents* web_contents = CreateMockWebContents(false, "");
EnableOneClick(true);
EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, true));
@@ -129,25 +105,22 @@ TEST_F(OneClickSigninHelperTest, CanOffer) {
}
TEST_F(OneClickSigninHelperTest, CanOfferProfileConnected) {
- MarkCurrentThreadAsUIThread();
- content::WebContents* web_contents = CreateMockWebContents(false);
- ConnectProfileToAccount("foo@gmail.com");
+ content::WebContents* web_contents = CreateMockWebContents(false,
+ "foo@gmail.com");
EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false));
}
TEST_F(OneClickSigninHelperTest, CanOfferIncognito) {
- MarkCurrentThreadAsUIThread();
- content::WebContents* web_contents = CreateMockWebContents(true);
+ content::WebContents* web_contents = CreateMockWebContents(true, "");
EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false));
}
TEST_F(OneClickSigninHelperTest, CanOfferNoSigninCookies) {
- MarkCurrentThreadAsUIThread();
- content::WebContents* web_contents = CreateMockWebContents(true);
+ content::WebContents* web_contents = CreateMockWebContents(false, "");
AllowSigninCookies(false);
EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698