Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / sync / sync_promo_ui_unittest.cc
blob0c6505468beb8dc0493880c1da02cc85183f1c9d
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/sync/sync_promo_ui.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/signin/fake_signin_manager.h"
12 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 class SyncPromoUITest : public testing::Test {
18 public:
19 SyncPromoUITest() {}
21 // testing::Test:
22 virtual void SetUp() OVERRIDE {
23 testing::Test::SetUp();
24 profile_.reset(new TestingProfile());
27 protected:
28 void CreateSigninManager(const std::string& username) {
29 SigninManagerBase* signin_manager =
30 #if defined(OS_CHROMEOS)
31 static_cast<FakeSigninManagerBase*>(
32 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
33 profile_.get(),
34 &FakeSigninManagerBase::Build));
35 #else
36 static_cast<FakeSigninManager*>(
37 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
38 profile_.get(),
39 &FakeSigninManager::Build));
40 #endif
41 signin_manager->Initialize(profile_.get(), NULL);
43 if (!username.empty()) {
44 ASSERT_TRUE(signin_manager);
45 signin_manager->SetAuthenticatedUsername(username);
49 void DisableSync() {
50 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
53 scoped_ptr<TestingProfile> profile_;
55 private:
56 DISALLOW_COPY_AND_ASSIGN(SyncPromoUITest);
59 // Verifies that ShouldShowSyncPromo returns false if sync is disabled by
60 // policy.
61 TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncDisabled) {
62 CreateSigninManager("");
63 DisableSync();
64 EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(profile_.get()));
67 // Verifies that ShouldShowSyncPromo returns true if all conditions to
68 // show the promo are met.
69 TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncEnabled) {
70 CreateSigninManager("");
71 #if defined(OS_CHROMEOS)
72 // No sync promo on CrOS.
73 EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(profile_.get()));
74 #else
75 EXPECT_TRUE(SyncPromoUI::ShouldShowSyncPromo(profile_.get()));
76 #endif