browser_dbg-sourcemaps-bogus.js (4456B)
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 errors while loading sourcemap does not break debugging. 6 7 "use strict"; 8 9 requestLongerTimeout(2); 10 11 add_task(async function () { 12 // NOTE: the CORS call makes the test run times inconsistent 13 14 // - non-existant-map.js has a reference to source map file which doesn't exists. 15 // There is no particular warning and no original file is displayed, only the generated file. 16 // - map-with-failed-original-request.js has a reference to a valid source map file, 17 // but the map doesn't inline source content and refers to a URL which fails loading. 18 // (this file is based on dom-mutation.js and related map) 19 const dbg = await initDebugger( 20 "doc-sourcemap-bogus.html", 21 "non-existant-map.js", 22 "map-with-failed-original-request.js", 23 "map-with-failed-original-request.original.js", 24 "invalid-json-map.js" 25 ); 26 // Make sure there is only the expected sources and we miss some original sources. 27 is(dbg.selectors.getSourceCount(), 4, "Only 4 source exists"); 28 29 await selectSource(dbg, "non-existant-map.js"); 30 is( 31 findFooterNotificationMessage(dbg), 32 "Source Map Error: request failed with status 404", 33 "There is a warning about the missing source map file" 34 ); 35 36 // We should still be able to set breakpoints and pause in the 37 // generated source. 38 await addBreakpoint(dbg, "non-existant-map.js", 4); 39 invokeInTab("runCode"); 40 await waitForPaused(dbg); 41 await assertPausedAtSourceAndLine( 42 dbg, 43 findSource(dbg, "non-existant-map.js").id, 44 4 45 ); 46 await resume(dbg); 47 48 // Test a Source Map with invalid JSON 49 await selectSource(dbg, "invalid-json-map.js"); 50 is( 51 findFooterNotificationMessage(dbg), 52 "Source Map Error: JSON.parse: expected property name or '}' at line 2 column 3 of the JSON data", 53 "There is a warning about the missing source map file" 54 ); 55 56 let footerButton = findElement(dbg, "sourceMapFooterButton"); 57 ok( 58 footerButton.classList.contains("not-mapped"), 59 "The source map error causes the file to be reported as not mapped" 60 ); 61 ok( 62 footerButton.classList.contains("error"), 63 "The source map error is displayed in the source map icon" 64 ); 65 66 // Test a Source Map with missing original text content 67 await selectSource(dbg, "map-with-failed-original-request.js"); 68 ok( 69 !findElement(dbg, "editorNotificationFooter"), 70 "The source-map is valid enough to not spawn a warning message" 71 ); 72 await addBreakpoint(dbg, "map-with-failed-original-request.js", 7); 73 invokeInTab("changeStyleAttribute"); 74 await waitForPaused(dbg); 75 76 // As the original file can't be loaded, the generated source is automatically selected 77 await assertPausedAtSourceAndLine( 78 dbg, 79 findSource(dbg, "map-with-failed-original-request.js").id, 80 7 81 ); 82 83 // The original file is visible in the source tree and can be selected, 84 // but its content can't be displayed 85 await selectSource(dbg, "map-with-failed-original-request.original.js"); 86 const notificationMessage = DEBUGGER_L10N.getFormatStr( 87 "editorNotificationFooter.noOriginalScopes", 88 DEBUGGER_L10N.getStr("scopes.showOriginalScopes") 89 ); 90 is( 91 findFooterNotificationMessage(dbg), 92 notificationMessage, 93 "There is no warning about source-map but rather one about original scopes" 94 ); 95 const editorContent = getEditorContent(dbg); 96 Assert.stringContains( 97 editorContent, 98 `Error while fetching an original source: request failed with status 404\n` 99 ); 100 // Ignore the stack logged in between these two strings 101 Assert.stringContains( 102 editorContent, 103 `Source URL: ${EXAMPLE_URL}map-with-failed-original-request.original.js` 104 ); 105 106 footerButton = findElement(dbg, "sourceMapFooterButton"); 107 is( 108 footerButton.textContent, 109 "original file", 110 "Even if the original can't be loaded, it is reported as original in the footer" 111 ); 112 ok( 113 !footerButton.classList.contains("loading"), 114 "The source map isn't loading because of the missing text content" 115 ); 116 ok( 117 !footerButton.classList.contains("error"), 118 "The source map isn't reported with an error because of the missing text content" 119 ); 120 ok( 121 footerButton.classList.contains("original"), 122 "The source map icon is set to original" 123 ); 124 125 await resume(dbg); 126 });