- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / notifications / api / csp / background.js
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 const notifications = chrome.notifications;
6
7 var idString = "foo";
8
9 var testCSP = function() {
10   var onCreateCallback = function(id) {
11     if (chrome.runtime.lastError) {
12       chrome.test.succeed();
13       return;
14     }
15     chrome.test.fail();
16   }
17
18   var options = {
19     type: "basic",
20     iconUrl: "http://google.com/clearly-a-security-problem.png",
21     title: "Attention!",
22     message: "Check out Cirque du Soleil"
23   };
24   notifications.create(idString, options, onCreateCallback);
25 };
26
27 function testDataURL() {
28   chrome.runtime.lastError = undefined;
29   var onCreateCallback = function(id) {
30     if (chrome.runtime.lastError) {
31       chrome.test.fail();
32       return;
33     }
34     chrome.test.succeed();
35   }
36   var options = {
37     type: "basic",
38     iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
39              "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
40              "AAAABJRU5ErkJggg==",
41     title: "Attention!",
42     message: "Check out Cirque du Soleil"
43   };
44   notifications.create(idString, options, onCreateCallback);
45 }
46
47 function testCSPUpdateIconURL() {
48   var onUpdateCallback = function(id) {
49     if (chrome.runtime.lastError) {
50       chrome.test.succeed();
51       return;
52     }
53     chrome.test.fail();
54   };
55   var onCreateCallback = function(id) {
56     if (chrome.runtime.lastError) {
57       chrome.test.fail();
58       return;
59     }
60     var options2 = {
61       type: "basic",
62       iconUrl: "http://www.google.com/favicon.ico",
63       title: "Attention!",
64       message: "Check out Cirque du Soleil"
65     };
66     notifications.update(idString, options2, onUpdateCallback);
67   }
68   var options = {
69     type: "basic",
70     iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
71              "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
72              "AAAABJRU5ErkJggg==",
73     title: "Attention!",
74     message: "Check out Cirque du Soleil"
75   };
76   notifications.create(idString, options, onCreateCallback);
77 }
78
79 function testCSPUpdateImageURL() {
80   var onUpdateCallback = function(id) {
81     if (chrome.runtime.lastError) {
82       chrome.test.succeed();
83       return;
84     }
85     chrome.test.fail();
86   };
87   var onCreateCallback = function(id) {
88     if (chrome.runtime.lastError) {
89       chrome.test.fail();
90       return;
91     }
92     var options2 = {
93       type: "basic",
94       iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
95                "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
96                "AAAABJRU5ErkJggg==",
97       imageUrl: "http://www.google.com/favicon.ico",
98       title: "Attention!",
99       message: "Check out Cirque du Soleil"
100     };
101     notifications.update(idString, options2, onUpdateCallback);
102   }
103   var options = {
104     type: "image",
105     iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
106              "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
107              "AAAABJRU5ErkJggg==",
108     imageUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
109              "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
110              "AAAABJRU5ErkJggg==",
111     title: "Attention!",
112     message: "Check out Cirque du Soleil"
113   };
114   notifications.create(idString, options, onCreateCallback);
115 }
116
117 function testCSPUpdateButtonIconURL() {
118   var onUpdateCallback = function(id) {
119     if (chrome.runtime.lastError) {
120       chrome.test.succeed();
121       return;
122     }
123     chrome.test.fail();
124   };
125   var onCreateCallback = function(id) {
126     if (chrome.runtime.lastError) {
127       chrome.test.fail();
128       return;
129     }
130     var options2 = {
131       type: "basic",
132       iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
133                "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
134                "AAAABJRU5ErkJggg==",
135       title: "Attention!",
136       buttons: [ {
137         title: "Foo",
138         iconUrl: "http://www.google.com/favicon.ico"
139       } ],
140       message: "Check out Cirque du Soleil"
141     };
142     notifications.update(idString, options2, onUpdateCallback);
143   }
144   var options = {
145     type: "basic",
146     iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
147              "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
148              "AAAABJRU5ErkJggg==",
149     title: "Attention!",
150     buttons: [ {
151       title: "Foo",
152       iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" +
153                "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" +
154                "AAAABJRU5ErkJggg=="
155     } ],
156     message: "Check out Cirque du Soleil"
157   };
158   notifications.create(idString, options, onCreateCallback);
159 }
160 chrome.test.runTests([
161     testCSP,
162     testDataURL,
163     testCSPUpdateIconURL,
164     testCSPUpdateImageURL,
165     testCSPUpdateButtonIconURL ]);