browser_application_panel_manifest-display.js (4914B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Check that the manifest is being properly shown 8 */ 9 10 add_task(async function () { 11 info("Test that we are displaying correctly a valid manifest"); 12 const url = URL_ROOT + "resources/manifest/load-ok.html"; 13 14 await enableApplicationPanel(); 15 const { panel, tab } = await openNewTabAndApplicationPanel(url); 16 const doc = panel.panelWin.document; 17 18 selectPage(panel, "manifest"); 19 20 info("Waiting for the manifest to be displayed"); 21 await waitUntil(() => doc.querySelector(".js-manifest") !== null); 22 ok(true, "Manifest is being displayed"); 23 24 // assert manifest members are being properly displayed 25 checkManifestMember(doc, "name", "Foo"); 26 checkManifestMember(doc, "background_color", "#ff0000"); 27 28 Assert.strictEqual( 29 doc.querySelector(".js-manifest-issues"), 30 null, 31 "No validation issues are being displayed" 32 ); 33 34 // close the tab 35 info("Closing the tab."); 36 await BrowserTestUtils.removeTab(tab); 37 }); 38 39 add_task(async function () { 40 info( 41 "Test that we are displaying correctly a manifest with validation warnings" 42 ); 43 const url = URL_ROOT + "resources/manifest/load-ok-warnings.html"; 44 45 await enableApplicationPanel(); 46 const { panel, tab } = await openNewTabAndApplicationPanel(url); 47 const doc = panel.panelWin.document; 48 49 selectPage(panel, "manifest"); 50 51 info("Waiting for the manifest to be displayed"); 52 await waitUntil(() => doc.querySelector(".js-manifest") !== null); 53 ok(true, "Manifest is being displayed"); 54 55 // assert manifest members are being properly displayed 56 checkManifestMember(doc, "name", "Foo"); 57 checkManifestMember(doc, "background_color", ""); 58 59 const issuesEl = doc.querySelector(".js-manifest-issues"); 60 Assert.notStrictEqual(issuesEl, null, "Validation issues are displayed"); 61 62 const warningEl = [...issuesEl.querySelectorAll(".js-manifest-issue")].find( 63 x => x.textContent.includes("background_color") 64 ); 65 Assert.notStrictEqual( 66 warningEl, 67 null, 68 "A warning about background_color is displayed" 69 ); 70 71 // close the tab 72 info("Closing the tab."); 73 await BrowserTestUtils.removeTab(tab); 74 }); 75 76 add_task(async function () { 77 info("Test that we are displaying correctly a manifest with JSON errors"); 78 const url = URL_ROOT + "resources/manifest/load-ok-json-error.html"; 79 80 await enableApplicationPanel(); 81 const { panel, tab } = await openNewTabAndApplicationPanel(url); 82 const doc = panel.panelWin.document; 83 84 selectPage(panel, "manifest"); 85 86 info("Waiting for the manifest to be displayed"); 87 await waitUntil(() => doc.querySelector(".js-manifest") !== null); 88 ok(true, "Manifest is being displayed"); 89 90 const issuesEl = doc.querySelector(".js-manifest-issues"); 91 Assert.notStrictEqual(issuesEl, null, "Validation issues are displayed"); 92 93 const errorEl = [...issuesEl.querySelectorAll(".js-manifest-issue")].find(x => 94 x.textContent.includes("JSON") 95 ); 96 Assert.notStrictEqual( 97 errorEl, 98 null, 99 "An error about JSON parsing is displayed" 100 ); 101 102 // close the tab 103 info("Closing the tab."); 104 await BrowserTestUtils.removeTab(tab); 105 }); 106 107 add_task(async function () { 108 info("Test that we are displaying correctly a manifest with icons"); 109 const url = URL_ROOT + "resources/manifest/load-ok-icons.html"; 110 111 await enableApplicationPanel(); 112 const { panel, tab } = await openNewTabAndApplicationPanel(url); 113 const doc = panel.panelWin.document; 114 115 selectPage(panel, "manifest"); 116 117 info("Waiting for the manifest to be displayed"); 118 await waitUntil(() => doc.querySelector(".js-manifest") !== null); 119 ok(true, "Manifest is being displayed"); 120 121 // assert manifest icon is being displayed 122 const iconEl = findMemberByLabel(doc, "128x128image/svg"); 123 Assert.notStrictEqual( 124 iconEl, 125 null, 126 "Icon label is being displayed with size and image type" 127 ); 128 const imgEl = iconEl.querySelector(".js-manifest-item-content img"); 129 Assert.notStrictEqual(imgEl, null, "An image is displayed for the icon"); 130 is( 131 imgEl.src, 132 URL_ROOT + "resources/manifest/icon.svg", 133 "The icon image has the the icon url as source" 134 ); 135 const iconTextContent = iconEl.querySelector( 136 ".js-manifest-item-content" 137 ).textContent; 138 ok(iconTextContent.includes("any"), "Purpose is being displayed"); 139 140 // close the tab 141 info("Closing the tab."); 142 await BrowserTestUtils.removeTab(tab); 143 }); 144 145 function findMemberByLabel(doc, member) { 146 return [...doc.querySelectorAll(".js-manifest-item")].find(x => 147 x.querySelector(".js-manifest-item-label").textContent.startsWith(member) 148 ); 149 } 150 151 function checkManifestMember(doc, member, expectedValue) { 152 const itemEl = findMemberByLabel(doc, member); 153 is( 154 itemEl.querySelector(".js-manifest-item-content").textContent, 155 expectedValue, 156 `Manifest member ${member} displays the correct value` 157 ); 158 }