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/remote/remote_suggestions_status_service.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "components/ntp_snippets/features.h" | |
10 #include "components/ntp_snippets/ntp_snippets_constants.h" | |
9 #include "components/ntp_snippets/pref_names.h" | 11 #include "components/ntp_snippets/pref_names.h" |
10 #include "components/ntp_snippets/remote/test_utils.h" | 12 #include "components/ntp_snippets/remote/test_utils.h" |
11 #include "components/prefs/pref_registry_simple.h" | 13 #include "components/prefs/pref_registry_simple.h" |
12 #include "components/prefs/testing_pref_service.h" | 14 #include "components/prefs/testing_pref_service.h" |
13 #include "components/signin/core/browser/account_tracker_service.h" | 15 #include "components/signin/core/browser/account_tracker_service.h" |
14 #include "components/signin/core/browser/fake_signin_manager.h" | 16 #include "components/signin/core/browser/fake_signin_manager.h" |
15 #include "components/signin/core/browser/test_signin_client.h" | 17 #include "components/signin/core/browser/test_signin_client.h" |
16 #include "components/signin/core/common/signin_pref_names.h" | 18 #include "components/signin/core/common/signin_pref_names.h" |
19 #include "components/variations/variations_params_manager.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
19 | 22 |
20 namespace ntp_snippets { | 23 namespace ntp_snippets { |
21 | 24 |
22 class RemoteSuggestionsStatusServiceTest : public ::testing::Test { | 25 class RemoteSuggestionsStatusServiceTest : public ::testing::Test { |
23 public: | 26 public: |
24 RemoteSuggestionsStatusServiceTest() { | 27 RemoteSuggestionsStatusServiceTest() { |
25 RemoteSuggestionsStatusService::RegisterProfilePrefs( | 28 RemoteSuggestionsStatusService::RegisterProfilePrefs( |
26 utils_.pref_service()->registry()); | 29 utils_.pref_service()->registry()); |
27 } | 30 } |
28 | 31 |
29 std::unique_ptr<RemoteSuggestionsStatusService> MakeService() { | 32 std::unique_ptr<RemoteSuggestionsStatusService> MakeService() { |
30 return base::MakeUnique<RemoteSuggestionsStatusService>( | 33 return base::MakeUnique<RemoteSuggestionsStatusService>( |
31 utils_.fake_signin_manager(), utils_.pref_service()); | 34 utils_.fake_signin_manager(), utils_.pref_service()); |
32 } | 35 } |
33 | 36 |
34 protected: | 37 protected: |
35 test::RemoteSuggestionsTestUtils utils_; | 38 test::RemoteSuggestionsTestUtils utils_; |
39 variations::testing::VariationParamsManager params_manager_; | |
36 }; | 40 }; |
37 | 41 |
38 // TODO(jkrcal): Extend the ways to override variation parameters in unit-test | 42 TEST_F(RemoteSuggestionsStatusServiceTest, SigninNeededIfSpecifiedByParam) { |
39 // (bug 645447), and recover the SigninStateCompatibility test that sign-in is | 43 // Specify by the parameter that no signin is required. |
Marc Treib
2016/12/06 10:21:09
I think the "no" shouldn't be here?
jkrcal
2016/12/06 10:32:44
Done.
| |
40 // required when the parameter is overriden. | 44 params_manager_.SetVariationParamsWithFeatureAssociations( |
45 ntp_snippets::kStudyName, {{"fetching_requires_signin", "true"}}, | |
46 {ntp_snippets::kArticleSuggestionsFeature.name}); | |
47 | |
48 auto service = MakeService(); | |
49 | |
50 // The default test setup is signed out. | |
51 EXPECT_EQ(RemoteSuggestionsStatus::SIGNED_OUT_AND_DISABLED, | |
52 service->GetStatusFromDeps()); | |
53 | |
54 // Once signed in, we should be in a compatible state. | |
55 utils_.fake_signin_manager()->SignIn("foo@bar.com"); | |
56 EXPECT_EQ(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN, | |
57 service->GetStatusFromDeps()); | |
Marc Treib
2016/12/06 10:21:09
Would be nice to rewrite this tests in terms of th
jkrcal
2016/12/06 10:32:44
Done.
| |
58 } | |
59 | |
60 TEST_F(RemoteSuggestionsStatusServiceTest, NoSigninNeeded) { | |
61 auto service = MakeService(); | |
62 | |
63 // Indeed, no signin is required. | |
Marc Treib
2016/12/06 10:21:09
s/Indeed/By default/
?
jkrcal
2016/12/06 10:32:44
Done.
| |
64 EXPECT_EQ(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | |
65 service->GetStatusFromDeps()); | |
66 | |
67 // Once can still sign in. | |
Marc Treib
2016/12/06 10:21:09
s/Once/One/
?
jkrcal
2016/12/06 10:32:44
Done.
| |
68 utils_.fake_signin_manager()->SignIn("foo@bar.com"); | |
69 EXPECT_EQ(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN, | |
70 service->GetStatusFromDeps()); | |
71 } | |
72 | |
41 TEST_F(RemoteSuggestionsStatusServiceTest, DisabledViaPref) { | 73 TEST_F(RemoteSuggestionsStatusServiceTest, DisabledViaPref) { |
42 auto service = MakeService(); | 74 auto service = MakeService(); |
43 | 75 |
44 // The default test setup is signed out. The service is enabled. | 76 // The default test setup is signed out. The service is enabled. |
45 ASSERT_EQ(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | 77 ASSERT_EQ(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, |
46 service->GetStatusFromDeps()); | 78 service->GetStatusFromDeps()); |
47 | 79 |
48 // Once the enabled pref is set to false, we should be disabled. | 80 // Once the enabled pref is set to false, we should be disabled. |
49 utils_.pref_service()->SetBoolean(prefs::kEnableSnippets, false); | 81 utils_.pref_service()->SetBoolean(prefs::kEnableSnippets, false); |
50 EXPECT_EQ(RemoteSuggestionsStatus::EXPLICITLY_DISABLED, | 82 EXPECT_EQ(RemoteSuggestionsStatus::EXPLICITLY_DISABLED, |
51 service->GetStatusFromDeps()); | 83 service->GetStatusFromDeps()); |
52 | 84 |
53 // Signing-in shouldn't matter anymore. | 85 // The other dependencies shouldn't matter anymore. |
54 utils_.fake_signin_manager()->SignIn("foo@bar.com"); | 86 utils_.fake_signin_manager()->SignIn("foo@bar.com"); |
55 EXPECT_EQ(RemoteSuggestionsStatus::EXPLICITLY_DISABLED, | 87 EXPECT_EQ(RemoteSuggestionsStatus::EXPLICITLY_DISABLED, |
56 service->GetStatusFromDeps()); | 88 service->GetStatusFromDeps()); |
57 } | 89 } |
58 | 90 |
59 } // namespace ntp_snippets | 91 } // namespace ntp_snippets |
OLD | NEW |