summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser
diff options
context:
space:
mode:
Diffstat (limited to 'dom/tests/browser')
-rwxr-xr-x[-rw-r--r--]dom/tests/browser/browser.ini2
-rwxr-xr-xdom/tests/browser/browser_performanceAPI.js139
-rwxr-xr-xdom/tests/browser/file_workerPerformance.js65
3 files changed, 206 insertions, 0 deletions
diff --git a/dom/tests/browser/browser.ini b/dom/tests/browser/browser.ini
index 35ebd56c6..4d3a60a2c 100644..100755
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -8,6 +8,7 @@ support-files =
worker_bug1004814.js
geo_leak_test.html
dummy.html
+ file_workerPerformance.js
test_largeAllocation.html
test_largeAllocation.html^headers^
!/dom/tests/mochitest/geolocation/network_geolocation.sjs
@@ -44,3 +45,4 @@ support-files =
support-files =
test_new_window_from_content_child.html
[browser_xhr_sandbox.js]
+[browser_performanceAPI.js]
diff --git a/dom/tests/browser/browser_performanceAPI.js b/dom/tests/browser/browser_performanceAPI.js
new file mode 100755
index 000000000..2c28fe3d1
--- /dev/null
+++ b/dom/tests/browser/browser_performanceAPI.js
@@ -0,0 +1,139 @@
+/**
+ * Bug 1369303 - A test for making sure that performance APIs have been correctly
+ * spoofed or disabled.
+ */
+
+const TEST_PATH = "http://example.net/browser/" +
+ "dom/tests/browser/";
+
+const PERFORMANCE_TIMINGS = [
+ "navigationStart",
+ "unloadEventStart",
+ "unloadEventEnd",
+ "redirectStart",
+ "redirectEnd",
+ "fetchStart",
+ "domainLookupStart",
+ "domainLookupEnd",
+ "connectStart",
+ "connectEnd",
+ "requestStart",
+ "responseStart",
+ "responseEnd",
+ "domLoading",
+ "domInteractive",
+ "domContentLoadedEventStart",
+ "domContentLoadedEventEnd",
+ "domComplete",
+ "loadEventStart",
+ "loadEventEnd",
+];
+
+let isRounded = (x, expectedPrecision) => {
+ let rounded = (Math.floor(x / expectedPrecision) * expectedPrecision);
+ // First we do the perfectly normal check that should work just fine
+ if (rounded === x || x === 0)
+ return true;
+
+ // When we're diving by non-whole numbers, we may not get perfect
+ // multiplication/division because of floating points
+ if (Math.abs(rounded - x + expectedPrecision) < .0000001) {
+ return true;
+ } else if (Math.abs(rounded - x) < .0000001) {
+ return true;
+ }
+
+ // Then we handle the case where you're sub-millisecond and the timer is not
+ // We check that the timer is not sub-millisecond by assuming it is not if it
+ // returns an even number of milliseconds
+ if (expectedPrecision < 1 && Math.round(x) == x) {
+ if (Math.round(rounded) == x) {
+ return true;
+ }
+ }
+
+ ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
+ " Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) +
+ " Fuzzy 2: " + Math.abs(rounded - x));
+
+ return false;
+};
+
+// ================================================================================================
+// ================================================================================================
+add_task(function* () {
+ let tab = yield BrowserTestUtils.openNewForegroundTab(
+ gBrowser, TEST_PATH + "dummy.html");
+
+ yield ContentTask.spawn(tab.linkedBrowser, {
+ list: PERFORMANCE_TIMINGS,
+ precision: 2,
+ isRoundedFunc: isRounded.toString()
+ }, (data) => {
+ let timerlist = data.list;
+ let expectedPrecision = data.precision;
+ // eslint beleives that isrounded is available in this scope, but if you
+ // remove the assignment, you will see it is not
+ // eslint-disable-next-line
+ let isRounded = eval(data.isRoundedFunc);
+
+ // Check that whether the performance timing API is correctly spoofed.
+ for (let time of timerlist) {
+ ok(isRounded(content.performance.timing[time], expectedPrecision), `For reduceTimerPrecision(` + expectedPrecision + `), the timing(${time}) is not correctly rounded: ` + content.performance.timing[time]);
+ }
+
+ // Try to add some entries.
+ content.performance.mark("Test");
+ content.performance.mark("Test-End");
+ content.performance.measure("Test-Measure", "Test", "Test-End");
+
+ // Check the entries for performance.getEntries/getEntriesByType/getEntriesByName.
+ is(content.performance.getEntries().length, 3, "For reduceTimerPrecision, there should be 3 entries for performance.getEntries()");
+ for (var i = 0; i < 3; i++) {
+ let startTime = content.performance.getEntries()[i].startTime;
+ let duration = content.performance.getEntries()[i].duration;
+ ok(isRounded(startTime, expectedPrecision), "For reduceTimerPrecision(" + expectedPrecision + "), performance.getEntries(" + i + ").startTime is not rounded: " + startTime);
+ ok(isRounded(duration, expectedPrecision), "For reduceTimerPrecision(" + expectedPrecision + "), performance.getEntries(" + i + ").duration is not rounded: " + duration);
+ }
+ is(content.performance.getEntriesByType("mark").length, 2, "For reduceTimerPrecision, there should be 2 entries for performance.getEntriesByType()");
+ is(content.performance.getEntriesByName("Test", "mark").length, 1, "For reduceTimerPrecision, there should be 1 entry for performance.getEntriesByName()");
+ content.performance.clearMarks();
+ content.performance.clearMeasures();
+ content.performance.clearResourceTimings();
+ });
+ gBrowser.removeTab(tab);
+});
+
+// ================================================================================================
+// ================================================================================================
+add_task(function*() {
+ let tab = yield BrowserTestUtils.openNewForegroundTab(
+ gBrowser, TEST_PATH + "dummy.html");
+
+ yield ContentTask.spawn(tab.linkedBrowser, {
+ list: PERFORMANCE_TIMINGS,
+ precision: 2,
+ isRoundedFunc: isRounded.toString()
+ }, (data) => {
+ let expectedPrecision = data.precision;
+ let workerCall = data.workerCall;
+ return new Promise(resolve => {
+ let worker = new content.Worker("file_workerPerformance.js");
+ worker.onmessage = function(e) {
+ if (e.data.type == "status") {
+ ok(e.data.status, e.data.msg);
+ } else if (e.data.type == "finish") {
+ worker.terminate();
+ resolve();
+ } else {
+ ok(false, "Unknown message type");
+ worker.terminate();
+ resolve();
+ }
+ };
+ worker.postMessage({precision: expectedPrecision});
+ });
+ });
+
+ gBrowser.removeTab(tab);
+});
diff --git a/dom/tests/browser/file_workerPerformance.js b/dom/tests/browser/file_workerPerformance.js
new file mode 100755
index 000000000..c77ba4377
--- /dev/null
+++ b/dom/tests/browser/file_workerPerformance.js
@@ -0,0 +1,65 @@
+function ok(a, msg) {
+ postMessage({type: "status", status: !!a, msg});
+}
+
+function is(a, b, msg) {
+ ok(a === b, msg);
+}
+
+function finish() {
+ postMessage({type: "finish"});
+}
+
+let isRounded = (x, expectedPrecision) => {
+ let rounded = (Math.floor(x / expectedPrecision) * expectedPrecision);
+ // First we do the perfectly normal check that should work just fine
+ if (rounded === x || x === 0)
+ return true;
+
+ // When we're diving by non-whole numbers, we may not get perfect
+ // multiplication/division because of floating points
+ if (Math.abs(rounded - x + expectedPrecision) < .0000001) {
+ return true;
+ } else if (Math.abs(rounded - x) < .0000001) {
+ return true;
+ }
+
+ // Then we handle the case where you're sub-millisecond and the timer is not
+ // We check that the timer is not sub-millisecond by assuming it is not if it
+ // returns an even number of milliseconds
+ if (expectedPrecision < 1 && Math.round(x) == x) {
+ if (Math.round(rounded) == x) {
+ return true;
+ }
+ }
+
+ ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
+ " Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) +
+ " Fuzzy 2: " + Math.abs(rounded - x));
+
+ return false;
+};
+
+function runRTPTests(expectedPrecision) {
+ // Try to add some entries.
+ performance.mark("Test");
+ performance.mark("Test-End");
+ performance.measure("Test-Measure", "Test", "Test-End");
+
+ // Check the entries in performance.getEntries/getEntriesByType/getEntriesByName.
+ is(performance.getEntries().length, 3, "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntries() for workers: " + performance.getEntries().length);
+ for (var i = 0; i < 3; i++) {
+ let startTime = performance.getEntries()[i].startTime;
+ let duration = performance.getEntries()[i].duration;
+ ok(isRounded(startTime, expectedPrecision), "In a worker, for reduceTimerPrecision(" + expectedPrecision + "), performance.getEntries(" + i.toString() + ").startTime is not rounded: " + startTime.toString());
+ ok(isRounded(duration, expectedPrecision), "In a worker, for reduceTimerPrecision(" + expectedPrecision + "), performance.getEntries(" + i.toString() + ").duration is not rounded: " + duration.toString());
+ }
+ is(performance.getEntriesByType("mark").length, 2, "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntriesByType() for workers: " + performance.getEntriesByType("resource").length);
+ is(performance.getEntriesByName("Test", "mark").length, 1, "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntriesByName() for workers: " + performance.getEntriesByName("Test", "mark").length);
+
+ finish();
+}
+
+self.onmessage = function(e) {
+ runRTPTests(e.data.precision);
+};