OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 7 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_gcm_app_handler.h" | 9 #include "chrome/browser/extensions/extension_gcm_app_handler.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 11 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
12 #include "chrome/browser/services/gcm/gcm_client_factory.h" | 12 #include "chrome/browser/services/gcm/gcm_client_factory.h" |
13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "google_apis/gcm/gcm_client.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const char kEventsExtension[] = "gcm/events"; | 21 const char kEventsExtension[] = "gcm/events"; |
21 | 22 |
22 gcm::GCMClient::SendErrorDetails CreateErrorDetails( | 23 gcm::GCMClient::SendErrorDetails CreateErrorDetails( |
23 const std::string& message_id, | 24 const std::string& message_id, |
24 const gcm::GCMClient::Result result, | 25 const gcm::GCMClient::Result result, |
25 const std::string& total_messages) { | 26 const std::string& total_messages) { |
26 gcm::GCMClient::SendErrorDetails error; | 27 gcm::GCMClient::SendErrorDetails error; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 145 |
145 IN_PROC_BROWSER_TEST_F(GcmApiTest, SendMessageData) { | 146 IN_PROC_BROWSER_TEST_F(GcmApiTest, SendMessageData) { |
146 StartCollecting(); | 147 StartCollecting(); |
147 ASSERT_TRUE(RunExtensionTest("gcm/functions/send_message_data")); | 148 ASSERT_TRUE(RunExtensionTest("gcm/functions/send_message_data")); |
148 | 149 |
149 EXPECT_EQ("destination-id", service()->last_receiver_id()); | 150 EXPECT_EQ("destination-id", service()->last_receiver_id()); |
150 const gcm::GCMClient::OutgoingMessage& message = | 151 const gcm::GCMClient::OutgoingMessage& message = |
151 service()->last_sent_message(); | 152 service()->last_sent_message(); |
152 gcm::GCMClient::MessageData::const_iterator iter; | 153 gcm::GCMClient::MessageData::const_iterator iter; |
153 | 154 |
| 155 EXPECT_EQ(100, message.time_to_live); |
| 156 |
154 EXPECT_TRUE((iter = message.data.find("key1")) != message.data.end()); | 157 EXPECT_TRUE((iter = message.data.find("key1")) != message.data.end()); |
155 EXPECT_EQ("value1", iter->second); | 158 EXPECT_EQ("value1", iter->second); |
156 | 159 |
157 EXPECT_TRUE((iter = message.data.find("key2")) != message.data.end()); | 160 EXPECT_TRUE((iter = message.data.find("key2")) != message.data.end()); |
158 EXPECT_EQ("value2", iter->second); | 161 EXPECT_EQ("value2", iter->second); |
159 } | 162 } |
160 | 163 |
| 164 IN_PROC_BROWSER_TEST_F(GcmApiTest, SendMessageDefaultTTL) { |
| 165 StartCollecting(); |
| 166 ASSERT_TRUE(RunExtensionTest("gcm/functions/send_message_default_ttl")); |
| 167 |
| 168 EXPECT_EQ("destination-id", service()->last_receiver_id()); |
| 169 const gcm::GCMClient::OutgoingMessage& message = |
| 170 service()->last_sent_message(); |
| 171 gcm::GCMClient::MessageData::const_iterator iter; |
| 172 |
| 173 EXPECT_EQ(gcm::GCMClient::OutgoingMessage::kMaximumTTL, message.time_to_live); |
| 174 } |
| 175 |
161 IN_PROC_BROWSER_TEST_F(GcmApiTest, OnMessagesDeleted) { | 176 IN_PROC_BROWSER_TEST_F(GcmApiTest, OnMessagesDeleted) { |
162 ResultCatcher catcher; | 177 ResultCatcher catcher; |
163 catcher.RestrictToProfile(profile()); | 178 catcher.RestrictToProfile(profile()); |
164 | 179 |
165 const extensions::Extension* extension = | 180 const extensions::Extension* extension = |
166 LoadTestExtension(kEventsExtension, "on_messages_deleted.html"); | 181 LoadTestExtension(kEventsExtension, "on_messages_deleted.html"); |
167 ASSERT_TRUE(extension); | 182 ASSERT_TRUE(extension); |
168 | 183 |
169 extensions::ExtensionGCMAppHandler app_handler(profile()); | 184 extensions::ExtensionGCMAppHandler app_handler(profile()); |
170 app_handler.OnMessagesDeleted(extension->id()); | 185 app_handler.OnMessagesDeleted(extension->id()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 ResultCatcher incognito_catcher; | 254 ResultCatcher incognito_catcher; |
240 incognito_catcher.RestrictToProfile(profile()->GetOffTheRecordProfile()); | 255 incognito_catcher.RestrictToProfile(profile()->GetOffTheRecordProfile()); |
241 | 256 |
242 ASSERT_TRUE(RunExtensionTestIncognito("gcm/functions/incognito")); | 257 ASSERT_TRUE(RunExtensionTestIncognito("gcm/functions/incognito")); |
243 | 258 |
244 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 259 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
245 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); | 260 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); |
246 } | 261 } |
247 | 262 |
248 } // namespace extensions | 263 } // namespace extensions |
OLD | NEW |