browser_webconsole_error_with_url.js (2093B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Check if an error with Unicode characters is reported correctly. 5 6 "use strict"; 7 8 const longParam = "0".repeat(200); 9 const url1 = `https://example.com?v=${longParam}`; 10 const url2 = `https://example.org?v=${longParam}`; 11 12 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html><script> 13 throw "Visit \u201c${url1}\u201d or \u201c${url2}\u201d to get more " + 14 "information on this error."; 15 </script>`; 16 const { ELLIPSIS } = require("resource://devtools/shared/l10n.js"); 17 18 add_task(async function () { 19 const hud = await openNewTabAndConsole(TEST_URI); 20 21 // On e10s, the exception is triggered in child process 22 // and is ignored by test harness 23 if (!Services.appinfo.browserTabsRemoteAutostart) { 24 expectUncaughtException(); 25 } 26 27 const getCroppedUrl = origin => { 28 const cropLimit = 120; 29 const half = cropLimit / 2; 30 const params = `?v=${"0".repeat( 31 half - origin.length - 3 32 )}${ELLIPSIS}${"0".repeat(half)}`; 33 return `${origin}${params}`; 34 }; 35 36 const getVisibleLinkText = linkEl => { 37 const [firstPart, , lastPart] = linkEl.children; 38 return `${firstPart.innerText}${ELLIPSIS}${lastPart.innerText}`; 39 }; 40 41 const EXPECTED_MESSAGE = `get more information on this error`; 42 43 const msg = await waitFor(() => findErrorMessage(hud, EXPECTED_MESSAGE)); 44 ok(msg, `Link in error message are cropped as expected`); 45 46 const [comLink, orgLink] = Array.from(msg.querySelectorAll("a")); 47 is(comLink.getAttribute("href"), url1, "First link has expected url"); 48 is(comLink.getAttribute("title"), url1, "First link has expected tooltip"); 49 is( 50 getVisibleLinkText(comLink), 51 getCroppedUrl("https://example.com"), 52 "First link has expected text" 53 ); 54 55 is(orgLink.getAttribute("href"), url2, "Second link has expected url"); 56 is(orgLink.getAttribute("title"), url2, "Second link has expected tooltip"); 57 is( 58 getVisibleLinkText(orgLink), 59 getCroppedUrl("https://example.org"), 60 "Second link has expected text" 61 ); 62 });