summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/browser/browser_application_panel_manifest-display.js
blob: 714fcc276eeb93e7a96356b4e03e2015d35a88ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Check that the manifest is being properly shown
 */

add_task(async function () {
  info("Test that we are displaying correctly a valid manifest");
  const url = URL_ROOT + "resources/manifest/load-ok.html";

  await enableApplicationPanel();
  const { panel, tab } = await openNewTabAndApplicationPanel(url);
  const doc = panel.panelWin.document;

  selectPage(panel, "manifest");

  info("Waiting for the manifest to be displayed");
  await waitUntil(() => doc.querySelector(".js-manifest") !== null);
  ok(true, "Manifest is being displayed");

  // assert manifest members are being properly displayed
  checkManifestMember(doc, "name", "Foo");
  checkManifestMember(doc, "background_color", "#ff0000");

  ok(
    doc.querySelector(".js-manifest-issues") === null,
    "No validation issues are being displayed"
  );

  // close the tab
  info("Closing the tab.");
  await BrowserTestUtils.removeTab(tab);
});

add_task(async function () {
  info(
    "Test that we are displaying correctly a manifest with validation warnings"
  );
  const url = URL_ROOT + "resources/manifest/load-ok-warnings.html";

  await enableApplicationPanel();
  const { panel, tab } = await openNewTabAndApplicationPanel(url);
  const doc = panel.panelWin.document;

  selectPage(panel, "manifest");

  info("Waiting for the manifest to be displayed");
  await waitUntil(() => doc.querySelector(".js-manifest") !== null);
  ok(true, "Manifest is being displayed");

  // assert manifest members are being properly displayed
  checkManifestMember(doc, "name", "Foo");
  checkManifestMember(doc, "background_color", "");

  const issuesEl = doc.querySelector(".js-manifest-issues");
  ok(issuesEl !== null, "Validation issues are displayed");

  const warningEl = [...issuesEl.querySelectorAll(".js-manifest-issue")].find(
    x => x.textContent.includes("background_color")
  );
  ok(warningEl !== null, "A warning about background_color is displayed");

  // close the tab
  info("Closing the tab.");
  await BrowserTestUtils.removeTab(tab);
});

add_task(async function () {
  info("Test that we are displaying correctly a manifest with JSON errors");
  const url = URL_ROOT + "resources/manifest/load-ok-json-error.html";

  await enableApplicationPanel();
  const { panel, tab } = await openNewTabAndApplicationPanel(url);
  const doc = panel.panelWin.document;

  selectPage(panel, "manifest");

  info("Waiting for the manifest to be displayed");
  await waitUntil(() => doc.querySelector(".js-manifest") !== null);
  ok(true, "Manifest is being displayed");

  const issuesEl = doc.querySelector(".js-manifest-issues");
  ok(issuesEl !== null, "Validation issues are displayed");

  const errorEl = [...issuesEl.querySelectorAll(".js-manifest-issue")].find(x =>
    x.textContent.includes("JSON")
  );
  ok(errorEl !== null, "An error about JSON parsing is displayed");

  // close the tab
  info("Closing the tab.");
  await BrowserTestUtils.removeTab(tab);
});

add_task(async function () {
  info("Test that we are displaying correctly a manifest with icons");
  const url = URL_ROOT + "resources/manifest/load-ok-icons.html";

  await enableApplicationPanel();
  const { panel, tab } = await openNewTabAndApplicationPanel(url);
  const doc = panel.panelWin.document;

  selectPage(panel, "manifest");

  info("Waiting for the manifest to be displayed");
  await waitUntil(() => doc.querySelector(".js-manifest") !== null);
  ok(true, "Manifest is being displayed");

  // assert manifest icon is being displayed
  const iconEl = findMemberByLabel(doc, "128x128image/svg");
  ok(iconEl !== null, "Icon label is being displayed with size and image type");
  const imgEl = iconEl.querySelector(".js-manifest-item-content img");
  ok(imgEl !== null, "An image is displayed for the icon");
  is(
    imgEl.src,
    URL_ROOT + "resources/manifest/icon.svg",
    "The icon image has the the icon url as source"
  );
  const iconTextContent = iconEl.querySelector(
    ".js-manifest-item-content"
  ).textContent;
  ok(iconTextContent.includes("any"), "Purpose is being displayed");

  // close the tab
  info("Closing the tab.");
  await BrowserTestUtils.removeTab(tab);
});

function findMemberByLabel(doc, member) {
  return [...doc.querySelectorAll(".js-manifest-item")].find(x =>
    x.querySelector(".js-manifest-item-label").textContent.startsWith(member)
  );
}

function checkManifestMember(doc, member, expectedValue) {
  const itemEl = findMemberByLabel(doc, member);
  is(
    itemEl.querySelector(".js-manifest-item-content").textContent,
    expectedValue,
    `Manifest member ${member} displays the correct value`
  );
}