| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function triggerCountNoArguments() { |
| for (let i = 0; i < 10; ++i) { |
| console.count(); |
| if (i % 2) |
| console.count(); |
| } |
| } |
| |
| function triggerLabeledCounters() { |
| for (let i = 0; i < 10; ++i) { |
| console.count("alpha"); |
| if (i % 2) { |
| console.count("beta"); |
| console.count("alpha"); |
| } |
| } |
| } |
| |
| function triggerConsoleResetWarnings() { |
| console.countReset("missing-label-1"); |
| console.countReset("missing-label-2"); |
| } |
| |
| function triggerConsoleResetBasic() { |
| for (let i = 1; i <= 10; ++i) { |
| console.count("reset-label"); |
| if (i === 6 || i === 8) |
| console.countReset("reset-label"); |
| } |
| } |
| |
| function test() |
| { |
| let suite = InspectorTest.createAsyncSuite("console.count"); |
| |
| suite.addTestCase({ |
| name: "console.count.NoArguments", |
| description: "No arguments uses the default label.", |
| test(resolve, reject) { |
| let seen = 0; |
| const expected = 16; |
| WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| function handler(event) { |
| let message = event.data.message; |
| InspectorTest.log(message.messageText); |
| if (++seen === expected) { |
| WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| resolve(); |
| } |
| } |
| |
| InspectorTest.evaluateInPage(`triggerCountNoArguments()`); // 15 |
| InspectorTest.evaluateInPage(`console.count("default")`); // 16 |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "console.count.WithLabel", |
| description: "Labeled counters increment the label.", |
| test(resolve, reject) { |
| let seen = 0; |
| const expected = 20; |
| WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| function handler(event) { |
| let message = event.data.message; |
| InspectorTest.log(message.messageText); |
| if (++seen === expected) { |
| WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| resolve(); |
| } |
| } |
| |
| InspectorTest.evaluateInPage(`triggerLabeledCounters()`); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "console.countReset.NoCounter", |
| description: "A reset of a non-existing counter should warn.", |
| test(resolve, reject) { |
| let seen = 0; |
| const expected = 2; |
| WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| function handler(event) { |
| let message = event.data.message; |
| InspectorTest.expectEqual(message.level, WI.ConsoleMessage.MessageLevel.Warning, "Should produce a warning console message."); |
| InspectorTest.log(message.messageText); |
| if (++seen === expected) { |
| WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| resolve(); |
| } |
| } |
| |
| InspectorTest.evaluateInPage(`triggerConsoleResetWarnings()`); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "console.countReset.Basic", |
| description: "A reset of a non-existing counter should warn.", |
| test(resolve, reject) { |
| let seen = 0; |
| const expected = 10; |
| WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| function handler(event) { |
| let message = event.data.message; |
| InspectorTest.log(message.messageText); |
| if (++seen === expected) { |
| WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler); |
| resolve(); |
| } |
| } |
| |
| InspectorTest.evaluateInPage(`triggerConsoleResetBasic()`); |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests for the console.count and console.countReset APIs.</p> |
| </body> |
| </html> |