OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 'use strict'; |
| 6 |
| 7 tvcm.require('ui.spy'); |
| 8 tvcm.require('tvcm.event_target'); |
| 9 |
| 10 tvcm.unittest.testSuite('ui.spy_test', function() { |
| 11 /** |
| 12 * @constructor |
| 13 */ |
| 14 function FakeChannel() { |
| 15 tvcm.EventTarget.call(this); |
| 16 } |
| 17 |
| 18 FakeChannel.prototype = { |
| 19 __proto__: tvcm.EventTarget.prototype, |
| 20 |
| 21 send: function(msg) { |
| 22 }, |
| 23 |
| 24 dispatchMessage: function(msg) { |
| 25 var event = new Event('message', false, false); |
| 26 event.data = msg; |
| 27 this.dispatchEvent(event); |
| 28 } |
| 29 }; |
| 30 |
| 31 test('basic', function() { |
| 32 var channel = new FakeChannel(); |
| 33 |
| 34 var spy = new ui.Spy(); |
| 35 spy.style.width = '600px'; |
| 36 spy.style.height = '400px'; |
| 37 spy.style.border = '1px solid black'; |
| 38 this.addHTMLOutput(spy); |
| 39 spy.channel = channel; |
| 40 |
| 41 channel.dispatchMessage({data: 'alo there'}); |
| 42 |
| 43 // Fake out echo reply |
| 44 channel.send = function(msg) { |
| 45 setTimeout(function() { |
| 46 channel.dispatchMessage({data: {type: 'reply', msg: msg}}); |
| 47 }, 10); |
| 48 } |
| 49 }); |
| 50 |
| 51 }); |
OLD | NEW |