browser_dbg-preview-jump-to-definition.js (2479B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 // Test that jump to definition works in preview popups 6 7 "use strict"; 8 9 const TEST_URL = 10 "data:text/html," + 11 encodeURIComponent(`<script> 12 function main() { 13 b(); 14 debugger; 15 } 16 function b() {} 17 const o = { b }; 18 </script>`); 19 20 const TEST_URL_ONE_LINE = 21 "data:text/html," + 22 encodeURIComponent( 23 `<script>function main() {b();debugger;}function b() {}</script>` 24 ); 25 26 add_task(async function testJumpToDefinition() { 27 const dbg = await initDebuggerWithAbsoluteURL(TEST_URL, TEST_URL); 28 29 invokeInTab("main"); 30 await waitForPaused(dbg); 31 32 info("Hovers over 'this' token to display the preview."); 33 await tryHovering(dbg, 3, 5, "previewPopup"); 34 35 info("Wait for the 'b' function to be previewed"); 36 await waitForAllElements(dbg, "previewPopupObjectFunction", 1); 37 38 info("Click on the function to jump to its location"); 39 await clickElement(dbg, "previewPopupObjectFunctionJumpToDefinition"); 40 41 await waitForSelectedLocation(dbg, 6, 13); 42 }); 43 44 add_task(async function testJumpToDefinitionInPrettyPrintedSource() { 45 const dbg = await initDebuggerWithAbsoluteURL( 46 TEST_URL_ONE_LINE, 47 TEST_URL_ONE_LINE 48 ); 49 50 await selectSource(dbg, TEST_URL_ONE_LINE); 51 await togglePrettyPrint(dbg); 52 53 invokeInTab("main"); 54 await waitForPaused(dbg); 55 56 info("Hovers over 'this' token to display the preview."); 57 await tryHovering(dbg, 3, 3, "previewPopup"); 58 59 info("Wait for the 'b' function to be previewed"); 60 await waitForAllElements(dbg, "previewPopupObjectFunction", 1); 61 62 info("Click on the function to jump to its location"); 63 await clickElement(dbg, "previewPopupObjectFunctionJumpToDefinition"); 64 65 await waitForSelectedLocation(dbg, 6, 11); 66 }); 67 68 add_task(async function testJumpToDefinitionOfObjectProperty() { 69 const dbg = await initDebuggerWithAbsoluteURL(TEST_URL, TEST_URL); 70 71 invokeInTab("main"); 72 await waitForPaused(dbg); 73 74 info("Hovers over 'o' token to display the preview."); 75 await tryHovering(dbg, 7, 9, "previewPopup"); 76 77 info("Wait for the 'b' function to be previewed"); 78 await waitForAllElements(dbg, "previewPopupObjectFunction", 1); 79 80 info("Click on the function to jump to its location"); 81 await clickElement(dbg, "previewPopupObjectFunctionJumpToDefinition"); 82 83 await waitForSelectedLocation(dbg, 6, 13); 84 });