tor-browser

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

mark-errors.any.js (2009B)


      1 // If you're testing an API that constructs a PerformanceMark, add your test here.
      2 // See the for loop below for details.
      3 const markConstructionTests = [
      4  {
      5    testName: "Number should be rejected as the mark-options.",
      6    testFunction: function(newMarkFunction) {
      7      assert_throws_js(TypeError, function() { newMarkFunction("mark1", 123); }, "Number passed as a dict argument should cause type-error.");
      8    },
      9  },
     10 
     11  {
     12    testName: "NaN should be rejected as the mark-options.",
     13    testFunction: function(newMarkFunction) {
     14      assert_throws_js(TypeError, function() { newMarkFunction("mark1", NaN); }, "NaN passed as a dict argument should cause type-error.");
     15    },
     16  },
     17 
     18  {
     19    testName: "Infinity should be rejected as the mark-options.",
     20    testFunction: function(newMarkFunction) {
     21      assert_throws_js(TypeError, function() { newMarkFunction("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error.");
     22    },
     23  },
     24 
     25  {
     26    testName: "String should be rejected as the mark-options.",
     27    testFunction: function(newMarkFunction) {
     28      assert_throws_js(TypeError, function() { newMarkFunction("mark1", "string"); }, "String passed as a dict argument should cause type-error.")
     29    },
     30  },
     31 
     32  {
     33    testName: "Negative startTime in mark-options should be rejected",
     34    testFunction: function(newMarkFunction) {
     35      assert_throws_js(TypeError, function() { newMarkFunction("mark1", {startTime: -1}); }, "Negative startTime should cause type-error.")
     36    },
     37  },
     38 ];
     39 
     40 // There are multiple function calls that can construct a mark using the same arguments so we run
     41 // each test on each construction method here, avoiding duplication.
     42 for (let testInfo of markConstructionTests) {
     43  test(function() {
     44    testInfo.testFunction(self.performance.mark);
     45  }, `[performance.mark]: ${testInfo.testName}`);
     46 
     47  test(function() {
     48    testInfo.testFunction((markName, obj) => new PerformanceMark(markName, obj));
     49  }, `[new PerformanceMark]: ${testInfo.testName}`);
     50 }