browser_webconsole_open-links-without-callback.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // Tests that if a link without an onclick callback is clicked the link is
  5. // opened in a new tab and no exception occurs (bug 999236).
  6. "use strict";
  7. function test() {
  8. function* runner() {
  9. const TEST_EVAL_STRING = "document";
  10. const TEST_PAGE_URI = "http://example.com/browser/devtools/client/" +
  11. "webconsole/test/test-console.html";
  12. const {tab} = yield loadTab(TEST_PAGE_URI);
  13. const hud = yield openConsole(tab);
  14. hud.jsterm.execute(TEST_EVAL_STRING);
  15. const EXPECTED_OUTPUT = new RegExp("HTMLDocument \.+");
  16. let messages = yield waitForMessages({
  17. webconsole: hud,
  18. messages: [{
  19. name: "JS eval output",
  20. text: EXPECTED_OUTPUT,
  21. category: CATEGORY_OUTPUT,
  22. }],
  23. });
  24. let messageNode = messages[0].matched.values().next().value;
  25. // The correct anchor is second in the message node; the first anchor has
  26. // class .cm-variable. Ignore the first one by not matching anchors that
  27. // have the class .cm-variable.
  28. let urlNode = messageNode.querySelector("a:not(.cm-variable)");
  29. let linkOpened = false;
  30. let oldOpenUILinkIn = window.openUILinkIn;
  31. window.openUILinkIn = function (aLink) {
  32. if (aLink == TEST_PAGE_URI) {
  33. linkOpened = true;
  34. }
  35. };
  36. EventUtils.synthesizeMouseAtCenter(urlNode, {}, hud.iframeWindow);
  37. ok(linkOpened, "Clicking the URL opens the desired page");
  38. window.openUILinkIn = oldOpenUILinkIn;
  39. }
  40. Task.spawn(runner).then(finishTest);
  41. }