Bug 1050376 - Test docshell recording of restyle/reflow/paint; r=smaug
☠☠ backed out by 756a0f510247 ☠ ☠
authorPaul Rouget <paul@mozilla.com>
Tue, 09 Sep 2014 09:48:45 +0200
changeset 227528 f3643ddd721fcf5882d9414ba7301e6025803b06
parent 227527 48816257a7b0e7f1f14e6d492591b5c3c2595c63
child 227529 380f8554aa170d3119abf7d9c81f28623a87dfa6
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1050376
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1050376 - Test docshell recording of restyle/reflow/paint; r=smaug
docshell/test/browser/browser.ini
docshell/test/browser/browser_timelineMarkers-01.js
docshell/test/browser/browser_timelineMarkers-02.js
--- a/docshell/test/browser/browser.ini
+++ b/docshell/test/browser/browser.ini
@@ -92,8 +92,10 @@ skip-if = e10s # Bug ?????? - event hand
 [browser_uriFixupIntegration.js]
 skip-if = e10s
 [browser_loadDisallowInherit.js]
 skip-if = e10s
 [browser_loadURI.js]
 skip-if = e10s # Bug ?????? - event handler checks event.target is the content document and test e10s-utils doesn't do that.
 [browser_search_notification.js]
 skip-if = e10s
+[browser_timelineMarkers-01.js]
+[browser_timelineMarkers-02.js]
new file mode 100644
--- /dev/null
+++ b/docshell/test/browser/browser_timelineMarkers-01.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that the docShell has the right profile timeline API
+
+let test = Task.async(function*() {
+  waitForExplicitFinish();
+
+  yield openUrl("data:text/html;charset=utf-8,Test page");
+
+  let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIWebNavigation)
+                        .QueryInterface(Ci.nsIDocShell);
+
+  ok("recordProfileTimelineMarkers" in docShell,
+    "The recordProfileTimelineMarkers attribute exists");
+  ok("popProfileTimelineMarkers" in docShell,
+    "The popProfileTimelineMarkers function exists");
+  ok(docShell.recordProfileTimelineMarkers === false,
+    "recordProfileTimelineMarkers is false by default");
+  ok(docShell.popProfileTimelineMarkers().length === 0,
+    "There are no markers by default");
+
+  docShell.recordProfileTimelineMarkers = true;
+  ok(docShell.recordProfileTimelineMarkers === true,
+    "recordProfileTimelineMarkers can be set to true");
+
+  docShell.recordProfileTimelineMarkers = false;
+  ok(docShell.recordProfileTimelineMarkers === false,
+    "recordProfileTimelineMarkers can be set to false");
+
+  gBrowser.removeCurrentTab();
+  finish();
+});
+
+function openUrl(url) {
+  return new Promise(function(resolve, reject) {
+    gBrowser.selectedTab = gBrowser.addTab(url);
+    gBrowser.selectedBrowser.addEventListener("load", function onload() {
+      gBrowser.selectedBrowser.removeEventListener("load", onload, true);
+      waitForFocus(resolve, content);
+    }, true);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/docshell/test/browser/browser_timelineMarkers-02.js
@@ -0,0 +1,112 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that the docShell profile timeline API returns the right markers when
+// restyles, reflows and paints occur
+
+let URL = 'data:text/html;charset=utf-8,<!DOCTYPE html><style>div.x{}</style>' +
+          '<div style="width:20px;height:2px;background:red"></div>';
+
+let TESTS = [{
+  desc: "Changing the width of the test element",
+  setup: function(div) {
+    div.style.width = "10px";
+  },
+  check: function(markers) {
+    ok(markers.length > 0, "markers were returned");
+    ok(markers.some(m => m.name == "Reflow"), "markers includes Reflow");
+    ok(markers.some(m => m.name == "Paint"), "markers includes Paint");
+    ok(markers.some(m => m.name == "Styles"), "markers includes Restyle");
+  }
+}, {
+  desc: "Changing the test element's background color",
+  setup: function(div) {
+    div.style.backgroundColor = "green";
+  },
+  check: function(markers) {
+    ok(markers.length > 0, "markers were returned");
+    ok(!markers.some(m => m.name == "Reflow"), "markers doesn't include Reflow");
+    ok(markers.some(m => m.name == "Paint"), "markers includes Paint");
+    ok(markers.some(m => m.name == "Styles"), "markers includes Restyle");
+  }
+}, {
+  desc: "Changing the test element's classname",
+  setup: function(div) {
+    div.className = "x";
+  },
+  check: function(markers) {
+    ok(markers.length > 0, "markers were returned");
+    ok(!markers.some(m => m.name == "Reflow"), "markers doesn't include Reflow");
+    ok(!markers.some(m => m.name == "Paint"), "markers doesn't include Paint");
+    ok(markers.some(m => m.name == "Styles"), "markers includes Restyle");
+  }
+}];
+
+let test = Task.async(function*() {
+  waitForExplicitFinish();
+
+  yield openUrl(URL);
+
+  let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIWebNavigation)
+                        .QueryInterface(Ci.nsIDocShell);
+  let div = content.document.querySelector("div");
+
+  info("Start recording");
+  docShell.recordProfileTimelineMarkers = true;
+
+  for (let {desc, setup, check} of TESTS) {
+    info("Running test: " + desc);
+
+    info("Flushing the previous markers if any");
+    docShell.popProfileTimelineMarkers();
+
+    info("Running the test setup function");
+    let onMarkers = waitForMarkers(docShell);
+    setup(div);
+
+    info("Waiting for new markers on the docShell");
+    let markers = yield onMarkers;
+
+    info("Running the test check function");
+    check(markers);
+  }
+
+  info("Stop recording");
+  docShell.recordProfileTimelineMarkers = false;
+
+  gBrowser.removeCurrentTab();
+  finish();
+});
+
+function openUrl(url) {
+  return new Promise(function(resolve, reject) {
+    gBrowser.selectedTab = gBrowser.addTab(url);
+    gBrowser.selectedBrowser.addEventListener("load", function onload() {
+      gBrowser.selectedBrowser.removeEventListener("load", onload, true);
+      waitForFocus(resolve, content);
+    }, true);
+  });
+}
+
+function waitForMarkers(docshell) {
+  return new Promise(function(resolve, reject) {
+    let waitIterationCount = 0;
+    let maxWaitIterationCount = 10; // Wait for 2sec maximum
+
+    let interval = setInterval(() => {
+      let markers = docshell.popProfileTimelineMarkers();
+      if (markers.length > 0) {
+        clearInterval(interval);
+        resolve(markers);
+      }
+      if (waitIterationCount > maxWaitIterationCount) {
+        clearInterval(interval);
+        resolve([]);
+      }
+      waitIterationCount++;
+    }, 200);
+  });
+}