tor-browser

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

test_frame_01.html (9942B)


      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 the formatting of the file name, line and columns are correct in frame components,
      8 with optional columns, unknown and non-URL sources.
      9 -->
     10  <head>
     11    <meta charset="utf-8" />
     12    <title>Frame component test</title>
     13    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     14    <link
     15      rel="stylesheet"
     16      type="text/css"
     17      href="chrome://mochikit/content/tests/SimpleTest/test.css"
     18    />
     19  </head>
     20  <body>
     21    <pre id="test">
     22 <script src="head.js" type="application/javascript"></script>
     23 <script type="application/javascript">
     24 
     25 'use strict'
     26 
     27 window.onload = async function () {
     28  try {
     29    const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
     30    const React = browserRequire("devtools/client/shared/vendor/react");
     31    const Frame = React.createFactory(browserRequire("devtools/client/shared/components/Frame"));
     32    ok(Frame, "Should get Frame");
     33 
     34    // Check when there's a column
     35    await checkFrameComponent({
     36      frame: {
     37        source: "https://myfile.com/mahscripts.js",
     38        line: 55,
     39        column: 10,
     40      }
     41    }, {
     42      file: "mahscripts.js",
     43      line: 55,
     44      column: 10,
     45      shouldLink: true,
     46      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55:10",
     47    });
     48 
     49    // Check when there's no column
     50    await checkFrameComponent({
     51      frame: {
     52        source: "https://myfile.com/mahscripts.js",
     53        line: 55,
     54      }
     55    }, {
     56      file: "mahscripts.js",
     57      line: 55,
     58      shouldLink: true,
     59      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55",
     60    });
     61 
     62    // Check when column === 0
     63    await checkFrameComponent({
     64      frame: {
     65        source: "https://myfile.com/mahscripts.js",
     66        line: 55,
     67        column: 0,
     68      }
     69    }, {
     70      file: "mahscripts.js",
     71      line: 55,
     72      shouldLink: true,
     73      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55",
     74    });
     75 
     76    // Check when there's an error in CSS (View source in Style Editor)
     77    await checkFrameComponent({
     78      frame: {
     79        source: "https://myfile.com/cafebabe.css",
     80        line: 13,
     81      },
     82      messageSource: "css",
     83    }, {
     84        file: "cafebabe.css",
     85        line: 13,
     86        shouldLink: true,
     87        tooltip: "View source in Style Editor → https://myfile.com/cafebabe.css:13",
     88    });
     89 
     90 
     91    // Check when there's no parseable URL source;
     92    // should not link but should render line/columns
     93    await checkFrameComponent({
     94      frame: {
     95        source: "self-hosted",
     96        line: 1,
     97      }
     98    }, {
     99      file: "self-hosted",
    100      line: "1",
    101      shouldLink: false,
    102      tooltip: "self-hosted:1",
    103    });
    104    await checkFrameComponent({
    105      frame: {
    106        source: "self-hosted",
    107        line: 1,
    108        column: 10,
    109      }
    110    }, {
    111      file: "self-hosted",
    112      line: "1",
    113      column: "10",
    114      shouldLink: false,
    115      tooltip: "self-hosted:1:10",
    116    });
    117 
    118    // Check when there's no source;
    119    // should not link but should render line/columns
    120    await checkFrameComponent({
    121      frame: {
    122        line: 1,
    123      }
    124    }, {
    125      file: "(unknown)",
    126      line: "1",
    127      shouldLink: false,
    128      tooltip: "(unknown):1",
    129    });
    130    await checkFrameComponent({
    131      frame: {
    132        line: 1,
    133        column: 10,
    134      }
    135    }, {
    136      file: "(unknown)",
    137      line: "1",
    138      column: "10",
    139      shouldLink: false,
    140      tooltip: "(unknown):1:10",
    141    });
    142 
    143    // Check when there's a column, but no line;
    144    // no line/column info should render
    145    await checkFrameComponent({
    146      frame: {
    147        source: "https://myfile.com/mahscripts.js",
    148        column: 55,
    149      }
    150    }, {
    151      file: "mahscripts.js",
    152      shouldLink: true,
    153      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    154    });
    155 
    156    // Check when line is 0; this should be an invalid
    157    // line option, so don't render line/column
    158    await checkFrameComponent({
    159      frame: {
    160        source: "https://myfile.com/mahscripts.js",
    161        line: 0,
    162        column: 55,
    163      }
    164    }, {
    165      file: "mahscripts.js",
    166      shouldLink: true,
    167      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    168    });
    169 
    170    // Check that line and column can be strings
    171    await checkFrameComponent({
    172      frame: {
    173        source: "https://myfile.com/mahscripts.js",
    174        line: "10",
    175        column: "55",
    176      }
    177    }, {
    178      file: "mahscripts.js",
    179      line: 10,
    180      column: 55,
    181      shouldLink: true,
    182      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:10:55",
    183    });
    184 
    185    // Check that line and column can be strings,
    186    // and that the `0` rendering rules apply when they are strings as well
    187    await checkFrameComponent({
    188      frame: {
    189        source: "https://myfile.com/mahscripts.js",
    190        line: "0",
    191        column: "55",
    192      }
    193    }, {
    194      file: "mahscripts.js",
    195      shouldLink: true,
    196      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    197    });
    198 
    199    // Check that the showFullSourceUrl option works correctly
    200    await checkFrameComponent({
    201      frame: {
    202        source: "https://myfile.com/mahscripts.js",
    203        line: 0,
    204      },
    205      showFullSourceUrl: true
    206    }, {
    207      file: "https://myfile.com/mahscripts.js",
    208      shouldLink: true,
    209      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    210    });
    211 
    212    // Check that the showFunctionName option works correctly
    213    await checkFrameComponent({
    214      frame: {
    215        functionDisplayName: "myfun",
    216        source: "https://myfile.com/mahscripts.js",
    217        line: 0,
    218      }
    219    }, {
    220      functionName: null,
    221      file: "mahscripts.js",
    222      shouldLink: true,
    223      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    224    });
    225 
    226    await checkFrameComponent({
    227      frame: {
    228        functionDisplayName: "myfun",
    229        source: "https://myfile.com/mahscripts.js",
    230        line: 0,
    231      },
    232      showFunctionName: true
    233    }, {
    234      functionName: "myfun",
    235      file: "mahscripts.js",
    236      shouldLink: true,
    237      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    238    });
    239 
    240    // Check that anonymous function name is not displayed unless explicitly enabled
    241    await checkFrameComponent({
    242      frame: {
    243        source: "https://myfile.com/mahscripts.js",
    244        line: 0,
    245      },
    246      showFunctionName: true
    247    }, {
    248      functionName: null,
    249      file: "mahscripts.js",
    250      shouldLink: true,
    251      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    252    });
    253 
    254    await checkFrameComponent({
    255      frame: {
    256        source: "https://myfile.com/mahscripts.js",
    257        line: 0,
    258      },
    259      showFunctionName: true,
    260      showAnonymousFunctionName: true
    261    }, {
    262      functionName: "<anonymous>",
    263      file: "mahscripts.js",
    264      shouldLink: true,
    265      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    266    });
    267 
    268    // Check if file is rendered with "/" for root documents when showEmptyPathAsHost is false
    269    await checkFrameComponent({
    270      frame: {
    271        source: "https://www.cnn.com/",
    272        line: "1",
    273      },
    274      showEmptyPathAsHost: false,
    275    }, {
    276      file: "/",
    277      line: "1",
    278      shouldLink: true,
    279      tooltip: "View source in Debugger → https://www.cnn.com/:1",
    280    });
    281 
    282    // Check if file is rendered with hostname for root documents when showEmptyPathAsHost is true
    283    await checkFrameComponent({
    284      frame: {
    285        source: "https://www.cnn.com/",
    286        line: "1",
    287      },
    288      showEmptyPathAsHost: true,
    289    }, {
    290      file: "www.cnn.com",
    291      line: "1",
    292      shouldLink: true,
    293      tooltip: "View source in Debugger → https://www.cnn.com/:1",
    294    });
    295 
    296    const resolvedLocation = {
    297      sourceId: "whatever",
    298      line: 23,
    299      sourceUrl: "https://bugzilla.mozilla.org/original.js",
    300    };
    301    const mockSourceMapURLService = {
    302      subscribeByLocation (loc, callback) {
    303        // Resolve immediately.
    304        callback({
    305          url: resolvedLocation.sourceUrl,
    306          line: resolvedLocation.line,
    307          column: undefined,
    308        });
    309        return () => {};
    310      },
    311    };
    312    await checkFrameComponent({
    313      frame: {
    314        line: 97,
    315        source: "https://bugzilla.mozilla.org/bundle.js",
    316      },
    317      sourceMapURLService: mockSourceMapURLService,
    318    }, {
    319      file: "original.js",
    320      line: resolvedLocation.line,
    321      shouldLink: true,
    322      tooltip: "View source in Debugger → https://bugzilla.mozilla.org/original.js:23",
    323      source: "https://bugzilla.mozilla.org/original.js",
    324    });
    325 
    326    // Check when a message comes from a logPoint,
    327    // a prefix should render before source
    328    await checkFrameComponent({
    329      frame: {
    330        source: "https://myfile.com/mahscripts.js",
    331        line: 55,
    332        column: 10,
    333        options: { logPoint: true },
    334      }
    335    }, {
    336      file: "mahscripts.js",
    337      line: 55,
    338      column: 10,
    339      shouldLink: true,
    340      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55:10",
    341    });
    342 
    343    function checkFrameComponent(input, expected) {
    344      const props = Object.assign({ onClick: () => {} }, input);
    345      const frame = ReactDOM.render(Frame(props), window.document.body);
    346      const el = ReactDOM.findDOMNode(frame);
    347      const { source } = input.frame;
    348      checkFrameString(Object.assign({ el, source }, expected));
    349      ReactDOM.unmountComponentAtNode(window.document.body);
    350    }
    351 
    352  } catch (e) {
    353    ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
    354  } finally {
    355    SimpleTest.finish();
    356  }
    357 };
    358 </script>
    359 </pre>
    360  </body>
    361 </html>