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

Side by Side Diff: chrome/browser/invalidation/ticl_invalidation_service_profile_settings_provider_unittest.cc

Issue 255443005: Remove Profile dependency from TiclInvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #include "chrome/browser/invalidation/ticl_invalidation_service_profile_settings _provider.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/invalidation/ticl_invalidation_service.h"
10 #include "chrome/browser/invalidation/ticl_invalidation_service_settings_provide r.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/services/gcm/gcm_profile_service.h"
13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "google_apis/gaia/fake_identity_provider.h"
18 #include "google_apis/gaia/fake_oauth2_token_service.h"
19 #include "google_apis/gaia/identity_provider.h"
20 #include "net/url_request/url_request_context_getter.h"
21 #include "sync/notifier/fake_invalidation_state_tracker.h"
22 #include "sync/notifier/invalidation_state_tracker.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 namespace invalidation {
26
27 class TiclInvalidationServiceProfileSettingsProviderTest
28 : public testing::Test {
29 protected:
30 TiclInvalidationServiceProfileSettingsProviderTest();
31 virtual ~TiclInvalidationServiceProfileSettingsProviderTest();
32
33 // testing::Test:
34 virtual void SetUp() OVERRIDE;
35 virtual void TearDown() OVERRIDE;
36
37 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel();
38
39 content::TestBrowserThreadBundle thread_bundle_;
40 TestingProfile profile_;
41 FakeOAuth2TokenService token_service_;
42
43 scoped_ptr<TiclInvalidationService> invalidation_service_;
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationServiceProfileSettingsProviderTest);
47 };
48
49 TiclInvalidationServiceProfileSettingsProviderTest::
50 TiclInvalidationServiceProfileSettingsProviderTest() {
51 }
52
53 TiclInvalidationServiceProfileSettingsProviderTest::
54 ~TiclInvalidationServiceProfileSettingsProviderTest() {
55 }
56
57 void TiclInvalidationServiceProfileSettingsProviderTest::SetUp() {
58 invalidation_service_.reset(new TiclInvalidationService(
59 scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
60 scoped_ptr<TiclInvalidationServiceSettingsProvider>(
61 new TiclInvalidationServiceProfileSettingsProvider(&profile_)),
62 gcm::GCMProfileServiceFactory::GetForProfile(&profile_),
63 profile_.GetRequestContext()));
64 invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
65 new syncer::FakeInvalidationStateTracker));
66 }
67
68 void TiclInvalidationServiceProfileSettingsProviderTest::TearDown() {
69 invalidation_service_->Shutdown();
70 }
71
72 TiclInvalidationService::InvalidationNetworkChannel
73 TiclInvalidationServiceProfileSettingsProviderTest::GetNetworkChannel() {
74 return invalidation_service_->network_channel_type_;
75 }
76
77 TEST_F(TiclInvalidationServiceProfileSettingsProviderTest,
78 ChannelSelectionTest) {
79 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
80 PrefService* prefs = profile_.GetPrefs();
81
82 // If stars align, use GCM channel.
83 prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
84 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
85 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
86
87 // If invalidation channel setting is not set or says false, fall back to push
88 // channel.
89 prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
90
91 prefs->ClearPref(prefs::kInvalidationServiceUseGCMChannel);
92 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
93
94 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
95 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
96
97 // If invalidation channel setting says use GCM but GCM is not ALWAYS_ENABLED,
98 // fall back to push channel.
99 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
100
101 prefs->ClearPref(prefs::kGCMChannelEnabled);
102 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
103
104 prefs->SetBoolean(prefs::kGCMChannelEnabled, false);
105 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
106
107 // If invalidation channel setting is enabled first and the GCM setting is
108 // enabled after that, switch to GCM channel.
109 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
110 prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
111 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
112 }
113
114 } // namespace invalidation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698