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

"use strict";

const {
  adbAddon,
} = require("resource://devtools/client/shared/remote-debugging/adb/adb-addon.js");

const ABD_ADDON_NAME = "ADB binary provider";

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

// Test that manifest URLs for addon targets show the manifest correctly in a new tab.
// This test reuses the ADB extension to be sure to have a valid manifest URL to open.
add_task(async function () {
  await pushPref(
    "devtools.remote.adb.extensionURL",
    CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
  );
  await checkAdbNotRunning();

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);
  const usbStatusElement = document.querySelector(".qa-sidebar-usb-status");

  info("Install ADB");
  adbAddon.install("internal");
  await waitUntil(() => usbStatusElement.textContent.includes("USB enabled"));
  await waitForAdbStart();

  info("Wait until the debug target for ADB appears");
  await waitUntil(() => findDebugTargetByText(ABD_ADDON_NAME, document));
  const adbExtensionItem = findDebugTargetByText(ABD_ADDON_NAME, document);

  const manifestUrlElement = adbExtensionItem.querySelector(".qa-manifest-url");
  ok(manifestUrlElement, "A link to the manifest is displayed");

  info("Click on the manifest URL and wait for the new tab to open");
  const onTabOpened = once(gBrowser.tabContainer, "TabOpen");
  manifestUrlElement.click();
  const { target } = await onTabOpened;
  await BrowserTestUtils.browserLoaded(target.linkedBrowser);

  info("Retrieve the text content of the new tab");
  const textContent = await SpecialPowers.spawn(
    target.linkedBrowser,
    [],
    function () {
      return content.wrappedJSObject.document.body.textContent;
    }
  );

  const manifestObject = JSON.parse(textContent);
  ok(manifestObject, "The displayed content is a valid JSON object");
  is(
    manifestObject.name,
    ABD_ADDON_NAME,
    "Manifest tab shows the expected content"
  );

  info("Close the manifest.json tab");
  await removeTab(target);

  info("Uninstall the adb extension and wait for the message to udpate");
  adbAddon.uninstall();
  await waitUntil(() => usbStatusElement.textContent.includes("USB disabled"));
  await stopAdbProcess();

  await waitForAboutDebuggingRequests(window.AboutDebugging.store);
  await removeTab(tab);
});