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