browser_webconsole_cd_iframe.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Test that the cd() jsterm helper function works as expected. See bug 609872.
  5. "use strict";
  6. function test() {
  7. let hud;
  8. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  9. "test/test-bug-609872-cd-iframe-parent.html";
  10. const parentMessages = [{
  11. name: "document.title in parent iframe",
  12. text: "bug 609872 - iframe parent",
  13. category: CATEGORY_OUTPUT,
  14. }, {
  15. name: "paragraph content",
  16. text: "p: test for bug 609872 - iframe parent",
  17. category: CATEGORY_OUTPUT,
  18. }, {
  19. name: "object content",
  20. text: "obj: parent!",
  21. category: CATEGORY_OUTPUT,
  22. }];
  23. const childMessages = [{
  24. name: "document.title in child iframe",
  25. text: "bug 609872 - iframe child",
  26. category: CATEGORY_OUTPUT,
  27. }, {
  28. name: "paragraph content",
  29. text: "p: test for bug 609872 - iframe child",
  30. category: CATEGORY_OUTPUT,
  31. }, {
  32. name: "object content",
  33. text: "obj: child!",
  34. category: CATEGORY_OUTPUT,
  35. }];
  36. Task.spawn(runner).then(finishTest);
  37. function* runner() {
  38. const {tab} = yield loadTab(TEST_URI);
  39. hud = yield openConsole(tab);
  40. yield executeWindowTest();
  41. yield waitForMessages({ webconsole: hud, messages: parentMessages });
  42. info("cd() into the iframe using a selector");
  43. hud.jsterm.clearOutput();
  44. yield hud.jsterm.execute("cd('iframe')");
  45. yield executeWindowTest();
  46. yield waitForMessages({ webconsole: hud, messages: childMessages });
  47. info("cd() out of the iframe, reset to default window");
  48. hud.jsterm.clearOutput();
  49. yield hud.jsterm.execute("cd()");
  50. yield executeWindowTest();
  51. yield waitForMessages({ webconsole: hud, messages: parentMessages });
  52. info("call cd() with unexpected arguments");
  53. hud.jsterm.clearOutput();
  54. yield hud.jsterm.execute("cd(document)");
  55. yield waitForMessages({
  56. webconsole: hud,
  57. messages: [{
  58. text: "Cannot cd()",
  59. category: CATEGORY_OUTPUT,
  60. severity: SEVERITY_ERROR,
  61. }],
  62. });
  63. hud.jsterm.clearOutput();
  64. yield hud.jsterm.execute("cd('p')");
  65. yield waitForMessages({
  66. webconsole: hud,
  67. messages: [{
  68. text: "Cannot cd()",
  69. category: CATEGORY_OUTPUT,
  70. severity: SEVERITY_ERROR,
  71. }],
  72. });
  73. info("cd() into the iframe using an iframe DOM element");
  74. hud.jsterm.clearOutput();
  75. yield hud.jsterm.execute("cd($('iframe'))");
  76. yield executeWindowTest();
  77. yield waitForMessages({ webconsole: hud, messages: childMessages });
  78. info("cd(window.parent)");
  79. hud.jsterm.clearOutput();
  80. yield hud.jsterm.execute("cd(window.parent)");
  81. yield executeWindowTest();
  82. yield waitForMessages({ webconsole: hud, messages: parentMessages });
  83. yield closeConsole(tab);
  84. }
  85. function* executeWindowTest() {
  86. yield hud.jsterm.execute("document.title");
  87. yield hud.jsterm.execute("'p: ' + document.querySelector('p').textContent");
  88. yield hud.jsterm.execute("'obj: ' + window.foobarBug609872");
  89. }
  90. }