browser_webconsole_time_methods.js (3046B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests that the Console API implements the time() and timeEnd() methods. 5 6 "use strict"; 7 8 const TEST_URI = 9 "http://example.com/browser/devtools/client/webconsole/" + 10 "test/browser/test-time-methods.html"; 11 12 const TEST_URI2 = 13 "data:text/html;charset=utf-8,<!DOCTYPE html><script>" + 14 "console.timeEnd('bTimer');</script>"; 15 16 const TEST_URI3 = 17 "data:text/html;charset=utf-8,<!DOCTYPE html><script>" + 18 "console.time('bTimer');console.log('smoke signal');</script>"; 19 20 const TEST_URI4 = 21 "data:text/html;charset=utf-8,<!DOCTYPE html>" + 22 "<script>console.timeEnd('bTimer');</script>"; 23 24 add_task(async function () { 25 // Calling console.time('aTimer') followed by console.timeEnd('aTimer') 26 // should result in the aTimer being ended, and a message like aTimer: 123ms 27 // printed to the console 28 const hud1 = await openNewTabAndConsole(TEST_URI); 29 30 const aTimerCompleted = await waitFor(() => 31 findConsoleAPIMessage(hud1, "aTimer: ") 32 ); 33 ok( 34 aTimerCompleted.textContent.includes("- timer ended"), 35 "Calling " + "console.time('a') and console.timeEnd('a')ends the 'a' timer" 36 ); 37 38 // Calling console.time('bTimer') in the current tab, opening a new tab 39 // and calling console.timeEnd('bTimer') in the new tab should not result in 40 // the bTimer in the initial tab being ended, but rather a warning message 41 // output to the console: Timer "bTimer" doesn't exist 42 const hud2 = await openNewTabAndConsole(TEST_URI2); 43 44 const error1 = await waitFor(() => 45 findWarningMessage(hud2, "bTimer", ".timeEnd") 46 ); 47 ok( 48 error1, 49 "Timers with the same name but in separate tabs do not contain " + 50 "the same value" 51 ); 52 53 // The next tests make sure that timers with the same name but in separate 54 // pages do not contain the same value. 55 await navigateTo(TEST_URI3); 56 57 // The new console front-end does not display a message when timers are started, 58 // so there should not be a 'bTimer started' message on the output 59 60 // We use this await to 'sync' until the message appears, as the console API 61 // guarantees us that the smoke signal will be printed after the message for 62 // console.time("bTimer") (if there were any) 63 await waitFor(() => findConsoleAPIMessage(hud2, "smoke signal")); 64 65 is( 66 findConsoleAPIMessage(hud2, "bTimer started"), 67 undefined, 68 "No message is printed to " + "the console when the timer starts" 69 ); 70 71 await clearOutput(hud2); 72 73 // Calling console.time('bTimer') on a page, then navigating to another page 74 // and calling console.timeEnd('bTimer') on the new console front-end should 75 // result on a warning message: 'Timer "bTimer" does not exist', 76 // as the timers in different pages are not related 77 await navigateTo(TEST_URI4); 78 79 const error2 = await waitFor(() => 80 findWarningMessage(hud2, "bTimer", ".timeEnd") 81 ); 82 ok( 83 error2, 84 "Timers with the same name but in separate pages do not contain " + 85 "the same value" 86 ); 87 });