summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/computed/test/browser_computed_original-source-link.js
blob: 771d349b3bdf4b95a8120b2208dd8029b32c1219 (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that the computed view shows the original source link when source maps
// are enabled.

const TESTCASE_URI = URL_ROOT_SSL + "doc_sourcemaps.html";
const PREF = "devtools.source-map.client-service.enabled";
const SCSS_LOC = "doc_sourcemaps.scss:4";
const CSS_LOC = "doc_sourcemaps.css:1";

add_task(async function () {
  info("Turning the pref " + PREF + " on");
  Services.prefs.setBoolPref(PREF, true);

  await addTab(TESTCASE_URI);
  const { toolbox, inspector, view } = await openComputedView();
  let onLinksUpdated = inspector.once("computed-view-sourcelinks-updated");
  await selectNode("div", inspector);

  info("Expanding the first property");
  await expandComputedViewPropertyByIndex(view, 0);

  info("Verifying the link text");
  await onLinksUpdated;
  verifyLinkText(view, SCSS_LOC);

  info("Toggling the pref");
  onLinksUpdated = inspector.once("computed-view-sourcelinks-updated");
  Services.prefs.setBoolPref(PREF, false);
  await onLinksUpdated;

  info("Verifying that the link text has changed after the pref change");
  await verifyLinkText(view, CSS_LOC);

  info("Toggling the pref again");
  onLinksUpdated = inspector.once("computed-view-sourcelinks-updated");
  Services.prefs.setBoolPref(PREF, true);
  await onLinksUpdated;

  info("Testing that clicking on the link works");
  await testClickingLink(toolbox, view);

  info("Turning the pref " + PREF + " off");
  Services.prefs.clearUserPref(PREF);
});

async function testClickingLink(toolbox, view) {
  const onEditor = waitForStyleEditor(toolbox, "doc_sourcemaps.scss");

  info("Clicking the computedview stylesheet link");
  const link = getComputedViewLinkByIndex(view, 0);
  link.scrollIntoView();
  link.click();

  const editor = await onEditor;

  const { line } = editor.sourceEditor.getCursor();
  is(line, 3, "cursor is at correct line number in original source");
}

function verifyLinkText(view, text) {
  const link = getComputedViewLinkByIndex(view, 0);
  is(
    link.textContent,
    text,
    "Linked text changed to display the correct location"
  );
}