test_console_assert.html (2756B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test for console.group styling with %c</title> 6 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 7 <script type="text/javascript" src="common.js"></script> 8 <!-- Any copyright is dedicated to the Public Domain. 9 - http://creativecommons.org/publicdomain/zero/1.0/ --> 10 <script> 11 "use strict"; 12 13 window.onload = async function () { 14 SimpleTest.waitForExplicitFinish(); 15 let state; 16 try { 17 state = (await attachConsole(["ConsoleAPI"])).state; 18 const {webConsoleFront} = state; 19 20 await testFalseAssert(webConsoleFront); 21 await testFalsyAssert(webConsoleFront); 22 await testUndefinedAssert(webConsoleFront); 23 await testNullAssert(webConsoleFront); 24 await testTrueAssert(webConsoleFront); 25 26 } catch (e) { 27 ok(false, `Error thrown: ${e.message}`); 28 } 29 30 await closeDebugger(state); 31 SimpleTest.finish(); 32 }; 33 34 async function testFalseAssert(consoleFront) { 35 info(`Testing console.assert(false)`); 36 const packet = await consoleAPICall( 37 consoleFront, 38 () => top.console.assert(false, "assertion is false") 39 ); 40 41 checkConsoleAPICall(packet.message, { 42 arguments: ["assertion is false"] 43 }); 44 } 45 46 async function testFalsyAssert(consoleFront) { 47 info(`Testing console.assert(0")`); 48 const packet = await consoleAPICall( 49 consoleFront, 50 () => top.console.assert(0, "assertion is false") 51 ); 52 53 checkConsoleAPICall(packet.message, { 54 arguments: ["assertion is false"] 55 }); 56 } 57 58 async function testUndefinedAssert(consoleFront) { 59 info(`Testing console.assert(undefined)`); 60 const packet = await consoleAPICall( 61 consoleFront, 62 () => top.console.assert(undefined, "assertion is false") 63 ); 64 65 checkConsoleAPICall(packet.message, { 66 arguments: ["assertion is false"] 67 }); 68 } 69 70 async function testNullAssert(consoleFront) { 71 info(`Testing console.assert(null)`); 72 const packet = await consoleAPICall( 73 consoleFront, 74 () => top.console.assert(null, "assertion is false") 75 ); 76 77 checkConsoleAPICall(packet.message, { 78 arguments: ["assertion is false"] 79 }); 80 } 81 82 async function testTrueAssert(consoleFront) { 83 info(`Testing console.assert(true)`); 84 const onConsoleApiCall = consoleAPICall( 85 consoleFront, 86 () => top.console.assert(true, "assertion is false") 87 ); 88 89 const TIMEOUT = Symbol(); 90 const onTimeout = new Promise(resolve => setTimeout(() => resolve(TIMEOUT), 1000)); 91 92 const res = await Promise.race([onConsoleApiCall, onTimeout]); 93 is(res, TIMEOUT, 94 "There was no consoleAPICall event in response to a truthy console.assert"); 95 } 96 97 </script> 98 </head> 99 <body> 100 <p id="display"></p> 101 <div id="content" style="display: none"> 102 </div> 103 <pre id="test"> 104 </pre> 105 </body> 106 </html>