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

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

Issue 10555005: Address bug where the one-click sign-in bar would never show again once (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: mostly addressed rogerta's comments 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 unified diff | Download patch | Annotate | Revision Log
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/prefs/scoped_user_pref_update.h"
7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/signin/signin_manager_factory.h" 9 #include "chrome/browser/signin/signin_manager_factory.h"
9 #include "chrome/browser/signin/signin_manager_fake.h" 10 #include "chrome/browser/signin/signin_manager_fake.h"
10 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 11 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
16 #include "content/public/test/test_renderer_host.h" 17 #include "content/public/test/test_renderer_host.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace { 20 namespace {
20 21
21 class OneClickSigninHelperTest : public content::RenderViewHostTestHarness { 22 class OneClickSigninHelperTest : public content::RenderViewHostTestHarness {
22 public: 23 public:
23 OneClickSigninHelperTest(); 24 OneClickSigninHelperTest();
24 25
25 virtual void SetUp() OVERRIDE; 26 virtual void SetUp() OVERRIDE;
26 27
27 protected: 28 protected:
28 // Creates a mock WebContents for tests. If |use_incognito| is true then 29 // Creates a mock WebContents for tests. If |use_incognito| is true then
29 // a WebContents for an incognito profile is created. If |username| is 30 // a WebContents for an incognito profile is created. If |username| is
30 // is not empty, the profile of the mock WebContents will be connected to 31 // is not empty, the profile of the mock WebContents will be connected to
31 // the given account. 32 // the given account.
32 content::WebContents* CreateMockWebContents(bool use_incognito, 33 content::WebContents* CreateMockWebContents(bool use_incognito,
33 const std::string& username); 34 const std::string& username);
34 35
36 void AddEmailToOneClickRejectedList(const std::string& email);
35 void EnableOneClick(bool enable); 37 void EnableOneClick(bool enable);
36 38
37 void AllowSigninCookies(bool enable); 39 void AllowSigninCookies(bool enable);
38 40
39 private: 41 private:
40 // Members to fake that we are on the UI thread. 42 // Members to fake that we are on the UI thread.
41 content::TestBrowserThread ui_thread_; 43 content::TestBrowserThread ui_thread_;
42 44
43 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); 45 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest);
44 }; 46 };
(...skipping 25 matching lines...) Expand all
70 72
71 return CreateTestWebContents(); 73 return CreateTestWebContents();
72 } 74 }
73 75
74 void OneClickSigninHelperTest::EnableOneClick(bool enable) { 76 void OneClickSigninHelperTest::EnableOneClick(bool enable) {
75 PrefService* pref_service = Profile::FromBrowserContext( 77 PrefService* pref_service = Profile::FromBrowserContext(
76 browser_context_.get())->GetPrefs(); 78 browser_context_.get())->GetPrefs();
77 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); 79 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable);
78 } 80 }
79 81
82 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList(
83 const std::string& email) {
84 PrefService* pref_service = Profile::FromBrowserContext(
85 browser_context_.get())->GetPrefs();
86 ListPrefUpdate updater(pref_service,
87 prefs::kReverseAutologinRejectedEmailList);
88 updater->AppendIfNotPresent(Value::CreateStringValue(email));
89 }
90
80 void OneClickSigninHelperTest::AllowSigninCookies(bool enable) { 91 void OneClickSigninHelperTest::AllowSigninCookies(bool enable) {
81 CookieSettings* cookie_settings = 92 CookieSettings* cookie_settings =
82 CookieSettings::Factory::GetForProfile( 93 CookieSettings::Factory::GetForProfile(
83 Profile::FromBrowserContext(browser_context_.get())); 94 Profile::FromBrowserContext(browser_context_.get()));
84 cookie_settings->SetDefaultCookieSetting( 95 cookie_settings->SetDefaultCookieSetting(
85 enable ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); 96 enable ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
86 } 97 }
87 98
88 } // namespace 99 } // namespace
89 100
90 TEST_F(OneClickSigninHelperTest, CanOfferNoContents) { 101 TEST_F(OneClickSigninHelperTest, CanOfferNoContents) {
91 EXPECT_FALSE(OneClickSigninHelper::CanOffer(NULL, true)); 102 EXPECT_FALSE(OneClickSigninHelper::CanOffer(NULL, "user@gmail.com", true));
92 EXPECT_FALSE(OneClickSigninHelper::CanOffer(NULL, false)); 103 EXPECT_FALSE(OneClickSigninHelper::CanOffer(NULL, "", false));
93 } 104 }
94 105
95 TEST_F(OneClickSigninHelperTest, CanOffer) { 106 TEST_F(OneClickSigninHelperTest, CanOffer) {
96 content::WebContents* web_contents = CreateMockWebContents(false, ""); 107 content::WebContents* web_contents = CreateMockWebContents(false, "");
97 108
98 EnableOneClick(true); 109 EnableOneClick(true);
99 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, true)); 110 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, "user@gmail.com",
100 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false)); 111 true));
112 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, "", false));
101 113
102 EnableOneClick(false); 114 EnableOneClick(false);
103 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 115 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "user@gmail.com",
104 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false)); 116 true));
117 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "", false));
105 } 118 }
106 119
107 TEST_F(OneClickSigninHelperTest, CanOfferProfileConnected) { 120 TEST_F(OneClickSigninHelperTest, CanOfferProfileConnected) {
108 content::WebContents* web_contents = CreateMockWebContents(false, 121 content::WebContents* web_contents = CreateMockWebContents(false,
109 "foo@gmail.com"); 122 "foo@gmail.com");
110 123
111 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 124 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents,
112 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, false)); 125 "foo@gmail.com",
126 true));
127 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents,
128 "user@gmail.com",
129 true));
Roger Tawa OOO till Jul 10th 2012/06/21 13:45:51 align 2nd and 3rd arguments with first.
Mathieu 2012/06/26 15:54:13 Done.
130 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents,
131 "",
132 false));
133 }
134
135 TEST_F(OneClickSigninHelperTest, CanOfferWithRejectedEmail) {
136 content::WebContents* web_contents = CreateMockWebContents(false, "");
137
138 AddEmailToOneClickRejectedList("foo@gmail.com");
139 AddEmailToOneClickRejectedList("user@gmail.com");
140 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "foo@gmail.com",
141 true));
142 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "user@gmail.com",
143 true));
144 EXPECT_TRUE(OneClickSigninHelper::CanOffer(web_contents, "john@gmail.com",
145 true));
113 } 146 }
114 147
115 TEST_F(OneClickSigninHelperTest, CanOfferIncognito) { 148 TEST_F(OneClickSigninHelperTest, CanOfferIncognito) {
116 content::WebContents* web_contents = CreateMockWebContents(true, ""); 149 content::WebContents* web_contents = CreateMockWebContents(true, "");
117 150
118 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 151 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "user@gmail.com",
119 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false)); 152 true));
153 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "", false));
120 } 154 }
121 155
122 TEST_F(OneClickSigninHelperTest, CanOfferNoSigninCookies) { 156 TEST_F(OneClickSigninHelperTest, CanOfferNoSigninCookies) {
123 content::WebContents* web_contents = CreateMockWebContents(false, ""); 157 content::WebContents* web_contents = CreateMockWebContents(false, "");
124 AllowSigninCookies(false); 158 AllowSigninCookies(false);
125 159
126 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, true)); 160 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "user@gmail.com",
127 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, false)); 161 true));
162 EXPECT_FALSE(OneClickSigninHelper::CanOffer(web_contents, "", false));
128 } 163 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | chrome/browser/ui/tab_contents/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698