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 equal height items case.'); (async function() {
TestRunner.addResult('Test ListControl rendering and selection for equal height items case.');
class Delegate { class Delegate {
constructor() { constructor() {
this.height = 10; this.height = 10;
} }
...@@ -28,16 +29,16 @@ class Delegate { ...@@ -28,16 +29,16 @@ class Delegate {
if (toElement) if (toElement)
toElement.classList.add('selected'); toElement.classList.add('selected');
} }
} }
var delegate = new Delegate(); var delegate = new Delegate();
var model = new UI.ListModel(); var model = new UI.ListModel();
var list = new UI.ListControl(model, delegate, UI.ListMode.EqualHeightItems); var list = new UI.ListControl(model, delegate, UI.ListMode.EqualHeightItems);
list.element.style.height = '73px'; list.element.style.height = '73px';
UI.inspectorView.element.appendChild(list.element); UI.inspectorView.element.appendChild(list.element);
function dumpList() function dumpList()
{ {
var height = list.element.offsetHeight; var height = list.element.offsetHeight;
TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`); TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`);
for (var child of list.element.children) { for (var child of list.element.children) {
...@@ -50,169 +51,170 @@ function dumpList() ...@@ -50,169 +51,170 @@ function dumpList()
TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`); TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
} }
TestRunner.addResult(''); TestRunner.addResult('');
} }
TestRunner.addResult('Adding 0, 1, 2');
model.replaceAll([0, 1, 2]);
dumpList();
TestRunner.addResult('Scrolling to 0');
list.scrollItemIntoView(0);
dumpList();
TestRunner.addResult('Scrolling to 2');
list.scrollItemIntoView(2);
dumpList();
TestRunner.addResult('ArrowDown');
list._onKeyDown(TestRunner.createKeyEvent('ArrowDown'));
dumpList();
TestRunner.addResult('Selecting 2');
list.selectItem(2);
dumpList();
TestRunner.addResult('PageUp');
list._onKeyDown(TestRunner.createKeyEvent('PageUp'));
dumpList();
TestRunner.addResult('PageDown');
list._onKeyDown(TestRunner.createKeyEvent('PageDown'));
dumpList();
TestRunner.addResult('ArrowDown');
list._onKeyDown(TestRunner.createKeyEvent('ArrowDown'));
dumpList();
TestRunner.addResult('Replacing 0 with 5, 6, 7');
model.replaceRange(0, 1, [5, 6, 7]);
dumpList();
TestRunner.addResult('ArrowUp');
list._onKeyDown(TestRunner.createKeyEvent('ArrowUp'));
dumpList();
TestRunner.addResult('Pushing 10');
model.insert(model.length, 10);
dumpList();
TestRunner.addResult('Selecting 10');
list.selectItem(10);
dumpList();
TestRunner.addResult('Popping 10');
model.remove(model.length - 1);
dumpList();
TestRunner.addResult('Removing 2'); TestRunner.addResult('Adding 0, 1, 2');
model.remove(4); model.replaceAll([0, 1, 2]);
dumpList(); dumpList();
TestRunner.addResult('Inserting 8'); TestRunner.addResult('Scrolling to 0');
model.insert(1, 8); list.scrollItemIntoView(0);
dumpList(); dumpList();
TestRunner.addResult('Replacing with 0...20'); TestRunner.addResult('Scrolling to 2');
model.replaceAll([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); list.scrollItemIntoView(2);
dumpList(); dumpList();
TestRunner.addResult('Resizing'); TestRunner.addResult('ArrowDown');
list.element.style.height = '84px'; list._onKeyDown(TestRunner.createKeyEvent('ArrowDown'));
list.viewportResized(); dumpList();
dumpList();
TestRunner.addResult('Scrolling to 19'); TestRunner.addResult('Selecting 2');
list.scrollItemIntoView(19); list.selectItem(2);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 5'); TestRunner.addResult('PageUp');
list.scrollItemIntoView(5); list._onKeyDown(TestRunner.createKeyEvent('PageUp'));
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 12'); TestRunner.addResult('PageDown');
list.scrollItemIntoView(12); list._onKeyDown(TestRunner.createKeyEvent('PageDown'));
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 13'); TestRunner.addResult('ArrowDown');
list.scrollItemIntoView(13); list._onKeyDown(TestRunner.createKeyEvent('ArrowDown'));
dumpList(); dumpList();
TestRunner.addResult('Changing the item height'); TestRunner.addResult('Replacing 0 with 5, 6, 7');
delegate.height = 15; model.replaceRange(0, 1, [5, 6, 7]);
list.invalidateItemHeight(); dumpList();
dumpList();
TestRunner.addResult('Selecting 7'); TestRunner.addResult('ArrowUp');
list.selectItem(7); list._onKeyDown(TestRunner.createKeyEvent('ArrowUp'));
dumpList(); dumpList();
TestRunner.addResult('Replacing 7 with 27'); TestRunner.addResult('Pushing 10');
model.replaceRange(7, 8, [27]); model.insert(model.length, 10);
dumpList(); dumpList();
TestRunner.addResult('Replacing 18, 19 with 28, 29'); TestRunner.addResult('Selecting 10');
model.replaceRange(18, 20, [28, 29]); list.selectItem(10);
dumpList(); dumpList();
TestRunner.addResult('PageDown'); TestRunner.addResult('Popping 10');
list._onKeyDown(TestRunner.createKeyEvent('PageDown')); model.remove(model.length - 1);
dumpList(); dumpList();
TestRunner.addResult('Replacing 1, 2, 3 with [31-43]'); TestRunner.addResult('Removing 2');
model.replaceRange(1, 4, [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43]); model.remove(4);
dumpList(); dumpList();
TestRunner.addResult('Scrolling to 13 (center)'); TestRunner.addResult('Inserting 8');
list.scrollItemIntoView(13, true); model.insert(1, 8);
dumpList(); dumpList();
TestRunner.addResult('ArrowUp'); TestRunner.addResult('Replacing with 0...20');
list._onKeyDown(TestRunner.createKeyEvent('ArrowUp')); model.replaceAll([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
dumpList(); dumpList();
TestRunner.addResult('Selecting -1'); TestRunner.addResult('Resizing');
list.selectItem(null); list.element.style.height = '84px';
dumpList(); list.viewportResized();
dumpList();
TestRunner.addResult('ArrowUp'); TestRunner.addResult('Scrolling to 19');
list._onKeyDown(TestRunner.createKeyEvent('ArrowUp')); list.scrollItemIntoView(19);
dumpList(); dumpList();
TestRunner.addResult('Selecting -1'); TestRunner.addResult('Scrolling to 5');
list.selectItem(null); list.scrollItemIntoView(5);
dumpList(); dumpList();
TestRunner.addResult('ArrowDown'); TestRunner.addResult('Scrolling to 12');
list._onKeyDown(TestRunner.createKeyEvent('ArrowDown')); list.scrollItemIntoView(12);
dumpList(); dumpList();
TestRunner.addResult('Selecting -1'); TestRunner.addResult('Scrolling to 13');
list.selectItem(null); list.scrollItemIntoView(13);
dumpList(); dumpList();
TestRunner.addResult('PageUp'); TestRunner.addResult('Changing the item height');
list._onKeyDown(TestRunner.createKeyEvent('PageUp')); delegate.height = 15;
dumpList(); list.invalidateItemHeight();
dumpList();
TestRunner.addResult('Replacing all but 29 with []'); TestRunner.addResult('Selecting 7');
model.replaceRange(0, 29, []); list.selectItem(7);
dumpList(); dumpList();
TestRunner.addResult('ArrowDown'); TestRunner.addResult('Replacing 7 with 27');
list._onKeyDown(TestRunner.createKeyEvent('ArrowDown')); model.replaceRange(7, 8, [27]);
dumpList(); dumpList();
var newModel = new UI.ListModel([5, 6, 7]); TestRunner.addResult('Replacing 18, 19 with 28, 29');
TestRunner.addResult('Replacing model with [5-7]'); model.replaceRange(18, 20, [28, 29]);
list.setModel(newModel); dumpList();
dumpList();
TestRunner.addResult('PageDown');
list._onKeyDown(TestRunner.createKeyEvent('PageDown'));
dumpList();
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]);
dumpList();
TestRunner.addResult('Scrolling to 13 (center)');
list.scrollItemIntoView(13, true);
dumpList();
TestRunner.addResult('ArrowUp');
list._onKeyDown(TestRunner.createKeyEvent('ArrowUp'));
dumpList();
TestRunner.addResult('Selecting -1');
list.selectItem(null);
dumpList();
TestRunner.addResult('ArrowUp');
list._onKeyDown(TestRunner.createKeyEvent('ArrowUp'));
dumpList();
TestRunner.addResult('Selecting -1');
list.selectItem(null);
dumpList();
TestRunner.addResult('ArrowDown');
list._onKeyDown(TestRunner.createKeyEvent('ArrowDown'));
dumpList();
TestRunner.addResult('Selecting -1');
list.selectItem(null);
dumpList();
TestRunner.addResult('PageUp');
list._onKeyDown(TestRunner.createKeyEvent('PageUp'));
dumpList();
TestRunner.addResult('Replacing all but 29 with []');
model.replaceRange(0, 29, []);
dumpList();
TestRunner.addResult('ArrowDown');
list._onKeyDown(TestRunner.createKeyEvent('ArrowDown'));
dumpList();
var newModel = new UI.ListModel([5, 6, 7]);
TestRunner.addResult('Replacing model with [5-7]');
list.setModel(newModel);
dumpList();
TestRunner.addResult('Pushing 8'); TestRunner.addResult('Pushing 8');
newModel.insert(newModel.length, 8); newModel.insert(newModel.length, 8);
dumpList(); dumpList();
TestRunner.addResult('Pushing 9 to old model'); TestRunner.addResult('Pushing 9 to old model');
model.insert(model.length, 9); model.insert(model.length, 9);
dumpList(); dumpList();
TestRunner.completeTest(); TestRunner.completeTest();
})();
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 { class Delegate {
constructor() { constructor() {
} }
...@@ -28,15 +29,15 @@ class Delegate { ...@@ -28,15 +29,15 @@ class Delegate {
if (toElement) if (toElement)
toElement.classList.add('selected'); toElement.classList.add('selected');
} }
} }
var delegate = new Delegate(); var delegate = new Delegate();
var model = new UI.ListModel(); var model = new UI.ListModel();
var list = new UI.ListControl(model, delegate, UI.ListMode.NonViewport); var list = new UI.ListControl(model, delegate, UI.ListMode.NonViewport);
UI.inspectorView.element.appendChild(list.element); UI.inspectorView.element.appendChild(list.element);
function dumpList() function dumpList()
{ {
var height = list.element.offsetHeight; var height = list.element.offsetHeight;
TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`); TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`);
for (var child of list.element.children) { for (var child of list.element.children) {
...@@ -49,54 +50,55 @@ function dumpList() ...@@ -49,54 +50,55 @@ function dumpList()
TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`); TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
} }
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]);
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 { class Delegate {
constructor() { constructor() {
} }
...@@ -27,16 +28,16 @@ class Delegate { ...@@ -27,16 +28,16 @@ class Delegate {
if (toElement) if (toElement)
toElement.classList.add('selected'); toElement.classList.add('selected');
} }
} }
var delegate = new Delegate(); var delegate = new Delegate();
var model = new UI.ListModel(); var model = new UI.ListModel();
var list = new UI.ListControl(model, delegate, UI.ListMode.VariousHeightItems); var list = new UI.ListControl(model, delegate, UI.ListMode.VariousHeightItems);
list.element.style.height = '73px'; list.element.style.height = '73px';
UI.inspectorView.element.appendChild(list.element); UI.inspectorView.element.appendChild(list.element);
function dumpList() function dumpList()
{ {
var height = list.element.offsetHeight; var height = list.element.offsetHeight;
TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`); TestRunner.addResult(`----list[length=${model.length}][height=${height}]----`);
for (var child of list.element.children) { for (var child of list.element.children) {
...@@ -50,67 +51,68 @@ function dumpList() ...@@ -50,67 +51,68 @@ function dumpList()
} }
TestRunner.addResult('offsets: ' + list._variableOffsets.join(' ')); TestRunner.addResult('offsets: ' + list._variableOffsets.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]);
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",
"-", "-",
...@@ -29,10 +30,10 @@ var queries = [ ...@@ -29,10 +30,10 @@ var queries = [
"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) {
...@@ -40,5 +41,6 @@ for (var query of queries) { ...@@ -40,5 +41,6 @@ for (var query of queries) {
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() {
var commands = [
'0', '0',
'await 0', 'await 0',
'async function foo() { await 0; }', 'async function foo() { await 0; }',
...@@ -20,9 +21,8 @@ var commands = [ ...@@ -20,9 +21,8 @@ var commands = [
'if (await true) { let a = 1; }', 'if (await true) { let a = 1; }',
'var a = await 1; let b = 2; const c = 3;', 'var a = await 1; let b = 2; const c = 3;',
'let o = await 1, p' '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() {
var menu = new UI.SoftContextMenu([{
type: 'item', type: 'item',
label: 'First', label: 'First',
enabled: true enabled: true
}, },
{ {
type: 'subMenu', type: 'subMenu',
label: 'Second', label: 'Second',
enabled: true, enabled: true,
...@@ -13,47 +14,47 @@ var menu = new UI.SoftContextMenu([{ ...@@ -13,47 +14,47 @@ var menu = new UI.SoftContextMenu([{
{type: 'item', label: 'Child 3', enabled: true}, {type: 'item', label: 'Child 3', enabled: true},
{type: 'item', label: 'Child 4', enabled: true} {type: 'item', label: 'Child 4', enabled: true}
] ]
}, },
{ {
type: 'separator', type: 'separator',
},{ },{
type: 'item', type: 'item',
label: 'Third', label: 'Third',
enabled: true enabled: true
}], item => TestRunner.addResult('Item Selected: ' + item)); }], 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(); dumpContextMenu();
menu.show(document, new AnchorBox(50, 50, 0, 0)); menu.show(document, new AnchorBox(50, 50, 0, 0));
dumpContextMenu(); dumpContextMenu();
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');
TestRunner.addResult('Enter Submenu'); TestRunner.addResult('Enter Submenu');
pressKey('ArrowRight'); pressKey('ArrowRight');
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('ArrowDown'); pressKey('ArrowDown');
pressKey('ArrowDown'); pressKey('ArrowDown');
TestRunner.addResult('Leave Submenu ArrowLeft'); TestRunner.addResult('Leave Submenu ArrowLeft');
pressKey('ArrowLeft'); pressKey('ArrowLeft');
pressKey('ArrowRight'); pressKey('ArrowRight');
TestRunner.addResult('Leave Submenu Escape'); TestRunner.addResult('Leave Submenu Escape');
pressKey('Escape'); pressKey('Escape');
TestRunner.addResult('Enter Sub-Submenu'); TestRunner.addResult('Enter Sub-Submenu');
pressKey(' '); pressKey(' ');
pressKey('Enter'); pressKey('Enter');
pressKey('Enter'); pressKey('Enter');
TestRunner.completeTest(); TestRunner.completeTest();
function pressKey(key) { function pressKey(key) {
var element = document.deepActiveElement(); var element = document.deepActiveElement();
if (!element) if (!element)
return; return;
...@@ -62,9 +63,9 @@ function pressKey(key) { ...@@ -62,9 +63,9 @@ function pressKey(key) {
key = 'Space'; key = 'Space';
TestRunner.addResult(key); TestRunner.addResult(key);
dumpContextMenu(); dumpContextMenu();
} }
function dumpContextMenu() { function dumpContextMenu() {
if (initialFocusedElement.hasFocus()) { if (initialFocusedElement.hasFocus()) {
TestRunner.addResult('Initial focused element has focus'); TestRunner.addResult('Initial focused element has focus');
return; return;
...@@ -86,4 +87,5 @@ function dumpContextMenu() { ...@@ -86,4 +87,5 @@ function dumpContextMenu() {
} }
while (subMenu = subMenu._subMenu) while (subMenu = subMenu._subMenu)
TestRunner.addResult(selection); TestRunner.addResult(selection);
} }
\ No newline at end of file })();
var items = [ (async function () {
var items = [
{ {
title: "first", title: "first",
index: 0 index: 0
...@@ -36,9 +37,9 @@ var items = [ ...@@ -36,9 +37,9 @@ var items = [
title: "eighth", title: "eighth",
index: 8 index: 8
} }
]; ];
class Delegate { class Delegate {
titleFor(item) { titleFor(item) {
return item.title; return item.title;
} }
...@@ -62,33 +63,34 @@ class Delegate { ...@@ -62,33 +63,34 @@ class Delegate {
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 = { var delegate = {
applySuggestion: function(suggestion, isIntermediateSuggestion) { applySuggestion: function(suggestion, isIntermediateSuggestion) {
TestRunner.addResult((isIntermediateSuggestion ? "Intermediate " : "") + "Suggestion Applied: " + suggestion); TestRunner.addResult((isIntermediateSuggestion ? "Intermediate " : "") + "Suggestion Applied: " + suggestion);
}, },
acceptSuggestion: function() { acceptSuggestion: function() {
TestRunner.addResult("Suggestion accepted"); TestRunner.addResult("Suggestion accepted");
} }
}; };
var div = document.createElement("div"); var div = document.createElement("div");
UI.inspectorView.element.appendChild(div); UI.inspectorView.element.appendChild(div);
var suggestBox = new UI.SuggestBox(delegate); var suggestBox = new UI.SuggestBox(delegate);
TestRunner.addResult(""); TestRunner.addResult("");
TestRunner.addResult("Testing that the first item is selected."); TestRunner.addResult("Testing that the first item is selected.");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "First"}, {text: "First"},
{text: "Hello"}, {text: "Hello"},
{text: "The best suggestion"}], true, true, "e"); {text: "The best suggestion"}], true, true, "e");
TestRunner.addResult(""); TestRunner.addResult("");
TestRunner.addResult("Testing that no item is selected."); TestRunner.addResult("Testing that no item is selected.");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "First"}, {text: "First"},
{text: "Hello", priority: 2}, {text: "Hello", priority: 2},
{text: "The best suggestion", priority: 5}], false, true, "e"); {text: "The best suggestion", priority: 5}], false, true, "e");
TestRunner.addResult(""); TestRunner.addResult("");
TestRunner.addResult("Testing that highest priority item is selected."); TestRunner.addResult("Testing that highest priority item is selected.");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "First"}, {text: "First"},
{text: "Hello", priority: 2}, {text: "Hello", priority: 2},
{text: "The best suggestion", priority: 5}], true, true, "e"); {text: "The best suggestion", priority: 5}], true, true, "e");
TestRunner.addResult(""); TestRunner.addResult("");
TestRunner.addResult("Testing that arrow keys can be used for selection."); 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("ArrowUp")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowUp"));
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown"));
suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown")); suggestBox.keyPressed(TestRunner.createKeyEvent("ArrowDown"));
TestRunner.addResult(""); TestRunner.addResult("");
TestRunner.addResult("Testing that enter can be used to accept a suggestion."); TestRunner.addResult("Testing that enter can be used to accept a suggestion.");
suggestBox.keyPressed(TestRunner.createKeyEvent("Enter")); suggestBox.keyPressed(TestRunner.createKeyEvent("Enter"));
TestRunner.addResult(""); TestRunner.addResult("");
TestRunner.addResult("Testing that highest priority item is selected."); TestRunner.addResult("Testing that highest priority item is selected.");
suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [ suggestBox.updateSuggestions(new AnchorBox(50, 50, 400, 400), [
{text: "First"}, {text: "First"},
{text: "Hello", priority: 2}, {text: "Hello", priority: 2},
{text: "The best suggestion", priority: 5}], true, true, "e"); {text: "The best suggestion", priority: 5}], true, true, "e");
TestRunner.completeTest(); TestRunner.completeTest();
\ No newline at end of file })();
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 { class FocusableWidget extends UI.Widget {
constructor(name) { constructor(name) {
super(); super();
this.element.tabIndex = -1; this.element.tabIndex = -1;
this.element.textContent = name; this.element.textContent = name;
this.setDefaultFocusedElement(this.element); 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(); tabbedPane._currentTab.tabElement.focus();
dumpFocus(); dumpFocus();
TestRunner.addResult('Moving right and wrapping around'); TestRunner.addResult('Moving right and wrapping around');
...@@ -28,35 +29,37 @@ function tabsAdded() { ...@@ -28,35 +29,37 @@ function tabsAdded() {
tabbedPane._currentTab.tabElement.focus(); tabbedPane._currentTab.tabElement.focus();
} }
TestRunner.completeTest(); TestRunner.completeTest();
} }
function right() { function right() {
var element = document.deepActiveElement(); var element = document.deepActiveElement();
if (element) if (element)
element.dispatchEvent(TestRunner.createKeyEvent('ArrowRight')); element.dispatchEvent(TestRunner.createKeyEvent('ArrowRight'));
dumpFocus(); dumpFocus();
} }
function left() { function left() {
var element = document.deepActiveElement(); var element = document.deepActiveElement();
if (element) if (element)
element.dispatchEvent(TestRunner.createKeyEvent('ArrowLeft')); element.dispatchEvent(TestRunner.createKeyEvent('ArrowLeft'));
dumpFocus(); dumpFocus();
} }
function enter() { function enter() {
var element = document.deepActiveElement(); var element = document.deepActiveElement();
if (element) if (element)
element.dispatchEvent(TestRunner.createKeyEvent('Enter')); element.dispatchEvent(TestRunner.createKeyEvent('Enter'));
dumpFocus(); dumpFocus();
} }
function dumpFocus() { function dumpFocus() {
var element = document.deepActiveElement(); var element = document.deepActiveElement();
if (!element) { if (!element) {
TestRunner.addResult("null"); TestRunner.addResult("null");
return; return;
} }
TestRunner.addResult(element.textContent); 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();
...@@ -56,10 +57,10 @@ function step5() ...@@ -56,10 +57,10 @@ function step5()
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");
...@@ -72,22 +73,22 @@ function completions(expression, query) ...@@ -72,22 +73,22 @@ function completions(expression, query)
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) : ""
...@@ -105,4 +106,5 @@ function typeCharacter(character) ...@@ -105,4 +106,5 @@ function typeCharacter(character)
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());
...@@ -18,9 +19,10 @@ function step2() { ...@@ -18,9 +19,10 @@ function step2() {
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([ TestRunner.runTests([
function testAddWord() function testAddWord()
{ {
var trie = new Common.Trie(); var trie = new Common.Trie();
...@@ -132,39 +133,40 @@ TestRunner.runTests([ ...@@ -132,39 +133,40 @@ TestRunner.runTests([
longestPrefix(trie, "foo", false); longestPrefix(trie, "foo", false);
longestPrefix(trie, "foo", true); longestPrefix(trie, "foo", true);
}, },
]); ]);
function hasWord(trie, word) function hasWord(trie, word)
{ {
TestRunner.addResult(`trie.has("${word}") = ${trie.has(word)}`); TestRunner.addResult(`trie.has("${word}") = ${trie.has(word)}`);
} }
function addWord(trie, word) function addWord(trie, word)
{ {
TestRunner.addResult(`trie.add("${word}")`); TestRunner.addResult(`trie.add("${word}")`);
trie.add(word); trie.add(word);
} }
function removeWord(trie, word) function removeWord(trie, word)
{ {
TestRunner.addResult(`trie.remove("${word}") = ${trie.remove(word)}`); TestRunner.addResult(`trie.remove("${word}") = ${trie.remove(word)}`);
} }
function words(trie, prefix) function words(trie, prefix)
{ {
var title = prefix ? `trie.words("${prefix}")` : `trie.words()`; var title = prefix ? `trie.words("${prefix}")` : `trie.words()`;
var words = trie.words(prefix); var words = trie.words(prefix);
var text = words.length ? `[\n ${words.join(",\n ")}\n]` : "[]"; var text = words.length ? `[\n ${words.join(",\n ")}\n]` : "[]";
TestRunner.addResult(title + " = " + text); TestRunner.addResult(title + " = " + text);
} }
function clear(trie) function clear(trie)
{ {
trie.clear(); trie.clear();
TestRunner.addResult("trie.clear()"); TestRunner.addResult("trie.clear()");
} }
function longestPrefix(trie, word, fullWordOnly) function longestPrefix(trie, word, fullWordOnly)
{ {
TestRunner.addResult(`trie.longestPrefix("${word}", ${fullWordOnly}) = "${trie.longestPrefix(word, fullWordOnly)}"`); TestRunner.addResult(`trie.longestPrefix("${word}", ${fullWordOnly}) = "${trie.longestPrefix(word, fullWordOnly)}"`);
} }
\ No newline at end of file })();
\ No newline at end of file
runtime._registerModule({ (async function() {
runtime._registerModule({
name: "mock-module", name: "mock-module",
extensions: ['first', 'second', 'third', 'fourth'].map(title => { extensions: ['first', 'second', 'third', 'fourth'].map(title => {
return { return {
...@@ -11,44 +12,45 @@ runtime._registerModule({ ...@@ -11,44 +12,45 @@ runtime._registerModule({
} }
}), }),
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