Skip to content

Commit

Permalink
Document integration tests sendTestMessage and add error checking
Browse files Browse the repository at this point in the history
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/1013359
Reviewed-by: Tomasz Mikolajewski <mtomasz@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550932}
  • Loading branch information
Noel Gordon authored and Commit Bot committed Apr 16, 2018
1 parent 8efff62 commit 9d31e1c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions ui/file_manager/integration_tests/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,31 @@
'use strict';

/**
* Sends a test message.
* @param {Object} message Message to be sent. It is converted into JSON string
* before sending.
* @return {Promise} Promise to be fulfilled with a returned value.
* Sends a message to the controlling test harness, namely and usually, the
* chrome FileManagerBrowserTest harness: it expects the message to contain
* the 'name' of the command, and any required or optional arguments of the
* 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) {
return new Promise(function(fulfill) {
chrome.test.sendMessage(JSON.stringify(message), fulfill);
});
if (typeof message.name === 'string') {
return new Promise(function(fulfill) {
chrome.test.sendMessage(JSON.stringify(message), fulfill);
});
} else {
let error = 'sendTestMessage requires a message.name <string>';
throw new Error(error);
}
}

/**
Expand Down

0 comments on commit 9d31e1c

Please sign in to comment.