browser_net_fonts.js (2518B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests if font preview is generated correctly 8 */ 9 10 add_task(async function () { 11 const { monitor } = await initNetMonitor(FONTS_URL + "?name=fonts", { 12 requestCount: 1, 13 }); 14 info("Starting test... "); 15 16 const { document, store, windowRequire } = monitor.panelWin; 17 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 18 19 store.dispatch(Actions.batchEnable(false)); 20 21 // Reload the page to get the font request 22 const waitForRequests = waitForNetworkEvents(monitor, 3); 23 await reloadBrowser(); 24 await waitForRequests; 25 26 const wait = waitForDOMIfNeeded( 27 document, 28 "#response-panel .response-font[src^='data:']" 29 ); 30 31 const requests = document.querySelectorAll( 32 ".request-list-item .requests-list-status" 33 ); 34 35 // Check first font request 36 clickElement(requests[1], monitor); 37 clickOnSidebarTab(document, "response"); 38 39 await wait; 40 41 ok(true, "Font preview is shown"); 42 43 const tabpanel = document.querySelector("#response-panel"); 44 let image = tabpanel.querySelector(".response-font"); 45 await once(image, "load"); 46 47 ok( 48 image.complete && image.naturalHeight !== 0, 49 "Font preview got generated correctly" 50 ); 51 52 let fontData = document.querySelectorAll(".tabpanel-summary-value"); 53 is(fontData[0].textContent, "Ostrich Sans Medium", "Font name is correct"); 54 // "font/ttf" is returned on Linux, which is the expected MIME type, though 55 // "application/octet-stream" is also accepted which is returned on Windows and MacOS. 56 ok( 57 ["font/ttf", "application/octet-stream"].includes(fontData[1].textContent), 58 "MIME type is correct" 59 ); 60 61 // Check second font request 62 clickElement(requests[2], monitor); 63 64 await waitForDOM(document, "#response-panel .response-font[src^='data:']"); 65 66 image = tabpanel.querySelector(".response-font"); 67 await once(image, "load"); 68 69 ok( 70 image.complete && image.naturalHeight !== 0, 71 "Font preview got generated correctly" 72 ); 73 74 fontData = document.querySelectorAll(".tabpanel-summary-value"); 75 is(fontData[0].textContent, "Ostrich Sans Black", "Font name is correct"); 76 // Actually expected is "font/ttf", though "application/octet-stream" is 77 // ok as well and obviously returned when running the test locally. 78 ok( 79 ["font/ttf", "application/octet-stream"].includes(fontData[1].textContent), 80 "MIME type is correct" 81 ); 82 83 await teardown(monitor); 84 });