Commit def91982 authored by Will Chen's avatar Will Chen Committed by Commit Bot

DevTools: immediately finish test and print error if uncaught error is thrown

When there's an uncaught exception from running our test, the test times out
which is annoying to wait for and it doesn't provide any intermediate output.

This executes our test script in an awaited try-catch block so we can print
the error and end the test early.

This updates our unit tests to follow the async IIFE pattern that the rest of
the new tests uses so it plays nicely with our new error-handling code.

R=dgozman@chromium.org,einbinder@chromium.org

Bug: 667560
Change-Id: I2f693c704ef2991a2970fa925e52422d633bc06c
Reviewed-on: https://chromium-review.googlesource.com/773565
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarJoel Einbinder <einbinder@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517510}
parent 6315b73e
TestRunner.loadModule('data_grid').then(test); (async function() {
await TestRunner.loadModule('data_grid');
function test() {
TestRunner.addResult("This tests long text in datagrid."); TestRunner.addResult("This tests long text in datagrid.");
var columns = [ var columns = [
...@@ -69,4 +69,4 @@ function test() { ...@@ -69,4 +69,4 @@ function test() {
function onEdit() { function onEdit() {
TestRunner.addResult("Editor value committed."); TestRunner.addResult("Editor value committed.");
} }
} })();
\ No newline at end of file
TestRunner.loadModule('data_grid').then(test); (async function() {
function test() { await TestRunner.loadModule('data_grid');
TestRunner.addResult("This tests viewport datagrid."); TestRunner.addResult("This tests viewport datagrid.");
var div = document.createElement("div"); var div = document.createElement("div");
...@@ -52,4 +53,4 @@ function test() { ...@@ -52,4 +53,4 @@ function test() {
} }
TestRunner.addResult(""); TestRunner.addResult("");
} }
} })();
TestRunner.loadModule("quick_open").then(test); (async function() {
function test() { await TestRunner.loadModule("quick_open");
TestRunner.addResult("Check to see that FilteredItemSelectionDialog uses proper regex to filter results."); TestRunner.addResult("Check to see that FilteredItemSelectionDialog uses proper regex to filter results.");
var overridenInput = []; var overridenInput = [];
...@@ -83,4 +83,4 @@ function test() { ...@@ -83,4 +83,4 @@ function test() {
return checkQuery("", ["abc", "abcd"]); return checkQuery("", ["abc", "abcd"]);
} }
]); ]);
} })();
TestRunner.loadModule('quick_open').then(test); (async function() {
function test() { await TestRunner.loadModule('quick_open');
TestRunner.addResult( TestRunner.addResult(
'Test that FilteredListWidget.setProvider changes the provider.'); 'Test that FilteredListWidget.setProvider changes the provider.');
...@@ -55,4 +56,4 @@ function test() { ...@@ -55,4 +56,4 @@ function test() {
output.push(filteredListWidget._provider.itemKeyAt(item)); output.push(filteredListWidget._provider.itemKeyAt(item));
TestRunner.addResult('Output:' + JSON.stringify(output)); TestRunner.addResult('Output:' + JSON.stringify(output));
} }
} })();
TestRunner.addResult('Test ListControl rendering and selection for non-viewport mode.'); (async function() {
TestRunner.addResult('Test ListControl rendering and selection for non-viewport mode.');
class Delegate {
constructor() { class Delegate {
} constructor() {
}
createElementForItem(item) {
TestRunner.addResult('Creating element for ' + item); createElementForItem(item) {
var element = document.createElement('div'); TestRunner.addResult('Creating element for ' + item);
element.style.height = (10 + item % 5) + 'px'; var element = document.createElement('div');
element.textContent = item; element.style.height = (10 + item % 5) + 'px';
return element; element.textContent = item;
} return element;
}
heightForItem(item) {
TestRunner.addResult('heightForItem should not be called'); heightForItem(item) {
return 10 + item % 5; TestRunner.addResult('heightForItem should not be called');
} return 10 + item % 5;
}
isItemSelectable(item) {
return (item % 5 === 0) || (item % 5 === 2); isItemSelectable(item) {
return (item % 5 === 0) || (item % 5 === 2);
}
selectedItemChanged(from, to, fromElement, toElement) {
TestRunner.addResult('Selection changed from ' + from + ' to ' + to);
if (fromElement)
fromElement.classList.remove('selected');
if (toElement)
toElement.classList.add('selected');
}
} }
selectedItemChanged(from, to, fromElement, toElement) { var delegate = new Delegate();
TestRunner.addResult('Selection changed from ' + from + ' to ' + to); var model = new UI.ListModel();
if (fromElement) var list = new UI.ListControl(model, delegate, UI.ListMode.NonViewport);
fromElement.classList.remove('selected'); UI.inspectorView.element.appendChild(list.element);
if (toElement)
toElement.classList.add('selected'); function dumpList()
} {
} var height = list.element.offsetHeight;
TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`);
var delegate = new Delegate(); for (var child of list.element.children) {
var model = new UI.ListModel(); var offsetTop = child.getBoundingClientRect().top - list.element.getBoundingClientRect().top;
var list = new UI.ListControl(model, delegate, UI.ListMode.NonViewport); var offsetBottom = child.getBoundingClientRect().bottom - list.element.getBoundingClientRect().top;
UI.inspectorView.element.appendChild(list.element); var visible = (offsetBottom <= 0 || offsetTop >= height) ? ' ' :
(offsetTop >= 0 && offsetBottom <= height ? '*' : '+');
function dumpList() var selected = child.classList.contains('selected') ? ' (selected)' : '';
{ var text = child === list._topElement ? 'top' : (child === list._bottomElement ? 'bottom' : child.textContent);
var height = list.element.offsetHeight; TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`); }
for (var child of list.element.children) { TestRunner.addResult('');
var offsetTop = child.getBoundingClientRect().top - list.element.getBoundingClientRect().top;
var offsetBottom = child.getBoundingClientRect().bottom - list.element.getBoundingClientRect().top;
var visible = (offsetBottom <= 0 || offsetTop >= height) ? ' ' :
(offsetTop >= 0 && offsetBottom <= height ? '*' : '+');
var selected = child.classList.contains('selected') ? ' (selected)' : '';
var text = child === list._topElement ? 'top' : (child === list._bottomElement ? 'bottom' : child.textContent);
TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
} }
TestRunner.addResult('');
}
TestRunner.addResult('Adding 0, 1, 2'); TestRunner.addResult('Adding 0, 1, 2');
model.replaceAll([0, 1, 2]); model.replaceAll([0, 1, 2]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 0'); TestRunner.addResult('Scrolling to 0');
list.scrollItemIntoView(0); list.scrollItemIntoView(0);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 2'); TestRunner.addResult('Scrolling to 2');
list.scrollItemIntoView(2); list.scrollItemIntoView(2);
dumpList(); dumpList();
TestRunner.addResult('Adding 3-20'); TestRunner.addResult('Adding 3-20');
model.replaceRange(3, 3, [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); model.replaceRange(3, 3, [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 19'); TestRunner.addResult('Scrolling to 19');
list.scrollItemIntoView(19); list.scrollItemIntoView(19);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 13 (center)'); TestRunner.addResult('Scrolling to 13 (center)');
list.scrollItemIntoView(13, true); list.scrollItemIntoView(13, true);
dumpList(); dumpList();
TestRunner.addResult('Replacing 0, 1 with 25-36'); TestRunner.addResult('Replacing 0, 1 with 25-36');
model.replaceRange(0, 2, [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]); model.replaceRange(0, 2, [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 18'); TestRunner.addResult('Scrolling to 18');
list.scrollItemIntoView(28); list.scrollItemIntoView(28);
dumpList(); dumpList();
TestRunner.addResult('Replacing 25-36 with 0-1'); TestRunner.addResult('Replacing 25-36 with 0-1');
model.replaceRange(0, 12, [0, 1]); model.replaceRange(0, 12, [0, 1]);
dumpList(); dumpList();
TestRunner.addResult('Replacing 16-18 with 45'); TestRunner.addResult('Replacing 16-18 with 45');
model.replaceRange(16, 19, [45]); model.replaceRange(16, 19, [45]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 4'); TestRunner.addResult('Scrolling to 4');
list.scrollItemIntoView(4); list.scrollItemIntoView(4);
dumpList(); dumpList();
TestRunner.addResult('Replacing 45 with 16-18'); TestRunner.addResult('Replacing 45 with 16-18');
model.replaceRange(16, 17, [16, 17, 18]); model.replaceRange(16, 17, [16, 17, 18]);
dumpList(); dumpList();
TestRunner.completeTest(); TestRunner.completeTest();
})();
TestRunner.addResult('Test ListControl rendering for various height items case.'); (async function() {
TestRunner.addResult('Test ListControl rendering for various height items case.');
class Delegate {
constructor() { class Delegate {
} constructor() {
}
createElementForItem(item) {
TestRunner.addResult('Creating element for ' + item); createElementForItem(item) {
var element = document.createElement('div'); TestRunner.addResult('Creating element for ' + item);
element.style.height = this.heightForItem(item) + 'px'; var element = document.createElement('div');
element.textContent = item; element.style.height = this.heightForItem(item) + 'px';
return element; element.textContent = item;
} return element;
}
heightForItem(item) {
return 7 + item % 10; heightForItem(item) {
} return 7 + item % 10;
}
isItemSelectable(item) {
return (item % 5 === 0) || (item % 5 === 2); isItemSelectable(item) {
return (item % 5 === 0) || (item % 5 === 2);
}
selectedItemChanged(from, to, fromElement, toElement) {
TestRunner.addResult('Selection changed from ' + from + ' to ' + to);
if (fromElement)
fromElement.classList.remove('selected');
if (toElement)
toElement.classList.add('selected');
}
} }
selectedItemChanged(from, to, fromElement, toElement) { var delegate = new Delegate();
TestRunner.addResult('Selection changed from ' + from + ' to ' + to); var model = new UI.ListModel();
if (fromElement) var list = new UI.ListControl(model, delegate, UI.ListMode.VariousHeightItems);
fromElement.classList.remove('selected'); list.element.style.height = '73px';
if (toElement) UI.inspectorView.element.appendChild(list.element);
toElement.classList.add('selected');
} function dumpList()
} {
var height = list.element.offsetHeight;
var delegate = new Delegate(); TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`);
var model = new UI.ListModel(); for (var child of list.element.children) {
var list = new UI.ListControl(model, delegate, UI.ListMode.VariousHeightItems); var offsetTop = child.getBoundingClientRect().top - list.element.getBoundingClientRect().top;
list.element.style.height = '73px'; var offsetBottom = child.getBoundingClientRect().bottom - list.element.getBoundingClientRect().top;
UI.inspectorView.element.appendChild(list.element); var visible = (offsetBottom <= 0 || offsetTop >= height) ? ' ' :
(offsetTop >= 0 && offsetBottom <= height ? '*' : '+');
function dumpList() var selected = child.classList.contains('selected') ? ' (selected)' : '';
{ var text = child === list._topElement ? 'top' : (child === list._bottomElement ? 'bottom' : child.textContent);
var height = list.element.offsetHeight; TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`); }
for (var child of list.element.children) { TestRunner.addResult('offsets: ' + list._variableOffsets.join(' '));
var offsetTop = child.getBoundingClientRect().top - list.element.getBoundingClientRect().top; TestRunner.addResult('');
var offsetBottom = child.getBoundingClientRect().bottom - list.element.getBoundingClientRect().top;
var visible = (offsetBottom <= 0 || offsetTop >= height) ? ' ' :
(offsetTop >= 0 && offsetBottom <= height ? '*' : '+');
var selected = child.classList.contains('selected') ? ' (selected)' : '';
var text = child === list._topElement ? 'top' : (child === list._bottomElement ? 'bottom' : child.textContent);
TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
} }
TestRunner.addResult('offsets: ' + list._variableOffsets.join(' '));
TestRunner.addResult('');
}
TestRunner.addResult('Adding 0, 1, 2'); TestRunner.addResult('Adding 0, 1, 2');
model.replaceAll([0, 1, 2]); model.replaceAll([0, 1, 2]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 0'); TestRunner.addResult('Scrolling to 0');
list.scrollItemIntoView(0); list.scrollItemIntoView(0);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 2'); TestRunner.addResult('Scrolling to 2');
list.scrollItemIntoView(2); list.scrollItemIntoView(2);
dumpList(); dumpList();
TestRunner.addResult('Adding 3-20'); TestRunner.addResult('Adding 3-20');
model.replaceRange(3, 3, [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); model.replaceRange(3, 3, [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 11'); TestRunner.addResult('Scrolling to 11');
list.scrollItemIntoView(11); list.scrollItemIntoView(11);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 19'); TestRunner.addResult('Scrolling to 19');
list.scrollItemIntoView(19); list.scrollItemIntoView(19);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 16 (center)'); TestRunner.addResult('Scrolling to 16 (center)');
list.scrollItemIntoView(16, true); list.scrollItemIntoView(16, true);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 3'); TestRunner.addResult('Scrolling to 3');
list.scrollItemIntoView(3); list.scrollItemIntoView(3);
dumpList(); dumpList();
TestRunner.addResult('Replacing 0, 1 with 25-36'); TestRunner.addResult('Replacing 0, 1 with 25-36');
model.replaceRange(0, 2, [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]); model.replaceRange(0, 2, [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 18'); TestRunner.addResult('Scrolling to 18');
list.scrollItemIntoView(18); list.scrollItemIntoView(18);
dumpList(); dumpList();
TestRunner.addResult('Replacing 25-36 with 0-1'); TestRunner.addResult('Replacing 25-36 with 0-1');
model.replaceRange(0, 12, [0, 1]); model.replaceRange(0, 12, [0, 1]);
dumpList(); dumpList();
TestRunner.addResult('Replacing 16-18 with 45'); TestRunner.addResult('Replacing 16-18 with 45');
model.replaceRange(16, 19, [45]); model.replaceRange(16, 19, [45]);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 4'); TestRunner.addResult('Scrolling to 4');
list.scrollItemIntoView(4); list.scrollItemIntoView(4);
dumpList(); dumpList();
TestRunner.addResult('Replacing 45 with 16-18'); TestRunner.addResult('Replacing 45 with 16-18');
model.replaceRange(16, 17, [16, 17, 18]); model.replaceRange(16, 17, [16, 17, 18]);
dumpList(); dumpList();
TestRunner.addResult('Resizing'); TestRunner.addResult('Resizing');
list.element.style.height = '190px'; list.element.style.height = '190px';
list.viewportResized(); list.viewportResized();
dumpList(); dumpList();
TestRunner.completeTest(); TestRunner.completeTest();
})();
TestRunner.addResult('Test ListModel API.'); (async function() {
TestRunner.addResult('Test ListModel API.');
var model = new UI.ListModel(); var model = new UI.ListModel();
model.addEventListener(UI.ListModel.Events.ItemsReplaced, event => { model.addEventListener(UI.ListModel.Events.ItemsReplaced, event => {
var data = event.data; var data = event.data;
var inserted = model.slice(data.index, data.index + data.inserted); var inserted = model.slice(data.index, data.index + data.inserted);
TestRunner.addResult(`Replaced [${data.removed.join(', ')}] at index ${data.index} with [${inserted.join(', ')}]`); TestRunner.addResult(`Replaced [${data.removed.join(', ')}] at index ${data.index} with [${inserted.join(', ')}]`);
TestRunner.addResult(`Resulting list: [${model.join(', ')}]`); TestRunner.addResult(`Resulting list: [${model.join(', ')}]`);
TestRunner.addResult(''); TestRunner.addResult('');
}); });
TestRunner.addResult('Adding 0, 1, 2'); TestRunner.addResult('Adding 0, 1, 2');
model.replaceAll([0, 1, 2]); model.replaceAll([0, 1, 2]);
TestRunner.addResult('Replacing 0 with 5, 6, 7'); TestRunner.addResult('Replacing 0 with 5, 6, 7');
model.replaceRange(0, 1, [5, 6, 7]); model.replaceRange(0, 1, [5, 6, 7]);
TestRunner.addResult('Pushing 10'); TestRunner.addResult('Pushing 10');
model.insert(model.length, 10); model.insert(model.length, 10);
TestRunner.addResult('Popping 10'); TestRunner.addResult('Popping 10');
model.remove(model.length - 1); model.remove(model.length - 1);
TestRunner.addResult('Removing 2'); TestRunner.addResult('Removing 2');
model.remove(4); model.remove(4);
TestRunner.addResult('Inserting 8'); TestRunner.addResult('Inserting 8');
model.insert(1, 8); model.insert(1, 8);
TestRunner.addResult('Replacing with 0...20'); TestRunner.addResult('Replacing with 0...20');
model.replaceAll([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); model.replaceAll([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
TestRunner.addResult('Replacing 7 with 27'); TestRunner.addResult('Replacing 7 with 27');
model.replaceRange(7, 8, [27]); model.replaceRange(7, 8, [27]);
TestRunner.addResult('Replacing 18, 19 with 28, 29'); TestRunner.addResult('Replacing 18, 19 with 28, 29');
model.replaceRange(18, 20, [28, 29]); model.replaceRange(18, 20, [28, 29]);
TestRunner.addResult('Replacing 1, 2, 3 with [31-43]'); TestRunner.addResult('Replacing 1, 2, 3 with [31-43]');
model.replaceRange(1, 4, [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43]); model.replaceRange(1, 4, [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43]);
TestRunner.addResult('Replacing all but 29 with []'); TestRunner.addResult('Replacing all but 29 with []');
model.replaceRange(0, 29, []); model.replaceRange(0, 29, []);
TestRunner.completeTest(); TestRunner.completeTest();
})();
TestRunner.addResult("This tests a utility's ability to parse filter queries."); (async function () {
TestRunner.addResult("This tests a utility's ability to parse filter queries.");
var keys = ["key1", "key2"]; var keys = ["key1", "key2"];
var queries = [ var queries = [
"text", "text",
"text with spaces", "text with spaces",
"-", "-",
"-text", "-text",
"//", "//",
"/regex/", "/regex/",
"/regex/ /another/", "/regex/ /another/",
"/complex\/regex/", "/complex\/regex/",
"/regex/ text", "/regex/ text",
"key1:foo", "key1:foo",
"-key1:foo", "-key1:foo",
"key1:foo key2:bar", "key1:foo key2:bar",
"-key1:foo key2:bar", "-key1:foo key2:bar",
"key1:foo -key2:bar", "key1:foo -key2:bar",
"-key1:foo -key2:bar", "-key1:foo -key2:bar",
"key1:/regex/", "key1:/regex/",
"key1:foo innerText key2:bar", "key1:foo innerText key2:bar",
"bar key1 foo", "bar key1 foo",
"bar key1:foo", "bar key1:foo",
"bar key1:foo baz", "bar key1:foo baz",
"bar key1:foo yek:roo baz", "bar key1:foo yek:roo baz",
"bar key1:foo -yek:roo baz", "bar key1:foo -yek:roo baz",
"bar baz key1:foo goo zoo", "bar baz key1:foo goo zoo",
"bar key1:key1:foo", "bar key1:key1:foo",
"bar :key1:foo baz", "bar :key1:foo baz",
"bar -:key1:foo baz", "bar -:key1:foo baz",
"bar key1:-foo baz", "bar key1:-foo baz",
]; ];
var parser = new TextUtils.FilterParser(keys); var parser = new TextUtils.FilterParser(keys);
for (var query of queries) { for (var query of queries) {
var result = parser.parse(query); var result = parser.parse(query);
TestRunner.addResult("\nQuery: " + query); TestRunner.addResult("\nQuery: " + query);
for (var descriptor of result) { for (var descriptor of result) {
if (descriptor.regex) if (descriptor.regex)
descriptor.regex = descriptor.regex.source; descriptor.regex = descriptor.regex.source;
TestRunner.addResult(JSON.stringify(descriptor)); TestRunner.addResult(JSON.stringify(descriptor));
}
} }
} TestRunner.completeTest();
TestRunner.completeTest(); })();
\ No newline at end of file
var commands = [ (async function() {
'0', var commands = [
'await 0', '0',
'async function foo() { await 0; }', 'await 0',
'async () => await 0', 'async function foo() { await 0; }',
'class A { async method() { await 0 } }', 'async () => await 0',
'await 0; return 0;', 'class A { async method() { await 0 } }',
'var a = await 1', 'await 0; return 0;',
'let a = await 1', 'var a = await 1',
'const a = await 1', 'let a = await 1',
'for (var i = 0; i < 1; ++i) { await i }', 'const a = await 1',
'for (let i = 0; i < 1; ++i) { await i }', 'for (var i = 0; i < 1; ++i) { await i }',
'var {a} = {a:1}, [b] = [1], {c:{d}} = {c:{d: await 1}}', 'for (let i = 0; i < 1; ++i) { await i }',
'console.log(`${(await {a:1}).a}`)', 'var {a} = {a:1}, [b] = [1], {c:{d}} = {c:{d: await 1}}',
'await 0;function foo() {}', 'console.log(`${(await {a:1}).a}`)',
'await 0;class Foo {}', 'await 0;function foo() {}',
'if (await true) { function foo() {} }', 'await 0;class Foo {}',
'if (await true) { class Foo{} }', 'if (await true) { function foo() {} }',
'if (await true) { var a = 1; }', 'if (await true) { class Foo{} }',
'if (await true) { let a = 1; }', 'if (await true) { var a = 1; }',
'var a = await 1; let b = 2; const c = 3;', 'if (await true) { let a = 1; }',
'let o = await 1, p' 'var a = await 1; let b = 2; const c = 3;',
]; 'let o = await 1, p'
];
(async function test() {
await TestRunner.loadModule("formatter"); await TestRunner.loadModule("formatter");
TestRunner.addResult("This tests preprocessTopLevelAwaitExpressions."); TestRunner.addResult("This tests preprocessTopLevelAwaitExpressions.");
for (var command of commands) { for (var command of commands) {
...@@ -37,4 +37,4 @@ var commands = [ ...@@ -37,4 +37,4 @@ var commands = [
} }
} }
TestRunner.completeTest(); TestRunner.completeTest();
})() })();
\ No newline at end of file
(async function(){
TestRunner.loadModule('product_registry_impl').then(test); await TestRunner.loadModule('product_registry_impl');
function test() {
TestRunner.addResult("This tests product registry impl's register function."); TestRunner.addResult("This tests product registry impl's register function.");
resetProductRegistry(); resetProductRegistry();
...@@ -60,4 +59,4 @@ function test() { ...@@ -60,4 +59,4 @@ function test() {
TestRunner.addResult("Cleared ProductRegistryImpl"); TestRunner.addResult("Cleared ProductRegistryImpl");
ProductRegistryImpl._productsByDomainHash.clear(); ProductRegistryImpl._productsByDomainHash.clear();
} }
} })();
TestRunner.addResult("http://example.com/map.json === " + Common.ParsedURL.completeURL("http://example.com/script.js", "http://example.com/map.json")); (async function () {
TestRunner.addResult("http://example.com/map.json === " + Common.ParsedURL.completeURL("http://example.com/script.js", "/map.json")); TestRunner.addResult("http://example.com/map.json === " + Common.ParsedURL.completeURL("http://example.com/script.js", "http://example.com/map.json"));
TestRunner.addResult("http://example.com/maps/map.json === " + Common.ParsedURL.completeURL("http://example.com/scripts/script.js", "../maps/map.json")); TestRunner.addResult("http://example.com/map.json === " + Common.ParsedURL.completeURL("http://example.com/script.js", "/map.json"));
TestRunner.addResult("http://example.com/maps/map.json === " + Common.ParsedURL.completeURL("http://example.com/scripts/script.js", "../maps/map.json"));
function testCompleteURL(base, lhs, rhs) function testCompleteURL(base, lhs, rhs)
{ {
var actual = Common.ParsedURL.completeURL(base, lhs); var actual = Common.ParsedURL.completeURL(base, lhs);
TestRunner.addResult(lhs + " resolves to " + actual + "===" + rhs + " passes: " + (actual === rhs)); TestRunner.addResult(lhs + " resolves to " + actual + "===" + rhs + " passes: " + (actual === rhs));
} }
var rfc3986_5_4_baseURL = "http://a/b/c/d;p?q"; var rfc3986_5_4_baseURL = "http://a/b/c/d;p?q";
TestRunner.addResult("Tests from http://tools.ietf.org/html/rfc3986#section-5.4 using baseURL=\"" + rfc3986_5_4_baseURL + "\""); TestRunner.addResult("Tests from http://tools.ietf.org/html/rfc3986#section-5.4 using baseURL=\"" + rfc3986_5_4_baseURL + "\"");
var rfc3986_5_4 = testCompleteURL.bind(null, rfc3986_5_4_baseURL); var rfc3986_5_4 = testCompleteURL.bind(null, rfc3986_5_4_baseURL);
rfc3986_5_4("http://h", "http://h"); // modified from RFC3986 rfc3986_5_4("http://h", "http://h"); // modified from RFC3986
rfc3986_5_4("g", "http://a/b/c/g"); rfc3986_5_4("g", "http://a/b/c/g");
rfc3986_5_4("./g", "http://a/b/c/g"); rfc3986_5_4("./g", "http://a/b/c/g");
rfc3986_5_4("g/", "http://a/b/c/g/"); rfc3986_5_4("g/", "http://a/b/c/g/");
rfc3986_5_4("/g", "http://a/g"); rfc3986_5_4("/g", "http://a/g");
rfc3986_5_4("//g", "http://g"); rfc3986_5_4("//g", "http://g");
rfc3986_5_4("?y", "http://a/b/c/d;p?y"); rfc3986_5_4("?y", "http://a/b/c/d;p?y");
rfc3986_5_4("g?y", "http://a/b/c/g?y"); rfc3986_5_4("g?y", "http://a/b/c/g?y");
rfc3986_5_4("#s", "http://a/b/c/d;p?q#s"); rfc3986_5_4("#s", "http://a/b/c/d;p?q#s");
rfc3986_5_4("g#s", "http://a/b/c/g#s"); rfc3986_5_4("g#s", "http://a/b/c/g#s");
rfc3986_5_4("g?y#s", "http://a/b/c/g?y#s"); rfc3986_5_4("g?y#s", "http://a/b/c/g?y#s");
rfc3986_5_4(";x", "http://a/b/c/;x"); rfc3986_5_4(";x", "http://a/b/c/;x");
rfc3986_5_4("g;x", "http://a/b/c/g;x"); rfc3986_5_4("g;x", "http://a/b/c/g;x");
rfc3986_5_4("g;x?y#s", "http://a/b/c/g;x?y#s"); rfc3986_5_4("g;x?y#s", "http://a/b/c/g;x?y#s");
rfc3986_5_4("", "http://a/b/c/d;p?q"); rfc3986_5_4("", "http://a/b/c/d;p?q");
rfc3986_5_4(".", "http://a/b/c/"); rfc3986_5_4(".", "http://a/b/c/");
rfc3986_5_4("./", "http://a/b/c/"); rfc3986_5_4("./", "http://a/b/c/");
rfc3986_5_4("..", "http://a/b/"); rfc3986_5_4("..", "http://a/b/");
rfc3986_5_4("../", "http://a/b/"); rfc3986_5_4("../", "http://a/b/");
rfc3986_5_4("../g", "http://a/b/g"); rfc3986_5_4("../g", "http://a/b/g");
rfc3986_5_4("../..", "http://a/"); rfc3986_5_4("../..", "http://a/");
rfc3986_5_4("../../", "http://a/"); rfc3986_5_4("../../", "http://a/");
rfc3986_5_4("../../g", "http://a/g"); rfc3986_5_4("../../g", "http://a/g");
rfc3986_5_4("../../../g", "http://a/g"); rfc3986_5_4("../../../g", "http://a/g");
rfc3986_5_4("../../../../g", "http://a/g"); rfc3986_5_4("../../../../g", "http://a/g");
rfc3986_5_4("/./g", "http://a/g"); rfc3986_5_4("/./g", "http://a/g");
rfc3986_5_4("/../g", "http://a/g"); rfc3986_5_4("/../g", "http://a/g");
rfc3986_5_4("g." , "http://a/b/c/g."); rfc3986_5_4("g." , "http://a/b/c/g.");
rfc3986_5_4(".g" , "http://a/b/c/.g"); rfc3986_5_4(".g" , "http://a/b/c/.g");
rfc3986_5_4("g..", "http://a/b/c/g.."); rfc3986_5_4("g..", "http://a/b/c/g..");
rfc3986_5_4("..g", "http://a/b/c/..g"); rfc3986_5_4("..g", "http://a/b/c/..g");
rfc3986_5_4("./../g", "http://a/b/g"); rfc3986_5_4("./../g", "http://a/b/g");
rfc3986_5_4("./g/.", "http://a/b/c/g/"); rfc3986_5_4("./g/.", "http://a/b/c/g/");
rfc3986_5_4("g/./h", "http://a/b/c/g/h"); rfc3986_5_4("g/./h", "http://a/b/c/g/h");
rfc3986_5_4("g/../h", "http://a/b/c/h"); rfc3986_5_4("g/../h", "http://a/b/c/h");
rfc3986_5_4("g;x=1/./y", "http://a/b/c/g;x=1/y"); rfc3986_5_4("g;x=1/./y", "http://a/b/c/g;x=1/y");
rfc3986_5_4("g;x=1/../y", "http://a/b/c/y"); rfc3986_5_4("g;x=1/../y", "http://a/b/c/y");
rfc3986_5_4("g?y/./x", "http://a/b/c/g?y/./x"); rfc3986_5_4("g?y/./x", "http://a/b/c/g?y/./x");
rfc3986_5_4("g?y/../x", "http://a/b/c/g?y/../x"); rfc3986_5_4("g?y/../x", "http://a/b/c/g?y/../x");
rfc3986_5_4("g#s/./x", "http://a/b/c/g#s/./x"); rfc3986_5_4("g#s/./x", "http://a/b/c/g#s/./x");
rfc3986_5_4("g#s/../x", "http://a/b/c/g#s/../x"); rfc3986_5_4("g#s/../x", "http://a/b/c/g#s/../x");
TestRunner.addResult("Custom completeURL tests"); TestRunner.addResult("Custom completeURL tests");
testCompleteURL("http://a/b/c/d;p?q", "//secure.com/moo", "http://secure.com/moo"); testCompleteURL("http://a/b/c/d;p?q", "//secure.com/moo", "http://secure.com/moo");
testCompleteURL("http://a/b/c/d;p?q", "cat.jpeg", "http://a/b/c/cat.jpeg"); testCompleteURL("http://a/b/c/d;p?q", "cat.jpeg", "http://a/b/c/cat.jpeg");
testCompleteURL("http://example.com/path.css?query#fragment","", "http://example.com/path.css?query"); testCompleteURL("http://example.com/path.css?query#fragment","", "http://example.com/path.css?query");
TestRunner.completeTest(); TestRunner.completeTest();
})();
var menu = new UI.SoftContextMenu([{ (async function() {
type: 'item', var menu = new UI.SoftContextMenu([{
label: 'First', type: 'item',
enabled: true label: 'First',
}, enabled: true
{ },
type: 'subMenu', {
label: 'Second', type: 'subMenu',
enabled: true, label: 'Second',
subItems: [ enabled: true,
{type: 'subMenu', label: 'Child 1', enabled: true, subItems: [{type: 'item', label: 'Grandchild', id: 'Grandchild', enabled: true}]}, subItems: [
{type: 'item', label: 'Child 2', enabled: true}, {type: 'subMenu', label: 'Child 1', enabled: true, subItems: [{type: 'item', label: 'Grandchild', id: 'Grandchild', enabled: true}]},
{type: 'item', label: 'Child 3', enabled: true}, {type: 'item', label: 'Child 2', enabled: true},
{type: 'item', label: 'Child 4', enabled: true} {type: 'item', label: 'Child 3', enabled: true},
] {type: 'item', label: 'Child 4', enabled: true}
}, ]
{ },
type: 'separator', {
},{ type: 'separator',
type: 'item', },{
label: 'Third', type: 'item',
enabled: true label: 'Third',
}], item => TestRunner.addResult('Item Selected: ' + item)); enabled: true
}], item => TestRunner.addResult('Item Selected: ' + item));
var initialFocusedElement = UI.inspectorView.element.createChild('div'); var initialFocusedElement = UI.inspectorView.element.createChild('div');
initialFocusedElement.textContent = 'Initial Focused Element'; initialFocusedElement.textContent = 'Initial Focused Element';
initialFocusedElement.tabIndex = -1; initialFocusedElement.tabIndex = -1;
initialFocusedElement.focus(); initialFocusedElement.focus();
dumpContextMenu();
menu.show(document, new AnchorBox(50, 50, 0, 0));
dumpContextMenu();
pressKey('ArrowDown');
pressKey('ArrowDown');
pressKey('ArrowDown');
pressKey('ArrowUp');
pressKey('ArrowUp');
pressKey('ArrowUp');
pressKey('ArrowDown');
TestRunner.addResult('Enter Submenu');
pressKey('ArrowRight');
pressKey('ArrowDown');
pressKey('ArrowDown');
pressKey('ArrowDown');
TestRunner.addResult('Leave Submenu ArrowLeft');
pressKey('ArrowLeft');
pressKey('ArrowRight');
TestRunner.addResult('Leave Submenu Escape');
pressKey('Escape');
TestRunner.addResult('Enter Sub-Submenu');
pressKey(' ');
pressKey('Enter');
pressKey('Enter');
TestRunner.completeTest();
function pressKey(key) {
var element = document.deepActiveElement();
if (!element)
return;
element.dispatchEvent(TestRunner.createKeyEvent(key));
if (key === ' ')
key = 'Space';
TestRunner.addResult(key);
dumpContextMenu(); dumpContextMenu();
} menu.show(document, new AnchorBox(50, 50, 0, 0));
dumpContextMenu();
pressKey('ArrowDown');
pressKey('ArrowDown');
pressKey('ArrowDown');
pressKey('ArrowUp');
pressKey('ArrowUp');
pressKey('ArrowUp');
pressKey('ArrowDown');
TestRunner.addResult('Enter Submenu');
pressKey('ArrowRight');
pressKey('ArrowDown');
pressKey('ArrowDown');
pressKey('ArrowDown');
TestRunner.addResult('Leave Submenu ArrowLeft');
pressKey('ArrowLeft');
pressKey('ArrowRight');
TestRunner.addResult('Leave Submenu Escape');
pressKey('Escape');
TestRunner.addResult('Enter Sub-Submenu');
pressKey(' ');
pressKey('Enter');
pressKey('Enter');
TestRunner.completeTest();
function dumpContextMenu() { function pressKey(key) {
if (initialFocusedElement.hasFocus()) { var element = document.deepActiveElement();
TestRunner.addResult('Initial focused element has focus'); if (!element)
return; return;
element.dispatchEvent(TestRunner.createKeyEvent(key));
if (key === ' ')
key = 'Space';
TestRunner.addResult(key);
dumpContextMenu();
} }
var selection = '';
var subMenu = menu; function dumpContextMenu() {
var activeElement = document.deepActiveElement(); if (initialFocusedElement.hasFocus()) {
do { TestRunner.addResult('Initial focused element has focus');
if (selection) return;
selection += ' -> '; }
if (subMenu._contextMenuElement === activeElement) var selection = '';
selection += '['; var subMenu = menu;
if (subMenu._highlightedMenuItemElement) var activeElement = document.deepActiveElement();
selection += subMenu._highlightedMenuItemElement.textContent.replace(/[^A-z0-9 ]/g, ''); do {
else if (selection)
selection += 'null' selection += ' -> ';
if (subMenu._contextMenuElement === activeElement) if (subMenu._contextMenuElement === activeElement)
selection += ']'; selection += '[';
if (subMenu._highlightedMenuItemElement)
selection += subMenu._highlightedMenuItemElement.textContent.replace(/[^A-z0-9 ]/g, '');
else
selection += 'null'
if (subMenu._contextMenuElement === activeElement)
selection += ']';
}
while (subMenu = subMenu._subMenu)
TestRunner.addResult(selection);
} }
while (subMenu = subMenu._subMenu) })();
TestRunner.addResult(selection);
}
\ No newline at end of file
var items = [ (async function () {
{ var items = [
title: "first", {
index: 0 title: "first",
}, index: 0
{ },
title: "second", {
index: 1 title: "second",
}, index: 1
{ },
title: "third", {
index: 2 title: "third",
}, index: 2
{ },
title: "fourth", {
index: 3 title: "fourth",
}, index: 3
{ },
title: "disabled 4.5", {
disabled: true, title: "disabled 4.5",
index: 4 disabled: true,
}, index: 4
{ },
title: "fifth", {
index: 5 title: "fifth",
}, index: 5
{ },
title: "sixth", {
index: 6 title: "sixth",
}, index: 6
{ },
title: "seventh", {
index: 7 title: "seventh",
}, index: 7
{ },
title: "eighth", {
index: 8 title: "eighth",
} index: 8
]; }
];
class Delegate { class Delegate {
titleFor(item) { titleFor(item) {
return item.title; return item.title;
} }
createElementForItem(item) { createElementForItem(item) {
var element = createElement("div"); var element = createElement("div");
element.textContent = this.titleFor(item); element.textContent = this.titleFor(item);
return element; return element;
} }
isItemSelectable(item) { isItemSelectable(item) {
return !item.disabled; return !item.disabled;
} }
itemSelected(item) { itemSelected(item) {
if (item !== null) if (item !== null)
TestRunner.addResult("Item selected: " + this.titleFor(item)); TestRunner.addResult("Item selected: " + this.titleFor(item));
} }
highlightedItemChanged(from, to, fromElement, toElement) { highlightedItemChanged(from, to, fromElement, toElement) {
if (to !== null) if (to !== null)
TestRunner.addResult("Item highlighted: " + this.titleFor(to)); TestRunner.addResult("Item highlighted: " + this.titleFor(to));
} }
}; };
function pressKey(key) { function pressKey(key) {
var element = document.deepActiveElement(); var element = document.deepActiveElement();
if (!element) if (!element)
return; return;
TestRunner.addResult(key); TestRunner.addResult(key);
element.dispatchEvent(TestRunner.createKeyEvent(key)); element.dispatchEvent(TestRunner.createKeyEvent(key));
} }
var model = new UI.ListModel(); var model = new UI.ListModel();
var dropDown = new UI.SoftDropDown(model, new Delegate()); var dropDown = new UI.SoftDropDown(model, new Delegate());
for (var i = items.length - 1; i >= 0; i--) for (var i = items.length - 1; i >= 0; i--)
model.insertWithComparator(items[i], (a, b) => a.index - b.index); model.insertWithComparator(items[i], (a, b) => a.index - b.index);
UI.inspectorView.element.appendChild(dropDown.element); UI.inspectorView.element.appendChild(dropDown.element);
dropDown.selectItem(items[5]); dropDown.selectItem(items[5]);
TestRunner.addResult("Showing drop down"); TestRunner.addResult("Showing drop down");
dropDown.element.dispatchEvent(new Event("mousedown")); dropDown.element.dispatchEvent(new Event("mousedown"));
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('ArrowUp'); pressKey('ArrowUp');
pressKey('ArrowUp'); pressKey('ArrowUp');
pressKey('ArrowUp'); pressKey('ArrowUp');
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('f'); pressKey('f');
pressKey('f'); pressKey('f');
pressKey('t'); pressKey('t');
TestRunner.completeTest(); TestRunner.completeTest();
\ No newline at end of file })();
TestRunner.addResult("This tests if the SuggestBox works properly."); (async function() {
TestRunner.addResult("This tests if the SuggestBox works properly.");
var delegate = {
applySuggestion: function(suggestion, isIntermediateSuggestion) { var delegate = {
TestRunner.addResult((isIntermediateSuggestion ? "Intermediate " : "") + "Suggestion Applied: " + suggestion); applySuggestion: function(suggestion, isIntermediateSuggestion) {
}, TestRunner.addResult((isIntermediateSuggestion ? "Intermediate " : "") + "Suggestion Applied: " + suggestion);
acceptSuggestion: function() { },
TestRunner.addResult("Suggestion accepted"); acceptSuggestion: function() {
} TestRunner.addResult("Suggestion accepted");
}; }
var div = document.createElement("div"); };
UI.inspectorView.element.appendChild(div); var div = document.createElement("div");
var suggestBox = new UI.SuggestBox(delegate); UI.inspectorView.element.appendChild(div);
var suggestBox = new UI.SuggestBox(delegate);
TestRunner.addResult("");
TestRunner.addResult("Testing that the first item is selected."); TestRunner.addResult("");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ TestRunner.addResult("Testing that the first item is selected.");
{text: "First"}, suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "Hello"}, {text: "First"},
{text: "The best suggestion"}], true, true, "e"); {text: "Hello"},
{text: "The best suggestion"}], true, true, "e");
TestRunner.addResult("");
TestRunner.addResult("Testing that no item is selected."); TestRunner.addResult("");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ TestRunner.addResult("Testing that no item is selected.");
{text: "First"}, suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "Hello", priority: 2}, {text: "First"},
{text: "The best suggestion", priority: 5}], false, true, "e"); {text: "Hello", priority: 2},
{text: "The best suggestion", priority: 5}], false, true, "e");
TestRunner.addResult("");
TestRunner.addResult("Testing that highest priority item is selected."); TestRunner.addResult("");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ TestRunner.addResult("Testing that highest priority item is selected.");
{text: "First"}, suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "Hello", priority: 2}, {text: "First"},
{text: "The best suggestion", priority: 5}], true, true, "e"); {text: "Hello", priority: 2},
{text: "The best suggestion", priority: 5}], true, true, "e");
TestRunner.addResult("");
TestRunner.addResult("Testing that arrow keys can be used for selection."); TestRunner.addResult("");
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp")); TestRunner.addResult("Testing that arrow keys can be used for selection.");
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp"));
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp"));
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp"));
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown"));
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown"));
TestRunner.addResult("");
TestRunner.addResult("Testing that enter can be used to accept a suggestion."); TestRunner.addResult("");
suggestBox.keyPressed(TestRunner.createKeyEvent("Enter")); TestRunner.addResult("Testing that enter can be used to accept a suggestion.");
suggestBox.keyPressed(TestRunner.createKeyEvent("Enter"));
TestRunner.addResult("");
TestRunner.addResult("Testing that highest priority item is selected."); TestRunner.addResult("");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ TestRunner.addResult("Testing that highest priority item is selected.");
{text: "First"}, suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "Hello", priority: 2}, {text: "First"},
{text: "The best suggestion", priority: 5}], true, true, "e"); {text: "Hello", priority: 2},
{text: "The best suggestion", priority: 5}], true, true, "e");
TestRunner.completeTest();
\ No newline at end of file TestRunner.completeTest();
})();
TestRunner.addResult("This tests if the TabbedPane is keyboard navigable."); (async function() {
TestRunner.addResult("This tests if the TabbedPane is keyboard navigable.");
class FocusableWidget extends UI.Widget {
constructor(name) { class FocusableWidget extends UI.Widget {
super(); constructor(name) {
this.element.tabIndex = -1; super();
this.element.textContent = name; this.element.tabIndex = -1;
this.setDefaultFocusedElement(this.element); this.element.textContent = name;
this.setDefaultFocusedElement(this.element);
}
} }
}
var tabbedPane = new UI.TabbedPane();
var tabbedPane = new UI.TabbedPane(); tabbedPane.show(UI.inspectorView.element);
tabbedPane.show(UI.inspectorView.element); TestRunner.addSnifferPromise(tabbedPane, '_innerUpdateTabElements').then(tabsAdded);
TestRunner.addSnifferPromise(tabbedPane, '_innerUpdateTabElements').then(tabsAdded); for (var i = 0; i < 10; i++)
for (var i = 0; i < 10; i++) tabbedPane.appendTab(i.toString(), 'Tab ' + i, new FocusableWidget('Widget ' + i));
tabbedPane.appendTab(i.toString(), 'Tab ' + i, new FocusableWidget('Widget ' + i));
function tabsAdded() {
function tabsAdded() {
tabbedPane._currentTab.tabElement.focus();
dumpFocus();
TestRunner.addResult('Moving right and wrapping around');
for (var i = 0; i < 20; i++)
right();
TestRunner.addResult('Moving left and focusing widgets')
for (var i = 0; i < 10; i++) {
left();
enter();
tabbedPane._currentTab.tabElement.focus(); tabbedPane._currentTab.tabElement.focus();
dumpFocus();
TestRunner.addResult('Moving right and wrapping around');
for (var i = 0; i < 20; i++)
right();
TestRunner.addResult('Moving left and focusing widgets')
for (var i = 0; i < 10; i++) {
left();
enter();
tabbedPane._currentTab.tabElement.focus();
}
TestRunner.completeTest();
}
function right() {
var element = document.deepActiveElement();
if (element)
element.dispatchEvent(TestRunner.createKeyEvent('ArrowRight'));
dumpFocus();
}
function left() {
var element = document.deepActiveElement();
if (element)
element.dispatchEvent(TestRunner.createKeyEvent('ArrowLeft'));
dumpFocus();
}
function enter() {
var element = document.deepActiveElement();
if (element)
element.dispatchEvent(TestRunner.createKeyEvent('Enter'));
dumpFocus();
} }
TestRunner.completeTest();
}
function dumpFocus() {
function right() { var element = document.deepActiveElement();
var element = document.deepActiveElement(); if (!element) {
if (element) TestRunner.addResult("null");
element.dispatchEvent(TestRunner.createKeyEvent('ArrowRight')); return;
dumpFocus(); }
} TestRunner.addResult(element.textContent);
function left() {
var element = document.deepActiveElement();
if (element)
element.dispatchEvent(TestRunner.createKeyEvent('ArrowLeft'));
dumpFocus();
}
function enter() {
var element = document.deepActiveElement();
if (element)
element.dispatchEvent(TestRunner.createKeyEvent('Enter'));
dumpFocus();
}
function dumpFocus() {
var element = document.deepActiveElement();
if (!element) {
TestRunner.addResult("null");
return;
} }
TestRunner.addResult(element.textContent);
} })();
TestRunner.addResult("Tests that a test will properly exit if it has an asynchronous error."); (async function() {
setTimeout(_ => { throw {stack: "This error is expected"} }, 0); TestRunner.addResult("Tests that a test will properly exit if it has an asynchronous error.");
\ No newline at end of file setTimeout(_ => { throw {stack: "This error is expected"} }, 0);
})();
TestRunner.addResult("Tests that the hint displays properly on a UI.TextPrompt with autocomplete."); (async function() {
TestRunner.addResult("Tests that the hint displays properly on a UI.TextPrompt with autocomplete.");
var suggestions = [{text:"testTextPrompt"}]; var suggestions = [{text:"testTextPrompt"}];
var waitingForAutocomplete = null; var waitingForAutocomplete = null;
var completionsDone = function () { var completionsDone = function () {
console.error("completionsDone called too early!"); console.error("completionsDone called too early!");
TestRunner.completeTest(); TestRunner.completeTest();
} }
var prompt = new UI.TextPrompt(); var prompt = new UI.TextPrompt();
prompt.initialize(completions); prompt.initialize(completions);
var element = createElement("div"); var element = createElement("div");
UI.inspectorView.element.appendChild(element); UI.inspectorView.element.appendChild(element);
var proxy = prompt.attachAndStartEditing(element); var proxy = prompt.attachAndStartEditing(element);
prompt.setText("testT"); prompt.setText("testT");
waitForAutocomplete().then(step1); waitForAutocomplete().then(step1);
prompt.complete(); prompt.complete();
dumpTextPrompt(); dumpTextPrompt();
function step1() { function step1() {
dumpTextPrompt(); dumpTextPrompt();
typeCharacter("e"); typeCharacter("e");
dumpTextPrompt(); dumpTextPrompt();
waitForAutocomplete().then(step2); waitForAutocomplete().then(step2);
} }
function step2() function step2()
{ {
dumpTextPrompt(); dumpTextPrompt();
typeCharacter("z"); typeCharacter("z");
waitForAutocomplete().then(step3); waitForAutocomplete().then(step3);
} }
function step3() function step3()
{ {
dumpTextPrompt(); dumpTextPrompt();
typeCharacter(null); typeCharacter(null);
waitForAutocomplete().then(step4); waitForAutocomplete().then(step4);
} }
function step4() function step4()
{ {
dumpTextPrompt(); dumpTextPrompt();
typeCharacter(null); typeCharacter(null);
waitForAutocomplete().then(step5); waitForAutocomplete().then(step5);
} }
function step5() function step5()
{ {
dumpTextPrompt(); dumpTextPrompt();
prompt.setText("something_before test"); prompt.setText("something_before test");
prompt.complete(); prompt.complete();
completionsDone().then(()=>{ completionsDone().then(()=>{
dumpTextPrompt(); dumpTextPrompt();
typeCharacter("T"); typeCharacter("T");
dumpTextPrompt(); dumpTextPrompt();
TestRunner.completeTest(); TestRunner.completeTest();
}); });
} }
function completions(expression, query) function completions(expression, query)
{ {
var callback; var callback;
var promise = new Promise(x => callback = x); var promise = new Promise(x => callback = x);
TestRunner.addResult("Requesting completions"); TestRunner.addResult("Requesting completions");
completionsDone = () => { completionsDone = () => {
callback(suggestions.filter(s => s.text.startsWith(query.toString()))) callback(suggestions.filter(s => s.text.startsWith(query.toString())))
return Promise.resolve(); return Promise.resolve();
}; };
var temp = waitingForAutocomplete; var temp = waitingForAutocomplete;
waitingForAutocomplete = null; waitingForAutocomplete = null;
if (temp) if (temp)
temp(); temp();
return promise; return promise;
} }
function waitForAutocomplete() function waitForAutocomplete()
{ {
return new Promise(x => waitingForAutocomplete = x).then(() => completionsDone()); return new Promise(x => waitingForAutocomplete = x).then(() => completionsDone());
} }
function dumpTextPrompt() function dumpTextPrompt()
{ {
TestRunner.addResult("Text:" + prompt.text()); TestRunner.addResult("Text:" + prompt.text());
TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion()); TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion());
TestRunner.addResult(""); TestRunner.addResult("");
} }
function typeCharacter(character) function typeCharacter(character)
{ {
var keyboardEvent = new KeyboardEvent("keydown", { var keyboardEvent = new KeyboardEvent("keydown", {
key: character || "Backspace", key: character || "Backspace",
charCode: character ? character.charCodeAt(0) : "" charCode: character ? character.charCodeAt(0) : ""
}); });
element.dispatchEvent(keyboardEvent); element.dispatchEvent(keyboardEvent);
var selection = element.getComponentSelection(); var selection = element.getComponentSelection();
var range = selection.getRangeAt(0); var range = selection.getRangeAt(0);
var textNode = prompt._ghostTextElement.parentNode ? prompt._ghostTextElement.previousSibling : element.childTextNodes()[element.childTextNodes().length - 1]; var textNode = prompt._ghostTextElement.parentNode ? prompt._ghostTextElement.previousSibling : element.childTextNodes()[element.childTextNodes().length - 1];
if (!character) if (!character)
textNode.textContent = textNode.textContent.substring(0,textNode.textContent.length-1); textNode.textContent = textNode.textContent.substring(0,textNode.textContent.length-1);
else else
textNode.textContent += character; textNode.textContent += character;
range.setStart(range.startContainer, range.startContainer.textContent.length); range.setStart(range.startContainer, range.startContainer.textContent.length);
selection.removeAllRanges(); selection.removeAllRanges();
selection.addRange(range); selection.addRange(range);
element.dispatchEvent(new Event("input", {bubbles: true, cancelable: false})); element.dispatchEvent(new Event("input", {bubbles: true, cancelable: false}));
} }
\ No newline at end of file })();
TestRunner.addResult("This tests if the TextPrompt autocomplete works properly."); (async function() {
TestRunner.addResult("This tests if the TextPrompt autocomplete works properly.");
var suggestions = ["heyoo", "hey it's a suggestion", "hey another suggestion"].map(s => ({text: s})); var suggestions = ["heyoo", "hey it's a suggestion", "hey another suggestion"].map(s => ({text: s}));
var prompt = new UI.TextPrompt(); var prompt = new UI.TextPrompt();
prompt.initialize(() => Promise.resolve(suggestions)); prompt.initialize(() => Promise.resolve(suggestions));
var div = document.createElement("div"); var div = document.createElement("div");
UI.inspectorView.element.appendChild(div); UI.inspectorView.element.appendChild(div);
prompt.attachAndStartEditing(div); prompt.attachAndStartEditing(div);
prompt.setText("hey"); prompt.setText("hey");
TestRunner.addSnifferPromise(prompt, "_completionsReady").then(step2); TestRunner.addSnifferPromise(prompt, "_completionsReady").then(step2);
prompt.complete(); prompt.complete();
function step2() { function step2() {
TestRunner.addResult("Text:" + prompt.text()); TestRunner.addResult("Text:" + prompt.text());
TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion()); TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion());
TestRunner.addResult("Test with inexact match:"); TestRunner.addResult("Test with inexact match:");
prompt.clearAutocomplete(); prompt.clearAutocomplete();
prompt.setText("inexactmatch"); prompt.setText("inexactmatch");
TestRunner.addSnifferPromise(prompt, "_completionsReady").then(step3); TestRunner.addSnifferPromise(prompt, "_completionsReady").then(step3);
prompt.complete(); prompt.complete();
} }
function step3() { function step3() {
TestRunner.addResult("Text:" + prompt.text()); TestRunner.addResult("Text:" + prompt.text());
TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion()); TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion());
TestRunner.completeTest(); TestRunner.completeTest();
} }
\ No newline at end of file })();
var trie; (async function() {
TestRunner.addResult(`Verify "trie" functionality.`); var trie;
TestRunner.addResult(`Verify "trie" functionality.`);
TestRunner.runTests([
function testAddWord() TestRunner.runTests([
{ function testAddWord()
var trie = new Common.Trie(); {
addWord(trie, "hello"); var trie = new Common.Trie();
hasWord(trie, "he"); addWord(trie, "hello");
hasWord(trie, "hello"); hasWord(trie, "he");
hasWord(trie, "helloo"); hasWord(trie, "hello");
}, hasWord(trie, "helloo");
},
function testAddWords()
{ function testAddWords()
var trie = new Common.Trie(); {
addWord(trie, "foo"); var trie = new Common.Trie();
addWord(trie, "bar"); addWord(trie, "foo");
addWord(trie, "bazz"); addWord(trie, "bar");
hasWord(trie, "f"); addWord(trie, "bazz");
hasWord(trie, "ba"); hasWord(trie, "f");
hasWord(trie, "baz"); hasWord(trie, "ba");
hasWord(trie, "bar"); hasWord(trie, "baz");
hasWord(trie, "bazz"); hasWord(trie, "bar");
}, hasWord(trie, "bazz");
},
function testRemoveWord()
{ function testRemoveWord()
var trie = new Common.Trie(); {
addWord(trie, "foo"); var trie = new Common.Trie();
removeWord(trie, "f"); addWord(trie, "foo");
removeWord(trie, "fo"); removeWord(trie, "f");
removeWord(trie, "fooo"); removeWord(trie, "fo");
hasWord(trie, "foo"); removeWord(trie, "fooo");
removeWord(trie, "foo"); hasWord(trie, "foo");
hasWord(trie, "foo"); removeWord(trie, "foo");
}, hasWord(trie, "foo");
},
function testAddAfterRemove()
{ function testAddAfterRemove()
var trie = new Common.Trie(); {
addWord(trie, "foo"); var trie = new Common.Trie();
removeWord(trie, "foo"); addWord(trie, "foo");
addWord(trie, "bar"); removeWord(trie, "foo");
hasWord(trie, "foo"); addWord(trie, "bar");
hasWord(trie, "bar"); hasWord(trie, "foo");
}, hasWord(trie, "bar");
},
function testWordOverwrite()
{ function testWordOverwrite()
var trie = new Common.Trie(); {
addWord(trie, "foo"); var trie = new Common.Trie();
addWord(trie, "foo"); addWord(trie, "foo");
removeWord(trie, "foo"); addWord(trie, "foo");
hasWord(trie, "foo"); removeWord(trie, "foo");
}, hasWord(trie, "foo");
},
function testRemoveNonExisting()
function testRemoveNonExisting()
{
var trie = new Common.Trie();
addWord(trie, "foo");
removeWord(trie, "bar");
removeWord(trie, "baz");
hasWord(trie, "foo");
},
function testEmptyWord()
{
var trie = new Common.Trie();
addWord(trie, "");
hasWord(trie, "");
removeWord(trie, "");
hasWord(trie, "");
},
function testAllWords()
{
var trie = new Common.Trie();
addWord(trie, "foo");
addWord(trie, "bar");
addWord(trie, "bazzz");
words(trie);
words(trie, "f");
words(trie, "g");
words(trie, "b");
words(trie, "ba");
words(trie, "bar");
words(trie, "barz");
words(trie, "baz");
},
function testOneCharWords()
{
var trie = new Common.Trie();
addWord(trie, "a");
addWord(trie, "b");
addWord(trie, "c");
words(trie);
},
function testChainWords()
{
var trie = new Common.Trie();
addWord(trie, "f");
addWord(trie, "fo");
addWord(trie, "foo");
addWord(trie, "foo");
words(trie);
},
function testClearTrie()
{
var trie = new Common.Trie();
addWord(trie, "foo");
addWord(trie, "bar");
words(trie);
clear(trie);
words(trie);
},
function testLongestPrefix()
{
var trie = new Common.Trie();
addWord(trie, "fo");
addWord(trie, "food");
longestPrefix(trie, "fear", false);
longestPrefix(trie, "fear", true);
longestPrefix(trie, "football", false);
longestPrefix(trie, "football", true);
longestPrefix(trie, "bar", false);
longestPrefix(trie, "bar", true);
longestPrefix(trie, "foo", false);
longestPrefix(trie, "foo", true);
},
]);
function hasWord(trie, word)
{ {
var trie = new Common.Trie(); TestRunner.addResult(`trie.has("${word}") = ${trie.has(word)}`);
addWord(trie, "foo"); }
removeWord(trie, "bar");
removeWord(trie, "baz"); function addWord(trie, word)
hasWord(trie, "foo");
},
function testEmptyWord()
{
var trie = new Common.Trie();
addWord(trie, "");
hasWord(trie, "");
removeWord(trie, "");
hasWord(trie, "");
},
function testAllWords()
{ {
var trie = new Common.Trie(); TestRunner.addResult(`trie.add("${word}")`);
addWord(trie, "foo"); trie.add(word);
addWord(trie, "bar"); }
addWord(trie, "bazzz");
words(trie); function removeWord(trie, word)
words(trie, "f");
words(trie, "g");
words(trie, "b");
words(trie, "ba");
words(trie, "bar");
words(trie, "barz");
words(trie, "baz");
},
function testOneCharWords()
{ {
var trie = new Common.Trie(); TestRunner.addResult(`trie.remove("${word}") = ${trie.remove(word)}`);
addWord(trie, "a"); }
addWord(trie, "b");
addWord(trie, "c"); function words(trie, prefix)
words(trie);
},
function testChainWords()
{ {
var trie = new Common.Trie(); var title = prefix ? `trie.words("${prefix}")` : `trie.words()`;
addWord(trie, "f"); var words = trie.words(prefix);
addWord(trie, "fo"); var text = words.length ? `[\n ${words.join(",\n ")}\n]` : "[]";
addWord(trie, "foo"); TestRunner.addResult(title + " = " + text);
addWord(trie, "foo"); }
words(trie);
}, function clear(trie)
function testClearTrie()
{ {
var trie = new Common.Trie(); trie.clear();
addWord(trie, "foo"); TestRunner.addResult("trie.clear()");
addWord(trie, "bar"); }
words(trie);
clear(trie); function longestPrefix(trie, word, fullWordOnly)
words(trie);
},
function testLongestPrefix()
{ {
var trie = new Common.Trie(); TestRunner.addResult(`trie.longestPrefix("${word}", ${fullWordOnly}) = "${trie.longestPrefix(word, fullWordOnly)}"`);
addWord(trie, "fo"); }
addWord(trie, "food"); })();
longestPrefix(trie, "fear", false); \ No newline at end of file
longestPrefix(trie, "fear", true);
longestPrefix(trie, "football", false);
longestPrefix(trie, "football", true);
longestPrefix(trie, "bar", false);
longestPrefix(trie, "bar", true);
longestPrefix(trie, "foo", false);
longestPrefix(trie, "foo", true);
},
]);
function hasWord(trie, word)
{
TestRunner.addResult(`trie.has("${word}") = ${trie.has(word)}`);
}
function addWord(trie, word)
{
TestRunner.addResult(`trie.add("${word}")`);
trie.add(word);
}
function removeWord(trie, word)
{
TestRunner.addResult(`trie.remove("${word}") = ${trie.remove(word)}`);
}
function words(trie, prefix)
{
var title = prefix ? `trie.words("${prefix}")` : `trie.words()`;
var words = trie.words(prefix);
var text = words.length ? `[\n ${words.join(",\n ")}\n]` : "[]";
TestRunner.addResult(title + " = " + text);
}
function clear(trie)
{
trie.clear();
TestRunner.addResult("trie.clear()");
}
function longestPrefix(trie, word, fullWordOnly)
{
TestRunner.addResult(`trie.longestPrefix("${word}", ${fullWordOnly}) = "${trie.longestPrefix(word, fullWordOnly)}"`);
}
\ No newline at end of file
runtime._registerModule({ (async function() {
name: "mock-module", runtime._registerModule({
extensions: ['first', 'second', 'third', 'fourth'].map(title => { name: "mock-module",
return { extensions: ['first', 'second', 'third', 'fourth'].map(title => {
"type": "view", return {
"location": "mock-location", "type": "view",
"id": title, "location": "mock-location",
"title": title, "id": title,
"persistence": "closeable", "title": title,
"factoryName": "UI.Widget" "persistence": "closeable",
} "factoryName": "UI.Widget"
}), }
scripts: [] }),
}); scripts: []
});
var tabbedLocation; var tabbedLocation;
var viewManager; var viewManager;
createTabbedLocation(); createTabbedLocation();
dumpTabs(); dumpTabs();
TestRunner.addResult('Appending three views') TestRunner.addResult('Appending three views')
viewManager.showView('first'); viewManager.showView('first');
viewManager.showView('second'); viewManager.showView('second');
viewManager.showView('third'); viewManager.showView('third');
dumpTabs(); dumpTabs();
createTabbedLocation(); createTabbedLocation();
dumpTabs(); dumpTabs();
TestRunner.addResult('Re-order tabs'); TestRunner.addResult('Re-order tabs');
tabbedLocation.tabbedPane()._insertBefore(tabbedLocation.tabbedPane()._tabsById.get("third"), 0); tabbedLocation.tabbedPane()._insertBefore(tabbedLocation.tabbedPane()._tabsById.get("third"), 0);
dumpTabs(); dumpTabs();
createTabbedLocation(); createTabbedLocation();
dumpTabs(); dumpTabs();
viewManager.showView('fourth'); viewManager.showView('fourth');
dumpTabs(); dumpTabs();
createTabbedLocation(); createTabbedLocation();
dumpTabs(); dumpTabs();
TestRunner.addResult('Closing second tab'); TestRunner.addResult('Closing second tab');
tabbedLocation.tabbedPane().closeTab('second'); tabbedLocation.tabbedPane().closeTab('second');
dumpTabs(); dumpTabs();
createTabbedLocation(); createTabbedLocation();
dumpTabs(); dumpTabs();
TestRunner.completeTest(); TestRunner.completeTest();
function createTabbedLocation() { function createTabbedLocation() {
TestRunner.addResult('Creating new TabbedLocation'); TestRunner.addResult('Creating new TabbedLocation');
if (tabbedLocation) if (tabbedLocation)
tabbedLocation.tabbedPane().detach(true); tabbedLocation.tabbedPane().detach(true);
viewManager = new UI.ViewManager(); viewManager = new UI.ViewManager();
tabbedLocation = viewManager.createTabbedLocation(undefined, 'mock-location', true, true); tabbedLocation = viewManager.createTabbedLocation(undefined, 'mock-location', true, true);
tabbedLocation.widget().show(UI.inspectorView.element); tabbedLocation.widget().show(UI.inspectorView.element);
} }
function dumpTabs() { function dumpTabs() {
TestRunner.addResult(JSON.stringify(tabbedLocation.tabbedPane().tabIds())); TestRunner.addResult(JSON.stringify(tabbedLocation.tabbedPane().tabIds()));
} }
\ No newline at end of file })();
TestRunner.loadModule('data_grid').then(test); (async function() {
function test() { await TestRunner.loadModule('data_grid');
TestRunner.addResult("This tests viewport datagrid."); TestRunner.addResult("This tests viewport datagrid.");
var div = document.createElement("div"); var div = document.createElement("div");
...@@ -89,4 +90,4 @@ function test() { ...@@ -89,4 +90,4 @@ function test() {
} }
TestRunner.addResult(""); TestRunner.addResult("");
} }
} })();
TestRunner.loadModule('data_grid').then(test); (async function() {
function test() { await TestRunner.loadModule('data_grid');
TestRunner.addResult("This tests viewport datagrid."); TestRunner.addResult("This tests viewport datagrid.");
var div = document.createElement("div"); var div = document.createElement("div");
...@@ -104,4 +105,4 @@ function test() { ...@@ -104,4 +105,4 @@ function test() {
} }
TestRunner.addResult(""); TestRunner.addResult("");
} }
} })();
\ No newline at end of file
...@@ -28,7 +28,22 @@ TestRunner.executeTestScript = function() { ...@@ -28,7 +28,22 @@ TestRunner.executeTestScript = function() {
self.eval(`function test(){${testScript}}\n//# sourceURL=${testScriptURL}`); self.eval(`function test(){${testScript}}\n//# sourceURL=${testScriptURL}`);
return; return;
} }
eval(`(function test(){${testScript}})()\n//# sourceURL=${testScriptURL}`);
// Convert the test script into an expression (if needed)
testScript = testScript.trimRight();
if (testScript.endsWith(';'))
testScript = testScript.slice(0, testScript.length - 1);
(async function() {
try {
await eval(testScript + `\n//# sourceURL=${testScriptURL}`);
} catch (err) {
TestRunner.addResult('TEST ENDED EARLY DUE TO UNCAUGHT ERROR:');
TestRunner.addResult(err && err.stack || err);
TestRunner.addResult('=== DO NOT COMMIT THIS INTO -expected.txt ===');
TestRunner.completeTest();
}
})();
}) })
.catch(error => { .catch(error => {
TestRunner.addResult(`Unable to execute test script because of error: ${error}`); TestRunner.addResult(`Unable to execute test script because of 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