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

Unified Diff: chrome/test/data/extensions/api_test/notification/galore/app/view.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
Index: chrome/test/data/extensions/api_test/notification/galore/app/view.js
diff --git a/chrome/test/data/extensions/api_test/notification/galore/app/view.js b/chrome/test/data/extensions/api_test/notification/galore/app/view.js
new file mode 100644
index 0000000000000000000000000000000000000000..cc5469aac3ab281ca46b94692a941f1276f241d5
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/notification/galore/app/view.js
@@ -0,0 +1,92 @@
+// 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.view = {
+ create: function(onLoad) {
+ var view = Object.create(this);
+ chrome.app.window.create('window.html', {
+ id: 'window',
+ frame: 'none',
+ defaultWidth: 512, minWidth: 512, maxWidth: 512,
+ defaultHeight: 736, minHeight: 736, maxHeight: 736,
+ }, function(appWindow) {
+ view.sections = {}
+ view.window = appWindow.contentWindow;
+ view.window.onload = this.loaded_.bind(view, onLoad);
+ }.bind(this));
+ return view;
+ },
+
+ addNotificationButton: function(sectionId, sectionTitle, imageUrl, onClick) {
+ var section = this.section_(sectionId, sectionTitle);
+ var button = this.button_(section, onClick);
+ this.fetch_(imageUrl, button.querySelector('img'));
+ },
+
+ getPriority: function() {
+ var inputs = this.elements_('#priority input');
+ var checked = Array.prototype.filter.call(inputs, function(input) {
+ return input.checked;
+ });
+ return (checked && checked.length) ? Number(checked[0].value) : 0;
+ },
+
+ logEvent: function(message) {
+ var event = this.element_('#templates .event').cloneNode(true);
+ event.textContent = message;
+ this.element_('#events-scroll').appendChild(event).scrollIntoView();
+ },
+
+ /** @private */
+ loaded_: function(onLoad) {
+ this.element_('#close').onclick = this.window.close.bind(this.window);
+ if (onLoad)
+ onLoad.call(this);
+ },
+
+ /** @private */
+ fetch_: function(url, image) {
+ var request = new XMLHttpRequest();
+ request.open('GET', url, true);
+ request.responseType = 'blob';
+ request.onload = this.fetched_.bind(this, request, image);
+ request.send();
+ },
+
+ /** @private */
+ fetched_: function(request, image) {
+ image.src = window.URL.createObjectURL(request.response);
+ },
+
+ /** @private */
+ section_: function(id, title) {
+ if (!this.sections[id]) {
+ this.sections[id] = this.element_('#templates .section').cloneNode(true);
+ this.sections[id].querySelector('span').textContent = title;
+ this.element_('#sections').appendChild(this.sections[id]);
+ }
+ return this.sections[id];
+ },
+
+ /** @private */
+ button_: function(section, onClick) {
+ var button = this.element_('#templates button');
+ button = button.cloneNode(true);
+ button.onclick = onClick;
+ section.appendChild(button);
+ return button;
+ },
+
+ /** @private */
+ element_: function(selector) {
+ return this.window.document.querySelector(selector)
+ },
+
+ /** @private */
+ elements_: function(selector) {
+ return this.window.document.querySelectorAll(selector)
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698