summaryrefslogtreecommitdiffstats
path: root/docshell/test/chrome/test_bug453650.xhtml
blob: 2283e29206eb136ea4208b261421b5234307d754 (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
115
116
117
118
119
120
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=453650
-->
<window title="Mozilla Bug 453650"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[

  /** Test for Bug 453650 */
  SimpleTest.waitForExplicitFinish();

  var iter = runTests();
  nextTest();

  function* runTests() {
    var iframe = document.createXULElement("iframe");
    iframe.style.width = "300px";
    iframe.style.height = "300px";
    iframe.setAttribute("src", "data:text/html,<h1 id='h'>hello</h1>");

    document.documentElement.appendChild(iframe);
    yield whenLoaded(iframe);
    info("iframe loaded");

    var h1 = iframe.contentDocument.getElementById("h");
    let myCallback = function() { h1.style.width = "400px"; };
    info("Calling waitForInterruptibleReflow");
    yield waitForInterruptibleReflow(iframe.docShell, myCallback);
    info("got past top-level waitForInterruptibleReflow");

    myCallback = function() { h1.style.width = "300px"; };
    info("Calling waitForReflow");
    waitForReflow(iframe.docShell, myCallback);
    info("got past top-level waitForReflow");
    yield is(300, h1.offsetWidth, "h1 has correct width");

    SimpleTest.finish();
  }

  function waitForInterruptibleReflow(docShell,
                                      callbackThatShouldTriggerReflow) {
    waitForReflow(docShell, callbackThatShouldTriggerReflow, true);
  }

  function waitForReflow(docShell, callbackThatShouldTriggerReflow,
                         interruptible = false) {
    info("Entering waitForReflow");
    function done() {
      info("Entering done (inside of waitForReflow)");

      docShell.removeWeakReflowObserver(observer);
      SimpleTest.executeSoon(nextTest);
    }

    var observer = {
      reflow (start, end) {
        info("Entering observer.reflow");
        if (interruptible) {
          ok(false, "expected interruptible reflow");
        } else {
          ok(true, "observed uninterruptible reflow");
        }

        info("times: " + start + ", " + end);
        ok(start <= end, "reflow start time lower than end time");
        done();
      },

      reflowInterruptible (start, end) {
        info("Entering observer.reflowInterruptible");
        if (!interruptible) {
          ok(false, "expected uninterruptible reflow");
        } else {
          ok(true, "observed interruptible reflow");
        }

        info("times: " + start + ", " + end);
        ok(start <= end, "reflow start time lower than end time");
        done();
      },

      QueryInterface: ChromeUtils.generateQI([
        "nsIReflowObserver",
        "nsISupportsWeakReference",
      ]),
    };

    info("waitForReflow is adding a reflow observer");
    docShell.addWeakReflowObserver(observer);
    callbackThatShouldTriggerReflow();
  }

  function whenLoaded(iframe) {
    info("entering whenLoaded");
    iframe.addEventListener("load", function() {
      SimpleTest.executeSoon(nextTest);
    }, { once: true });
  }

  function nextTest() {
    info("entering nextTest");
    iter.next();
  }

  ]]>
  </script>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=453650"
     target="_blank">Mozilla Bug 453650</a>
  </body>
</window>