summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/chrome/test_leaf_layers_partition_browser_window.xul
blob: c3cce54e51f8f47f5f467ebb8e3eb1be4916658d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?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/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();

    var winLowerThanVista = navigator.platform.indexOf("Win") == 0;
    if (winLowerThanVista) {
      var version = Components.classes["@mozilla.org/system-info;1"]
                              .getService(Components.interfaces.nsIPropertyBag2)
                              .getProperty("version");
      winLowerThanVista = parseFloat(version) < 6.0;
    }

    var tests = [{maximize: false}, {maximize: true}];
    var testIndex = 0;
    var win;

    function testInfo() {
      return tests[testIndex].maximize ? " (maximized)" : " (non-maximized)";
    }

    function doTest(evt) {
      var initialCount = win.mozPaintCount;

      function nextStep() {
        if (win.mozPaintCount == initialCount || win.isMozAfterPaintPending) {
          SimpleTest.info("Waiting for mozPaintCount (= " + initialCount + ") to increase" + testInfo());
          // Do not use SimpleTest.executeSoon() here: give a little more time.
          setTimeout(nextStep, 100);
          return;
        }

        isnot(win.mozPaintCount, initialCount, "mozPaintCount has increased" + testInfo());

        function testLeafLayersPartitionWindow() {
          var success = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                           .getInterface(Components.interfaces.nsIDOMWindowUtils)
                           .leafLayersPartitionWindow();
          // "[leafLayersPartitionWindow()] Always returns true in non-DEBUG builds."
          // To prevent random failures on Windows, try to run this again after a timeout.
          if (!success && navigator.platform.indexOf("Win") >= 0) {
            setTimeout(testLeafLayersPartitionWindow, 100);
            return;
          }
          ok(success,
             "Leaf layers should form a non-overlapping partition of the browser window" + testInfo() +
             (success ? "" : ". [Set MOZ_DUMP_PAINT_LIST=1 env var to investigate.]"));

          win.close();
          ++testIndex;
          nextTest();
        }
        testLeafLayersPartitionWindow();
      }

      if (tests[testIndex].maximize) {
        function resizeListener() {
          win.removeEventListener("resize", resizeListener, true);
          // We want a paint after resize.
          initialCount = win.mozPaintCount;
          SimpleTest.executeSoon(nextStep);
        }
        win.addEventListener("resize", resizeListener, true);
        SimpleTest.info("Maximizing test " + testIndex + " window" + testInfo());
        Components.classes["@mozilla.org/appshell/window-mediator;1"]
                  .getService(Components.interfaces.nsIWindowMediator)
                  .getMostRecentWindow("navigator:browser")
                  .maximize();
      } else {
        SimpleTest.executeSoon(nextStep);
      }
    }

    function nextTest() {
      if (testIndex >= tests.length) {
        SimpleTest.finish();
        return;
      }

      if (winLowerThanVista && !tests[testIndex].maximize) {
        ok(true, "Skipping non-maximized test " + testIndex + " on winLowerThanVista since the resizer causes overlapping layers");
        ++testIndex;
        nextTest();
        return;
      }

      window.focus();
      // Run the test in a separate window so we get a clean browser window.
      win = window.open("data:text/html,<html style='overflow:scroll'>",
                "", "scrollbars=yes,toolbar,menubar,width=500,height=500");
      setTimeout(setupWindow, 0);
    }

    function setupWindow() {
      win.addEventListener("load", doTest, false);
      win.focus();
    }

    nextTest();
  ]]>
  </script>
</window>