From 395ca3718fc369c68f9d82d92f43da1e0436a002 Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Tue, 16 Jul 2013 19:21:33 +0300 Subject: [PATCH] Bug 888407 - Fix for intermittent browser_console_iframe_messages.js | Test timed out, failed to match rule: iframe 1; r=me --- .../test/browser_console_iframe_messages.js | 116 ++++++++++-------- browser/devtools/webconsole/test/head.js | 19 ++- 2 files changed, 78 insertions(+), 57 deletions(-) diff --git a/browser/devtools/webconsole/test/browser_console_iframe_messages.js b/browser/devtools/webconsole/test/browser_console_iframe_messages.js index 3f6ed2db5c4..8131f928bf2 100644 --- a/browser/devtools/webconsole/test/browser_console_iframe_messages.js +++ b/browser/devtools/webconsole/test/browser_console_iframe_messages.js @@ -8,16 +8,56 @@ const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-consoleiframes.html"; +let expectedMessages = [ + { + text: "main file", + category: CATEGORY_WEBDEV, + severity: SEVERITY_LOG, + }, + { + text: "blah", + category: CATEGORY_JS, + severity: SEVERITY_ERROR + }, + { + text: "iframe 2", + category: CATEGORY_WEBDEV, + severity: SEVERITY_LOG + }, + { + text: "iframe 3", + category: CATEGORY_WEBDEV, + severity: SEVERITY_LOG + } +]; + +// "iframe 1" console messages can be coalesced into one if they follow each +// other in the sequence of messages (depending on timing). If they do not, then +// they will be displayed in the console output independently, as separate +// messages. This is why we need to match any of the following two rules. +let expectedMessagesAny = [ + { + name: "iframe 1 (count: 2)", + text: "iframe 1", + category: CATEGORY_WEBDEV, + severity: SEVERITY_LOG, + count: 2 + }, + { + name: "iframe 1 (repeats: 2)", + text: "iframe 1", + category: CATEGORY_WEBDEV, + severity: SEVERITY_LOG, + repeats: 2 + }, +]; + function test() { expectUncaughtException(); addTab(TEST_URI); browser.addEventListener("load", function onLoad() { browser.removeEventListener("load", onLoad, true); - - // Test for cached nsIConsoleMessages. - Services.console.logStringMessage("test1 for bug859756"); - info("open web console"); openConsole(null, consoleOpened); }, true); @@ -29,31 +69,16 @@ function consoleOpened(hud) waitForMessages({ webconsole: hud, - messages: [ - { - text: "main file", - category: CATEGORY_WEBDEV, - severity: SEVERITY_LOG, - }, - { - text: "blah", - category: CATEGORY_JS, - severity: SEVERITY_ERROR - }, - { - text: "iframe 1", - category: CATEGORY_WEBDEV, - severity: SEVERITY_LOG, - count: 2 - }, - { - text: "iframe 2", - category: CATEGORY_WEBDEV, - severity: SEVERITY_LOG - } - ], + messages: expectedMessages, }).then(() => { - closeConsole(null, onWebConsoleClose); + info("first messages matched"); + waitForMessages({ + webconsole: hud, + messages: expectedMessagesAny, + matchCondition: "any", + }).then(() => { + closeConsole(null, onWebConsoleClose); + }); }); } @@ -66,34 +91,17 @@ function onWebConsoleClose() function onBrowserConsoleOpen(hud) { ok(hud, "browser console opened"); - Services.console.logStringMessage("test2 for bug859756"); - waitForMessages({ webconsole: hud, - messages: [ - { - text: "main file", - category: CATEGORY_WEBDEV, - severity: SEVERITY_LOG, - }, - { - text: "blah", - category: CATEGORY_JS, - severity: SEVERITY_ERROR - }, - { - text: "iframe 1", - category: CATEGORY_WEBDEV, - severity: SEVERITY_LOG, - count: 2 - }, - { - text: "iframe 2", - category: CATEGORY_WEBDEV, - severity: SEVERITY_LOG - } - ], + messages: expectedMessages, }).then(() => { - closeConsole(null, finishTest); + info("first messages matched"); + waitForMessages({ + webconsole: hud, + messages: expectedMessagesAny, + matchCondition: "any", + }).then(() => { + closeConsole(null, finishTest); + }); }); } diff --git a/browser/devtools/webconsole/test/head.js b/browser/devtools/webconsole/test/head.js index b1f5d622ea1..b7f1f4ce2cd 100644 --- a/browser/devtools/webconsole/test/head.js +++ b/browser/devtools/webconsole/test/head.js @@ -855,6 +855,12 @@ function getMessageElementText(aElement) * @param object aOptions * Options for what you want to wait for: * - webconsole: the webconsole instance you work with. + * - matchCondition: "any" or "all". Default: "all". The promise + * returned by this function resolves when all of the messages are + * matched, if the |matchCondition| is "all". If you set the condition to + * "any" then the promise is resolved by any message rule that matches, + * irrespective of order - waiting for messages stops whenever any rule + * matches. * - messages: an array of objects that tells which messages to wait for. * Properties: * - text: string or RegExp to match the textContent of each new @@ -905,6 +911,7 @@ function waitForMessages(aOptions) let rulesMatched = 0; let listenerAdded = false; let deferred = promise.defer(); + aOptions.matchCondition = aOptions.matchCondition || "all"; function checkText(aRule, aText) { @@ -1154,9 +1161,15 @@ function waitForMessages(aOptions) } } + function allRulesMatched() + { + return aOptions.matchCondition == "all" && rulesMatched == rules.length || + aOptions.matchCondition == "any" && rulesMatched > 0; + } + function maybeDone() { - if (rulesMatched == rules.length) { + if (allRulesMatched()) { if (listenerAdded) { webconsole.ui.off("messages-added", onMessagesAdded); webconsole.ui.off("messages-updated", onMessagesAdded); @@ -1169,7 +1182,7 @@ function waitForMessages(aOptions) } function testCleanup() { - if (rulesMatched == rules.length) { + if (allRulesMatched()) { return; } @@ -1198,7 +1211,7 @@ function waitForMessages(aOptions) executeSoon(() => { onMessagesAdded("messages-added", webconsole.outputNode.childNodes); - if (rulesMatched != rules.length) { + if (!allRulesMatched()) { listenerAdded = true; registerCleanupFunction(testCleanup); webconsole.ui.on("messages-added", onMessagesAdded);