OLD | NEW |
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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 protected: | 42 protected: |
43 GCMProfileServiceTest(); | 43 GCMProfileServiceTest(); |
44 virtual ~GCMProfileServiceTest(); | 44 virtual ~GCMProfileServiceTest(); |
45 | 45 |
46 // testing::Test: | 46 // testing::Test: |
47 virtual void SetUp() OVERRIDE; | 47 virtual void SetUp() OVERRIDE; |
48 | 48 |
49 GCMClientMock* GetGCMClient() const; | 49 GCMClientMock* GetGCMClient() const; |
50 | 50 |
51 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); | 51 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); |
52 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); | 52 void SendAndWaitForCompletion(const OutgoingMessage& message); |
53 | 53 |
54 void RegisterCompleted(const base::Closure& callback, | 54 void RegisterCompleted(const base::Closure& callback, |
55 const std::string& registration_id, | 55 const std::string& registration_id, |
56 GCMClient::Result result); | 56 Result result); |
57 void SendCompleted(const base::Closure& callback, | 57 void SendCompleted(const base::Closure& callback, |
58 const std::string& message_id, | 58 const std::string& message_id, |
59 GCMClient::Result result); | 59 Result result); |
60 | 60 |
61 content::TestBrowserThreadBundle thread_bundle_; | 61 content::TestBrowserThreadBundle thread_bundle_; |
62 scoped_ptr<TestingProfile> profile_; | 62 scoped_ptr<TestingProfile> profile_; |
63 GCMProfileService* gcm_profile_service_; | 63 GCMProfileService* gcm_profile_service_; |
64 | 64 |
65 std::string registration_id_; | 65 std::string registration_id_; |
66 GCMClient::Result registration_result_; | 66 Result registration_result_; |
67 std::string send_message_id_; | 67 std::string send_message_id_; |
68 GCMClient::Result send_result_; | 68 Result send_result_; |
69 | 69 |
70 private: | 70 private: |
71 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTest); | 71 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTest); |
72 }; | 72 }; |
73 | 73 |
74 GCMProfileServiceTest::GCMProfileServiceTest() | 74 GCMProfileServiceTest::GCMProfileServiceTest() |
75 : gcm_profile_service_(NULL), | 75 : gcm_profile_service_(NULL), |
76 registration_result_(GCMClient::UNKNOWN_ERROR), | 76 registration_result_(RESULT_UNKNOWN_ERROR), |
77 send_result_(GCMClient::UNKNOWN_ERROR) { | 77 send_result_(RESULT_UNKNOWN_ERROR) { |
78 } | 78 } |
79 | 79 |
80 GCMProfileServiceTest::~GCMProfileServiceTest() { | 80 GCMProfileServiceTest::~GCMProfileServiceTest() { |
81 } | 81 } |
82 | 82 |
83 GCMClientMock* GCMProfileServiceTest::GetGCMClient() const { | 83 GCMClientMock* GCMProfileServiceTest::GetGCMClient() const { |
84 return static_cast<GCMClientMock*>( | 84 return static_cast<GCMClientMock*>( |
85 gcm_profile_service_->GetGCMClientForTesting()); | 85 gcm_profile_service_->GetGCMClientForTesting()); |
86 } | 86 } |
87 | 87 |
(...skipping 22 matching lines...) Expand all Loading... |
110 gcm_profile_service_->Register( | 110 gcm_profile_service_->Register( |
111 kTestAppID, | 111 kTestAppID, |
112 sender_ids, | 112 sender_ids, |
113 base::Bind(&GCMProfileServiceTest::RegisterCompleted, | 113 base::Bind(&GCMProfileServiceTest::RegisterCompleted, |
114 base::Unretained(this), | 114 base::Unretained(this), |
115 run_loop.QuitClosure())); | 115 run_loop.QuitClosure())); |
116 run_loop.Run(); | 116 run_loop.Run(); |
117 } | 117 } |
118 | 118 |
119 void GCMProfileServiceTest::SendAndWaitForCompletion( | 119 void GCMProfileServiceTest::SendAndWaitForCompletion( |
120 const GCMClient::OutgoingMessage& message) { | 120 const OutgoingMessage& message) { |
121 base::RunLoop run_loop; | 121 base::RunLoop run_loop; |
122 gcm_profile_service_->Send(kTestAppID, | 122 gcm_profile_service_->Send(kTestAppID, |
123 kUserID, | 123 kUserID, |
124 message, | 124 message, |
125 base::Bind(&GCMProfileServiceTest::SendCompleted, | 125 base::Bind(&GCMProfileServiceTest::SendCompleted, |
126 base::Unretained(this), | 126 base::Unretained(this), |
127 run_loop.QuitClosure())); | 127 run_loop.QuitClosure())); |
128 run_loop.Run(); | 128 run_loop.Run(); |
129 } | 129 } |
130 | 130 |
131 void GCMProfileServiceTest::RegisterCompleted( | 131 void GCMProfileServiceTest::RegisterCompleted( |
132 const base::Closure& callback, | 132 const base::Closure& callback, |
133 const std::string& registration_id, | 133 const std::string& registration_id, |
134 GCMClient::Result result) { | 134 Result result) { |
135 registration_id_ = registration_id; | 135 registration_id_ = registration_id; |
136 registration_result_ = result; | 136 registration_result_ = result; |
137 callback.Run(); | 137 callback.Run(); |
138 } | 138 } |
139 | 139 |
140 void GCMProfileServiceTest::SendCompleted( | 140 void GCMProfileServiceTest::SendCompleted( |
141 const base::Closure& callback, | 141 const base::Closure& callback, |
142 const std::string& message_id, | 142 const std::string& message_id, |
143 GCMClient::Result result) { | 143 Result result) { |
144 send_message_id_ = message_id; | 144 send_message_id_ = message_id; |
145 send_result_ = result; | 145 send_result_ = result; |
146 callback.Run(); | 146 callback.Run(); |
147 } | 147 } |
148 | 148 |
149 TEST_F(GCMProfileServiceTest, RegisterUnderNeutralChannelSignal) { | 149 TEST_F(GCMProfileServiceTest, RegisterUnderNeutralChannelSignal) { |
150 // GCMClient should not be checked in. | 150 // GCMClient should not be checked in. |
151 EXPECT_FALSE(gcm_profile_service_->IsGCMClientReady()); | 151 EXPECT_FALSE(gcm_profile_service_->IsGCMClientReady()); |
152 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); | 152 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); |
153 | 153 |
154 // Invoking register will make GCMClient checked in. | 154 // Invoking register will make GCMClient checked in. |
155 std::vector<std::string> sender_ids; | 155 std::vector<std::string> sender_ids; |
156 sender_ids.push_back("sender"); | 156 sender_ids.push_back("sender"); |
157 RegisterAndWaitForCompletion(sender_ids); | 157 RegisterAndWaitForCompletion(sender_ids); |
158 | 158 |
159 // GCMClient should be checked in. | 159 // GCMClient should be checked in. |
160 EXPECT_TRUE(gcm_profile_service_->IsGCMClientReady()); | 160 EXPECT_TRUE(gcm_profile_service_->IsGCMClientReady()); |
161 EXPECT_EQ(GCMClientMock::LOADED, GetGCMClient()->status()); | 161 EXPECT_EQ(GCMClientMock::LOADED, GetGCMClient()->status()); |
162 | 162 |
163 // Registration should succeed. | 163 // Registration should succeed. |
164 std::string expected_registration_id = | 164 std::string expected_registration_id = |
165 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 165 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); |
166 EXPECT_EQ(expected_registration_id, registration_id_); | 166 EXPECT_EQ(expected_registration_id, registration_id_); |
167 EXPECT_EQ(GCMClient::SUCCESS, registration_result_); | 167 EXPECT_EQ(RESULT_SUCCESS, registration_result_); |
168 } | 168 } |
169 | 169 |
170 TEST_F(GCMProfileServiceTest, SendUnderNeutralChannelSignal) { | 170 TEST_F(GCMProfileServiceTest, SendUnderNeutralChannelSignal) { |
171 // GCMClient should not be checked in. | 171 // GCMClient should not be checked in. |
172 EXPECT_FALSE(gcm_profile_service_->IsGCMClientReady()); | 172 EXPECT_FALSE(gcm_profile_service_->IsGCMClientReady()); |
173 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); | 173 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); |
174 | 174 |
175 // Invoking send will make GCMClient checked in. | 175 // Invoking send will make GCMClient checked in. |
176 GCMClient::OutgoingMessage message; | 176 OutgoingMessage message; |
177 message.id = "1"; | 177 message.id = "1"; |
178 message.data["key1"] = "value1"; | 178 message.data["key1"] = "value1"; |
179 SendAndWaitForCompletion( message); | 179 SendAndWaitForCompletion( message); |
180 | 180 |
181 // GCMClient should be checked in. | 181 // GCMClient should be checked in. |
182 EXPECT_TRUE(gcm_profile_service_->IsGCMClientReady()); | 182 EXPECT_TRUE(gcm_profile_service_->IsGCMClientReady()); |
183 EXPECT_EQ(GCMClientMock::LOADED, GetGCMClient()->status()); | 183 EXPECT_EQ(GCMClientMock::LOADED, GetGCMClient()->status()); |
184 | 184 |
185 // Sending should succeed. | 185 // Sending should succeed. |
186 EXPECT_EQ(message.id, send_message_id_); | 186 EXPECT_EQ(message.id, send_message_id_); |
187 EXPECT_EQ(GCMClient::SUCCESS, send_result_); | 187 EXPECT_EQ(RESULT_SUCCESS, send_result_); |
188 } | 188 } |
189 | 189 |
190 } // namespace gcm | 190 } // namespace gcm |
OLD | NEW |