OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/ntp_snippets/ntp_snippets_status_service.h" | 5 #include "components/ntp_snippets/ntp_snippets_status_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "components/ntp_snippets/ntp_snippets_test_utils.h" | 9 #include "components/ntp_snippets/ntp_snippets_test_utils.h" |
10 #include "components/ntp_snippets/pref_names.h" | 10 #include "components/ntp_snippets/pref_names.h" |
11 #include "components/prefs/pref_registry_simple.h" | 11 #include "components/prefs/pref_registry_simple.h" |
12 #include "components/prefs/testing_pref_service.h" | 12 #include "components/prefs/testing_pref_service.h" |
13 #include "components/signin/core/browser/account_tracker_service.h" | 13 #include "components/signin/core/browser/account_tracker_service.h" |
14 #include "components/signin/core/browser/fake_signin_manager.h" | 14 #include "components/signin/core/browser/fake_signin_manager.h" |
15 #include "components/signin/core/browser/test_signin_client.h" | 15 #include "components/signin/core/browser/test_signin_client.h" |
16 #include "components/signin/core/common/signin_pref_names.h" | 16 #include "components/signin/core/common/signin_pref_names.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using testing::Return; | 20 using testing::Return; |
21 | 21 |
22 namespace ntp_snippets { | 22 namespace ntp_snippets { |
23 | 23 |
24 class NTPSnippetsStatusServiceTest : public test::NTPSnippetsTestBase { | 24 class NTPSnippetsStatusServiceTest : public ::testing::Test { |
25 public: | 25 public: |
26 NTPSnippetsStatusServiceTest() { | 26 NTPSnippetsStatusServiceTest() { |
27 NTPSnippetsStatusService::RegisterProfilePrefs(pref_service()->registry()); | 27 NTPSnippetsStatusService::RegisterProfilePrefs( |
| 28 utils_.pref_service()->registry()); |
28 } | 29 } |
29 | 30 |
30 void SetUp() override { | 31 std::unique_ptr<NTPSnippetsStatusService> MakeService() { |
31 test::NTPSnippetsTestBase::SetUp(); | 32 return base::MakeUnique<NTPSnippetsStatusService>( |
32 | 33 utils_.fake_signin_manager(), utils_.pref_service()); |
33 service_.reset( | |
34 new NTPSnippetsStatusService(fake_signin_manager(), pref_service())); | |
35 } | 34 } |
36 | 35 |
37 protected: | 36 protected: |
38 NTPSnippetsStatusService* service() { return service_.get(); } | 37 test::NTPSnippetsTestUtils utils_; |
39 | |
40 private: | |
41 std::unique_ptr<NTPSnippetsStatusService> service_; | |
42 }; | 38 }; |
43 | 39 |
44 TEST_F(NTPSnippetsStatusServiceTest, SigninStateCompatibility) { | 40 TEST_F(NTPSnippetsStatusServiceTest, SigninStateCompatibility) { |
| 41 auto service = MakeService(); |
| 42 |
45 // The default test setup is signed out. | 43 // The default test setup is signed out. |
46 EXPECT_EQ(DisabledReason::SIGNED_OUT, service()->GetDisabledReasonFromDeps()); | 44 EXPECT_EQ(DisabledReason::SIGNED_OUT, service->GetDisabledReasonFromDeps()); |
47 | 45 |
48 // Once signed in, we should be in a compatible state. | 46 // Once signed in, we should be in a compatible state. |
49 fake_signin_manager()->SignIn("foo@bar.com"); | 47 utils_.fake_signin_manager()->SignIn("foo@bar.com"); |
50 EXPECT_EQ(DisabledReason::NONE, service()->GetDisabledReasonFromDeps()); | 48 EXPECT_EQ(DisabledReason::NONE, service->GetDisabledReasonFromDeps()); |
51 } | 49 } |
52 | 50 |
53 TEST_F(NTPSnippetsStatusServiceTest, DisabledViaPref) { | 51 TEST_F(NTPSnippetsStatusServiceTest, DisabledViaPref) { |
| 52 auto service = MakeService(); |
| 53 |
54 // The default test setup is signed out. | 54 // The default test setup is signed out. |
55 ASSERT_EQ(DisabledReason::SIGNED_OUT, service()->GetDisabledReasonFromDeps()); | 55 ASSERT_EQ(DisabledReason::SIGNED_OUT, service->GetDisabledReasonFromDeps()); |
56 | 56 |
57 // Once the enabled pref is set to false, we should be disabled. | 57 // Once the enabled pref is set to false, we should be disabled. |
58 pref_service()->SetBoolean(prefs::kEnableSnippets, false); | 58 utils_.pref_service()->SetBoolean(prefs::kEnableSnippets, false); |
59 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED, | 59 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED, |
60 service()->GetDisabledReasonFromDeps()); | 60 service->GetDisabledReasonFromDeps()); |
61 | 61 |
62 // The other dependencies shouldn't matter anymore. | 62 // The other dependencies shouldn't matter anymore. |
63 fake_signin_manager()->SignIn("foo@bar.com"); | 63 utils_.fake_signin_manager()->SignIn("foo@bar.com"); |
64 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED, | 64 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED, |
65 service()->GetDisabledReasonFromDeps()); | 65 service->GetDisabledReasonFromDeps()); |
66 } | 66 } |
67 | 67 |
68 } // namespace ntp_snippets | 68 } // namespace ntp_snippets |
OLD | NEW |