diff options
author | miket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 03:56:48 +0000 |
---|---|---|
committer | miket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 03:56:48 +0000 |
commit | 357b2331eee05e9f5e13c832c3ef5814bbf0d0ee (patch) | |
tree | a08aa0b609132f4e662173d342ea96596295be28 /chrome/browser/extensions/api/notification | |
parent | 6ca243e5421486d5103338a2ba51e7df7ddc6a09 (diff) | |
download | chromium_src-357b2331eee05e9f5e13c832c3ef5814bbf0d0ee.zip chromium_src-357b2331eee05e9f5e13c832c3ef5814bbf0d0ee.tar.gz chromium_src-357b2331eee05e9f5e13c832c3ef5814bbf0d0ee.tar.bz2 |
Reland 11358144 (Switch fields over to base format fields).
Continuing TODO items from a previous CL, remove the "extra_field" and
"second_extra_field" keys from the API and replace with real keys from the Base
Format View spec. Implement a rough layout that resembles the expanded mode of
the view.
(Broke win_aura on original landing, now adds dependency on base.gyp:base_i18n.)
Outstanding items:
- As stated above, the layout is still ugly.
- We don't gracefully handle empty buttons. We don't crash, either, but it
looks even uglier when the buttons are missing.
- The buttons don't do anything when the user clicks on them.
- The second icon is just a redraw of the first.
TBR=mukai@chromium.org
BUG=161038
Review URL: https://chromiumcodereview.appspot.com/11312241
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167851 0039d316-1c4b-4281-b951-d872f2087c98
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, 78 insertions, 24 deletions
diff --git a/chrome/browser/extensions/api/notification/notification_api.cc b/chrome/browser/extensions/api/notification/notification_api.cc index a96d5b0..4d3e1d4 100644 --- a/chrome/browser/extensions/api/notification/notification_api.cc +++ b/chrome/browser/extensions/api/notification/notification_api.cc @@ -93,36 +93,50 @@ 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)); - // 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); + 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)); 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 d32f51c..b3ff3a2 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, TestNormalNotification) { +IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestSimpleNotification) { scoped_refptr<extensions::NotificationShowFunction> notification_show_function(new extensions::NotificationShowFunction()); scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); @@ -34,6 +34,7 @@ IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestNormalNotification) { 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!\"," @@ -43,4 +44,43 @@ IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestNormalNotification) { 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. } |