tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_frame_02.html (3205B)


      1 <!-- This Source Code Form is subject to the terms of the Mozilla Public
      2   - License, v. 2.0. If a copy of the MPL was not distributed with this
      3   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
      4 <!DOCTYPE HTML>
      5 <html>
      6 <!--
      7 Test that the frame component reacts to source-map pref changse.
      8 -->
      9 <head>
     10  <meta charset="utf-8">
     11  <title>Frame component source-map test</title>
     12  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     13  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
     14 </head>
     15 <body>
     16 <pre id="test">
     17 <script src="head.js" type="application/javascript"></script>
     18 <script type="application/javascript">
     19 
     20 'use strict'
     21 
     22 window.onload = async function () {
     23  try {
     24    const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
     25    const React = browserRequire("devtools/client/shared/vendor/react");
     26    const Frame = React.createFactory(browserRequire("devtools/client/shared/components/Frame"));
     27 
     28    const resolvedLocation = {
     29      sourceId: "whatever",
     30      line: 23,
     31      sourceUrl: "https://bugzilla.mozilla.org/original.js",
     32    };
     33    const mockSourceMapURLService = {
     34      _update () {
     35        this._callback(Services.prefs.getBoolPref(PREF)
     36          ? {
     37              url: resolvedLocation.sourceUrl,
     38              line: resolvedLocation.line,
     39              column: undefined,
     40            }
     41          : null);
     42      },
     43      subscribeByLocation (loc, callback) {
     44        this._callback = callback;
     45        // Resolve immediately.
     46        this._update();
     47 
     48        return () => {};
     49      },
     50    };
     51 
     52    const props = {
     53      onClick: () => {},
     54      frame: {
     55        line: 97,
     56        source: "https://bugzilla.mozilla.org/bundle.js",
     57      },
     58      sourceMapURLService: mockSourceMapURLService,
     59    };
     60 
     61    const PREF = "devtools.source-map.client-service.enabled";
     62    Services.prefs.setBoolPref(PREF, false);
     63 
     64    const frame = ReactDOM.render(Frame(props), window.document.body);
     65    const el = ReactDOM.findDOMNode(frame);
     66    const { source } = props.frame;
     67 
     68    const expectedOriginal = {
     69      file: "original.js",
     70      line: resolvedLocation.line,
     71      shouldLink: true,
     72      tooltip: "View source in Debugger → https://bugzilla.mozilla.org/original.js:23",
     73      source: "https://bugzilla.mozilla.org/original.js",
     74    };
     75    const expectedGenerated = {
     76      file: "bundle.js",
     77      line: 97,
     78      shouldLink: true,
     79      tooltip: "View source in Debugger → https://bugzilla.mozilla.org/bundle.js:97",
     80      source: "https://bugzilla.mozilla.org/bundle.js",
     81    };
     82 
     83    checkFrameString(Object.assign({ el, source }, expectedGenerated));
     84 
     85    Services.prefs.setBoolPref(PREF, true);
     86    mockSourceMapURLService._update();
     87    checkFrameString(Object.assign({ el, source }, expectedOriginal));
     88 
     89    Services.prefs.setBoolPref(PREF, false);
     90    mockSourceMapURLService._update();
     91    checkFrameString(Object.assign({ el, source }, expectedGenerated));
     92 
     93    Services.prefs.clearUserPref(PREF);
     94  } catch (e) {
     95    ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
     96  } finally {
     97    SimpleTest.finish();
     98  }
     99 };
    100 </script>
    101 </pre>
    102 </body>
    103 </html>