summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions/api')
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_api.cc222
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_apitest.cc38
2 files changed, 113 insertions, 147 deletions
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc
index 1ee1c10..14bfc28 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc
@@ -254,66 +254,64 @@ bool NotificationsApiFunction::CreateNotification(
// Then, handle any optional data that's been provided.
message_center::RichNotificationData optional_fields;
- if (message_center::IsRichNotificationEnabled()) {
- if (options->priority.get())
- optional_fields.priority = *options->priority;
-
- if (options->event_time.get())
- optional_fields.timestamp = base::Time::FromJsTime(*options->event_time);
-
- if (options->buttons.get()) {
- // Currently we allow up to 2 buttons.
- size_t number_of_buttons = options->buttons->size();
- number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
-
- for (size_t i = 0; i < number_of_buttons; i++) {
- message_center::ButtonInfo info(
- base::UTF8ToUTF16((*options->buttons)[i]->title));
- NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(),
- &info.icon);
- optional_fields.buttons.push_back(info);
- }
+ if (options->priority.get())
+ optional_fields.priority = *options->priority;
+
+ if (options->event_time.get())
+ optional_fields.timestamp = base::Time::FromJsTime(*options->event_time);
+
+ if (options->buttons.get()) {
+ // Currently we allow up to 2 buttons.
+ size_t number_of_buttons = options->buttons->size();
+ number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
+
+ for (size_t i = 0; i < number_of_buttons; i++) {
+ message_center::ButtonInfo info(
+ base::UTF8ToUTF16((*options->buttons)[i]->title));
+ NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(),
+ &info.icon);
+ optional_fields.buttons.push_back(info);
}
+ }
- if (options->context_message) {
- optional_fields.context_message =
- base::UTF8ToUTF16(*options->context_message);
- }
+ if (options->context_message) {
+ optional_fields.context_message =
+ base::UTF8ToUTF16(*options->context_message);
+ }
- bool has_image = NotificationBitmapToGfxImage(options->image_bitmap.get(),
- &optional_fields.image);
- // We should have an image if and only if the type is an image type.
- if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE))
- return false;
+ bool has_image = NotificationBitmapToGfxImage(options->image_bitmap.get(),
+ &optional_fields.image);
+ // We should have an image if and only if the type is an image type.
+ if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE))
+ return false;
- // We should have list items if and only if the type is a multiple type.
- bool has_list_items = options->items.get() && options->items->size() > 0;
- if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE))
- return false;
+ // We should have list items if and only if the type is a multiple type.
+ bool has_list_items = options->items.get() && options->items->size() > 0;
+ if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE))
+ return false;
- if (options->progress.get() != NULL) {
- // We should have progress if and only if the type is a progress type.
- if (type != message_center::NOTIFICATION_TYPE_PROGRESS) {
- SetError(kUnexpectedProgressValueForNonProgressType);
- return false;
- }
- optional_fields.progress = *options->progress;
- // Progress value should range from 0 to 100.
- if (optional_fields.progress < 0 || optional_fields.progress > 100) {
- SetError(kInvalidProgressValue);
- return false;
- }
+ if (options->progress.get() != NULL) {
+ // We should have progress if and only if the type is a progress type.
+ if (type != message_center::NOTIFICATION_TYPE_PROGRESS) {
+ SetError(kUnexpectedProgressValueForNonProgressType);
+ return false;
+ }
+ optional_fields.progress = *options->progress;
+ // Progress value should range from 0 to 100.
+ if (optional_fields.progress < 0 || optional_fields.progress > 100) {
+ SetError(kInvalidProgressValue);
+ return false;
}
+ }
- if (has_list_items) {
- using api::notifications::NotificationItem;
- std::vector<linked_ptr<NotificationItem> >::iterator i;
- for (i = options->items->begin(); i != options->items->end(); ++i) {
- message_center::NotificationItem item(
- base::UTF8ToUTF16(i->get()->title),
- base::UTF8ToUTF16(i->get()->message));
- optional_fields.items.push_back(item);
- }
+ if (has_list_items) {
+ using api::notifications::NotificationItem;
+ std::vector<linked_ptr<NotificationItem> >::iterator i;
+ for (i = options->items->begin(); i != options->items->end(); ++i) {
+ message_center::NotificationItem item(
+ base::UTF8ToUTF16(i->get()->title),
+ base::UTF8ToUTF16(i->get()->message));
+ optional_fields.items.push_back(item);
}
}
@@ -360,73 +358,71 @@ bool NotificationsApiFunction::UpdateNotification(
notification->set_icon(icon);
}
- if (message_center::IsRichNotificationEnabled()) {
- if (options->priority)
- notification->set_priority(*options->priority);
-
- if (options->event_time)
- notification->set_timestamp(base::Time::FromJsTime(*options->event_time));
-
- if (options->buttons) {
- // Currently we allow up to 2 buttons.
- size_t number_of_buttons = options->buttons->size();
- number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
-
- std::vector<message_center::ButtonInfo> buttons;
- for (size_t i = 0; i < number_of_buttons; i++) {
- message_center::ButtonInfo button(
- base::UTF8ToUTF16((*options->buttons)[i]->title));
- NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(),
- &button.icon);
- buttons.push_back(button);
- }
- notification->set_buttons(buttons);
- }
+ if (options->priority)
+ notification->set_priority(*options->priority);
- if (options->context_message) {
- notification->set_context_message(
- base::UTF8ToUTF16(*options->context_message));
- }
+ if (options->event_time)
+ notification->set_timestamp(base::Time::FromJsTime(*options->event_time));
- gfx::Image image;
- if (NotificationBitmapToGfxImage(options->image_bitmap.get(), &image)) {
- // We should have an image if and only if the type is an image type.
- if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE)
- return false;
- notification->set_image(image);
+ if (options->buttons) {
+ // Currently we allow up to 2 buttons.
+ size_t number_of_buttons = options->buttons->size();
+ number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
+
+ std::vector<message_center::ButtonInfo> buttons;
+ for (size_t i = 0; i < number_of_buttons; i++) {
+ message_center::ButtonInfo button(
+ base::UTF8ToUTF16((*options->buttons)[i]->title));
+ NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(),
+ &button.icon);
+ buttons.push_back(button);
}
+ notification->set_buttons(buttons);
+ }
+
+ if (options->context_message) {
+ notification->set_context_message(
+ base::UTF8ToUTF16(*options->context_message));
+ }
+
+ gfx::Image image;
+ if (NotificationBitmapToGfxImage(options->image_bitmap.get(), &image)) {
+ // We should have an image if and only if the type is an image type.
+ if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE)
+ return false;
+ notification->set_image(image);
+ }
- if (options->progress) {
- // We should have progress if and only if the type is a progress type.
- if (notification->type() != message_center::NOTIFICATION_TYPE_PROGRESS) {
- SetError(kUnexpectedProgressValueForNonProgressType);
- return false;
- }
- int progress = *options->progress;
- // Progress value should range from 0 to 100.
- if (progress < 0 || progress > 100) {
- SetError(kInvalidProgressValue);
- return false;
- }
- notification->set_progress(progress);
+ if (options->progress) {
+ // We should have progress if and only if the type is a progress type.
+ if (notification->type() != message_center::NOTIFICATION_TYPE_PROGRESS) {
+ SetError(kUnexpectedProgressValueForNonProgressType);
+ return false;
+ }
+ int progress = *options->progress;
+ // Progress value should range from 0 to 100.
+ if (progress < 0 || progress > 100) {
+ SetError(kInvalidProgressValue);
+ return false;
}
+ notification->set_progress(progress);
+ }
+
+ if (options->items.get() && options->items->size() > 0) {
+ // We should have list items if and only if the type is a multiple type.
+ if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE)
+ return false;
- if (options->items.get() && options->items->size() > 0) {
- // We should have list items if and only if the type is a multiple type.
- if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE)
- return false;
-
- std::vector<message_center::NotificationItem> items;
- using api::notifications::NotificationItem;
- std::vector<linked_ptr<NotificationItem> >::iterator i;
- for (i = options->items->begin(); i != options->items->end(); ++i) {
- message_center::NotificationItem item(
- base::UTF8ToUTF16(i->get()->title),
- base::UTF8ToUTF16(i->get()->message));
- items.push_back(item);
- }
- notification->set_items(items);
+ std::vector<message_center::NotificationItem> items;
+ using api::notifications::NotificationItem;
+ std::vector<linked_ptr<NotificationItem> >::iterator i;
+ for (i = options->items->begin(); i != options->items->end(); ++i) {
+ message_center::NotificationItem item(
+ base::UTF8ToUTF16(i->get()->title),
+ base::UTF8ToUTF16(i->get()->message));
+ items.push_back(item);
}
+ notification->set_items(items);
}
// Then override if it's already set.
diff --git a/chrome/browser/extensions/api/notifications/notifications_apitest.cc b/chrome/browser/extensions/api/notifications/notifications_apitest.cc
index d859955..6456550 100644
--- a/chrome/browser/extensions/api/notifications/notifications_apitest.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_apitest.cc
@@ -456,16 +456,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) {
ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_;
}
-// MessaceCenter-specific test.
-#if defined(RUN_MESSAGE_CENTER_TESTS)
-#define MAYBE_TestByUser TestByUser
-#else
-#define MAYBE_TestByUser DISABLED_TestByUser
-#endif
-
-IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestByUser) {
- ASSERT_TRUE(message_center::IsRichNotificationEnabled());
-
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) {
const extensions::Extension* extension =
LoadExtensionAndWait("notifications/api/by_user");
ASSERT_TRUE(extension) << message_;
@@ -626,13 +617,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) {
}
}
-// MessaceCenter-specific test.
-#if defined(RUN_MESSAGE_CENTER_TESTS)
-#define MAYBE_TestPartialUpdate TestPartialUpdate
-#else
-#define MAYBE_TestPartialUpdate DISABLED_TestPartialUpdate
-#endif
-IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestPartialUpdate) {
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) {
scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
// Create a new notification.
@@ -726,14 +711,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestPartialUpdate) {
EXPECT_EQ(0u, notification->buttons().size());
}
-// MessaceCenter-specific test.
-#if defined(RUN_MESSAGE_CENTER_TESTS)
-#define MAYBE_TestGetPermissionLevel TestGetPermissionLevel
-#else
-#define MAYBE_TestGetPermissionLevel DISABLED_TestGetPermissionLevel
-#endif
-
-IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetPermissionLevel) {
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestGetPermissionLevel) {
scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
// Get permission level for the extension whose notifications are enabled.
@@ -786,15 +764,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetPermissionLevel) {
}
}
-// MessaceCenter-specific test.
-#if defined(RUN_MESSAGE_CENTER_TESTS)
-#define MAYBE_TestOnPermissionLevelChanged TestOnPermissionLevelChanged
-#else
-#define MAYBE_TestOnPermissionLevelChanged DISABLED_TestOnPermissionLevelChanged
-#endif
-
-IN_PROC_BROWSER_TEST_F(NotificationsApiTest,
- MAYBE_TestOnPermissionLevelChanged) {
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestOnPermissionLevelChanged) {
const extensions::Extension* extension =
LoadExtensionAndWait("notifications/api/permission");
ASSERT_TRUE(extension) << message_;