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

Unified 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: nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/examples/api/messaging/messaging.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/examples/api/messaging/test.js
diff --git a/native_client_sdk/src/examples/api/messaging/test.js b/native_client_sdk/src/examples/api/messaging/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..dbcecfd867370161738c912bd9fd0a47aa36a465
--- /dev/null
+++ b/native_client_sdk/src/examples/api/messaging/test.js
@@ -0,0 +1,65 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function addTests() {
+ var currentTest = null;
+
+ function dispatchClick(id) {
+ currentTest.log('Clicking button "' + id + '".');
+ $(id).dispatchEvent(new MouseEvent('click'));
+ }
+
+ function setInputValue(id, value) {
+ currentTest.log('Setting input box "' + id + '" to "' + value + '".');
+ $(id).value = value;
+ }
+
+ function clearResult() {
+ $('result').textContent = '';
+ }
+
+ function getResult() {
+ return $('result').textContent;
+ }
+
+ function waitForResult(expected) {
+ var intervalId = window.setInterval(function() {
+ var actual = parseInt(getResult());
+
+ if (result === '') {
+ currentTest.log('No result yet, waiting.');
+ return;
+ }
+
+ // Got a result.
+ window.clearInterval(intervalId);
+
+ if (actual === expected) {
+ currentTest.log('Got expected value (' + expected + ').');
+ currentTest.pass();
+ } else {
+ currentTest.fail('Unexpected value ' + actual + ', expected ' +
+ expected);
+ }
+ }, 100);
+ }
+
+ common.tester.addAsyncTest('async_message', function(test) {
+ currentTest = test;
+ clearResult();
+ setInputValue('addend1', 1234);
+ setInputValue('addend2', 2345);
+ dispatchClick('addAsync');
+ waitForResult(3579);
+ });
+
+ common.tester.addAsyncTest('sync_message', function(test) {
+ currentTest = test;
+ clearResult();
+ setInputValue('addend1', 42);
+ setInputValue('addend2', 314);
+ dispatchClick('addSync');
+ waitForResult(356);
+ });
+}
« no previous file with comments | « native_client_sdk/src/examples/api/messaging/messaging.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698