asynctypes-685526: constrainPredictionIndex can promise

If getPredictions() is able to return a promise then we first need
constrainPredictionIndex() to be able to work with promises.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Separate sync/async template data

completer._getCompleterTemplateData returns 6 bits of information, 3 are
not affected by predictions becoming asynchronous, 3 are. This separates
them by pushing the sync data (i.e. statusMarkup, unclosedJs and
scratchLink) into separate functions. The rest will become promises
which the template engine will lap up beautifully.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Make getCompleterTemplateData async

The changes to completer.js look more significant than they really are
we just introduce three new promisedXXX variables, and do all the
calculations in Q.resolve(prediction) passing the promises of the 3
promises in the return data.

getCompleterTemplateData is used in 2 places, completer.update and
the test helpers. completer.update does not need to change at all
because domtemplate is awesome.

The test helpers are affected in 3 places, the hints function which
has to resolve the 3 promised values, the debug outputted which remains
synchronous by inserting the string "<promise>" when it gets an
unresolved value, and the asserts themselves which use test.checkCalled
to defer the test and automagically include the results in the correct
test.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Fix ',' and ';'

Trying out WebStorm which told me about a bunch of semi-syntax errors.
I'm not sure if I care particularly, but it's easy to fix, so I did.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Make Requisition.complete async

The changes to testKeyboard mostly involve the indent caused by adding
Q.resolve.

Inputter gains a _completed promise that tracks if there are any
outstanding completions. This is something of an experiment.

There are some unknown consequences of this change with slow to finish
asynchronous types. It is likely that there will be some problems that
we need to work around in the future.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Use promised() after all

I raised bug 790973 to cover the issue with promised() unrolling arrays
and it was fixed in a few hours, so here is a (hopefully short term)
import of promised until it lands in core.js, and a revert to the
implementation of hints() that we originally wanted to use.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Make getPredictions() async

Given all the previous changes to make things that depend on
getPredictions asynchronous, this is fairly simple.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Minor tidy-ups

Fix a spelling mistake, add some blank lines, update some test error reporting
strings, and wrap to 80 column lines

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Add unit tests

These unit tests are incomplete, but are useful in guiding what work is
still required in this patch.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
Merge branch 'menuclick-788215' into asynctypes-685526

Conflicts:
	lib/gcli/cli.js
	lib/gclitest/helpers.js
	lib/gclitest/mockCommands.js
	lib/gclitest/testKeyboard.js
asynctypes-685526: Extract array compare code

We're going to need to compare two arrays in a few places, so make it a
function. Perhaps we might make this 'public' at some stage (i.e. not
prefixed with a _).

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Allow message test to be RegExp

Sometimes error messages are only partially predicable, for example:
"Error too many matches (124)". This allows us to insert a regular
expression for the unstable part.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Add 'unassigned' testing

Requisition keeps track of arguments that have not been assigned to
parameters. This allows us to check that the correct arguments are
being properly unassigned.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Add 'predictions' testing

This allows us to check what the menu should display. It is based on a
call to getPredictions rather than the actual menu (which might be a
better test, but can be left for another day)

This makes _createDebugCheck asynchronous so we also adjust the F2
action when in debug mode.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Properly check cursor value

Once again caught by a truthyness bug. If the tester set cursor=0, then
we would previously not set the cursor position. With this better test
we do.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Minor indentation fix.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Test update

testCli made several calls to getPredictions which assumed a sync reply.
This updated version (which makes use of recent changes to the test
helpers) doesn't do that, and also adds many tests that were previously
not done.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Minor test tidy-up

We have previously done s/test/assert/g to make the tests work more
easily in Firefox, and because the name is more logical. But we left a
few behind. Also we broke indentation in a few places. This change
fixes both.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Fix getPredictionAt()

getPredictionAt was working on a duplicate of the predictions rather
than resolving it. This worked by fluke when the predictions were not a
promise, but broke otherwise.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
asynctypes-685526: Make getPredictions return promise

Now getPredictions always returns a promise, and that promise always
resolves to an array (an empty one if there are no predictions).

Signed-off-by: Joe Walker <jwalker@mozilla.com>