tor-browser

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

test_performance_user_timing.js (12068B)


      1 var steps = [
      2  // Test single mark addition
      3  function () {
      4    ok(true, "Running mark addition test");
      5    performance.mark("test");
      6    var marks = performance.getEntriesByType("mark");
      7    is(marks.length, 1, "Number of marks should be 1");
      8    var mark = marks[0];
      9    is(mark.name, "test", "mark name should be 'test'");
     10    is(mark.entryType, "mark", "mark type should be 'mark'");
     11    isnot(mark.startTime, 0, "mark start time should not be 0");
     12    is(mark.duration, 0, "mark duration should be 0");
     13  },
     14  // Test multiple mark addition
     15  function () {
     16    ok(true, "Running multiple mark with same name addition test");
     17    performance.mark("test");
     18    performance.mark("test");
     19    performance.mark("test");
     20    var marks_type = performance.getEntriesByType("mark");
     21    is(marks_type.length, 3, "Number of marks by type should be 3");
     22    var marks_name = performance.getEntriesByName("test");
     23    is(marks_name.length, 3, "Number of marks by name should be 3");
     24    var mark = marks_name[0];
     25    is(mark.name, "test", "mark name should be 'test'");
     26    is(mark.entryType, "mark", "mark type should be 'mark'");
     27    isnot(mark.startTime, 0, "mark start time should not be 0");
     28    is(mark.duration, 0, "mark duration should be 0");
     29    var times = [];
     30    // This also tests the chronological ordering specified as
     31    // required for getEntries in the performance timeline spec.
     32    marks_name.forEach(function (s) {
     33      times.forEach(function (time) {
     34        ok(
     35          s.startTime >= time.startTime,
     36          "Times should be equal or increasing between similarly named marks: " +
     37            s.startTime +
     38            " >= " +
     39            time.startTime
     40        );
     41      });
     42      times.push(s);
     43    });
     44  },
     45  // Test all marks removal
     46  function () {
     47    ok(true, "Running all mark removal test");
     48    performance.mark("test");
     49    performance.mark("test2");
     50    var marks = performance.getEntriesByType("mark");
     51    is(marks.length, 2, "number of marks before all removal");
     52    performance.clearMarks();
     53    marks = performance.getEntriesByType("mark");
     54    is(marks.length, 0, "number of marks after all removal");
     55  },
     56  // Test single mark removal
     57  function () {
     58    ok(true, "Running removal test (0 'test' marks with other marks)");
     59    performance.mark("test2");
     60    var marks = performance.getEntriesByType("mark");
     61    is(marks.length, 1, "number of marks before all removal");
     62    performance.clearMarks("test");
     63    marks = performance.getEntriesByType("mark");
     64    is(marks.length, 1, "number of marks after all removal");
     65  },
     66  // Test single mark removal
     67  function () {
     68    ok(true, "Running removal test (0 'test' marks with no other marks)");
     69    var marks = performance.getEntriesByType("mark");
     70    is(marks.length, 0, "number of marks before all removal");
     71    performance.clearMarks("test");
     72    marks = performance.getEntriesByType("mark");
     73    is(marks.length, 0, "number of marks after all removal");
     74  },
     75  function () {
     76    ok(true, "Running removal test (1 'test' mark with other marks)");
     77    performance.mark("test");
     78    performance.mark("test2");
     79    var marks = performance.getEntriesByType("mark");
     80    is(marks.length, 2, "number of marks before all removal");
     81    performance.clearMarks("test");
     82    marks = performance.getEntriesByType("mark");
     83    is(marks.length, 1, "number of marks after all removal");
     84  },
     85  function () {
     86    ok(true, "Running removal test (1 'test' mark with no other marks)");
     87    performance.mark("test");
     88    var marks = performance.getEntriesByType("mark");
     89    is(marks.length, 1, "number of marks before all removal");
     90    performance.clearMarks("test");
     91    marks = performance.getEntriesByType("mark");
     92    is(marks.length, 0, "number of marks after all removal");
     93  },
     94  function () {
     95    ok(true, "Running removal test (2 'test' marks with other marks)");
     96    performance.mark("test");
     97    performance.mark("test");
     98    performance.mark("test2");
     99    var marks = performance.getEntriesByType("mark");
    100    is(marks.length, 3, "number of marks before all removal");
    101    performance.clearMarks("test");
    102    marks = performance.getEntriesByType("mark");
    103    is(marks.length, 1, "number of marks after all removal");
    104  },
    105  function () {
    106    ok(true, "Running removal test (2 'test' marks with no other marks)");
    107    performance.mark("test");
    108    performance.mark("test");
    109    var marks = performance.getEntriesByType("mark");
    110    is(marks.length, 2, "number of marks before all removal");
    111    performance.clearMarks("test");
    112    marks = performance.getEntriesByType("mark");
    113    is(marks.length, 0, "number of marks after all removal");
    114  },
    115  // Test mark name being same as navigation timing parameter
    116  function () {
    117    ok(true, "Running mark name collision test");
    118    for (n in performance.timing) {
    119      try {
    120        if (n == "toJSON") {
    121          ok(true, "Skipping toJSON entry in collision test");
    122          continue;
    123        }
    124        performance.mark(n);
    125        ok(
    126          false,
    127          "Mark name collision test failed for name " +
    128            n +
    129            ", shouldn't make it here!"
    130        );
    131      } catch (e) {
    132        ok(
    133          e instanceof DOMException,
    134          "DOM exception thrown for mark named " + n
    135        );
    136        is(
    137          e.code,
    138          e.SYNTAX_ERR,
    139          "DOM exception for name collision is syntax error"
    140        );
    141      }
    142    }
    143  },
    144  // Test measure
    145  function () {
    146    ok(true, "Running measure addition with no start/end time test");
    147    performance.measure("test");
    148    var measures = performance.getEntriesByType("measure");
    149    is(measures.length, 1, "number of measures should be 1");
    150    var measure = measures[0];
    151    is(measure.name, "test", "measure name should be 'test'");
    152    is(measure.entryType, "measure", "measure type should be 'measure'");
    153    is(measure.startTime, 0, "measure start time should be zero");
    154    ok(measure.duration >= 0, "measure duration should not be negative");
    155  },
    156  function () {
    157    ok(true, "Running measure addition with only start time test");
    158    performance.mark("test1");
    159    performance.measure("test", "test1", undefined);
    160    var measures = performance.getEntriesByName("test", "measure");
    161    var marks = performance.getEntriesByName("test1", "mark");
    162    var measure = measures[0];
    163    var mark = marks[0];
    164    is(
    165      measure.startTime,
    166      mark.startTime,
    167      "measure start time should be equal to the mark startTime"
    168    );
    169    ok(measure.duration >= 0, "measure duration should not be negative");
    170  },
    171  function () {
    172    ok(true, "Running measure addition with only end time test");
    173    performance.mark("test1");
    174    performance.measure("test", undefined, "test1");
    175    var measures = performance.getEntriesByName("test", "measure");
    176    var marks = performance.getEntriesByName("test1", "mark");
    177    var measure = measures[0];
    178    var mark = marks[0];
    179    ok(measure.duration >= 0, "measure duration should not be negative");
    180  },
    181  // Test measure picking latest version of similarly named tags
    182  function () {
    183    ok(true, "Running multiple mark with same name addition test");
    184    performance.mark("test");
    185    performance.mark("test");
    186    performance.mark("test");
    187    performance.mark("test2");
    188    var marks_name = performance.getEntriesByName("test");
    189    is(marks_name.length, 3, "Number of marks by name should be 3");
    190    var marks_name2 = performance.getEntriesByName("test2");
    191    is(marks_name2.length, 1, "Number of marks by name should be 1");
    192    var test_mark = marks_name2[0];
    193    performance.measure("test", "test", "test2");
    194    var measures_type = performance.getEntriesByType("measure");
    195    var last_mark = marks_name[marks_name.length - 1];
    196    is(measures_type.length, 1, "Number of measures by type should be 1");
    197    var measure = measures_type[0];
    198    is(
    199      measure.startTime,
    200      last_mark.startTime,
    201      "Measure start time should be the start time of the latest 'test' mark"
    202    );
    203    // Tolerance testing to avoid oranges, since we're doing double math across two different languages.
    204    ok(
    205      measure.duration - (test_mark.startTime - last_mark.startTime) < 0.00001,
    206      "Measure duration ( " +
    207        measure.duration +
    208        ") should be difference between two marks"
    209    );
    210  },
    211  function () {
    212    // We don't have navigationStart in workers.
    213    if ("window" in self) {
    214      ok(true, "Running measure addition with no start/end time test");
    215      performance.measure("test", "navigationStart");
    216      var measures = performance.getEntriesByType("measure");
    217      is(measures.length, 1, "number of measures should be 1");
    218      var measure = measures[0];
    219      is(measure.name, "test", "measure name should be 'test'");
    220      is(measure.entryType, "measure", "measure type should be 'measure'");
    221      is(measure.startTime, 0, "measure start time should be zero");
    222      ok(measure.duration >= 0, "measure duration should not be negative");
    223    }
    224  },
    225  // Test all measure removal
    226  function () {
    227    ok(true, "Running all measure removal test");
    228    performance.measure("test");
    229    performance.measure("test2");
    230    var measures = performance.getEntriesByType("measure");
    231    is(measures.length, 2, "measure entries should be length 2");
    232    performance.clearMeasures();
    233    measures = performance.getEntriesByType("measure");
    234    is(measures.length, 0, "measure entries should be length 0");
    235  },
    236  // Test single measure removal
    237  function () {
    238    ok(true, "Running all measure removal test");
    239    performance.measure("test");
    240    performance.measure("test2");
    241    var measures = performance.getEntriesByType("measure");
    242    is(measures.length, 2, "measure entries should be length 2");
    243    performance.clearMeasures("test");
    244    measures = performance.getEntriesByType("measure");
    245    is(measures.length, 1, "measure entries should be length 1");
    246  },
    247  // Test measure with invalid start time mark name
    248  function () {
    249    ok(true, "Running measure invalid start test");
    250    try {
    251      performance.measure("test", "notamark");
    252      ok(false, "invalid measure start time exception not thrown!");
    253    } catch (e) {
    254      ok(e instanceof DOMException, "DOM exception thrown for invalid measure");
    255      is(
    256        e.code,
    257        e.SYNTAX_ERR,
    258        "DOM exception for invalid time is syntax error"
    259      );
    260    }
    261  },
    262  // Test measure with invalid end time mark name
    263  function () {
    264    ok(true, "Running measure invalid end test");
    265    try {
    266      performance.measure("test", undefined, "notamark");
    267      ok(false, "invalid measure end time exception not thrown!");
    268    } catch (e) {
    269      ok(e instanceof DOMException, "DOM exception thrown for invalid measure");
    270      is(
    271        e.code,
    272        e.SYNTAX_ERR,
    273        "DOM exception for invalid time is syntax error"
    274      );
    275    }
    276  },
    277  // Test measure name being same as navigation timing parameter
    278  function () {
    279    ok(true, "Running measure name collision test");
    280    for (n in performance.timing) {
    281      if (n == "toJSON") {
    282        ok(true, "Skipping toJSON entry in collision test");
    283        continue;
    284      }
    285      performance.measure(n);
    286      ok(true, "Measure name supports name collisions: " + n);
    287    }
    288  },
    289  // Test measure mark being a reserved name
    290  function () {
    291    ok(true, "Create measures using all reserved names");
    292    for (n in performance.timing) {
    293      try {
    294        if (n == "toJSON") {
    295          ok(true, "Skipping toJSON entry in collision test");
    296          continue;
    297        }
    298        performance.measure("test", n);
    299        ok(true, "Measure created from reserved name as starting time: " + n);
    300      } catch (e) {
    301        ok(
    302          [
    303            "redirectStart",
    304            "redirectEnd",
    305            "unloadEventStart",
    306            "unloadEventEnd",
    307            "loadEventEnd",
    308            "secureConnectionStart",
    309          ].includes(n),
    310          "Measure created from reserved name as starting time: " +
    311            n +
    312            " and threw expected error"
    313        );
    314      }
    315    }
    316  },
    317  // TODO: Test measure picking latest version of similarly named tags
    318 ];