1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_console_iframe_messages.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Check that cached messages from nested iframes are displayed in the 1.10 +// Web/Browser Console. 1.11 + 1.12 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-consoleiframes.html"; 1.13 + 1.14 +let expectedMessages = [ 1.15 + { 1.16 + text: "main file", 1.17 + category: CATEGORY_WEBDEV, 1.18 + severity: SEVERITY_LOG, 1.19 + }, 1.20 + { 1.21 + text: "blah", 1.22 + category: CATEGORY_JS, 1.23 + severity: SEVERITY_ERROR 1.24 + }, 1.25 + { 1.26 + text: "iframe 2", 1.27 + category: CATEGORY_WEBDEV, 1.28 + severity: SEVERITY_LOG 1.29 + }, 1.30 + { 1.31 + text: "iframe 3", 1.32 + category: CATEGORY_WEBDEV, 1.33 + severity: SEVERITY_LOG 1.34 + } 1.35 +]; 1.36 + 1.37 +// "iframe 1" console messages can be coalesced into one if they follow each 1.38 +// other in the sequence of messages (depending on timing). If they do not, then 1.39 +// they will be displayed in the console output independently, as separate 1.40 +// messages. This is why we need to match any of the following two rules. 1.41 +let expectedMessagesAny = [ 1.42 + { 1.43 + name: "iframe 1 (count: 2)", 1.44 + text: "iframe 1", 1.45 + category: CATEGORY_WEBDEV, 1.46 + severity: SEVERITY_LOG, 1.47 + count: 2 1.48 + }, 1.49 + { 1.50 + name: "iframe 1 (repeats: 2)", 1.51 + text: "iframe 1", 1.52 + category: CATEGORY_WEBDEV, 1.53 + severity: SEVERITY_LOG, 1.54 + repeats: 2 1.55 + }, 1.56 +]; 1.57 + 1.58 +function test() 1.59 +{ 1.60 + expectUncaughtException(); 1.61 + addTab(TEST_URI); 1.62 + browser.addEventListener("load", function onLoad() { 1.63 + browser.removeEventListener("load", onLoad, true); 1.64 + info("open web console"); 1.65 + openConsole(null, consoleOpened); 1.66 + }, true); 1.67 +} 1.68 + 1.69 +function consoleOpened(hud) 1.70 +{ 1.71 + ok(hud, "web console opened"); 1.72 + 1.73 + waitForMessages({ 1.74 + webconsole: hud, 1.75 + messages: expectedMessages, 1.76 + }).then(() => { 1.77 + info("first messages matched"); 1.78 + waitForMessages({ 1.79 + webconsole: hud, 1.80 + messages: expectedMessagesAny, 1.81 + matchCondition: "any", 1.82 + }).then(() => { 1.83 + closeConsole(null, onWebConsoleClose); 1.84 + }); 1.85 + }); 1.86 +} 1.87 + 1.88 +function onWebConsoleClose() 1.89 +{ 1.90 + info("web console closed"); 1.91 + HUDService.toggleBrowserConsole().then(onBrowserConsoleOpen); 1.92 +} 1.93 + 1.94 +function onBrowserConsoleOpen(hud) 1.95 +{ 1.96 + ok(hud, "browser console opened"); 1.97 + waitForMessages({ 1.98 + webconsole: hud, 1.99 + messages: expectedMessages, 1.100 + }).then(() => { 1.101 + info("first messages matched"); 1.102 + waitForMessages({ 1.103 + webconsole: hud, 1.104 + messages: expectedMessagesAny, 1.105 + matchCondition: "any", 1.106 + }).then(() => { 1.107 + closeConsole(null, finishTest); 1.108 + }); 1.109 + }); 1.110 +}