Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/notification_provider/test_app/main.js |
| diff --git a/chrome/test/data/extensions/api_test/notification_provider/test_app/main.js b/chrome/test/data/extensions/api_test/notification_provider/test_app/main.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b3aedda1fa90d9179c2093b21d9b7cc97addcc7a |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/notification_provider/test_app/main.js |
| @@ -0,0 +1,165 @@ |
| +// Window initialization code. Set up event handlers |
| +window.addEventListener("load", function() { |
| + // set up the event listeners |
| + chrome.notificationProvider.onCreated.addListener(notificationCreated); |
| + chrome.notificationProvider.onUpdated.addListener(notificationUpdated); |
| + chrome.notificationProvider.onCleared.addListener(notificationCleared); |
| +}); |
| + |
| +function displayImage(text, bitmap, div) { |
| + var image = document.createElement("p"); |
| + image.appendChild(document.createTextNode(text)); |
| + var imageCanvas = document.createElement("canvas"); |
| + image.appendChild(imageCanvas); |
| + div.appendChild(image); |
| + |
| + var imageContext = imageCanvas.getContext('2d'); |
| + imageCanvas.width = bitmap.width; |
| + imageCanvas.height = bitmap.height; |
| + var imagedata = imageContext.createImageData(bitmap.width, |
| + bitmap.height); |
| + var dataView = new Uint8Array(bitmap.data); |
| + for (var i = 0; i < bitmap.width * bitmap.height * 4; i += 1) { |
| + imagedata.data[i] = dataView[i]; |
| + } |
| + imageContext.putImageData(imagedata, 0, 0); |
| +} |
| + |
| +function addNotification(senderId, notificationId, details) { |
| + console.log("--JS--- add notification"); |
| + var list = document.getElementById("notification_list"); |
| + |
| + var div = document.createElement("div"); |
| + div.class = "notifications"; |
| + div.id = senderId + notificationId; |
| + |
| + line = document.createElement("br"); |
| + div.appendChild(line); |
| + |
| + // close button |
| + var closeButton = document.createElement("button"); |
| + closeButton.class = "closeButtons"; |
| + var buttonText = document.createTextNode("close notificaiton"); |
| + closeButton.appendChild(buttonText); |
| + div.appendChild(closeButton); |
| + closeButton.addEventListener("click", function(){ |
| + clearNotification(senderId, notificationId) |
| + }, false); |
| + |
| + // title |
| + var bold = document.createElement("b"); |
| + var title = document.createElement("p"); |
| + bold.appendChild(document.createTextNode(details.title)); |
| + title.appendChild(bold); |
| + div.appendChild(title); |
| + |
| + // id |
| + var id = document.createElement("p"); |
| + id.appendChild(document.createTextNode("Notification ID: " + notificationId)); |
| + div.appendChild(id); |
| + |
| + // type |
| + var notType = document.createElement("p"); |
| + notType.appendChild(document.createTextNode("Type: " + details.type)); |
| + div.appendChild(notType); |
| + |
| + // priority |
| + var priority = document.createElement("p"); |
| + priority.appendChild(document.createTextNode("Priority: " + |
| + details.priority)); |
| + div.appendChild(priority); |
| + |
| + // message |
| + var message = document.createElement("p"); |
| + message.appendChild(document.createTextNode("Message: " + details.message)); |
| + div.appendChild(message); |
| + |
| + // icon |
| + displayImage("Icon: ", details.iconBitmap, div); |
| + |
| + // context message |
| + if ("contextMessage" in details) { |
| + var message = document.createElement("p"); |
| + message.appendChild(document.createTextNode("Message: " + details.message)); |
| + div.appendChild(message); |
| + } |
| + |
| + // progress |
| + if (details.type == "progress" && "progress" in details) { |
| + var progress = document.createElement("p"); |
| + progress.appendChild(document.createTextNode("Progress: " + |
| + details.progress)); |
| + div.appendChild(progress); |
| + } |
| + |
| + // isClickable |
| + if ("isClickable" in details) { |
| + var clickable = document.createElement("p"); |
| + clickable.appendChild(document.createTextNode("IsClickable: " + |
| + details.isClickable)); |
| + div.appendChild(clickable); |
| + } |
| + |
| + // eventTime |
| + if ("eventTime" in details) { |
| + var time = document.createElement("p"); |
| + time.appendChild(document.createTextNode("Event Time: " + |
| + details.eventTime)); |
| + div.appendChild(time); |
| + } |
| + |
| + // list |
| + if (details.tyep = "list" && "items" in details) { |
|
Pete Williamson
2014/08/14 00:07:55
tyep -> type?
liyanhou
2014/08/14 00:41:50
Done.
|
| + for (var i = 0, size = details.items.length; i < size; i++) { |
| + var item = document.createElement("p"); |
| + item.appendChild(document.createTextNode( |
| + "Item " + (i+1) + ": " + |
| + details.items[i].title + " - " + |
| + details.items[i].message)); |
| + div.appendChild(item); |
| + } |
| + } |
| + |
| + // image |
| + if (details.type = "image" && "imageBitmap" in details) { |
| + displayImage("Image: ", details.imageBitmap, div); |
| + } |
| + |
| + // buttons |
| + if ("buttons" in details) { |
| + for (var i = 0, size = details.buttons.length; i < size; i++) { |
| + var button = document.createElement("p"); |
| + // TODO: add button image after image is implemented |
|
Pete Williamson
2014/08/14 00:07:55
If you actually check in a TODO (instead of doing
liyanhou
2014/08/14 00:41:50
Done.
|
| + button.appendChild(document.createTextNode( |
| + "Button " + (i+1) + ": " + details.buttons[i].title)); |
| + div.appendChild(button); |
| + } |
| + } |
| + |
| + div.appendChild(document.createElement("br")); |
| + list.appendChild(div); |
| +} |
| + |
| +function clearedCallback(ifCleared){} |
| + |
| +function clearNotification(senderId, notificationId) { |
| + var list = document.getElementById("notification_list"); |
| + list.removeChild(document.getElementById(senderId + notificationId)); |
| + chrome.notificationProvider.notifyOnCleared(senderId, |
| + notificationId, |
| + clearedCallback); |
| +} |
| + |
| +function notificationCreated(senderId, notificationId, details){ |
| + addNotification(senderId, notificationId, details); |
| +} |
| + |
| +function notificationUpdated(senderId, notificationId, details){ |
| + var list = document.getElementById("notification_list"); |
| + list.removeChild(document.getElementById(senderId + notificationId)); |
| + addNotification(senderId, notificationId, details); |
| +} |
| + |
| +function notificationCleared(senderId, notificationId){ |
| + clearNotification(senderId, notificationId); |
| +} |