browser/devtools/webconsole/test/browser_webconsole_cd_iframe.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_cd_iframe.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Test that the cd() jsterm helper function works as expected. See bug 609872.
     1.8 +
     1.9 +function test() {
    1.10 +  let hud;
    1.11 +
    1.12 +  const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-609872-cd-iframe-parent.html";
    1.13 +
    1.14 +  const parentMessages = [{
    1.15 +    name: "document.title in parent iframe",
    1.16 +    text: "bug 609872 - iframe parent",
    1.17 +    category: CATEGORY_OUTPUT,
    1.18 +  }, {
    1.19 +    name: "paragraph content",
    1.20 +    text: "p: test for bug 609872 - iframe parent",
    1.21 +    category: CATEGORY_OUTPUT,
    1.22 +  }, {
    1.23 +    name: "object content",
    1.24 +    text: "obj: parent!",
    1.25 +    category: CATEGORY_OUTPUT,
    1.26 +  }];
    1.27 +
    1.28 +  const childMessages = [{
    1.29 +    name: "document.title in child iframe",
    1.30 +    text: "bug 609872 - iframe child",
    1.31 +    category: CATEGORY_OUTPUT,
    1.32 +  }, {
    1.33 +    name: "paragraph content",
    1.34 +    text: "p: test for bug 609872 - iframe child",
    1.35 +    category: CATEGORY_OUTPUT,
    1.36 +  }, {
    1.37 +    name: "object content",
    1.38 +    text: "obj: child!",
    1.39 +    category: CATEGORY_OUTPUT,
    1.40 +  }];
    1.41 +
    1.42 +  Task.spawn(runner).then(finishTest);
    1.43 +
    1.44 +  function* runner() {
    1.45 +    const {tab} = yield loadTab(TEST_URI);
    1.46 +    hud = yield openConsole(tab);
    1.47 +
    1.48 +    executeWindowTest();
    1.49 +
    1.50 +    yield waitForMessages({ webconsole: hud, messages: parentMessages });
    1.51 +
    1.52 +    info("cd() into the iframe using a selector");
    1.53 +    hud.jsterm.clearOutput();
    1.54 +    hud.jsterm.execute("cd('iframe')");
    1.55 +    executeWindowTest();
    1.56 +
    1.57 +    yield waitForMessages({ webconsole: hud, messages: childMessages });
    1.58 +
    1.59 +    info("cd() out of the iframe, reset to default window");
    1.60 +    hud.jsterm.clearOutput();
    1.61 +    hud.jsterm.execute("cd()");
    1.62 +    executeWindowTest();
    1.63 +
    1.64 +    yield waitForMessages({ webconsole: hud, messages: parentMessages });
    1.65 +
    1.66 +    info("call cd() with unexpected arguments");
    1.67 +    hud.jsterm.clearOutput();
    1.68 +    hud.jsterm.execute("cd(document)");
    1.69 +
    1.70 +    yield waitForMessages({
    1.71 +      webconsole: hud,
    1.72 +      messages: [{
    1.73 +        text: "Cannot cd()",
    1.74 +        category: CATEGORY_OUTPUT,
    1.75 +        severity: SEVERITY_ERROR,
    1.76 +      }],
    1.77 +    });
    1.78 +
    1.79 +    hud.jsterm.clearOutput();
    1.80 +    hud.jsterm.execute("cd('p')");
    1.81 +
    1.82 +    yield waitForMessages({
    1.83 +      webconsole: hud,
    1.84 +      messages: [{
    1.85 +        text: "Cannot cd()",
    1.86 +        category: CATEGORY_OUTPUT,
    1.87 +        severity: SEVERITY_ERROR,
    1.88 +      }],
    1.89 +    });
    1.90 +
    1.91 +    info("cd() into the iframe using an iframe DOM element");
    1.92 +    hud.jsterm.clearOutput();
    1.93 +    hud.jsterm.execute("cd($('iframe'))");
    1.94 +    executeWindowTest();
    1.95 +
    1.96 +    yield waitForMessages({ webconsole: hud, messages: childMessages });
    1.97 +
    1.98 +    info("cd(window.parent)");
    1.99 +    hud.jsterm.clearOutput();
   1.100 +    hud.jsterm.execute("cd(window.parent)");
   1.101 +    executeWindowTest();
   1.102 +
   1.103 +    yield waitForMessages({ webconsole: hud, messages: parentMessages });
   1.104 +
   1.105 +    yield closeConsole(tab);
   1.106 +  }
   1.107 +
   1.108 +  function executeWindowTest() {
   1.109 +    hud.jsterm.execute("document.title");
   1.110 +    hud.jsterm.execute("'p: ' + document.querySelector('p').textContent");
   1.111 +    hud.jsterm.execute("'obj: ' + window.foobarBug609872");
   1.112 +  }
   1.113 +}

mercurial