Bug 1217591 - Run autocomplete tests in worker console;r=fitzgen

--HG--
extra : commitid : 2MnaHsLiZe1
This commit is contained in:
Brian Grinstead 2015-10-26 11:55:41 -07:00
parent f2795041dc
commit 00584c089e
25 changed files with 260 additions and 126 deletions

View File

@ -7,6 +7,7 @@ support-files =
data.json^headers^
network_requests_iframe.html
sandboxed_iframe.html
console-test-worker.js
[test_basics.html]
[test_bug819670_getter_throws.html]
@ -19,6 +20,7 @@ support-files =
[test_file_uri.html]
[test_reflow.html]
[test_jsterm.html]
[test_jsterm_autocomplete.html]
[test_jsterm_cd_iframe.html]
[test_jsterm_last_result.html]
[test_jsterm_queryselector.html]

View File

@ -50,7 +50,17 @@ function connectToDebugger(aCallback)
client.connect(aCallback.bind(null, dbgState));
}
function attachConsole(aListeners, aCallback, aAttachToTab)
function attachConsole(aListeners, aCallback) {
_attachConsole(aListeners, aCallback);
}
function attachConsoleToTab(aListeners, aCallback) {
_attachConsole(aListeners, aCallback, true);
}
function attachConsoleToWorker(aListeners, aCallback) {
_attachConsole(aListeners, aCallback, true, true);
}
function _attachConsole(aListeners, aCallback, aAttachToTab, aAttachToWorker)
{
function _onAttachConsole(aState, aResponse, aWebConsoleClient)
{
@ -81,11 +91,26 @@ function attachConsole(aListeners, aCallback, aAttachToTab)
return;
}
let tab = aResponse.tabs[aResponse.selected];
let consoleActor = tab.consoleActor;
aState.dbgClient.attachTab(tab.actor, function () {
aState.actor = consoleActor;
aState.dbgClient.attachConsole(consoleActor, aListeners,
_onAttachConsole.bind(null, aState));
aState.dbgClient.attachTab(tab.actor, function (response, tabClient) {
if (aAttachToWorker) {
var worker = new Worker("console-test-worker.js");
worker.addEventListener("message", function listener() {
worker.removeEventListener("message", listener);
tabClient.listWorkers(function (response) {
tabClient.attachWorker(response.workers[0].actor, function (response, workerClient) {
workerClient.attachThread({}, function(aResponse) {
aState.actor = workerClient.consoleActor;
aState.dbgClient.attachConsole(workerClient.consoleActor, aListeners,
_onAttachConsole.bind(null, aState));
});
});
});
});
} else {
aState.actor = tab.consoleActor;
aState.dbgClient.attachConsole(tab.consoleActor, aListeners,
_onAttachConsole.bind(null, aState));
}
});
});
} else {

View File

@ -0,0 +1,16 @@
"use strict";
function f() {
var a = 1;
var b = 2;
var c = 3;
}
self.onmessage = function (event) {
if (event.data == "ping") {
f()
postMessage("pong");
}
};
postMessage("load");

View File

@ -18,7 +18,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["PageError"], onStartPageError, true);
attachConsoleToTab(["PageError"], onStartPageError);
}
function onStartPageError(aState, aResponse)
@ -30,8 +30,8 @@ function onStartPageError(aState, aResponse)
closeDebugger(aState, function() {
top.console_ = top.console;
top.console = { lolz: "foo" };
attachConsole(["PageError", "ConsoleAPI", "foo"],
onStartPageErrorAndConsoleAPI, true);
attachConsoleToTab(["PageError", "ConsoleAPI", "foo"],
onStartPageErrorAndConsoleAPI);
});
}
@ -56,7 +56,7 @@ function onStopConsoleAPI(aState, aResponse)
is(aResponse.stoppedListeners[0], "ConsoleAPI", "stoppedListeners: ConsoleAPI");
closeDebugger(aState, function() {
attachConsole(["ConsoleAPI"], onStartConsoleAPI, true);
attachConsoleToTab(["ConsoleAPI"], onStartConsoleAPI);
});
}

View File

@ -17,7 +17,7 @@ SimpleTest.waitForExplicitFinish();
function startTest()
{
removeEventListener("load", startTest);
attachConsole([], onAttach, true);
attachConsoleToTab([], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -28,10 +28,10 @@ function startTest() {
ok (!gWin.document.nodePrincipal.equals(systemPrincipal),
"The test document is not using the system principal");
attachConsole([], state => {
attachConsoleToTab([], state => {
gState = state;
runTests(tests, testEnd);
}, true);
});
}
tests = [

View File

@ -33,7 +33,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["PageError"], onAttach, true);
attachConsoleToTab(["PageError"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -83,7 +83,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ConsoleAPI"], onAttach, true);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -156,7 +156,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ConsoleAPI"], onAttach, true);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -121,7 +121,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ConsoleAPI"], onAttach, true);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -37,7 +37,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["PageError"], onAttach, true);
attachConsoleToTab(["PageError"], onAttach);
}
function onAttach(aState, aResponse)
@ -64,9 +64,7 @@ function onAttach(aState, aResponse)
gState = aState;
let tests = [doAutocomplete1, doAutocomplete2, doAutocomplete3,
doAutocomplete4, doAutocompleteLarge1, doAutocompleteLarge2,
doSimpleEval, doWindowEval, doEvalWithException,
let tests = [doSimpleEval, doWindowEval, doEvalWithException,
doEvalWithHelper, doEvalString, doEvalLongString,
doEvalWithBinding, doEvalWithBindingFrame].map(t => {
return Task.async(t);
@ -75,96 +73,6 @@ function onAttach(aState, aResponse)
runTests(tests, testEnd);
}
function doAutocomplete1() {
info("test autocomplete for 'window.foo'");
gState.client.autocomplete("window.foo", 10, onAutocomplete1);
}
function onAutocomplete1(aResponse) {
let matches = aResponse.matches;
is(aResponse.matchProp, "foo", "matchProp");
is(matches.length, 1, "matches.length");
is(matches[0], "foobarObject", "matches[0]");
nextTest();
}
function doAutocomplete2() {
info("test autocomplete for 'window.foobarObject.'");
gState.client.autocomplete("window.foobarObject.", 20, onAutocomplete2);
}
function onAutocomplete2(aResponse) {
let matches = aResponse.matches;
ok(!aResponse.matchProp, "matchProp");
is(matches.length, 7, "matches.length");
checkObject(matches,
["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]);
nextTest();
}
function doAutocomplete3() {
// Check that completion suggestions are offered inside the string.
info("test autocomplete for 'dump(window.foobarObject.)'");
gState.client.autocomplete("dump(window.foobarObject.)", 25, onAutocomplete3);
}
function onAutocomplete3(aResponse) {
let matches = aResponse.matches;
ok(!aResponse.matchProp, "matchProp");
is(matches.length, 7, "matches.length");
checkObject(matches,
["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]);
nextTest();
}
function doAutocomplete4() {
// Check that completion requests can have no suggestions.
info("test autocomplete for 'dump(window.foobarObject.)'");
gState.client.autocomplete("dump(window.foobarObject.)", 26, onAutocomplete4);
}
function onAutocomplete4(aResponse) {
ok(!aResponse.matchProp, "matchProp");
is(aResponse.matches.length, 0, "matches.length");
nextTest();
}
function doAutocompleteLarge1() {
// Check that completion requests with too large objects will
// have no suggestions.
info("test autocomplete for 'window.largeObject1.'");
gState.client.autocomplete("window.largeObject1.", 20, onAutocompleteLarge1);
}
function onAutocompleteLarge1(aResponse) {
ok(!aResponse.matchProp, "matchProp");
info (aResponse.matches.join("|"));
is(aResponse.matches.length, 0, "Bailed out with too many properties");
nextTest();
}
function doAutocompleteLarge2() {
// Check that completion requests with pretty large objects will
// have MAX_AUTOCOMPLETIONS suggestions
info("test autocomplete for 'window.largeObject2.'");
gState.client.autocomplete("window.largeObject2.", 20, onAutocompleteLarge2);
}
function onAutocompleteLarge2(aResponse) {
ok(!aResponse.matchProp, "matchProp");
is(aResponse.matches.length, MAX_AUTOCOMPLETIONS, "matches.length is MAX_AUTOCOMPLETIONS");
nextTest();
}
function* doSimpleEval() {
info("test eval '2+2'");
let response = yield evaluateJS("2+2");

View File

@ -0,0 +1,183 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for JavaScript terminal functionality</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript;version=1.8" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for JavaScript terminal autocomplete functionality</p>
<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();
let gState;
let {MAX_AUTOCOMPLETE_ATTEMPTS,MAX_AUTOCOMPLETIONS} = require("devtools/shared/webconsole/js-property-provider");
function evaluateJS(input, options = {}) {
return new Promise((resolve, reject) => {
gState.client.evaluateJSAsync(input, resolve, options);
});
}
function autocompletePromise(str, cursor, frameActor) {
return new Promise(resolve => {
gState.client.autocomplete(str, cursor, resolve, frameActor);
});
}
// This test runs all of its assertions twice - once with
// the tab as a target and once with a worker
let runningInTab = true;
function startTest({worker}) {
if (worker) {
attachConsoleToWorker(["PageError"], onAttach);
} else {
attachConsoleToTab(["PageError"], onAttach);
}
};
let onAttach = Task.async(function*(aState, response) {
gState = aState;
let longStrLength = DebuggerServer.LONG_STRING_LENGTH;
// Set up the global variables needed to test autocompletion
// in the target.
let script = `
// This is for workers so autocomplete acts the same
if (!this.window) {
window = this;
}
window.foobarObject = Object.create(null);
window.foobarObject.foo = 1;
window.foobarObject.foobar = 2;
window.foobarObject.foobaz = 3;
window.foobarObject.omg = 4;
window.foobarObject.omgfoo = 5;
window.foobarObject.strfoo = "foobarz";
window.foobarObject.omgstr = "foobarz" +
(new Array(${longStrLength})).join("abb");
window.largeObject1 = Object.create(null);
for (let i = 0; i < ${MAX_AUTOCOMPLETE_ATTEMPTS + 1}; i++) {
window.largeObject1['a' + i] = i;
}
window.largeObject2 = Object.create(null);
for (let i = 0; i < ${MAX_AUTOCOMPLETIONS * 2}; i++) {
window.largeObject2['a' + i] = i;
}
`;
yield evaluateJS(script);
let tests = [doAutocomplete1, doAutocomplete2, doAutocomplete3,
doAutocomplete4, doAutocompleteLarge1,
doAutocompleteLarge2].map(t => {
return Task.async(t);
});
runTests(tests, testEnd);
});
function* doAutocomplete1() {
info("test autocomplete for 'window.foo'");
let response = yield autocompletePromise("window.foo", 10);
let matches = response.matches;
is(response.matchProp, "foo", "matchProp");
is(matches.length, 1, "matches.length");
is(matches[0], "foobarObject", "matches[0]");
nextTest();
}
function* doAutocomplete2() {
info("test autocomplete for 'window.foobarObject.'");
let response = yield autocompletePromise("window.foobarObject.", 20);
let matches = response.matches;
ok(!response.matchProp, "matchProp");
is(matches.length, 7, "matches.length");
checkObject(matches,
["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]);
nextTest();
}
function* doAutocomplete3() {
// Check that completion suggestions are offered inside the string.
info("test autocomplete for 'dump(window.foobarObject.)'");
let response = yield autocompletePromise("dump(window.foobarObject.)", 25);
let matches = response.matches;
ok(!response.matchProp, "matchProp");
is(matches.length, 7, "matches.length");
checkObject(matches,
["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]);
nextTest();
}
function* doAutocomplete4() {
// Check that completion requests can have no suggestions.
info("test autocomplete for 'dump(window.foobarObject.)'");
let response = yield autocompletePromise("dump(window.foobarObject.)", 26);
ok(!response.matchProp, "matchProp");
is(response.matches.length, 0, "matches.length");
nextTest();
}
function* doAutocompleteLarge1() {
// Check that completion requests with too large objects will
// have no suggestions.
info("test autocomplete for 'window.largeObject1.'");
let response = yield autocompletePromise("window.largeObject1.", 20);
ok(!response.matchProp, "matchProp");
info (response.matches.join("|"));
is(response.matches.length, 0, "Bailed out with too many properties");
nextTest();
}
function* doAutocompleteLarge2() {
// Check that completion requests with pretty large objects will
// have MAX_AUTOCOMPLETIONS suggestions
info("test autocomplete for 'window.largeObject2.'");
let response = yield autocompletePromise("window.largeObject2.", 20);
ok(!response.matchProp, "matchProp");
is(response.matches.length, MAX_AUTOCOMPLETIONS, "matches.length is MAX_AUTOCOMPLETIONS");
nextTest();
}
function testEnd()
{
// If this is the first run, reload the page and do it again
// in a worker. Otherwise, end the test.
closeDebugger(gState, function() {
gState = null;
if (runningInTab) {
runningInTab = false;
startTest({
worker: true
});
} else {
SimpleTest.finish();
}
});
}
addEventListener("load", () => {
startTest({
worker: false
});
});
</script>
</body>
</html>

View File

@ -22,7 +22,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole([], onAttach, true);
attachConsoleToTab([], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -31,11 +31,11 @@ function evaluateJS(input, callback) {
function startTest()
{
removeEventListener("load", startTest);
attachConsole([], state => {
attachConsoleToTab([], state => {
gState = state;
let tests = [checkUndefinedResult,checkAdditionResult,checkObjectResult];
runTests(tests, testEnd);
}, true);
});
}
let checkUndefinedResult = Task.async(function*() {

View File

@ -27,7 +27,7 @@ function startTest() {
ok (!gWin.document.nodePrincipal.equals(systemPrincipal),
"The test document is not using the system principal");
attachConsole([], state => {
attachConsoleToTab([], state => {
gState = state;
let tests = [
setupWindow,
@ -37,7 +37,7 @@ function startTest() {
checkQuerySelectorAllException
];
runTests(tests, testEnd);
}, true);
});
}
let setupWindow = Task.async(function*() {

View File

@ -19,7 +19,7 @@ SimpleTest.waitForExplicitFinish();
function startTest()
{
removeEventListener("load", startTest);
attachConsole(["NetworkActivity"], onAttach, true);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -20,7 +20,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["NetworkActivity"], onAttach, true);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -20,7 +20,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["NetworkActivity"], onAttach, true);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -61,7 +61,7 @@ function startTest()
info("Test detection of Public Key Pinning.");
removeEventListener("load", startTest);
attachConsole(["NetworkActivity"], onAttach, true);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -53,7 +53,7 @@ function startTest()
info("Test detection of HTTP Strict Transport Security.");
removeEventListener("load", startTest);
attachConsole(["NetworkActivity"], onAttach, true);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -20,7 +20,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ConsoleAPI"], onAttach, true);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -21,7 +21,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ConsoleAPI"], onAttach, true);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -19,7 +19,7 @@ function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ConsoleAPI"], onAttach, true);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -26,7 +26,7 @@ function generateReflow()
function startTest()
{
removeEventListener("load", startTest);
attachConsole(["ReflowActivity"], onAttach, true);
attachConsoleToTab(["ReflowActivity"], onAttach);
}
function onAttach(aState, aResponse)

View File

@ -17,7 +17,7 @@ SimpleTest.waitForExplicitFinish();
function startTest()
{
removeEventListener("load", startTest);
attachConsole([], onAttach, true);
attachConsoleToTab([], onAttach);
}
function onAttach(aState, aResponse)