Bug 1189901: part 1: remove code redundancy between tscrollx and tp5o_scroll. r=jmaher
authorAvi Halachmi <avihpit@yahoo.com>
Thu, 29 Sep 2016 21:00:21 +0300
changeset 315861 4cb1b2ae58c0ad71fb41c095b4bf09947da0fb51
parent 315860 14d41b959f3a21fb40c49fa66dc1c7b23642afe8
child 315862 f8719709d98a121fbd36242098026aa0031b303f
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1189901
milestone52.0a1
Bug 1189901: part 1: remove code redundancy between tscrollx and tp5o_scroll. r=jmaher
testing/talos/talos/pageloader/chrome/tscroll.js
testing/talos/talos/tests/scroll/iframe.svg
testing/talos/talos/tests/scroll/reader.htm
testing/talos/talos/tests/scroll/scroll-test.js
testing/talos/talos/tests/scroll/scroll.js
testing/talos/talos/tests/scroll/tiled-downscale.html
testing/talos/talos/tests/scroll/tiled-fixed-downscale.html
testing/talos/talos/tests/scroll/tiled-fixed.html
testing/talos/talos/tests/scroll/tiled.html
--- a/testing/talos/talos/pageloader/chrome/tscroll.js
+++ b/testing/talos/talos/pageloader/chrome/tscroll.js
@@ -1,14 +1,11 @@
-// Note: The content from here upto '// End scroll test' is duplicated at:
-//       - talos/tests/scroll/scroll-test.js
-//       - inside talos/pageloader/chrome/tscroll.js
-//
-// - Please keep these copies in sync.
-// - Pleace make sure that any changes apply cleanly to all use cases.
+// Note: This file is used at both tscrollx and tp5o_scroll. With the former as
+//       unprivileged code.
+// - Please make sure that any changes apply cleanly to all use cases.
 
 function testScroll(target, stepSize, opt_reportFunc, opt_numSteps)
 {
   var win;
   if (target == "content") {
     target = content.wrappedJSObject;
     win = content;
   } else {
@@ -116,17 +113,18 @@ function testScroll(target, stepSize, op
     document.head.appendChild(imported);
   }
 
   setTimeout(function(){
     gotoTop();
     rAF(startTest);
   }, 260);
 }
-// End scroll test - End duplicated code
 
 // This code below here is unique to tscroll.js inside of pageloader
-function handleMessageFromChrome(message) {
-  var payload = message.data.details;
-  testScroll(payload.target, payload.stepSize, 'PageLoader:RecordTime', payload.opt_numSteps);
-}
+try {
+  function handleMessageFromChrome(message) {
+    var payload = message.data.details;
+    testScroll(payload.target, payload.stepSize, 'PageLoader:RecordTime', payload.opt_numSteps);
+  }
 
-addMessageListener("PageLoader:ScrollTest", handleMessageFromChrome);
+  addMessageListener("PageLoader:ScrollTest", handleMessageFromChrome);
+} catch (e) {}
--- a/testing/talos/talos/tests/scroll/iframe.svg
+++ b/testing/talos/talos/tests/scroll/iframe.svg
@@ -30,10 +30,10 @@
 	  }
   </script>	
   <foreignObject x="5%" height="85%" width="90%">
     <iframe onload="iframeLoad();" id="ifrm" width="99%" height="99%" xmlns="http://www.w3.org/1999/xhtml" src="drac.htm"/>
   </foreignObject>
   <!-- this has to come after the iframe for some reason -->
 	<script type="text/javascript" xlink:href="../../scripts/talos-debug.js"/>
 	<script type="text/javascript" xlink:href="../../scripts/Profiler.js"/>
-	<script type="text/javascript" xlink:href="scroll-test.js"/>
+	<script type="text/javascript" xlink:href="../../pageloader/chrome/tscroll.js"/>
 </svg>
--- a/testing/talos/talos/tests/scroll/reader.htm
+++ b/testing/talos/talos/tests/scroll/reader.htm
@@ -1,15 +1,15 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html><head>
 		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 <title>Perf test case</title>
 <link type="text/css" rel="stylesheet" href="reader.css">
 <script src="../../scripts/Profiler.js" type="text/javascript"></script>
-<script src="scroll-test.js" type="text/javascript"></script>
+<script src="../../pageloader/chrome/tscroll.js" type="text/javascript"></script>
 <!-- 
 This resembles the layout of Google Reader as of 2009-11-23
 and exposed bug 530686.
 -->
 </head>
 <body onload = "testScroll(document.getElementById('entries'), 5)">
   <table id="chrome-viewer-container">
     <tbody>
deleted file mode 100644
--- a/testing/talos/talos/tests/scroll/scroll-test.js
+++ /dev/null
@@ -1,124 +0,0 @@
-// Note: The content from here upto '// End scroll test' is duplicated at:
-//       - talos/tests/scroll/scroll-test.js
-//       - inside talos/pageloader/chrome/tscroll.js
-//
-// - Please keep these copies in sync.
-// - Pleace make sure that any changes apply cleanly to all use cases.
-
-function testScroll(target, stepSize, opt_reportFunc, opt_numSteps)
-{
-  var win;
-  if (target == "content") {
-    target = content.wrappedJSObject;
-    win = content;
-  } else {
-    win = window;
-  }
-
-  function rAF(fn) {
-    return content.requestAnimationFrame(fn);
-  }
-
-
-  function myNow() {
-    return (win.performance && win.performance.now) ?
-            win.performance.now() :
-            Date.now();
-  };
-
-  var isWindow = target.self === target;
-
-  var getPos =       isWindow ? function() { return target.pageYOffset; }
-                              : function() { return target.scrollTop; };
-
-  var gotoTop =      isWindow ? function() { target.scroll(0, 0);  ensureScroll(); }
-                              : function() { target.scrollTop = 0; ensureScroll(); };
-
-  var doScrollTick = isWindow ? function() { target.scrollBy(0, stepSize); ensureScroll(); }
-                              : function() { target.scrollTop += stepSize; ensureScroll(); };
-
-  function ensureScroll() { // Ensure scroll by reading computed values. screenY is for X11.
-    if (!this.dummyEnsureScroll) {
-      this.dummyEnsureScroll = 1;
-    }
-    this.dummyEnsureScroll += win.screenY + getPos();
-  }
-
-  // For reference, rAF should fire on vsync, but Gecko currently doesn't use vsync.
-  // Instead, it uses 1000/layout.frame_rate
-  // (with 60 as default value when layout.frame_rate == -1).
-  function startTest()
-  {
-    // We should be at the top of the page now.
-    var start = myNow();
-    var lastScrollPos = getPos();
-    var lastScrollTime = start;
-    var durations = [];
-    var report = opt_reportFunc || tpRecordTime;
-    if (report == 'PageLoader:RecordTime') {
-      report = function(duration) {
-        var msg = { time: duration, startTime: '', testName: '' };
-        sendAsyncMessage('PageLoader:RecordTime', msg);
-      }
-    }
-
-    function tick() {
-      var now = myNow();
-      var duration = now - lastScrollTime;
-      lastScrollTime = now;
-
-      durations.push(duration);
-      doScrollTick();
-
-      /* stop scrolling if we can't scroll more, or if we've reached requested number of steps */
-      if ((getPos() == lastScrollPos) || (opt_numSteps && (durations.length >= (opt_numSteps + 2)))) {
-        if (typeof(Profiler) !== "undefined") {
-          Profiler.pause();
-        }
-
-        // Note: The first (1-5) intervals WILL be longer than the rest.
-        // First interval might include initial rendering and be extra slow.
-        // Also requestAnimationFrame needs to sync (optimally in 1 frame) after long frames.
-        // Suggested: Ignore the first 5 intervals.
-
-        durations.pop(); // Last step was 0.
-        durations.pop(); // and the prev one was shorter and with end-of-page logic, ignore both.
-
-        if (win.talosDebug)
-          win.talosDebug.displayData = true; // In a browser: also display all data points.
-
-        // For analysis (otherwise, it's too many data points for talos):
-        var sum = 0;
-        for (var i = 0; i < durations.length; i++)
-          sum += Number(durations[i]);
-
-        // Report average interval or (failsafe) 0 if no intervls were recorded
-        report(durations.length ? sum / durations.length : 0);
-        return;
-      }
-
-      lastScrollPos = getPos();
-      rAF(tick);
-    }
-
-    if (typeof(Profiler) !== "undefined") {
-      Profiler.resume();
-    }
-    rAF(tick);
-  }
-
-  // Not part of the test and does nothing if we're within talos,
-  // But provides an alternative tpRecordTime (with some stats display) if running in a browser
-  // If a callback is provided, then we don't need this debug reporting.
-  if(!opt_reportFunc && document.head) {
-    var imported = document.createElement('script');
-    imported.src = '../../scripts/talos-debug.js?dummy=' + Date.now(); // For some browsers to re-read
-    document.head.appendChild(imported);
-  }
-
-  setTimeout(function(){
-    gotoTop();
-    rAF(startTest);
-  }, 260);
-}
-// End scroll test - End duplicated code
deleted file mode 100644
--- a/testing/talos/talos/tests/scroll/tiled-downscale.html
+++ b/testing/talos/talos/tests/scroll/tiled-downscale.html
@@ -4,17 +4,17 @@
 		-moz-background-size: 2.5px;	
 		-webkit-background-size: 2.5px;
 		background-size: 2.5px;
 		margin-left: 160pt;
 		width: 400pt;
 	}
 	</style>
 	<script src="../../scripts/Profiler.js" type="text/javascript"></script>
-	<script src="scroll-test.js" type="text/javascript"></script>
+	<script src="../../pageloader/chrome/tscroll.js" type="text/javascript"></script>
 </head>
 <body onload = "testScroll(window, 5)">
 <P>
 3 May. Bistritz.--Left Munich at 8:35 P.M., on 1st May, arriving at
 Vienna early next morning; should have arrived at 6:46, but train was
 an hour late.  Buda-Pesth seems a wonderful place, from the glimpse
 which I got of it from the train and the little I could walk through
 the streets.  I feared to go very far from the station, as we had
--- a/testing/talos/talos/tests/scroll/tiled-fixed-downscale.html
+++ b/testing/talos/talos/tests/scroll/tiled-fixed-downscale.html
@@ -5,17 +5,17 @@
 		-webkit-background-size: 2.5px;
 		background-size: 2.5px;
 		background-attachment: fixed;
 		margin-left: 160pt;
 		width: 400pt;
 	}
 	</style>
 	<script src="../../scripts/Profiler.js" type="text/javascript"></script>
-	<script src="scroll-test.js" type="text/javascript"></script>
+	<script src="../../pageloader/chrome/tscroll.js" type="text/javascript"></script>
 </head>
 <body onload = "testScroll(window, 5)">
 <P>
 3 May. Bistritz.--Left Munich at 8:35 P.M., on 1st May, arriving at
 Vienna early next morning; should have arrived at 6:46, but train was
 an hour late.  Buda-Pesth seems a wonderful place, from the glimpse
 which I got of it from the train and the little I could walk through
 the streets.  I feared to go very far from the station, as we had
--- a/testing/talos/talos/tests/scroll/tiled-fixed.html
+++ b/testing/talos/talos/tests/scroll/tiled-fixed.html
@@ -2,17 +2,17 @@
 	<style>
 	body { background: url("strips.png");
 	       background-attachment: fixed;
 		margin-left: 160pt;
 		width: 400pt;
 	}
 	</style>
 	<script src="../../scripts/Profiler.js" type="text/javascript"></script>
-	<script src="scroll-test.js" type="text/javascript"></script>
+	<script src="../../pageloader/chrome/tscroll.js" type="text/javascript"></script>
 </head>
 <body onload = "testScroll(window, 5)">
 <P>
 3 May. Bistritz.--Left Munich at 8:35 P.M., on 1st May, arriving at
 Vienna early next morning; should have arrived at 6:46, but train was
 an hour late.  Buda-Pesth seems a wonderful place, from the glimpse
 which I got of it from the train and the little I could walk through
 the streets.  I feared to go very far from the station, as we had
--- a/testing/talos/talos/tests/scroll/tiled.html
+++ b/testing/talos/talos/tests/scroll/tiled.html
@@ -1,17 +1,17 @@
 <head>
 	<style>
 	body { background: url("strips.png");
 		margin-left: 160pt;
 		width: 400pt;
 	}
 	</style>
 	<script src="../../scripts/Profiler.js" type="text/javascript"></script>
-	<script src="scroll-test.js" type="text/javascript"></script>
+	<script src="../../pageloader/chrome/tscroll.js" type="text/javascript"></script>
 </head>
 <body onload = "testScroll(window, 5)">
 <P>
 3 May. Bistritz.--Left Munich at 8:35 P.M., on 1st May, arriving at
 Vienna early next morning; should have arrived at 6:46, but train was
 an hour late.  Buda-Pesth seems a wonderful place, from the glimpse
 which I got of it from the train and the little I could walk through
 the streets.  I feared to go very far from the station, as we had