1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI =
"http://example.com/browser/devtools/client/webconsole/" +
"test/browser/" +
"test-location-styleeditor-link.html";
add_task(async function () {
await pushPref("devtools.webconsole.filter.css", true);
const hud = await openNewTabAndConsole(TEST_URI);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
await testViewSource(hud, toolbox, "\u2018font-weight\u2019");
info("Selecting the console again");
await toolbox.selectTool("webconsole");
await testViewSource(hud, toolbox, "\u2018color\u2019");
info("Selecting the console again");
await toolbox.selectTool("webconsole");
await testViewSource(hud, toolbox, "\u2018display\u2019");
});
async function testViewSource(hud, toolbox, text) {
info(`Testing message with text "${text}"`);
const messageNode = await waitFor(
() => findWarningMessage(hud, text),
`couldn't find message containing "${text}"`
);
const messageLocationNode = messageNode.querySelector(".message-location");
ok(messageLocationNode, "The message does have a location link");
const onStyleEditorSelected = toolbox.once("styleeditor-selected");
EventUtils.sendMouseEvent(
{ type: "click" },
messageNode.querySelector(".frame-link-filename")
);
const panel = await onStyleEditorSelected;
ok(
true,
"The style editor is selected when clicking on the location element"
);
const win = panel.panelWindow;
ok(win, "Style Editor Window is defined");
is(
win.location.toString(),
"chrome://devtools/content/styleeditor/index.xhtml",
"This is the expected styleEditor document"
);
info("Waiting the style editor to be focused");
await new Promise(resolve => waitForFocus(resolve, win));
info("style editor window focused");
const href = messageLocationNode.getAttribute("data-url");
const line = messageLocationNode.getAttribute("data-line");
const column = messageLocationNode.getAttribute("data-column");
ok(line, "found source line");
const editor = panel.UI.editors.find(e => e.styleSheet.href == href);
ok(editor, "found style editor for " + href);
await waitFor(
() => panel.UI.selectedStyleSheetIndex == editor.styleSheet.styleSheetIndex
);
ok(true, "correct stylesheet is selected in the editor");
info("wait for source editor to load and to move the cursor");
await editor.getSourceEditor();
await waitFor(() => editor.sourceEditor.getCursor().line !== 0);
// Get the updated line and column position if the CSS source was prettified.
const position = editor.translateCursorPosition(line - 1, column - 1);
const cursor = editor.sourceEditor.getCursor();
is(cursor.line, position.line, "correct line is selected");
is(cursor.ch, position.column, "correct column is selected");
}
|