| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (async function() { | 5 (async function() { |
| 6 TestRunner.addResult('Tests that command line api works.\n'); | 6 TestRunner.addResult('Tests that command line api works.\n'); |
| 7 | 7 |
| 8 await TestRunner.loadModule("console_test_runner"); | 8 await TestRunner.loadModule('console_test_runner'); |
| 9 await TestRunner.loadModule("elements_test_runner"); | 9 await TestRunner.loadModule('elements_test_runner'); |
| 10 await TestRunner.loadPanel("console"); | 10 await TestRunner.loadPanel('console'); |
| 11 | |
| 12 var expressions = [ | |
| 13 "String($0)", | |
| 14 "$3", | |
| 15 "String(keys([3,4]))", | |
| 16 "String(values([3,4]))", | |
| 17 "String($('#foo'))", | |
| 18 "String($('#foo', document.body))", | |
| 19 "String($('#foo', 'non-node'))", | |
| 20 "String($('#foo', $('#bar')))", | |
| 21 "String($$('p'))", | |
| 22 "String($$('p', document.body))", | |
| 23 "String($('foo'))", | |
| 24 "console.assert(keys(window).indexOf('__commandLineAPI') === -1)" | |
| 25 ]; | |
| 26 | 11 |
| 27 await TestRunner.loadHTML(` | 12 await TestRunner.loadHTML(` |
| 28 <p id="foo"> | 13 <p id="foo"> |
| 29 Tests that command line api works. | |
| 30 </p><p id="bar"></p> | 14 </p><p id="bar"></p> |
| 31 `); | 15 `); |
| 32 | 16 |
| 33 ElementsTestRunner.selectNodeWithId("foo", step1); | 17 function assertNoBoundCommandLineAPI() { |
| 18 ['__commandLineAPI', '__scopeChainForEval'].forEach(function(name) { |
| 19 console.assert(!(name in window), 'FAIL: Should be no ' + name); |
| 20 }); |
| 21 } |
| 22 |
| 23 var expressions = [ |
| 24 'String($0)', |
| 25 '$3', |
| 26 'String(keys([3,4]))', |
| 27 'String(values([3,4]))', |
| 28 'String($(\'#foo\'))', |
| 29 'String($(\'#foo\', document.body))', |
| 30 'String($(\'#foo\', \'non-node\'))', |
| 31 'String($(\'#foo\', $(\'#bar\')))', |
| 32 'String($$(\'p\'))', |
| 33 'String($$(\'p\', document.body))', |
| 34 'String($(\'foo\'))', |
| 35 'console.assert(keys(window).indexOf(\'__commandLineAPI\') === -1)' |
| 36 ]; |
| 37 |
| 38 ElementsTestRunner.selectNodeWithId('foo', step1); |
| 34 | 39 |
| 35 function step1(node) { | 40 function step1(node) { |
| 36 var expression = expressions.shift(); | 41 var expression = expressions.shift(); |
| 42 |
| 37 if (!expression) { | 43 if (!expression) { |
| 38 step2(); | 44 step2(); |
| 39 return; | 45 return; |
| 40 } | 46 } |
| 41 Common.console.log(""); | 47 |
| 48 Common.console.log(''); |
| 42 ConsoleTestRunner.evaluateInConsole(expression, step1); | 49 ConsoleTestRunner.evaluateInConsole(expression, step1); |
| 43 } | 50 } |
| 44 | 51 |
| 45 function step2() { | 52 function step2() { |
| 46 function assertNoBoundCommandLineAPI() { | 53 TestRunner.evaluateInPage('assertNoBoundCommandLineAPI()', step3); |
| 47 ["__commandLineAPI", "__scopeChainForEval"].forEach(function(name) { | |
| 48 console.assert(!(name in window), "FAIL: Should be no " + name); | |
| 49 }); | |
| 50 } | |
| 51 TestRunner.evaluateInPage(assertNoBoundCommandLineAPI, step3); | |
| 52 } | 54 } |
| 53 | 55 |
| 54 function step3() { | 56 function step3() { |
| 55 ConsoleTestRunner.dumpConsoleMessages(); | 57 ConsoleTestRunner.dumpConsoleMessages(); |
| 56 TestRunner.completeTest(); | 58 TestRunner.completeTest(); |
| 57 } | 59 } |
| 58 })(); | 60 })(); |
| OLD | NEW |