summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/source-map-loader/test/browser/browser_source-map.js
blob: 34d4fedf27d407bc1d8a8e639fdbfb50b1f274fc (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Cover the high level API of these modules:
// getOriginalURLs getGeneratedRangesForOriginal functions

async function assertFixtureOriginalURLs(
  fixtureName,
  expectedUrls,
  testMessage
) {
  const originalSources = await fetchFixtureSourceMap(fixtureName);
  const urls = originalSources.map(s => s.url);
  Assert.deepEqual(urls, expectedUrls, testMessage);
}

add_task(async function testGetOriginalURLs() {
  await assertFixtureOriginalURLs(
    "absolute",
    ["https://example.com/cheese/heart.js"],
    "Test absolute URL"
  );

  await assertFixtureOriginalURLs(
    "bundle",
    [
      "webpack:///webpack/bootstrap%204ef8c7ec7c1df790781e",
      "webpack:///entry.js",
      "webpack:///times2.js",
      "webpack:///output.js",
      "webpack:///opts.js",
    ],
    "Test source with a url"
  );

  await assertFixtureOriginalURLs(
    "empty",
    [`${URL_ROOT_SSL}fixtures/heart.js`],
    "Test empty sourceRoot resolution"
  );

  await assertFixtureOriginalURLs(
    "noroot",
    [`${URL_ROOT_SSL}fixtures/heart.js`],
    "Test Non-existing sourceRoot resolution"
  );

  await assertFixtureOriginalURLs(
    "noroot2",
    [`${URL_ROOT_SSL}fixtures/heart.js`],
    "Test Non-existing sourceRoot resolution with relative URLs"
  );
});

add_task(async function testGetGeneratedRangesForOriginal() {
  const originals = await fetchFixtureSourceMap("intermingled-sources");

  const ranges = await gSourceMapLoader.getGeneratedRangesForOriginal(
    originals[0].id
  );

  Assert.deepEqual(
    ranges,
    [
      {
        start: {
          line: 4,
          column: 69,
        },
        end: {
          line: 9,
          column: Infinity,
        },
      },
      {
        start: {
          line: 11,
          column: 0,
        },
        end: {
          line: 17,
          column: 3,
        },
      },
      {
        start: {
          line: 19,
          column: 18,
        },
        end: {
          line: 19,
          column: 22,
        },
      },
      {
        start: {
          line: 26,
          column: 0,
        },
        end: {
          line: 26,
          column: Infinity,
        },
      },
      {
        start: {
          line: 28,
          column: 0,
        },
        end: {
          line: 28,
          column: Infinity,
        },
      },
    ],
    "Test the overall generated ranges on the source"
  );

  {
    // Note that we have to clear the source map in order to get the merged ranges,
    // otherwise we are still fetching the previous unmerged ones!
    const secondOriginals = await fetchFixtureSourceMap("intermingled-sources");
    const mergedRanges = await gSourceMapLoader.getGeneratedRangesForOriginal(
      secondOriginals[0].id,
      true
    );

    Assert.deepEqual(
      mergedRanges,
      [
        {
          start: {
            line: 4,
            column: 69,
          },
          end: {
            line: 28,
            column: Infinity,
          },
        },
      ],
      "Test the merged generated ranges on the source"
    );
  }
});

add_task(async function testBaseURLErrorHandling() {
  const source = {
    id: "missingmap.js",
    sourceMapURL: "missingmap.js.map",
    // Notice the duplicated ":" which cause the error here
    sourceMapBaseURL: "http:://example.com/",
  };

  try {
    await gSourceMapLoader.getOriginalURLs(source);
    ok(false, "Should throw");
  } catch (e) {
    is(e.message, "URL constructor: http:://example.com/ is not a valid URL.");
  }
});