blob: ae2ad1b0e25c0bc9b21ec59bf6c49bb4e8d32349 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(`Verifies that SelectUISourceCodeDialog rendering works properly.\n`);
await TestRunner.loadModule('sources_test_runner');
await TestRunner.evaluateInPagePromise(` function dummy1() { }
//# sourceURL=http://test/helloWorld12.js
`);
await TestRunner.evaluateInPagePromise(` function dummy2() { }
//# sourceURL=http://test/some/very-long-url/which/usually/breaks-rendering/due-to/trancation/so/that/the-path-is-cut-appropriately/and-no-horizontal-scrollbars/are-shown.js
`);
var provider = new Sources.FilteredUISourceCodeListProvider();
provider.attach();
TestRunner.runTestSuite([
function testRenderingInNameOnly(next) {
checkQuery('12');
next();
},
function testRenderingInPathAndName(next) {
checkQuery('te12');
next();
},
function testRenderingInNameInTruncatedPath(next) {
checkQuery('shown.js');
next();
},
function testRenderingInTruncatedPath(next) {
checkQuery('usually-shown.js');
next();
},
]);
function checkQuery(query) {
TestRunner.addResult('filter query: ' + query);
var titleElement = document.createElement('div');
var subtitleElement = document.createElement('div');
var outputs = [];
for (var i = 0; i < provider.itemCount(); ++i) {
provider.renderItem(i, query, titleElement, subtitleElement);
if (!subtitleElement.textContent.startsWith('test'))
continue;
var text = elementHighlightedText(titleElement);
text += '\n' + elementHighlightedText(subtitleElement);
outputs.push(text);
}
outputs.sort();
TestRunner.addResult(outputs.join('\n--------------------\n'));
}
function elementHighlightedText(element) {
var text = '';
for (var i = 0; i < element.childNodes.length; ++i) {
var node = element.childNodes[i];
if (node.nodeType === Node.TEXT_NODE)
text += node.textContent;
else
text += String.sprintf('[%s]', node.textContent);
}
return text;
}
})();