Bug 1372261 - Make tps Talos test use the performance timing API instead of Date.now() to avoid clock skew. r?jmaher draft
authorMike Conley <mconley@mozilla.com>
Fri, 30 Jun 2017 01:32:25 -0400
changeset 606165 a4e91062bde0ec8e0179b3374456825430afc05c
parent 606124 91c943f7373722ad4e122d98a2ddd6c79708b732
child 606166 1969c6320f7b85b529338d47908b63cb07566f51
push id67628
push usermconley@mozilla.com
push dateMon, 10 Jul 2017 15:01:34 +0000
reviewersjmaher
bugs1372261
milestone56.0a1
Bug 1372261 - Make tps Talos test use the performance timing API instead of Date.now() to avoid clock skew. r?jmaher MozReview-Commit-ID: CPzaN7T5fJV
testing/talos/talos/tests/tabswitch/bootstrap.js
--- a/testing/talos/talos/tests/tabswitch/bootstrap.js
+++ b/testing/talos/talos/tests/tabswitch/bootstrap.js
@@ -160,19 +160,18 @@ function loadTPSContentScript(browser) {
       let cwu = content.QueryInterface(Ci.nsIInterfaceRequestor)
                        .getInterface(Ci.nsIDOMWindowUtils);
       let lastTransactionId = cwu.lastTransactionId;
       Services.profiler.AddMarker("Content waiting for id > " + lastTransactionId);
       addEventListener("MozAfterPaint", function onPaint(event) {
         Services.profiler.AddMarker("Content saw transaction id: " + event.transactionId);
         if (event.transactionId > lastTransactionId) {
           Services.profiler.AddMarker("Content saw correct MozAfterPaint");
-          sendAsyncMessage("TPS:ContentSawPaint", {
-            time: Date.now().valueOf(),
-          });
+          let time = Math.floor(content.performance.timing.navigationStart + content.performance.now());
+          sendAsyncMessage("TPS:ContentSawPaint", { time });
           removeEventListener("MozAfterPaint", onPaint);
         }
       });
 
       sendAsyncMessage("TPS:ContentReady");
     };
 
     let mm = browser.messageManager;
@@ -187,30 +186,31 @@ function loadTPSContentScript(browser) {
 /**
  * For some <xul:tab> in a browser window, have that window switch
  * to that tab. Returns a Promise that resolves ones the tab content
  * has been presented to the user.
  */
 function switchToTab(tab) {
   let browser = tab.linkedBrowser;
   let gBrowser = tab.ownerGlobal.gBrowser;
+  let window = tab.ownerGlobal;
 
   // Single-process tab switching works quite differently from
   // multi-process tab switching. In the single-process case, tab
   // switching is synchronous, whereas in the multi-process case,
   // it is not. The following two tab switching mechanisms encapsulate
   // those two differences.
 
   if (browser.isRemoteBrowser) {
     return Task.spawn(function*() {
       // The multi-process case requires that we load our utility script
       // inside the content, since it's the content that will hear a MozAfterPaint
       // once the content is presented to the user.
       yield loadTPSContentScript(browser);
-      let start = Date.now().valueOf();
+      let start = Math.floor(window.performance.timing.navigationStart + window.performance.now());
       TalosParentProfiler.resume("start (" + start + "): " + browser.currentURI.spec);
 
       // We need to wait for the TabSwitchDone event to make sure
       // that the async tab switcher has shut itself down.
       let switchDone = waitForTabSwitchDone(browser);
       // Set up our promise that will wait for the content to be
       // presented.
       let finishPromise = waitForContentPresented(browser);
@@ -224,17 +224,17 @@ function switchToTab(tab) {
     });
   }
 
   return Task.spawn(function*() {
     let win = browser.ownerGlobal;
     let winUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
                       .getInterface(Ci.nsIDOMWindowUtils);
 
-    let start = Date.now().valueOf();
+    let start = Math.floor(window.performance.timing.navigationStart + window.performance.now());
     TalosParentProfiler.resume("start (" + start + "): " + browser.currentURI.spec);
 
     // There is no async tab switcher for the single-process case,
     // but tabbrowser.xml will still fire this once the updateCurrentBrowser
     // method runs.
     let switchDone = waitForTabSwitchDone(browser);
     // Do our tab switch
     gBrowser.selectedTab = tab;
@@ -313,17 +313,18 @@ function waitForContentPresented(browser
   return new Promise((resolve) => {
     let win = browser.ownerGlobal;
     win.addEventListener("MozAfterPaint", function onPaint(event) {
       if (event instanceof Ci.nsIDOMNotifyPaintEvent) {
         TalosParentProfiler.mark("Content saw transaction id: " + event.transactionId);
         if (event.transactionId > lastTransactionId) {
           win.removeEventListener("MozAfterPaint", onPaint);
           TalosParentProfiler.mark("Content saw MozAfterPaint");
-          resolve(Date.now().valueOf());
+          let time = Math.floor(win.performance.timing.navigationStart + win.performance.now());
+          resolve(time);
         }
       }
     });
   });
 }
 
 /**
  * Given some browser, do a garbage collect in the parent, and then