OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/stringprintf.h" | |
6 #include "chrome/browser/browser_process.h" | 5 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 6 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 8 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/extensions/features/feature.h" | 11 #include "chrome/common/extensions/features/feature.h" |
13 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
14 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
15 #include "ui/message_center/message_center.h" | 14 #include "ui/message_center/message_center.h" |
16 #include "ui/message_center/message_center_switches.h" | |
17 #include "ui/message_center/message_center_util.h" | 15 #include "ui/message_center/message_center_util.h" |
18 | 16 |
19 // TODO(kbr): remove: http://crbug.com/222296 | 17 // TODO(kbr): remove: http://crbug.com/222296 |
20 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
21 #import "base/mac/mac_util.h" | 19 #import "base/mac/mac_util.h" |
22 #endif | 20 #endif |
23 | 21 |
24 using extensions::Extension; | 22 using extensions::Extension; |
25 | 23 |
26 namespace utils = extension_function_test_utils; | 24 namespace utils = extension_function_test_utils; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 "}]", | 253 "}]", |
256 browser(), utils::NONE)); | 254 browser(), utils::NONE)); |
257 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...] | 255 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...] |
258 | 256 |
259 std::string notification_id; | 257 std::string notification_id; |
260 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); | 258 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
261 ASSERT_TRUE(result->GetAsString(¬ification_id)); | 259 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
262 ASSERT_TRUE(notification_id.length() > 0); | 260 ASSERT_TRUE(notification_id.length() > 0); |
263 } | 261 } |
264 | 262 |
265 #if defined(OS_LINUX) && defined(USE_AURA) | |
266 #define MAYBE_TestGetAll DISABLED_TestGetAll | |
267 #else | |
268 #define MAYBE_TestGetAll TestGetAll | |
269 #endif | |
270 | |
271 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetAll) { | |
272 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | |
273 | |
274 { | |
275 scoped_refptr<extensions::NotificationsGetAllFunction> | |
276 notification_get_all_function( | |
277 new extensions::NotificationsGetAllFunction()); | |
278 notification_get_all_function->set_extension(empty_extension.get()); | |
279 notification_get_all_function->set_has_callback(true); | |
280 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
281 notification_get_all_function, "[]", browser(), utils::NONE)); | |
282 | |
283 base::DictionaryValue* return_value; | |
284 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | |
285 ASSERT_TRUE(result->GetAsDictionary(&return_value)); | |
286 ASSERT_TRUE(return_value->size() == 0); | |
287 } | |
288 | |
289 const unsigned int kNotificationsToCreate = 4; | |
290 | |
291 for (unsigned int i = 0; i < kNotificationsToCreate; i++) { | |
292 scoped_refptr<extensions::NotificationsCreateFunction> | |
293 notification_create_function( | |
294 new extensions::NotificationsCreateFunction()); | |
295 | |
296 notification_create_function->set_extension(empty_extension.get()); | |
297 notification_create_function->set_has_callback(true); | |
298 | |
299 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
300 notification_create_function, | |
301 base::StringPrintf("[\"identifier-%u\", " | |
302 "{" | |
303 "\"type\": \"list\"," | |
304 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," | |
305 "\"title\": \"Title\"," | |
306 "\"message\": \"Message.\"," | |
307 "\"items\": [" | |
308 " {\"title\": \"Grace Goe\"," | |
309 " \"message\": \"I saw Frank steal a sandwich :-)\"}" | |
310 "]," | |
311 "\"priority\": 1," | |
312 "\"eventTime\": 1361488019.9999999" | |
313 "}]", | |
314 i), | |
315 browser(), | |
316 utils::NONE)); | |
317 } | |
318 | |
319 { | |
320 scoped_refptr<extensions::NotificationsGetAllFunction> | |
321 notification_get_all_function( | |
322 new extensions::NotificationsGetAllFunction()); | |
323 notification_get_all_function->set_extension(empty_extension.get()); | |
324 notification_get_all_function->set_has_callback(true); | |
325 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
326 notification_get_all_function, "[]", browser(), utils::NONE)); | |
327 | |
328 base::DictionaryValue* return_value; | |
329 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | |
330 ASSERT_TRUE(result->GetAsDictionary(&return_value)); | |
331 ASSERT_EQ(return_value->size(), kNotificationsToCreate); | |
332 bool dictionary_bool = false; | |
333 for (unsigned int i = 0; i < kNotificationsToCreate; i++) { | |
334 std::string id = base::StringPrintf("identifier-%u", i); | |
335 ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool)); | |
336 ASSERT_TRUE(dictionary_bool); | |
337 } | |
338 } | |
339 } | |
340 | |
341 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { | 263 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { |
342 #if defined(OS_MACOSX) | 264 #if defined(OS_MACOSX) |
343 // TODO(kbr): re-enable: http://crbug.com/222296 | 265 // TODO(kbr): re-enable: http://crbug.com/222296 |
344 if (base::mac::IsOSMountainLionOrLater()) | 266 if (base::mac::IsOSMountainLionOrLater()) |
345 return; | 267 return; |
346 #endif | 268 #endif |
347 | 269 |
348 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; | 270 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; |
349 } | 271 } |
350 | 272 |
(...skipping 24 matching lines...) Expand all Loading... |
375 } | 297 } |
376 | 298 |
377 { | 299 { |
378 ResultCatcher catcher; | 300 ResultCatcher catcher; |
379 g_browser_process->message_center()->RemoveNotification( | 301 g_browser_process->message_center()->RemoveNotification( |
380 extension->id() + "-BAR", | 302 extension->id() + "-BAR", |
381 true); | 303 true); |
382 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 304 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
383 } | 305 } |
384 } | 306 } |
OLD | NEW |