11cb0ef41Sopenharmony_ci// If you're testing an API that constructs a PerformanceMark, add your test here.
21cb0ef41Sopenharmony_ci// See the for loop below for details.
31cb0ef41Sopenharmony_ciconst markConstructionTests = [
41cb0ef41Sopenharmony_ci  {
51cb0ef41Sopenharmony_ci    testName: "Number should be rejected as the mark-options.",
61cb0ef41Sopenharmony_ci    testFunction: function(newMarkFunction) {
71cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, function() { newMarkFunction("mark1", 123); }, "Number passed as a dict argument should cause type-error.");
81cb0ef41Sopenharmony_ci    },
91cb0ef41Sopenharmony_ci  },
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci  {
121cb0ef41Sopenharmony_ci    testName: "NaN should be rejected as the mark-options.",
131cb0ef41Sopenharmony_ci    testFunction: function(newMarkFunction) {
141cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, function() { newMarkFunction("mark1", NaN); }, "NaN passed as a dict argument should cause type-error.");
151cb0ef41Sopenharmony_ci    },
161cb0ef41Sopenharmony_ci  },
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  {
191cb0ef41Sopenharmony_ci    testName: "Infinity should be rejected as the mark-options.",
201cb0ef41Sopenharmony_ci    testFunction: function(newMarkFunction) {
211cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, function() { newMarkFunction("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error.");
221cb0ef41Sopenharmony_ci    },
231cb0ef41Sopenharmony_ci  },
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  {
261cb0ef41Sopenharmony_ci    testName: "String should be rejected as the mark-options.",
271cb0ef41Sopenharmony_ci    testFunction: function(newMarkFunction) {
281cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, function() { newMarkFunction("mark1", "string"); }, "String passed as a dict argument should cause type-error.")
291cb0ef41Sopenharmony_ci    },
301cb0ef41Sopenharmony_ci  },
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  {
331cb0ef41Sopenharmony_ci    testName: "Negative startTime in mark-options should be rejected",
341cb0ef41Sopenharmony_ci    testFunction: function(newMarkFunction) {
351cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, function() { newMarkFunction("mark1", {startTime: -1}); }, "Negative startTime should cause type-error.")
361cb0ef41Sopenharmony_ci    },
371cb0ef41Sopenharmony_ci  },
381cb0ef41Sopenharmony_ci];
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci// There are multiple function calls that can construct a mark using the same arguments so we run
411cb0ef41Sopenharmony_ci// each test on each construction method here, avoiding duplication.
421cb0ef41Sopenharmony_cifor (let testInfo of markConstructionTests) {
431cb0ef41Sopenharmony_ci  test(function() {
441cb0ef41Sopenharmony_ci    testInfo.testFunction(self.performance.mark);
451cb0ef41Sopenharmony_ci  }, `[performance.mark]: ${testInfo.testName}`);
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  test(function() {
481cb0ef41Sopenharmony_ci    testInfo.testFunction((markName, obj) => new PerformanceMark(markName, obj));
491cb0ef41Sopenharmony_ci  }, `[new PerformanceMark]: ${testInfo.testName}`);
501cb0ef41Sopenharmony_ci}
51