Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <body> | 3 <body> |
| 4 | 4 |
| 5 <script> | 5 <script> |
| 6 | 6 |
| 7 var EventTarget; | 7 var EventTarget; |
| 8 | 8 |
| 9 function setUp() { | 9 function setUp() { |
| 10 EventTarget = cr.EventTarget; | 10 EventTarget = cr.EventTarget; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 | 236 |
| 237 var y = Foo.getInstance(); | 237 var y = Foo.getInstance(); |
| 238 assertEquals(x, y, 'Should return the same object'); | 238 assertEquals(x, y, 'Should return the same object'); |
| 239 | 239 |
| 240 delete Foo.instance_; | 240 delete Foo.instance_; |
| 241 | 241 |
| 242 var z = Foo.getInstance(); | 242 var z = Foo.getInstance(); |
| 243 assertEquals('object', typeof z, 'Should work after clearing for testing'); | 243 assertEquals('object', typeof z, 'Should work after clearing for testing'); |
| 244 assertNotEqual(null, z, 'Created object should not be null'); | 244 assertNotEqual(null, z, 'Created object should not be null'); |
| 245 | 245 |
| 246 assertNotEqual(x, z, | 246 assertNotEqual( |
| 247 'Should return a different object after clearing for testing'); | 247 x, z, 'Should return a different object after clearing for testing'); |
|
Dan Beam
2016/01/23 02:48:51
nit: revert
dpapad
2016/01/25 18:34:22
Reverting, but previous version violates styleguid
Dan Beam
2016/01/25 18:48:37
nah, it doesn't
https://engdoc.corp.google.com/en
| |
| 248 } | 248 } |
| 249 | 249 |
| 250 function testDefineWithGetter() { | 250 function testDefineWithGetter() { |
| 251 var v = 0; | 251 var v = 0; |
| 252 cr.define('foo', function() { | 252 cr.define('foo', function() { |
| 253 return { | 253 return { |
| 254 get v() { | 254 get v() { |
| 255 return v; | 255 return v; |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 }); | 258 }); |
| 259 | 259 |
| 260 assertEquals(0, foo.v); | 260 assertEquals(0, foo.v); |
| 261 | 261 |
| 262 v = 1; | 262 v = 1; |
| 263 assertEquals(1, foo.v); | 263 assertEquals(1, foo.v); |
| 264 } | 264 } |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * Executes a function given a potentially namespaced function name, e.g., | 267 * Tests that an event fired by a WebUI handler is sent to all listeners. |
| 268 * cr.webUIListenerCallback. | |
| 269 * @param {string} functionName The name of the function, including any | |
| 270 * namespaces, to execute. | |
| 271 */ | |
| 272 function executeFunctionByName(functionName) { | |
| 273 var args = Array.prototype.slice.call(arguments, 1); | |
| 274 var func = (0, eval)(functionName); | |
| 275 func.apply(undefined, args); | |
| 276 } | |
| 277 | |
| 278 /** | |
| 279 * Tests that cr.sendWithCallback correctly handles the case where the JS sends | |
| 280 * no arguments to the WebUI handler. | |
| 281 */ | |
| 282 function testSendWithCallback_PassesJSArgs() { | |
|
dpapad
2016/01/22 23:03:22
Interesting fact. Both this function and following
| |
| 283 var testMethodName = 'getFullscreenState'; | |
| 284 | |
| 285 // Mock out chrome.send to emulate a WebUI handler calling back with the | |
| 286 // result of a getFullscreenState call. | |
| 287 window.chrome = {}; | |
| 288 window.chrome.send = function(method, args) { | |
| 289 assertEquals(testMethodName, method); | |
| 290 var callbackName = args[0]; | |
| 291 var id = args[1]; | |
| 292 executeFunctionByName(callbackName, id, /* fullscreen */ true); | |
| 293 }; | |
| 294 | |
| 295 var callbackResponse; | |
| 296 cr.sendWithCallback(testMethodName, undefined, function(fullscreen) { | |
| 297 callbackResponse = fullscreen; | |
| 298 }); | |
| 299 | |
| 300 assertTrue(callbackResponse); | |
| 301 } | |
| 302 | |
| 303 /** | |
| 304 * Tests that cr.sendWithCallback passes arguments from JS to the WebUI | |
| 305 * handler. | |
| 306 */ | |
| 307 function testSendWithCallback_PassesJSArgs() { | |
| 308 var testMethodName = 'getSquareOfX'; | |
| 309 | |
| 310 // Mock out chrome.send to emulate a WebUI handler calling back with the | |
| 311 // result of a getSquareOfX call. | |
| 312 window.chrome = {}; | |
| 313 window.chrome.send = function(method, args) { | |
| 314 assertEquals(testMethodName, method); | |
| 315 var callbackName = args[0]; | |
| 316 var id = args[1]; | |
| 317 var x = args[2]; | |
| 318 executeFunctionByName(callbackName, id, x * x); | |
| 319 }; | |
| 320 | |
| 321 var callbackResponse; | |
| 322 cr.sendWithCallback(testMethodName, [5], function(square) { | |
| 323 callbackResponse = square; | |
| 324 }); | |
| 325 | |
| 326 assertEquals(25, callbackResponse); | |
| 327 } | |
| 328 | |
| 329 /** | |
| 330 * Tests that an event fired by a WebUI handler is sent to all listeners. | |
| 331 */ | 268 */ |
| 332 function testAddWebUIListener() { | 269 function testAddWebUIListener() { |
| 333 var responses = new Map(); | 270 var responses = new Map(); |
| 334 cr.addWebUIListener('fullscreen-enabled', function(enabled) { | 271 cr.addWebUIListener('fullscreen-enabled', function(enabled) { |
| 335 responses.set('first', enabled); | 272 responses.set('first', enabled); |
| 336 }); | 273 }); |
| 337 cr.addWebUIListener('fullscreen-enabled', function(enabled) { | 274 cr.addWebUIListener('fullscreen-enabled', function(enabled) { |
| 338 responses.set('second', enabled); | 275 responses.set('second', enabled); |
| 339 }); | 276 }); |
| 340 | 277 |
| 341 executeFunctionByName( | 278 window['cr']['webUIListenerCallback']('fullscreen-enabled', true); |
|
Dan Beam
2016/01/23 02:48:51
we don't do renaming, also why can't this just be
dpapad
2016/01/25 18:34:22
Done. No good reason (I was just trying to remove
| |
| 342 'cr.webUIListenerCallback', 'fullscreen-enabled', true); | |
| 343 | 279 |
| 344 assertTrue(responses.get('first')); | 280 assertTrue(responses.get('first')); |
| 345 assertTrue(responses.get('second')); | 281 assertTrue(responses.get('second')); |
| 346 } | 282 } |
| 347 | 283 |
| 348 </script> | 284 </script> |
| 349 | 285 |
| 350 </body> | 286 </body> |
| 351 </html> | 287 </html> |
| OLD | NEW |