blob: f5a0cbf9c4f51f66ef3e32151350aa5803b5c6b1 [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(`Tests that console nicely formats HTML Collections, NodeLists and DOMTokenLists.\n`);
await TestRunner.loadModule('console_test_runner');
await TestRunner.showPanel('console');
await TestRunner.loadHTML(`
<div style="display:none" class="c1 c2 c3">
<form id="f">
<select id="sel" name="sel">
<option value="1">one</option>
<option value="2">two</option>
</select>
<input type="radio" name="x" value="x1"> x1
<input type="radio" name="x" value="x2"> x2
</form>
</div>
`);
await TestRunner.evaluateInPagePromise(`
function logToConsole()
{
var formElement = document.getElementById("f");
var selectElement = document.getElementById("sel");
var spanElement = document.getElementById("span");
// NodeList
var nodelist = document.getElementsByTagName("select");
console.log(nodelist);
// HTMLCollection
var htmlcollection = document.head.children;
console.log(htmlcollection);
// HTMLOptionsCollection
var options = selectElement.options;
console.log(options);
// HTMLAllCollection
var all = document.all;
console.log(all);
// HTMLFormControlsCollection (currently shows HTMLCollection)
var formControls = formElement.elements;
console.log(formControls);
// RadioNodeList
var radioNodeList = formElement.x;
console.log(radioNodeList);
// Cross-referencing arrays.
var arrayX = [1];
var arrayY = [2, arrayX];
arrayX.push(arrayY);
console.log(arrayX);
var nonArray = new NonArrayWithLength();
console.log(nonArray);
// Arguments
function generateArguments(foo, bar)
{
return arguments;
}
console.log(generateArguments(1, "2"));
// DOMTokenList
var div = document.getElementsByTagName("div")[0];
console.log(div.classList);
// Array-like's.
console.log(new ArrayLike(5));
console.log(new ArrayLike(0xFFFFFFFF));
// Array-like's with wrong length.
console.log(new ArrayLike(-5));
console.log(new ArrayLike(5.6));
console.log(new ArrayLike(NaN));
console.log(new ArrayLike(Infinity));
console.log(new ArrayLike(-0));
console.log(new ArrayLike(0xFFFFFFFF + 1));
}
logToConsole();
function NonArrayWithLength()
{
this.keys = [];
}
NonArrayWithLength.prototype.__defineGetter__("length", function()
{
console.log("FAIL: 'length' should not be called");
return this.keys.length;
});
function ArrayLike(length)
{
this.length = length;
}
ArrayLike.prototype.splice = function() {};
`);
TestRunner.evaluateInPage('logToConsole()', callback);
function callback() {
ConsoleTestRunner.dumpConsoleMessages();
TestRunner.completeTest();
}
})();