Bug 625288. Part 3: Test that a browser window containing a single empty tab builds a layer tree whose leaf layers form a non-overlapping partition of the window. r=tnikkel,a=test
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 03 Feb 2011 21:47:11 +1300
changeset 61838 274e546e9da95d02da1e1706d2cf2ecfa5532020
parent 61837 c5b8aa1d4c8ac937c1ceeb518103f50ce3e99af1
child 61839 094a7967e1713423cf2d6c907ce4e54cf0819fd1
child 62007 3a32a792863e8aec0ceb3e9dfd50eea3e4e6d155
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewerstnikkel, test
bugs625288
milestone2.0b12pre
Bug 625288. Part 3: Test that a browser window containing a single empty tab builds a layer tree whose leaf layers form a non-overlapping partition of the window. r=tnikkel,a=test
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
layout/base/tests/chrome/Makefile.in
layout/base/tests/chrome/test_leaf_layers_partition_browser_window.xul
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1708,8 +1708,74 @@ nsDOMWindowUtils::GetOuterWindowWithId(P
   if (!IsUniversalXPConnectCapable()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   *aWindow = nsGlobalWindow::GetOuterWindowWithId(aWindowID);
   NS_IF_ADDREF(*aWindow);
   return NS_OK;
 }
+
+#ifdef DEBUG
+static PRBool
+CheckLeafLayers(Layer* aLayer, const nsIntPoint& aOffset, nsIntRegion* aCoveredRegion)
+{
+  gfxMatrix transform;
+  if (!aLayer->GetTransform().Is2D(&transform) ||
+      transform.HasNonIntegerTranslation())
+    return PR_FALSE;
+  transform.NudgeToIntegers();
+  nsIntPoint offset = aOffset + nsIntPoint(transform.x0, transform.y0);
+
+  Layer* child = aLayer->GetFirstChild();
+  if (child) {
+    while (child) {
+      if (!CheckLeafLayers(child, offset, aCoveredRegion))
+        return PR_FALSE;
+      child = child->GetNextSibling();
+    }
+  } else {
+    nsIntRegion rgn = aLayer->GetVisibleRegion();
+    rgn.MoveBy(offset);
+    nsIntRegion tmp;
+    tmp.And(rgn, *aCoveredRegion);
+    if (!tmp.IsEmpty())
+      return PR_FALSE;
+    aCoveredRegion->Or(*aCoveredRegion, rgn);
+  }
+
+  return PR_TRUE;
+}
+#endif
+
+NS_IMETHODIMP
+nsDOMWindowUtils::LeafLayersPartitionWindow(PRBool* aResult)
+{
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
+  *aResult = PR_TRUE;
+#ifdef DEBUG
+  nsIWidget* widget = GetWidget();
+  if (!widget)
+    return NS_ERROR_FAILURE;
+  LayerManager* manager = widget->GetLayerManager();
+  if (!manager)
+    return NS_ERROR_FAILURE;
+  nsPresContext* presContext = GetPresContext();
+  if (!presContext)
+    return NS_ERROR_FAILURE;
+  Layer* root = manager->GetRoot();
+  if (!root)
+    return NS_ERROR_FAILURE;
+
+  nsIntPoint offset(0, 0);
+  nsIntRegion coveredRegion;
+  if (!CheckLeafLayers(root, offset, &coveredRegion)) {
+    *aResult = PR_FALSE;
+  }
+  if (!coveredRegion.IsEqual(root->GetVisibleRegion())) {
+    *aResult = PR_FALSE;
+  }
+#endif
+  return NS_OK;
+}
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -819,17 +819,17 @@ interface nsIDOMWindowUtils : nsISupport
   double computeAnimationDistance(in nsIDOMElement element,
                                   in AString property,
                                   in AString value1,
                                   in AString value2);
 };
 
 typedef unsigned long long nsViewID;
 
-[scriptable, uuid(526d22ab-4997-8666-53f6-38c7f93e77a5)]
+[scriptable, uuid(be2e28c8-64f8-4100-906d-8a451ddd6835)]
 interface nsIDOMWindowUtils_MOZILLA_2_0_BRANCH : nsISupports {
   /**
    * Get the type of the currently focused html input, if any.
    */
   readonly attribute string focusedInputType;
 
   /**
    * Given a view ID from the compositor process, retrieve the element
@@ -845,9 +845,17 @@ interface nsIDOMWindowUtils_MOZILLA_2_0_
   nsIDOMWindow enterModalStateWithWindow();
 
   /**
    * Same as leaveModalState, but takes a window associated with the active
    * context when enterModalStateWithWindow was called. The currently context
    * might be different at the moment (see bug 621764).
    */
   void leaveModalStateWithWindow(in nsIDOMWindow aWindow);
+
+  /**
+   * Checks the layer tree for this window and returns true
+   * if all layers have transforms that are translations by integers,
+   * no leaf layers overlap, and the union of the leaf layers is exactly
+   * the bounds of the window. Always returns true in non-DEBUG builds.
+   */
+  boolean leafLayersPartitionWindow();
 };
--- a/layout/base/tests/chrome/Makefile.in
+++ b/layout/base/tests/chrome/Makefile.in
@@ -52,16 +52,17 @@ include $(topsrcdir)/config/rules.mk
 	test_bug551434.html \
 	bug551434_childframe.html \
 	test_chrome_content_integration.xul \
 	     chrome_content_integration_window.xul \
 	test_chrome_over_plugin.xul \
 	     chrome_over_plugin_window.xul \
 	test_default_background.xul \
 	     default_background_window.xul \
+    test_leaf_layers_partition_browser_window.xul \
 	test_printpreview.xul \
 	     printpreview_helper.xul \
 	test_printpreview_bug396024.xul \
 	     printpreview_bug396024_helper.xul \
 	test_printpreview_bug482976.xul \
 	     printpreview_bug482976_helper.xul \
     $(NULL)
 
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/chrome/test_leaf_layers_partition_browser_window.xul
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+    SimpleTest.waitForExplicitFinish();
+    // Run the test in a separate window so we get a clean browser window.
+    window.open("data:text/html,<html style='overflow:scroll'><script>opener.doTest(window)</script>",
+                "", "scrollbars=yes,toolbar,menubar,width=500,height=500");
+    function doTest(win) {
+      var currentCount = win.mozPaintCount;
+      function nextStep() {
+        if (win.mozPaintCount == currentCount) {
+          setTimeout(nextStep, 0, win);
+          return;
+        }
+        var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
+            getInterface(Components.interfaces.nsIDOMWindowUtils).
+            QueryInterface(Components.interfaces.nsIDOMWindowUtils_MOZILLA_2_0_BRANCH);
+        ok(utils.leafLayersPartitionWindow(),
+           "Leaf layers should form a non-overlapping partition of the browser window");
+        win.close();
+        SimpleTest.finish();
+      }
+      setTimeout(nextStep, 0);
+    }
+  ]]>
+  </script>
+</window>