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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 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 "base/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/content_settings/cookie_settings.h" 8 #include "chrome/browser/content_settings/cookie_settings.h"
9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
10 #include "chrome/browser/prefs/scoped_user_pref_update.h" 10 #include "chrome/browser/prefs/scoped_user_pref_update.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_pref_service_syncable.h" 25 #include "chrome/test/base/testing_pref_service_syncable.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "chrome/test/base/testing_profile_manager.h" 27 #include "chrome/test/base/testing_profile_manager.h"
28 #include "content/public/browser/browser_context.h" 28 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/password_form.h" 30 #include "content/public/common/password_form.h"
31 #include "content/public/common/url_constants.h" 31 #include "content/public/common/url_constants.h"
32 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
33 #include "content/public/test/test_browser_thread.h"
34 #include "content/public/test/test_renderer_host.h" 33 #include "content/public/test/test_renderer_host.h"
35 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
36 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
37 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
38 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
39 38
40 using ::testing::_; 39 using ::testing::_;
41 using ::testing::AtLeast; 40 using ::testing::AtLeast;
42 using ::testing::Return; 41 using ::testing::Return;
43 42
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ProfileSyncServiceMock* CreateProfileSyncServiceMock(); 219 ProfileSyncServiceMock* CreateProfileSyncServiceMock();
221 void SubmitGAIAPassword(OneClickSigninHelper* helper); 220 void SubmitGAIAPassword(OneClickSigninHelper* helper);
222 OneClickSigninHelper* SetupHelperForSignin(); 221 OneClickSigninHelper* SetupHelperForSignin();
223 222
224 SigninManagerMock* signin_manager_; 223 SigninManagerMock* signin_manager_;
225 224
226 protected: 225 protected:
227 TestingProfile* profile_; 226 TestingProfile* profile_;
228 227
229 private: 228 private:
230 // Members to fake that we are on the UI thread.
231 content::TestBrowserThread ui_thread_;
232
233 // The ID of the signin process the test will assume to be trusted. 229 // The ID of the signin process the test will assume to be trusted.
234 // By default, set to the test RenderProcessHost's process ID, but 230 // By default, set to the test RenderProcessHost's process ID, but
235 // overridden by SetTrustedSigninProcessID. 231 // overridden by SetTrustedSigninProcessID.
236 int trusted_signin_process_id_; 232 int trusted_signin_process_id_;
237 233
238 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); 234 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest);
239 }; 235 };
240 236
241 OneClickSigninHelperTest::OneClickSigninHelperTest() 237 OneClickSigninHelperTest::OneClickSigninHelperTest()
242 : profile_(NULL), 238 : profile_(NULL),
243 ui_thread_(content::BrowserThread::UI, &message_loop_),
244 trusted_signin_process_id_(-1) { 239 trusted_signin_process_id_(-1) {
245 } 240 }
246 241
247 void OneClickSigninHelperTest::SetUp() { 242 void OneClickSigninHelperTest::SetUp() {
248 SyncPromoUI::ForceWebBasedSigninFlowForTesting(true); 243 SyncPromoUI::ForceWebBasedSigninFlowForTesting(true);
249 profile_ = new TestingProfile(); 244 profile_ = new TestingProfile();
250 browser_context_.reset(profile_); 245 browser_context_.reset(profile_);
251 content::RenderViewHostTestHarness::SetUp(); 246 content::RenderViewHostTestHarness::SetUp();
252 SetTrustedSigninProcessID(process()->GetID()); 247 SetTrustedSigninProcessID(process()->GetID());
253 } 248 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 content::PasswordForm password_form; 322 content::PasswordForm password_form;
328 password_form.origin = GURL("https://accounts.google.com"); 323 password_form.origin = GURL("https://accounts.google.com");
329 password_form.signon_realm = "https://accounts.google.com"; 324 password_form.signon_realm = "https://accounts.google.com";
330 password_form.password_value = UTF8ToUTF16("password"); 325 password_form.password_value = UTF8ToUTF16("password");
331 helper->OnFormSubmitted(password_form); 326 helper->OnFormSubmitted(password_form);
332 } 327 }
333 328
334 class OneClickSigninHelperIOTest : public OneClickSigninHelperTest { 329 class OneClickSigninHelperIOTest : public OneClickSigninHelperTest {
335 public: 330 public:
336 OneClickSigninHelperIOTest(); 331 OneClickSigninHelperIOTest();
337 virtual ~OneClickSigninHelperIOTest();
338 332
339 virtual void SetUp() OVERRIDE; 333 virtual void SetUp() OVERRIDE;
340 334
341 TestProfileIOData* CreateTestProfileIOData(bool is_incognito); 335 TestProfileIOData* CreateTestProfileIOData(bool is_incognito);
342 336
343 protected: 337 protected:
344 TestingProfileManager testing_profile_manager_; 338 TestingProfileManager testing_profile_manager_;
345 TestURLRequest request_; 339 TestURLRequest request_;
346 const GURL valid_gaia_url_; 340 const GURL valid_gaia_url_;
347 341
348 private: 342 private:
349 content::TestBrowserThread db_thread_;
350 content::TestBrowserThread fub_thread_;
351 content::TestBrowserThread io_thread_;
352
353 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest); 343 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest);
354 }; 344 };
355 345
356 OneClickSigninHelperIOTest::OneClickSigninHelperIOTest() 346 OneClickSigninHelperIOTest::OneClickSigninHelperIOTest()
357 : testing_profile_manager_( 347 : testing_profile_manager_(
358 TestingBrowserProcess::GetGlobal()), 348 TestingBrowserProcess::GetGlobal()),
359 valid_gaia_url_("https://accounts.google.com/"), 349 valid_gaia_url_("https://accounts.google.com/") {
360 db_thread_(content::BrowserThread::DB, &message_loop_),
361 fub_thread_(content::BrowserThread::FILE_USER_BLOCKING, &message_loop_),
362 io_thread_(content::BrowserThread::IO, &message_loop_) {
363 }
364
365 OneClickSigninHelperIOTest::~OneClickSigninHelperIOTest() {
366 } 350 }
367 351
368 void OneClickSigninHelperIOTest::SetUp() { 352 void OneClickSigninHelperIOTest::SetUp() {
369 OneClickSigninHelperTest::SetUp(); 353 OneClickSigninHelperTest::SetUp();
370 ASSERT_TRUE(testing_profile_manager_.SetUp()); 354 ASSERT_TRUE(testing_profile_manager_.SetUp());
371 } 355 }
372 356
373 TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData( 357 TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData(
374 bool is_incognito) { 358 bool is_incognito) {
375 PrefService* pref_service = profile_->GetPrefs(); 359 PrefService* pref_service = profile_->GetPrefs();
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)) 644 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_))
661 .WillRepeatedly(Return(true)); 645 .WillRepeatedly(Return(true));
662 646
663 CreateProfileSyncServiceMock(); 647 CreateProfileSyncServiceMock();
664 648
665 content::WebContents* contents = web_contents(); 649 content::WebContents* contents = web_contents();
666 650
667 OneClickSigninHelper::CreateForWebContents(contents); 651 OneClickSigninHelper::CreateForWebContents(contents);
668 OneClickSigninHelper* helper = 652 OneClickSigninHelper* helper =
669 OneClickSigninHelper::FromWebContents(contents); 653 OneClickSigninHelper::FromWebContents(contents);
654 helper->SetDoNotClearPendingEmailForTesting();
670 655
671 GURL continueUrl("https://chrome.google.com/webstore?source=5"); 656 GURL continueUrl("https://chrome.google.com/webstore?source=5");
672 OneClickSigninHelper::ShowInfoBarUIThread( 657 OneClickSigninHelper::ShowInfoBarUIThread(
673 "session_index", "user@gmail.com", 658 "session_index", "user@gmail.com",
674 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, 659 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT,
675 SyncPromoUI::SOURCE_WEBSTORE_INSTALL, 660 SyncPromoUI::SOURCE_WEBSTORE_INSTALL,
676 continueUrl, process()->GetID(), rvh()->GetRoutingID()); 661 continueUrl, process()->GetID(), rvh()->GetRoutingID());
677 662
678 SubmitGAIAPassword(helper); 663 SubmitGAIAPassword(helper);
679 664
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); 819 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true));
835 820
836 // Simulate a policy disabling sync by writing kSyncManaged directly. 821 // Simulate a policy disabling sync by writing kSyncManaged directly.
837 // We should still offer to sign in the browser. 822 // We should still offer to sign in the browser.
838 profile_->GetTestingPrefService()->SetManagedPref( 823 profile_->GetTestingPrefService()->SetManagedPref(
839 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); 824 prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
840 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, 825 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
841 OneClickSigninHelper::CanOfferOnIOThreadImpl( 826 OneClickSigninHelper::CanOfferOnIOThreadImpl(
842 valid_gaia_url_, std::string(), &request_, io_data.get())); 827 valid_gaia_url_, std::string(), &request_, io_data.get()));
843 } 828 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | chrome/browser/ui/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698