summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/test/browser_jsonview_copy_json.js
blob: 56c7b3ff758ce877bb3ed8218a100ec64c055bd5 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_JSON_URL = URL_ROOT + "simple_json.json";

add_task(async function () {
  info("Test copy JSON started");

  await addJsonViewTab(TEST_JSON_URL);

  const countBefore = await getElementCount(
    ".jsonPanelBox .treeTable .treeRow"
  );
  ok(countBefore == 1, "There must be one row");

  const text = await getElementText(".jsonPanelBox .treeTable .treeRow");
  is(text, 'name"value"', "There must be proper JSON displayed");

  // Verify JSON copy into the clipboard.
  const value = '{ "name": "value" }\n';
  const browser = gBrowser.selectedBrowser;
  const selector = ".jsonPanelBox .toolbar button.copy";
  await waitForClipboardPromise(
    function setup() {
      BrowserTestUtils.synthesizeMouseAtCenter(selector, {}, browser);
    },
    function validator(result) {
      const str = normalizeNewLines(result);
      return str == value;
    }
  );
});