Commit 9d31e1ca authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Document integration tests sendTestMessage and add error checking

The integration test extensions send messages to the system under test
and also to the browser test harness (messages head in both directions
no matter how you depict the test system).

Add commentary to sendTestMessage to state where (or to whom) messages
are sent to. Explain the expected message format, add code to throw if
callers don't use that format (throw breaks browser tests).

Bug: 831074
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ia8085b3ebd28b7b001e7a5bfae4d883cdbd5660e
Reviewed-on: https://chromium-review.googlesource.com/1013359Reviewed-by: default avatarTomasz Mikolajewski <mtomasz@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550932}
parent 8efff62a
...@@ -5,15 +5,31 @@ ...@@ -5,15 +5,31 @@
'use strict'; 'use strict';
/** /**
* Sends a test message. * Sends a message to the controlling test harness, namely and usually, the
* @param {Object} message Message to be sent. It is converted into JSON string * chrome FileManagerBrowserTest harness: it expects the message to contain
* before sending. * the 'name' of the command, and any required or optional arguments of the
* @return {Promise} Promise to be fulfilled with a returned value. * command, e.g.,
*
* sendTestMessage({
* name: 'addEntries', // command with volume and entries arguments
* volume: volume,
* entries: entries
* }).then(...);
*
* @param {Object} message Message object to be sent. The object is converted
* to a JSON string prior to sending.
* @return {Promise} Promise to be fulfilled with the value returned by the
* chrome.test.sendMessage callback.
*/ */
function sendTestMessage(message) { function sendTestMessage(message) {
if (typeof message.name === 'string') {
return new Promise(function(fulfill) { return new Promise(function(fulfill) {
chrome.test.sendMessage(JSON.stringify(message), fulfill); chrome.test.sendMessage(JSON.stringify(message), fulfill);
}); });
} else {
let error = 'sendTestMessage requires a message.name <string>';
throw new Error(error);
}
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment