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

Side by Side Diff: chrome/browser/services/gcm/gcm_profile_service_unittest.cc

Issue 296053011: Start and stop the GCM service on demand (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 7 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
« no previous file with comments | « chrome/browser/services/gcm/gcm_driver_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/services/gcm/gcm_profile_service.h" 5 #include "chrome/browser/services/gcm/gcm_profile_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "chrome/browser/services/gcm/fake_gcm_app_handler.h"
14 #include "chrome/browser/services/gcm/fake_gcm_client.h" 15 #include "chrome/browser/services/gcm/fake_gcm_client.h"
15 #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" 16 #include "chrome/browser/services/gcm/fake_gcm_client_factory.h"
16 #include "chrome/browser/services/gcm/fake_signin_manager.h" 17 #include "chrome/browser/services/gcm/fake_signin_manager.h"
17 #include "chrome/browser/services/gcm/gcm_driver.h" 18 #include "chrome/browser/services/gcm/gcm_driver.h"
18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
21 #include "components/gcm_driver/gcm_client_factory.h" 22 #include "components/gcm_driver/gcm_client_factory.h"
22 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
23 #include "content/public/browser/browser_context.h" 24 #include "content/public/browser/browser_context.h"
(...skipping 23 matching lines...) Expand all
47 48
48 } // namespace 49 } // namespace
49 50
50 class GCMProfileServiceTest : public testing::Test { 51 class GCMProfileServiceTest : public testing::Test {
51 protected: 52 protected:
52 GCMProfileServiceTest(); 53 GCMProfileServiceTest();
53 virtual ~GCMProfileServiceTest(); 54 virtual ~GCMProfileServiceTest();
54 55
55 // testing::Test: 56 // testing::Test:
56 virtual void SetUp() OVERRIDE; 57 virtual void SetUp() OVERRIDE;
58 virtual void TearDown() OVERRIDE;
57 59
58 FakeGCMClient* GetGCMClient() const; 60 FakeGCMClient* GetGCMClient() const;
59 61
60 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); 62 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids);
61 void UnregisterAndWaitForCompletion(); 63 void UnregisterAndWaitForCompletion();
62 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); 64 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message);
63 65
64 void RegisterCompleted(const base::Closure& callback, 66 void RegisterCompleted(const base::Closure& callback,
65 const std::string& registration_id, 67 const std::string& registration_id,
66 GCMClient::Result result); 68 GCMClient::Result result);
67 void UnregisterCompleted(const base::Closure& callback, 69 void UnregisterCompleted(const base::Closure& callback,
68 GCMClient::Result result); 70 GCMClient::Result result);
69 void SendCompleted(const base::Closure& callback, 71 void SendCompleted(const base::Closure& callback,
70 const std::string& message_id, 72 const std::string& message_id,
71 GCMClient::Result result); 73 GCMClient::Result result);
72 74
73 GCMDriver* driver() const { return gcm_profile_service_->driver(); } 75 GCMDriver* driver() const { return gcm_profile_service_->driver(); }
74 std::string registration_id() const { return registration_id_; } 76 std::string registration_id() const { return registration_id_; }
75 GCMClient::Result registration_result() const { return registration_result_; } 77 GCMClient::Result registration_result() const { return registration_result_; }
76 GCMClient::Result unregistration_result() const { 78 GCMClient::Result unregistration_result() const {
77 return unregistration_result_; 79 return unregistration_result_;
78 } 80 }
79 std::string send_message_id() const { return send_message_id_; } 81 std::string send_message_id() const { return send_message_id_; }
80 GCMClient::Result send_result() const { return send_result_; } 82 GCMClient::Result send_result() const { return send_result_; }
81 83
82 private: 84 private:
83 content::TestBrowserThreadBundle thread_bundle_; 85 content::TestBrowserThreadBundle thread_bundle_;
84 scoped_ptr<TestingProfile> profile_; 86 scoped_ptr<TestingProfile> profile_;
85 GCMProfileService* gcm_profile_service_; 87 GCMProfileService* gcm_profile_service_;
88 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
86 89
87 std::string registration_id_; 90 std::string registration_id_;
88 GCMClient::Result registration_result_; 91 GCMClient::Result registration_result_;
89 GCMClient::Result unregistration_result_; 92 GCMClient::Result unregistration_result_;
90 std::string send_message_id_; 93 std::string send_message_id_;
91 GCMClient::Result send_result_; 94 GCMClient::Result send_result_;
92 95
93 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTest); 96 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTest);
94 }; 97 };
95 98
96 GCMProfileServiceTest::GCMProfileServiceTest() 99 GCMProfileServiceTest::GCMProfileServiceTest()
97 : gcm_profile_service_(NULL), 100 : gcm_profile_service_(NULL),
101 gcm_app_handler_(new FakeGCMAppHandler),
98 registration_result_(GCMClient::UNKNOWN_ERROR), 102 registration_result_(GCMClient::UNKNOWN_ERROR),
99 send_result_(GCMClient::UNKNOWN_ERROR) { 103 send_result_(GCMClient::UNKNOWN_ERROR) {
100 } 104 }
101 105
102 GCMProfileServiceTest::~GCMProfileServiceTest() { 106 GCMProfileServiceTest::~GCMProfileServiceTest() {
103 } 107 }
104 108
105 FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const { 109 FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const {
106 return static_cast<FakeGCMClient*>( 110 return static_cast<FakeGCMClient*>(
107 gcm_profile_service_->driver()->GetGCMClientForTesting()); 111 gcm_profile_service_->driver()->GetGCMClientForTesting());
108 } 112 }
109 113
110 void GCMProfileServiceTest::SetUp() { 114 void GCMProfileServiceTest::SetUp() {
111 TestingProfile::Builder builder; 115 TestingProfile::Builder builder;
112 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), 116 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
113 FakeSigninManager::Build); 117 FakeSigninManager::Build);
114 profile_ = builder.Build(); 118 profile_ = builder.Build();
115 119
116 gcm_profile_service_ = static_cast<GCMProfileService*>( 120 gcm_profile_service_ = static_cast<GCMProfileService*>(
117 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( 121 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse(
118 profile_.get(), 122 profile_.get(),
119 &BuildGCMProfileService)); 123 &BuildGCMProfileService));
124 gcm_profile_service_->driver()->AddAppHandler(
125 kTestAppID, gcm_app_handler_.get());
120 126
121 FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>( 127 FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>(
122 SigninManagerFactory::GetInstance()->GetForProfile(profile_.get())); 128 SigninManagerFactory::GetInstance()->GetForProfile(profile_.get()));
123 signin_manager->SignIn(kTestAccountID); 129 signin_manager->SignIn(kTestAccountID);
124 base::RunLoop().RunUntilIdle(); 130 base::RunLoop().RunUntilIdle();
125 } 131 }
126 132
133 void GCMProfileServiceTest::TearDown() {
134 gcm_profile_service_->driver()->RemoveAppHandler(kTestAppID);
135 }
136
127 void GCMProfileServiceTest::RegisterAndWaitForCompletion( 137 void GCMProfileServiceTest::RegisterAndWaitForCompletion(
128 const std::vector<std::string>& sender_ids) { 138 const std::vector<std::string>& sender_ids) {
129 base::RunLoop run_loop; 139 base::RunLoop run_loop;
130 gcm_profile_service_->driver()->Register( 140 gcm_profile_service_->driver()->Register(
131 kTestAppID, 141 kTestAppID,
132 sender_ids, 142 sender_ids,
133 base::Bind(&GCMProfileServiceTest::RegisterCompleted, 143 base::Bind(&GCMProfileServiceTest::RegisterCompleted,
134 base::Unretained(this), 144 base::Unretained(this),
135 run_loop.QuitClosure())); 145 run_loop.QuitClosure()));
136 run_loop.Run(); 146 run_loop.Run();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 GCMClient::OutgoingMessage message; 212 GCMClient::OutgoingMessage message;
203 message.id = "1"; 213 message.id = "1";
204 message.data["key1"] = "value1"; 214 message.data["key1"] = "value1";
205 SendAndWaitForCompletion( message); 215 SendAndWaitForCompletion( message);
206 216
207 EXPECT_EQ(message.id, send_message_id()); 217 EXPECT_EQ(message.id, send_message_id());
208 EXPECT_EQ(GCMClient::SUCCESS, send_result()); 218 EXPECT_EQ(GCMClient::SUCCESS, send_result());
209 } 219 }
210 220
211 } // namespace gcm 221 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_driver_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698