Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: native_client_sdk/src/examples/api/messaging/test.js

Issue 781623002: [NaCl SDK] Messaging example (demonstrates postMessageAndAwaitResponse) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698