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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper_unittest.cc

Issue 10829029: sync: don't display one-click if setup is in progress (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/content_settings/cookie_settings.h" 5 #include "chrome/browser/content_settings/cookie_settings.h"
6 #include "chrome/browser/prefs/pref_service.h" 6 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/signin/signin_manager_factory.h" 8 #include "chrome/browser/signin/signin_manager_factory.h"
9 #include "chrome/browser/signin/signin_manager_fake.h" 9 #include "chrome/browser/signin/signin_manager_fake.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h"
11 #include "chrome/browser/sync/test_profile_sync_service.h"
10 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 12 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
11 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
16 #include "content/public/test/test_renderer_host.h" 18 #include "content/public/test/test_renderer_host.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 namespace { 21 namespace {
(...skipping 26 matching lines...) Expand all
46 OneClickSigninHelperTest::OneClickSigninHelperTest() 48 OneClickSigninHelperTest::OneClickSigninHelperTest()
47 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 49 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
48 } 50 }
49 51
50 void OneClickSigninHelperTest::SetUp() { 52 void OneClickSigninHelperTest::SetUp() {
51 // Don't call base class so that default browser context and test WebContents 53 // Don't call base class so that default browser context and test WebContents
52 // are not created now. They will be created in CreateMockWebContents() 54 // are not created now. They will be created in CreateMockWebContents()
53 // as needed. 55 // as needed.
54 } 56 }
55 57
58 class OneClickTestProfileSyncService : public TestProfileSyncService {
59 public:
60 virtual ~OneClickTestProfileSyncService() {}
61
62 // Helper routine to be used in conjunction with
63 // ProfileKeyedServiceFactory::SetTestingFactory().
64 static ProfileKeyedService* Build(Profile* profile) {
65 return new OneClickTestProfileSyncService(profile);
66 }
67
68 // Need to control this for certain tests.
69 virtual bool FirstSetupInProgress() const OVERRIDE {
70 return first_setup_in_progress_;
71 }
72
73 // Controls return value of FirstSetupInProgress. Because some bits
74 // of UI depend on that value, it's useful to control it separately
75 // from the internal work and components that are triggered (such as
76 // ReconfigureDataTypeManager) to facilitate unit tests.
77 void set_first_setup_in_progress(bool in_progress) {
78 first_setup_in_progress_ = in_progress;
79 }
80
81 private:
82 explicit OneClickTestProfileSyncService(Profile* profile)
83 : TestProfileSyncService(NULL,
84 profile,
85 NULL,
86 ProfileSyncService::MANUAL_START,
87 false, // synchronous_backend_init
88 base::Closure()),
89 first_setup_in_progress_(false) {}
90
91 bool first_setup_in_progress_;
92 };
93
56 content::WebContents* OneClickSigninHelperTest::CreateMockWebContents( 94 content::WebContents* OneClickSigninHelperTest::CreateMockWebContents(
57 bool use_incognito, 95 bool use_incognito,
58 const std::string& username) { 96 const std::string& username) {
59 TestingProfile* testing_profile = new TestingProfile(); 97 TestingProfile* testing_profile = new TestingProfile();
60 browser_context_.reset(testing_profile); 98 browser_context_.reset(testing_profile);
61 99
62 testing_profile->set_incognito(use_incognito); 100 testing_profile->set_incognito(use_incognito);
63 SigninManager* signin_manager = static_cast<SigninManager*>( 101 SigninManager* signin_manager = static_cast<SigninManager*>(
64 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 102 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
65 testing_profile, FakeSigninManager::Build)); 103 testing_profile, FakeSigninManager::Build));
66 if (!username.empty()) { 104 if (!username.empty()) {
67 signin_manager->StartSignIn(username, std::string(), std::string(), 105 signin_manager->StartSignIn(username, std::string(), std::string(),
68 std::string()); 106 std::string());
69 } 107 }
70
71 return CreateTestWebContents(); 108 return CreateTestWebContents();
72 } 109 }
73 110
74 void OneClickSigninHelperTest::EnableOneClick(bool enable) { 111 void OneClickSigninHelperTest::EnableOneClick(bool enable) {
75 PrefService* pref_service = Profile::FromBrowserContext( 112 PrefService* pref_service = Profile::FromBrowserContext(
76 browser_context_.get())->GetPrefs(); 113 browser_context_.get())->GetPrefs();
77 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); 114 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable);
78 } 115 }
79 116
80 void OneClickSigninHelperTest::AllowSigninCookies(bool enable) { 117 void OneClickSigninHelperTest::AllowSigninCookies(bool enable) {
(...skipping 16 matching lines...) Expand all
97 134
98 EnableOneClick(true); 135 EnableOneClick(true);
99 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, true)); 136 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, true));
100 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false)); 137 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false));
101 138
102 EnableOneClick(false); 139 EnableOneClick(false);
103 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 140 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
104 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false)); 141 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false));
105 } 142 }
106 143
144 TEST_F(OneClickSigninHelperTest, CanOfferFirstSetup) {
145 content::WebContents* web_contents = CreateMockWebContents(false, "");
146
147 // Invoke OneClickTestProfileSyncService factory function and grab result.
148 OneClickTestProfileSyncService* sync =
149 static_cast<OneClickTestProfileSyncService*>(
150 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
151 static_cast<Profile*>(browser_context()),
152 OneClickTestProfileSyncService::Build));
153
154 sync->set_first_setup_in_progress(true);
155
156 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
157 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false));
158 }
159
107 TEST_F(OneClickSigninHelperTest, CanOfferProfileConnected) { 160 TEST_F(OneClickSigninHelperTest, CanOfferProfileConnected) {
108 content::WebContents* web_contents = CreateMockWebContents(false, 161 content::WebContents* web_contents = CreateMockWebContents(false,
109 "foo@gmail.com"); 162 "foo@gmail.com");
110 163
111 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 164 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
112 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false)); 165 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false));
113 } 166 }
114 167
115 TEST_F(OneClickSigninHelperTest, CanOfferIncognito) { 168 TEST_F(OneClickSigninHelperTest, CanOfferIncognito) {
116 content::WebContents* web_contents = CreateMockWebContents(true, ""); 169 content::WebContents* web_contents = CreateMockWebContents(true, "");
117 170
118 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 171 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
119 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false)); 172 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false));
120 } 173 }
121 174
122 TEST_F(OneClickSigninHelperTest, CanOfferNoSigninCookies) { 175 TEST_F(OneClickSigninHelperTest, CanOfferNoSigninCookies) {
123 content::WebContents* web_contents = CreateMockWebContents(false, ""); 176 content::WebContents* web_contents = CreateMockWebContents(false, "");
124 AllowSigninCookies(false); 177 AllowSigninCookies(false);
125 178
126 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 179 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true));
127 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false)); 180 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false));
128 } 181 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698