Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Test that the cd() jsterm helper function works as expected. See bug 609872. |
michael@0 | 5 | |
michael@0 | 6 | function test() { |
michael@0 | 7 | let hud; |
michael@0 | 8 | |
michael@0 | 9 | const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-609872-cd-iframe-parent.html"; |
michael@0 | 10 | |
michael@0 | 11 | const parentMessages = [{ |
michael@0 | 12 | name: "document.title in parent iframe", |
michael@0 | 13 | text: "bug 609872 - iframe parent", |
michael@0 | 14 | category: CATEGORY_OUTPUT, |
michael@0 | 15 | }, { |
michael@0 | 16 | name: "paragraph content", |
michael@0 | 17 | text: "p: test for bug 609872 - iframe parent", |
michael@0 | 18 | category: CATEGORY_OUTPUT, |
michael@0 | 19 | }, { |
michael@0 | 20 | name: "object content", |
michael@0 | 21 | text: "obj: parent!", |
michael@0 | 22 | category: CATEGORY_OUTPUT, |
michael@0 | 23 | }]; |
michael@0 | 24 | |
michael@0 | 25 | const childMessages = [{ |
michael@0 | 26 | name: "document.title in child iframe", |
michael@0 | 27 | text: "bug 609872 - iframe child", |
michael@0 | 28 | category: CATEGORY_OUTPUT, |
michael@0 | 29 | }, { |
michael@0 | 30 | name: "paragraph content", |
michael@0 | 31 | text: "p: test for bug 609872 - iframe child", |
michael@0 | 32 | category: CATEGORY_OUTPUT, |
michael@0 | 33 | }, { |
michael@0 | 34 | name: "object content", |
michael@0 | 35 | text: "obj: child!", |
michael@0 | 36 | category: CATEGORY_OUTPUT, |
michael@0 | 37 | }]; |
michael@0 | 38 | |
michael@0 | 39 | Task.spawn(runner).then(finishTest); |
michael@0 | 40 | |
michael@0 | 41 | function* runner() { |
michael@0 | 42 | const {tab} = yield loadTab(TEST_URI); |
michael@0 | 43 | hud = yield openConsole(tab); |
michael@0 | 44 | |
michael@0 | 45 | executeWindowTest(); |
michael@0 | 46 | |
michael@0 | 47 | yield waitForMessages({ webconsole: hud, messages: parentMessages }); |
michael@0 | 48 | |
michael@0 | 49 | info("cd() into the iframe using a selector"); |
michael@0 | 50 | hud.jsterm.clearOutput(); |
michael@0 | 51 | hud.jsterm.execute("cd('iframe')"); |
michael@0 | 52 | executeWindowTest(); |
michael@0 | 53 | |
michael@0 | 54 | yield waitForMessages({ webconsole: hud, messages: childMessages }); |
michael@0 | 55 | |
michael@0 | 56 | info("cd() out of the iframe, reset to default window"); |
michael@0 | 57 | hud.jsterm.clearOutput(); |
michael@0 | 58 | hud.jsterm.execute("cd()"); |
michael@0 | 59 | executeWindowTest(); |
michael@0 | 60 | |
michael@0 | 61 | yield waitForMessages({ webconsole: hud, messages: parentMessages }); |
michael@0 | 62 | |
michael@0 | 63 | info("call cd() with unexpected arguments"); |
michael@0 | 64 | hud.jsterm.clearOutput(); |
michael@0 | 65 | hud.jsterm.execute("cd(document)"); |
michael@0 | 66 | |
michael@0 | 67 | yield waitForMessages({ |
michael@0 | 68 | webconsole: hud, |
michael@0 | 69 | messages: [{ |
michael@0 | 70 | text: "Cannot cd()", |
michael@0 | 71 | category: CATEGORY_OUTPUT, |
michael@0 | 72 | severity: SEVERITY_ERROR, |
michael@0 | 73 | }], |
michael@0 | 74 | }); |
michael@0 | 75 | |
michael@0 | 76 | hud.jsterm.clearOutput(); |
michael@0 | 77 | hud.jsterm.execute("cd('p')"); |
michael@0 | 78 | |
michael@0 | 79 | yield waitForMessages({ |
michael@0 | 80 | webconsole: hud, |
michael@0 | 81 | messages: [{ |
michael@0 | 82 | text: "Cannot cd()", |
michael@0 | 83 | category: CATEGORY_OUTPUT, |
michael@0 | 84 | severity: SEVERITY_ERROR, |
michael@0 | 85 | }], |
michael@0 | 86 | }); |
michael@0 | 87 | |
michael@0 | 88 | info("cd() into the iframe using an iframe DOM element"); |
michael@0 | 89 | hud.jsterm.clearOutput(); |
michael@0 | 90 | hud.jsterm.execute("cd($('iframe'))"); |
michael@0 | 91 | executeWindowTest(); |
michael@0 | 92 | |
michael@0 | 93 | yield waitForMessages({ webconsole: hud, messages: childMessages }); |
michael@0 | 94 | |
michael@0 | 95 | info("cd(window.parent)"); |
michael@0 | 96 | hud.jsterm.clearOutput(); |
michael@0 | 97 | hud.jsterm.execute("cd(window.parent)"); |
michael@0 | 98 | executeWindowTest(); |
michael@0 | 99 | |
michael@0 | 100 | yield waitForMessages({ webconsole: hud, messages: parentMessages }); |
michael@0 | 101 | |
michael@0 | 102 | yield closeConsole(tab); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | function executeWindowTest() { |
michael@0 | 106 | hud.jsterm.execute("document.title"); |
michael@0 | 107 | hud.jsterm.execute("'p: ' + document.querySelector('p').textContent"); |
michael@0 | 108 | hud.jsterm.execute("'obj: ' + window.foobarBug609872"); |
michael@0 | 109 | } |
michael@0 | 110 | } |