summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_error.js
blob: 21a30ab3bf09c81a1cccc272922fc2b3bd1f9db4 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/* import-globals-from helper-addons.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);

/**
 * Test that the installation error messages are displayed when installing temporary
 * extensions.
 */

const INVALID_JSON_EXTENSION_PATH =
  "resources/bad-extensions/invalid-json/manifest.json";
const INVALID_PROP_EXTENSION_PATH =
  "resources/bad-extensions/invalid-property/manifest.json";
const EXTENSION_PATH = "resources/test-temporary-extension/manifest.json";
const EXTENSION_NAME = "test-temporary-extension";

// Extension with an invalid JSON manifest will not be parsed. We check the expected
// error message is displayed
add_task(async function testInvalidJsonExtension() {
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const installError = await installBadExtension(
    INVALID_JSON_EXTENSION_PATH,
    document
  );
  ok(
    installError.textContent.includes("JSON.parse: unexpected keyword"),
    "The expected installation error is displayed: " + installError.textContent
  );

  info("Install a valid extension to make the message disappear");
  await installTemporaryExtension(EXTENSION_PATH, EXTENSION_NAME, document);

  info("Wait until the error message disappears");
  await waitUntil(
    () => !document.querySelector(".qa-tmp-extension-install-error")
  );

  info("Wait for the temporary addon to be displayed as a debug target");
  await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));

  await removeTemporaryExtension(EXTENSION_NAME, document);

  await removeTab(tab);
});

// Extension with a valid JSON manifest but containing an invalid property should display
// a detailed error message coming from the Addon Manager.
add_task(async function testInvalidPropertyExtension() {
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const installError = await installBadExtension(
    INVALID_PROP_EXTENSION_PATH,
    document
  );

  ok(
    installError.textContent.includes("Extension is invalid"),
    "The basic installation error is displayed: " + installError.textContent
  );
  ok(
    installError.textContent.includes(
      "Reading manifest: Error processing content_scripts.0.matches"
    ),
    "The detailed installation error is also displayed: " +
      installError.textContent
  );

  await removeTab(tab);
});

async function installBadExtension(path, document) {
  info("Install a bad extension at path: " + path);
  // Do not use installTemporaryAddon here since the install will fail.
  prepareMockFilePicker(path);
  document.querySelector(".qa-temporary-extension-install-button").click();

  info("Wait until the install error message appears");
  await waitUntil(() =>
    document.querySelector(".qa-tmp-extension-install-error")
  );
  return document.querySelector(".qa-tmp-extension-install-error");
}