| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/sync/sync_promo_ui.h" | 5 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/signin/fake_signin_manager.h" | 11 #include "chrome/browser/signin/fake_signin_manager.h" |
| 12 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 class SyncPromoUITest : public testing::Test { | 18 class SyncPromoUITest : public testing::Test { |
| 18 public: | |
| 19 SyncPromoUITest() {} | |
| 20 | |
| 21 // testing::Test: | |
| 22 virtual void SetUp() OVERRIDE { | |
| 23 testing::Test::SetUp(); | |
| 24 profile_.reset(new TestingProfile()); | |
| 25 } | |
| 26 | |
| 27 protected: | 19 protected: |
| 28 void CreateSigninManager(const std::string& username) { | 20 void CreateSigninManager(const std::string& username) { |
| 29 SigninManagerBase* signin_manager = | 21 SigninManagerBase* signin_manager = |
| 30 static_cast<FakeSigninManagerBase*>( | 22 static_cast<FakeSigninManagerBase*>( |
| 31 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 23 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 32 profile_.get(), | 24 &profile_, |
| 33 &FakeSigninManagerBase::Build)); | 25 &FakeSigninManagerBase::Build)); |
| 34 signin_manager->Initialize(profile_.get(), NULL); | 26 signin_manager->Initialize(&profile_, NULL); |
| 35 | 27 |
| 36 if (!username.empty()) { | 28 if (!username.empty()) { |
| 37 ASSERT_TRUE(signin_manager); | 29 ASSERT_TRUE(signin_manager); |
| 38 signin_manager->SetAuthenticatedUsername(username); | 30 signin_manager->SetAuthenticatedUsername(username); |
| 39 } | 31 } |
| 40 } | 32 } |
| 41 | 33 |
| 42 void DisableSync() { | 34 void DisableSync() { |
| 43 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); | 35 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); |
| 44 } | 36 } |
| 45 | 37 |
| 46 scoped_ptr<TestingProfile> profile_; | 38 content::TestBrowserThreadBundle thread_bundle_; |
| 47 | 39 TestingProfile profile_; |
| 48 private: | |
| 49 DISALLOW_COPY_AND_ASSIGN(SyncPromoUITest); | |
| 50 }; | 40 }; |
| 51 | 41 |
| 52 // Verifies that ShouldShowSyncPromo returns false if sync is disabled by | 42 // Verifies that ShouldShowSyncPromo returns false if sync is disabled by |
| 53 // policy. | 43 // policy. |
| 54 TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncDisabled) { | 44 TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncDisabled) { |
| 55 CreateSigninManager(""); | 45 CreateSigninManager(""); |
| 56 DisableSync(); | 46 DisableSync(); |
| 57 EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(profile_.get())); | 47 EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(&profile_)); |
| 58 } | 48 } |
| 59 | 49 |
| 60 // Verifies that ShouldShowSyncPromo returns true if all conditions to | 50 // Verifies that ShouldShowSyncPromo returns true if all conditions to |
| 61 // show the promo are met. | 51 // show the promo are met. |
| 62 TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncEnabled) { | 52 TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncEnabled) { |
| 63 CreateSigninManager(""); | 53 CreateSigninManager(""); |
| 64 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 65 // No sync promo on CrOS. | 55 // No sync promo on CrOS. |
| 66 EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(profile_.get())); | 56 EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(&profile_)); |
| 67 #else | 57 #else |
| 68 EXPECT_TRUE(SyncPromoUI::ShouldShowSyncPromo(profile_.get())); | 58 EXPECT_TRUE(SyncPromoUI::ShouldShowSyncPromo(&profile_)); |
| 69 #endif | 59 #endif |
| 70 } | 60 } |
| OLD | NEW |