summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_menu-02-copy-items.js
blob: 57a5dbaa08e7f41da4d4e8d48122c2c5be575edb (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
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that the various copy items in the context menu works correctly.

const TEST_URL = URL_ROOT + "doc_inspector_menu.html";
const COPY_ITEMS_TEST_DATA = [
  {
    desc: "copy inner html",
    id: "node-menu-copyinner",
    selector: "[data-id=\"copy\"]",
    text: "Paragraph for testing copy",
  },
  {
    desc: "copy outer html",
    id: "node-menu-copyouter",
    selector: "[data-id=\"copy\"]",
    text: "<p data-id=\"copy\">Paragraph for testing copy</p>",
  },
  {
    desc: "copy unique selector",
    id: "node-menu-copyuniqueselector",
    selector: "[data-id=\"copy\"]",
    text: "body > div:nth-child(1) > p:nth-child(2)",
  },
  {
    desc: "copy css path",
    id: "node-menu-copycsspath",
    selector: "[data-id=\"copy\"]",
    text: "html body div p",
  },
  {
    desc: "copy image data uri",
    id: "node-menu-copyimagedatauri",
    selector: "#copyimage",
    text: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC" +
      "AAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==",
  },
];

add_task(function* () {
  let { inspector } = yield openInspectorForURL(TEST_URL);
  for (let {desc, id, selector, text} of COPY_ITEMS_TEST_DATA) {
    info("Testing " + desc);
    yield selectNode(selector, inspector);

    let allMenuItems = openContextMenuAndGetAllItems(inspector);
    let item = allMenuItems.find(i => i.id === id);
    ok(item, "The popup has a " + desc + " menu item.");

    yield waitForClipboardPromise(() => item.click(), text);
  }
});