Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / webui / cr_test.html
blob834c252eb59621fb158c73206403d322cf828e00
1 <!DOCTYPE html>
2 <html>
3 <body>
5 <script>
7 var EventTarget;
9 function setUp() {
10 EventTarget = cr.EventTarget;
13 function testDefineProperty() {
14 var obj = new EventTarget;
15 cr.defineProperty(obj, 'test');
17 obj.test = 1;
18 assertEquals(1, obj.test);
19 assertEquals(1, obj.test_);
22 function testDefinePropertyOnClass() {
23 function C() {}
24 C.prototype = {
25 __proto__: EventTarget.prototype
28 cr.defineProperty(C, 'test');
30 var obj = new C;
31 assertEquals(undefined, obj.test);
33 obj.test = 1;
34 assertEquals(1, obj.test);
35 assertEquals(1, obj.test_);
38 function testDefinePropertyWithSetter() {
39 var obj = new EventTarget;
41 var hit = false;
42 function onTestSet(value, oldValue) {
43 assertEquals(obj, this);
44 assertEquals(2, this.test);
45 assertEquals(undefined, oldValue);
46 assertEquals(2, value);
47 hit = true;
49 cr.defineProperty(obj, 'test', cr.PropertyKind.JS, onTestSet);
50 obj.test = 2;
51 assertTrue(hit);
54 function testDefinePropertyEvent() {
55 var obj = new EventTarget;
56 cr.defineProperty(obj, 'test');
57 obj.test = 1;
59 var count = 0;
60 function f(e) {
61 assertEquals('testChange', e.type);
62 assertEquals('test', e.propertyName);
63 assertEquals(1, e.oldValue);
64 assertEquals(2, e.newValue);
65 count++;
68 obj.addEventListener('testChange', f);
69 obj.test = 2;
70 assertEquals(2, obj.test);
71 assertEquals(1, count, 'Should have called the property change listener');
73 obj.test = 2;
74 assertEquals(1, count);
77 function testDefinePropertyEventWithDefault() {
78 var obj = new EventTarget;
79 cr.defineProperty(obj, 'test', cr.PropertyKind.JS);
81 var count = 0;
82 function f(e) {
83 assertEquals('testChange', e.type);
84 assertEquals('test', e.propertyName);
85 assertEquals(undefined, e.oldValue);
86 assertEquals(2, e.newValue);
87 count++;
90 obj.addEventListener('testChange', f);
92 obj.test = undefined;
93 assertEquals(0, count, 'Should not have called the property change listener');
95 obj.test = 2;
96 assertEquals(2, obj.test);
97 assertEquals(1, count, 'Should have called the property change listener');
99 obj.test = 2;
100 assertEquals(1, count);
103 function testDefinePropertyAttr() {
104 var obj = document.createElement('div');
105 cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR);
107 obj.test = 'a';
108 assertEquals('a', obj.test);
109 assertEquals('a', obj.getAttribute('test'));
111 obj.test = undefined;
112 assertEquals(null, obj.test);
113 assertFalse(obj.hasAttribute('test'));
116 function testDefinePropertyAttrOnClass() {
117 var obj = document.createElement('button');
118 cr.defineProperty(HTMLButtonElement, 'test', cr.PropertyKind.ATTR);
120 assertEquals(null, obj.test);
122 obj.test = 'a';
123 assertEquals('a', obj.test);
124 assertEquals('a', obj.getAttribute('test'));
126 obj.test = undefined;
127 assertEquals(null, obj.test);
128 assertFalse(obj.hasAttribute('test'));
131 function testDefinePropertyAttrWithSetter() {
132 var obj = document.createElement('div');
134 var hit = false;
135 function onTestSet(value, oldValue) {
136 assertEquals(obj, this);
137 assertEquals(null, oldValue);
138 assertEquals('b', value);
139 assertEquals('b', this.test);
140 hit = true;
142 cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR, onTestSet);
143 obj.test = 'b';
144 assertTrue(hit);
147 function testDefinePropertyAttrEvent() {
148 var obj = document.createElement('div');
149 cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR);
151 var count = 0;
152 function f(e) {
153 assertEquals('testChange', e.type);
154 assertEquals('test', e.propertyName);
155 assertEquals(null, e.oldValue);
156 assertEquals('b', e.newValue);
157 count++;
160 obj.addEventListener('testChange', f);
162 obj.test = null;
163 assertEquals(0, count, 'Should not have called the property change listener');
165 obj.test = 'b';
166 assertEquals('b', obj.test);
167 assertEquals(1, count, 'Should have called the property change listener');
169 obj.test = 'b';
170 assertEquals(1, count);
173 function testDefinePropertyBoolAttr() {
174 var obj = document.createElement('div');
175 cr.defineProperty(obj, 'test', cr.PropertyKind.BOOL_ATTR);
177 assertFalse(obj.test);
178 assertFalse(obj.hasAttribute('test'));
180 obj.test = true;
181 assertTrue(obj.test);
182 assertTrue(obj.hasAttribute('test'));
184 obj.test = false;
185 assertFalse(obj.test);
186 assertFalse(obj.hasAttribute('test'));
189 function testDefinePropertyBoolAttrEvent() {
190 var obj = document.createElement('div');
191 cr.defineProperty(obj, 'test', cr.PropertyKind.BOOL_ATTR);
193 var count = 0;
194 function f(e) {
195 assertEquals('testChange', e.type);
196 assertEquals('test', e.propertyName);
197 assertEquals(false, e.oldValue);
198 assertEquals(true, e.newValue);
199 count++;
202 obj.addEventListener('testChange', f);
203 obj.test = true;
204 assertTrue(obj.test);
205 assertEquals(1, count, 'Should have called the property change listener');
207 obj.test = true;
208 assertEquals(1, count);
211 function testDefinePropertyBoolAttrEvent() {
212 var obj = document.createElement('div');
213 var hit = false;
214 function onTestSet(value, oldValue) {
215 assertEquals(obj, this);
216 assertTrue(this.test);
217 assertFalse(oldValue);
218 assertTrue(value);
219 hit = true;
221 cr.defineProperty(obj, 'test', cr.PropertyKind.BOOL_ATTR, onTestSet);
222 obj.test = true;
223 assertTrue(hit);
226 function testAddSingletonGetter() {
227 function Foo() {};
228 cr.addSingletonGetter(Foo);
230 assertEquals('function', typeof Foo.getInstance,
231 'Should add get instance function');
233 var x = Foo.getInstance();
234 assertEquals('object', typeof x, 'Should successfully create an object');
235 assertNotEqual(null, x, 'Created object should not be null');
237 var y = Foo.getInstance();
238 assertEquals(x, y, 'Should return the same object');
240 delete Foo.instance_;
242 var z = Foo.getInstance();
243 assertEquals('object', typeof z, 'Should work after clearing for testing');
244 assertNotEqual(null, z, 'Created object should not be null');
246 assertNotEqual(x, z,
247 'Should return a different object after clearing for testing');
250 function testDefineWithGetter() {
251 var v = 0;
252 cr.define('foo', function() {
253 return {
254 get v() {
255 return v;
260 assertEquals(0, foo.v);
262 v = 1;
263 assertEquals(1, foo.v);
266 </script>
268 </body>
269 </html>