| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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 function addTests() { |
| 6 var currentTest = null; |
| 7 |
| 8 function dispatchClick(id) { |
| 9 currentTest.log('Clicking button "' + id + '".'); |
| 10 $(id).dispatchEvent(new MouseEvent('click')); |
| 11 } |
| 12 |
| 13 function setInputValue(id, value) { |
| 14 currentTest.log('Setting input box "' + id + '" to "' + value + '".'); |
| 15 $(id).value = value; |
| 16 } |
| 17 |
| 18 function clearResult() { |
| 19 $('result').textContent = ''; |
| 20 } |
| 21 |
| 22 function getResult() { |
| 23 return $('result').textContent; |
| 24 } |
| 25 |
| 26 function waitForResult(expected) { |
| 27 var intervalId = window.setInterval(function() { |
| 28 var actual = parseInt(getResult()); |
| 29 |
| 30 if (result === '') { |
| 31 currentTest.log('No result yet, waiting.'); |
| 32 return; |
| 33 } |
| 34 |
| 35 // Got a result. |
| 36 window.clearInterval(intervalId); |
| 37 |
| 38 if (actual === expected) { |
| 39 currentTest.log('Got expected value (' + expected + ').'); |
| 40 currentTest.pass(); |
| 41 } else { |
| 42 currentTest.fail('Unexpected value ' + actual + ', expected ' + |
| 43 expected); |
| 44 } |
| 45 }, 100); |
| 46 } |
| 47 |
| 48 common.tester.addAsyncTest('async_message', function(test) { |
| 49 currentTest = test; |
| 50 clearResult(); |
| 51 setInputValue('addend1', 1234); |
| 52 setInputValue('addend2', 2345); |
| 53 dispatchClick('addAsync'); |
| 54 waitForResult(3579); |
| 55 }); |
| 56 |
| 57 common.tester.addAsyncTest('sync_message', function(test) { |
| 58 currentTest = test; |
| 59 clearResult(); |
| 60 setInputValue('addend1', 42); |
| 61 setInputValue('addend2', 314); |
| 62 dispatchClick('addSync'); |
| 63 waitForResult(356); |
| 64 }); |
| 65 } |
| OLD | NEW |