1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/invalidation/impl/ticl_profile_settings_provider.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/invalidation/impl/fake_invalidation_state_tracker.h"
#include "components/invalidation/impl/invalidation_prefs.h"
#include "components/invalidation/impl/invalidation_state_tracker.h"
#include "components/invalidation/impl/profile_invalidation_provider.h"
#include "components/invalidation/impl/ticl_invalidation_service.h"
#include "components/invalidation/impl/ticl_settings_provider.h"
#include "components/pref_registry/testing_pref_service_syncable.h"
#include "google_apis/gaia/fake_identity_provider.h"
#include "google_apis/gaia/fake_oauth2_token_service.h"
#include "google_apis/gaia/identity_provider.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace invalidation {
class TiclProfileSettingsProviderTest : public testing::Test {
protected:
TiclProfileSettingsProviderTest();
~TiclProfileSettingsProviderTest() override;
// testing::Test:
void SetUp() override;
void TearDown() override;
TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel();
base::MessageLoop message_loop_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
gcm::FakeGCMDriver gcm_driver_;
user_prefs::TestingPrefServiceSyncable pref_service_;
FakeOAuth2TokenService token_service_;
scoped_ptr<TiclInvalidationService> invalidation_service_;
private:
DISALLOW_COPY_AND_ASSIGN(TiclProfileSettingsProviderTest);
};
TiclProfileSettingsProviderTest::TiclProfileSettingsProviderTest() {}
TiclProfileSettingsProviderTest::~TiclProfileSettingsProviderTest() {}
void TiclProfileSettingsProviderTest::SetUp() {
gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(pref_service_.registry());
ProfileInvalidationProvider::RegisterProfilePrefs(pref_service_.registry());
request_context_getter_ =
new net::TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get());
invalidation_service_.reset(new TiclInvalidationService(
"TestUserAgent",
scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
scoped_ptr<TiclSettingsProvider>(
new TiclProfileSettingsProvider(&pref_service_)),
&gcm_driver_, request_context_getter_));
invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
new syncer::FakeInvalidationStateTracker));
}
void TiclProfileSettingsProviderTest::TearDown() {
invalidation_service_.reset();
}
TiclInvalidationService::InvalidationNetworkChannel
TiclProfileSettingsProviderTest::GetNetworkChannel() {
return invalidation_service_->network_channel_type_;
}
TEST_F(TiclProfileSettingsProviderTest, ChannelSelectionTest) {
// Default value should be GCM channel.
EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
// If GCM is enabled and invalidation channel setting is not set or set to
// true then use GCM channel.
pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, true);
pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, true);
pref_service_.ClearPref(prefs::kInvalidationServiceUseGCMChannel);
EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
pref_service_.ClearPref(gcm::prefs::kGCMChannelStatus);
pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
// If invalidation channel setting says use GCM but GCM is not enabled, do not
// fall back to push channel.
pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, false);
pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
// If invalidation channel setting is set to false, fall back to push channel.
pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, true);
pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
}
} // namespace invalidation
|