Bug 999236 - Webconsole - Ensure anchors with a URL have a click callback defined. r=robcee

This commit is contained in:
Sami Jaktholm 2014-05-01 10:06:00 -04:00
parent f618b68516
commit f90697436a
3 changed files with 56 additions and 3 deletions

View File

@ -1953,8 +1953,10 @@ Widgets.JSObject.prototype = Heritage.extend(Widgets.BaseWidget.prototype,
*/
_anchor: function(text, options = {})
{
if (!options.onClick && !options.href) {
options.onClick = this._onClick;
if (!options.onClick) {
// If the anchor has an URL, open it in a new tab. If not, show the
// current object actor.
options.onClick = options.href ? this._onClickAnchor : this._onClick;
}
let anchor = this.el("a", {
@ -1963,7 +1965,7 @@ Widgets.JSObject.prototype = Heritage.extend(Widgets.BaseWidget.prototype,
href: options.href || "#",
}, text);
this.message._addLinkCallback(anchor, !options.href ? options.onClick : null);
this.message._addLinkCallback(anchor, options.onClick);
if (options.appendTo) {
options.appendTo.appendChild(anchor);

View File

@ -258,6 +258,7 @@ run-if = os == "mac"
[browser_webconsole_netlogging.js]
[browser_webconsole_network_panel.js]
[browser_webconsole_notifications.js]
[browser_webconsole_open-links-without-callback.js]
[browser_webconsole_output_copy_newlines.js]
[browser_webconsole_output_order.js]
[browser_webconsole_property_provider.js]

View File

@ -0,0 +1,50 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that if a link without an onclick callback is clicked the link is
// opened in a new tab and no exception occurs (bug 999236).
function test() {
function* runner() {
const TEST_EVAL_STRING = "document";
const TEST_PAGE_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
const {tab} = yield loadTab(TEST_PAGE_URI);
const hud = yield openConsole(tab);
hud.jsterm.execute(TEST_EVAL_STRING);
const EXPECTED_OUTPUT = new RegExp("HTMLDocument \.+");
let messages = yield waitForMessages({
webconsole: hud,
messages: [{
name: "JS eval output",
text: EXPECTED_OUTPUT,
category: CATEGORY_OUTPUT,
}],
});
let messageNode = messages[0].matched.values().next().value;
// The correct anchor is second in the message node; the first anchor has
// class .cm-variable. Ignore the first one by not matching anchors that
// have the class .cm-variable.
let urlNode = messageNode.querySelector("a:not(.cm-variable)");
let linkOpened = false;
let oldOpenUILinkIn = window.openUILinkIn;
window.openUILinkIn = function(aLink) {
if (aLink == TEST_PAGE_URI) {
linkOpened = true;
}
}
EventUtils.synthesizeMouseAtCenter(urlNode, {}, hud.iframeWindow);
ok(linkOpened, "Clicking the URL opens the desired page");
window.openUILinkIn = oldOpenUILinkIn;
}
Task.spawn(runner).then(finishTest);
}