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

Side by Side Diff: components/ntp_snippets/ntp_snippets_status_service_unittest.cc

Issue 2191343002: 📰 Remove SnippetService's dependency on Sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update some doc, show NO_SNIPPETS instead of SIGNIN when during INITIALIZING state Created 4 years, 4 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
OLDNEW
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 "components/sync_driver/fake_sync_service.h"
18 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 using testing::Return; 20 using testing::Return;
22 21
23 namespace ntp_snippets { 22 namespace ntp_snippets {
24 23
25 class NTPSnippetsStatusServiceTest : public test::NTPSnippetsTestBase { 24 class NTPSnippetsStatusServiceTest : public test::NTPSnippetsTestBase {
26 public: 25 public:
27 NTPSnippetsStatusServiceTest() { 26 NTPSnippetsStatusServiceTest() {
28 NTPSnippetsStatusService::RegisterProfilePrefs(pref_service()->registry()); 27 NTPSnippetsStatusService::RegisterProfilePrefs(pref_service()->registry());
29 } 28 }
30 29
31 void SetUp() override { 30 void SetUp() override {
32 test::NTPSnippetsTestBase::SetUp(); 31 test::NTPSnippetsTestBase::SetUp();
33 32
34 service_.reset(new NTPSnippetsStatusService( 33 service_.reset(
35 fake_signin_manager(), mock_sync_service(), pref_service())); 34 new NTPSnippetsStatusService(fake_signin_manager(), pref_service()));
36 } 35 }
37 36
38 protected: 37 protected:
39 NTPSnippetsStatusService* service() { return service_.get(); } 38 NTPSnippetsStatusService* service() { return service_.get(); }
40 39
41 private: 40 private:
42 std::unique_ptr<NTPSnippetsStatusService> service_; 41 std::unique_ptr<NTPSnippetsStatusService> service_;
43 }; 42 };
44 43
45 TEST_F(NTPSnippetsStatusServiceTest, SyncStateCompatibility) { 44 TEST_F(NTPSnippetsStatusServiceTest, SigninStateCompatibility) {
46 // The default test setup is signed out. 45 // The default test setup is signed out.
47 EXPECT_EQ(DisabledReason::SIGNED_OUT, service()->GetDisabledReasonFromDeps()); 46 EXPECT_EQ(DisabledReason::SIGNED_OUT, service()->GetDisabledReasonFromDeps());
48 47
49 // Once signed in, we should be in a compatible sync state. 48 // Once signed in, we should be in a compatible state.
50 fake_signin_manager()->SignIn("foo@bar.com"); 49 fake_signin_manager()->SignIn("foo@bar.com");
51 EXPECT_EQ(DisabledReason::NONE, service()->GetDisabledReasonFromDeps()); 50 EXPECT_EQ(DisabledReason::NONE, service()->GetDisabledReasonFromDeps());
52
53 // History sync disabled.
54 mock_sync_service()->active_data_types_ = syncer::ModelTypeSet();
55 EXPECT_EQ(DisabledReason::HISTORY_SYNC_DISABLED,
56 service()->GetDisabledReasonFromDeps());
57
58 // Encryption enabled.
59 mock_sync_service()->is_encrypt_everything_enabled_ = true;
60 EXPECT_EQ(DisabledReason::PASSPHRASE_ENCRYPTION_ENABLED,
61 service()->GetDisabledReasonFromDeps());
62
63 // Not done loading.
64 mock_sync_service()->configuration_done_ = false;
65 mock_sync_service()->active_data_types_ = syncer::ModelTypeSet();
66 EXPECT_EQ(DisabledReason::HISTORY_SYNC_STATE_UNKNOWN,
67 service()->GetDisabledReasonFromDeps());
68
69 // Sync disabled.
70 mock_sync_service()->can_sync_start_ = false;
71 EXPECT_EQ(DisabledReason::SYNC_DISABLED,
72 service()->GetDisabledReasonFromDeps());
73 } 51 }
74 52
75 TEST_F(NTPSnippetsStatusServiceTest, DisabledViaPref) { 53 TEST_F(NTPSnippetsStatusServiceTest, DisabledViaPref) {
76 // The default test setup is signed out. 54 // The default test setup is signed out.
77 ASSERT_EQ(DisabledReason::SIGNED_OUT, service()->GetDisabledReasonFromDeps()); 55 ASSERT_EQ(DisabledReason::SIGNED_OUT, service()->GetDisabledReasonFromDeps());
78 56
79 // 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.
80 pref_service()->SetBoolean(prefs::kEnableSnippets, false); 58 pref_service()->SetBoolean(prefs::kEnableSnippets, false);
81 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED, 59 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED,
82 service()->GetDisabledReasonFromDeps()); 60 service()->GetDisabledReasonFromDeps());
83 61
84 // The other dependencies shouldn't matter anymore. 62 // The other dependencies shouldn't matter anymore.
85 fake_signin_manager()->SignIn("foo@bar.com"); 63 fake_signin_manager()->SignIn("foo@bar.com");
86 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED, 64 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED,
87 service()->GetDisabledReasonFromDeps()); 65 service()->GetDisabledReasonFromDeps());
88
89 mock_sync_service()->active_data_types_ = syncer::ModelTypeSet();
90 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED,
91 service()->GetDisabledReasonFromDeps());
92
93 mock_sync_service()->is_encrypt_everything_enabled_ = true;
94 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED,
95 service()->GetDisabledReasonFromDeps());
96
97 mock_sync_service()->configuration_done_ = false;
98 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED,
99 service()->GetDisabledReasonFromDeps());
100
101 mock_sync_service()->can_sync_start_ = false;
102 EXPECT_EQ(DisabledReason::EXPLICITLY_DISABLED,
103 service()->GetDisabledReasonFromDeps());
104 } 66 }
105 67
106 } // namespace ntp_snippets 68 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_status_service.cc ('k') | components/ntp_snippets_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698