diff options
Diffstat (limited to 'chrome/browser/extensions/api/notification')
-rw-r--r-- | chrome/browser/extensions/api/notification/notification_api.cc | 60 | ||||
-rw-r--r-- | chrome/browser/extensions/api/notification/notification_apitest.cc | 42 |
2 files changed, 24 insertions, 78 deletions
diff --git a/chrome/browser/extensions/api/notification/notification_api.cc b/chrome/browser/extensions/api/notification/notification_api.cc index 4d3e1d4..a96d5b0 100644 --- a/chrome/browser/extensions/api/notification/notification_api.cc +++ b/chrome/browser/extensions/api/notification/notification_api.cc @@ -93,50 +93,36 @@ bool NotificationShowFunction::RunImpl() { src_id_ = ExtractSrcId(options_dict.get()); event_notifier_ = CreateEventNotifier(src_id_); - ui::notifications::NotificationType type = - ui::notifications::StringToNotificationType(options->notification_type); GURL icon_url(UTF8ToUTF16(options->icon_url)); string16 title(UTF8ToUTF16(options->title)); string16 message(UTF8ToUTF16(options->message)); - scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); - - if (options->message_intent.get()) - optional_fields->SetString(ui::notifications::kMessageIntentKey, - UTF8ToUTF16(*options->message_intent)); - if (options->priority.get()) - optional_fields->SetInteger(ui::notifications::kPriorityKey, - *options->priority); - if (options->timestamp.get()) - optional_fields->SetString(ui::notifications::kTimestampKey, - *options->timestamp); - if (options->second_icon_url.get()) - optional_fields->SetString(ui::notifications::kSecondIconUrlKey, - UTF8ToUTF16(*options->second_icon_url)); - if (options->unread_count.get()) - optional_fields->SetInteger(ui::notifications::kUnreadCountKey, - *options->unread_count); - if (options->button_one_title.get()) - optional_fields->SetString(ui::notifications::kButtonOneTitleKey, - UTF8ToUTF16(*options->button_one_title)); - if (options->button_one_intent.get()) - optional_fields->SetString(ui::notifications::kButtonOneIntentKey, - UTF8ToUTF16(*options->button_one_intent)); - if (options->button_two_title.get()) - optional_fields->SetString(ui::notifications::kButtonTwoTitleKey, - UTF8ToUTF16(*options->button_two_title)); - if (options->button_two_intent.get()) - optional_fields->SetString(ui::notifications::kButtonTwoIntentKey, - UTF8ToUTF16(*options->button_two_intent)); - if (options->expanded_message.get()) - optional_fields->SetString(ui::notifications::kExpandedMessageKey, - UTF8ToUTF16(*options->expanded_message)); - if (options->image_url.get()) - optional_fields->SetString(ui::notifications::kImageUrlKey, - UTF8ToUTF16(*options->image_url)); + // TEMP fields that are here to demonstrate usage of... fields. + // TODO(miket): replace with real fields from BaseFormatView. + string16 extra_field; + if (options->extra_field.get()) + extra_field = UTF8ToUTF16(*options->extra_field); + string16 second_extra_field; + if (options->second_extra_field.get()) + second_extra_field = UTF8ToUTF16(*options->second_extra_field); string16 replace_id(UTF8ToUTF16(options->replace_id)); + ui::notifications::NotificationType type; + scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue()); + // TODO(miket): this is a lazy hacky way to distinguish the old and new + // notification types. Once we have something more than just "old" and "new," + // we'll probably want to pass the type all the way up from the JS, and then + // we won't need this hack at all. + if (extra_field.empty()) { + type = ui::notifications::NOTIFICATION_TYPE_SIMPLE; + } else { + type = ui::notifications::NOTIFICATION_TYPE_BASE_FORMAT; + optional_fields->SetString(ui::notifications::kExtraFieldKey, + extra_field); + optional_fields->SetString(ui::notifications::kSecondExtraFieldKey, + second_extra_field); + } Notification notification(type, icon_url, title, message, WebKit::WebTextDirectionDefault, string16(), replace_id, diff --git a/chrome/browser/extensions/api/notification/notification_apitest.cc b/chrome/browser/extensions/api/notification/notification_apitest.cc index b3ff3a2..d32f51c 100644 --- a/chrome/browser/extensions/api/notification/notification_apitest.cc +++ b/chrome/browser/extensions/api/notification/notification_apitest.cc @@ -23,7 +23,7 @@ class NotificationApiTest : public ExtensionApiTest { } // namespace -IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestSimpleNotification) { +IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestNormalNotification) { scoped_refptr<extensions::NotificationShowFunction> notification_show_function(new extensions::NotificationShowFunction()); scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); @@ -34,7 +34,6 @@ IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestSimpleNotification) { scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( notification_show_function, "[{" - "\"notificationType\": \"simple\"," "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/" "common/images/chrome_logo_2x.png\"," "\"title\": \"Attention!\"," @@ -44,43 +43,4 @@ IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestSimpleNotification) { browser(), utils::NONE)); ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); - - // TODO(miket): confirm that the show succeeded. -} - -IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestBaseFormatNotification) { - scoped_refptr<extensions::NotificationShowFunction> - notification_show_function(new extensions::NotificationShowFunction()); - scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); - - notification_show_function->set_extension(empty_extension.get()); - notification_show_function->set_has_callback(true); - - scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( - notification_show_function, - "[{" - "\"notificationType\": \"base\"," - "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/" - "common/images/chrome_logo_2x.png\"," - "\"title\": \"Attention!\"," - "\"message\": \"Check out Cirque du Soleil\"," - "\"messageIntent\": \"[pending]\"," - "\"priority\": 1," - "\"timestamp\": \"Tue, 15 Nov 1994 12:45:26 GMT\"," - "\"secondIconUrl\": \"http://www.google.com/logos/2012/" - "Day-Of-The-Dead-12-hp.jpg\"," - "\"unreadCount\": 42," - "\"buttonOneTitle\": \"Up\"," - "\"buttonOneIntent\": \"[pending]\"," - "\"buttonTwoTitle\": \"Down\"," - "\"buttonTwoIntent\": \"[pending]\"," - "\"expandedMessage\": \"This is a longer expanded message.\"," - "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\"," - "\"replaceId\": \"12345678\"" - "}]", - browser(), utils::NONE)); - - ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); - - // TODO(miket): confirm that the show succeeded. } |