Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: chrome/test/data/extensions/api_test/notification/galore/app/controller.js

Issue 12211020: Added "Notifications Galore!" notification test app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed copyright message for commit checks. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/notification/galore/app/images/Image1-300x225.jpg » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/notification/galore/app/controller.js
diff --git a/chrome/test/data/extensions/api_test/notification/galore/app/controller.js b/chrome/test/data/extensions/api_test/notification/galore/app/controller.js
new file mode 100644
index 0000000000000000000000000000000000000000..54e6084ac2e1684ae40cbf27ee37da7e3ac4685a
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/notification/galore/app/controller.js
@@ -0,0 +1,95 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var Galore = Galore || {};
+
+Galore.controller = {
+
+ BUTTON_IMAGE_SIZE: 64,
+ NOTIFICATION_ICON_SIZE: 80,
+
+ create: function() {
+ var controller = Object.create(this);
+ controller.counter = 0;
+ controller.prefix = chrome.runtime.getURL('').slice(0, -1);
+ controller.view = Galore.view.create(this.prepare_.bind(controller));
+ controller.listen_('onDisplayed');
+ controller.listen_('onError');
+ controller.listen_('onClosed');
+ controller.listen_('onClicked');
+ controller.listen_('onButtonClicked');
+ return controller;
+ },
+
+ /** @private */
+ listen_: function(event) {
+ var listener = this.event_.bind(this, event);
+ chrome.experimental.notification[event].addListener(listener);
+ },
+
+ /** @private */
+ prepare_: function() {
+ Galore.NOTIFICATIONS.forEach(function (type) {
+ type.notifications.forEach(function (options) {
+ this.view.addNotificationButton(
+ type.type,
+ type.name,
+ this.replace_(options.iconUrl, this.BUTTON_IMAGE_SIZE),
+ this.notify_.bind(this, type.type, options));
+ }, this);
+ }, this);
+ },
+
+ /** @private */
+ id_: function() {
+ this.counter += 1;
+ return String(this.counter);
+ },
+
+ /** @private */
+ notify_: function(type, options) {
+ var id = this.id_();
+ var priority = this.view.getPriority();
+ var expanded = this.expand_(options, type, priority);
+ if (chrome.experimental.notification.create) {
+ chrome.experimental.notification.create(id, expanded, function() {});
+ } else {
+ expanded.replaceId = id;
+ delete expanded.buttonOneIconUrl;
+ delete expanded.buttonOneTitle;
+ delete expanded.buttonTwoIconUrl;
+ delete expanded.buttonTwoTitle;
+ chrome.experimental.notification.show(expanded, function() {});
+ }
+ this.event_('create', id, 'priority: ' + priority);
+ },
+
+ /** @private */
+ expand_: function(options, type, priority) {
+ var expanded = {type: type, priority: priority};
+ Object.keys(options).forEach(function (key) {
+ expanded[key] = this.replace_(options[key], this.NOTIFICATION_ICON_SIZE);
+ }, this);
+ return expanded;
+ },
+
+ /** @private */
+ replace_: function(option, size) {
+ var replaced = option;
+ if (typeof replaced === 'string') {
+ replaced = replaced.replace(/\$#/g, this.counter);
+ replaced = replaced.replace(/\$@/g, this.prefix);
+ replaced = replaced.replace(/\$%/g, size);
+ }
+ return replaced;
+ },
+
+ /** @private */
+ event_: function(event, id, var_args) {
+ this.view.logEvent('Notification #' + id + ': ' + event + '(' +
+ Array.prototype.slice.call(arguments, 2).join(', ') +
+ ')');
+ }
+
+};
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/notification/galore/app/images/Image1-300x225.jpg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698