michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that the cd() jsterm helper function works as expected. See bug 609872. michael@0: michael@0: function test() { michael@0: let hud; michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-609872-cd-iframe-parent.html"; michael@0: michael@0: const parentMessages = [{ michael@0: name: "document.title in parent iframe", michael@0: text: "bug 609872 - iframe parent", michael@0: category: CATEGORY_OUTPUT, michael@0: }, { michael@0: name: "paragraph content", michael@0: text: "p: test for bug 609872 - iframe parent", michael@0: category: CATEGORY_OUTPUT, michael@0: }, { michael@0: name: "object content", michael@0: text: "obj: parent!", michael@0: category: CATEGORY_OUTPUT, michael@0: }]; michael@0: michael@0: const childMessages = [{ michael@0: name: "document.title in child iframe", michael@0: text: "bug 609872 - iframe child", michael@0: category: CATEGORY_OUTPUT, michael@0: }, { michael@0: name: "paragraph content", michael@0: text: "p: test for bug 609872 - iframe child", michael@0: category: CATEGORY_OUTPUT, michael@0: }, { michael@0: name: "object content", michael@0: text: "obj: child!", michael@0: category: CATEGORY_OUTPUT, michael@0: }]; michael@0: michael@0: Task.spawn(runner).then(finishTest); michael@0: michael@0: function* runner() { michael@0: const {tab} = yield loadTab(TEST_URI); michael@0: hud = yield openConsole(tab); michael@0: michael@0: executeWindowTest(); michael@0: michael@0: yield waitForMessages({ webconsole: hud, messages: parentMessages }); michael@0: michael@0: info("cd() into the iframe using a selector"); michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("cd('iframe')"); michael@0: executeWindowTest(); michael@0: michael@0: yield waitForMessages({ webconsole: hud, messages: childMessages }); michael@0: michael@0: info("cd() out of the iframe, reset to default window"); michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("cd()"); michael@0: executeWindowTest(); michael@0: michael@0: yield waitForMessages({ webconsole: hud, messages: parentMessages }); michael@0: michael@0: info("call cd() with unexpected arguments"); michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("cd(document)"); michael@0: michael@0: yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "Cannot cd()", michael@0: category: CATEGORY_OUTPUT, michael@0: severity: SEVERITY_ERROR, michael@0: }], michael@0: }); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("cd('p')"); michael@0: michael@0: yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "Cannot cd()", michael@0: category: CATEGORY_OUTPUT, michael@0: severity: SEVERITY_ERROR, michael@0: }], michael@0: }); michael@0: michael@0: info("cd() into the iframe using an iframe DOM element"); michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("cd($('iframe'))"); michael@0: executeWindowTest(); michael@0: michael@0: yield waitForMessages({ webconsole: hud, messages: childMessages }); michael@0: michael@0: info("cd(window.parent)"); michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("cd(window.parent)"); michael@0: executeWindowTest(); michael@0: michael@0: yield waitForMessages({ webconsole: hud, messages: parentMessages }); michael@0: michael@0: yield closeConsole(tab); michael@0: } michael@0: michael@0: function executeWindowTest() { michael@0: hud.jsterm.execute("document.title"); michael@0: hud.jsterm.execute("'p: ' + document.querySelector('p').textContent"); michael@0: hud.jsterm.execute("'obj: ' + window.foobarBug609872"); michael@0: } michael@0: }