test_reflow.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf8">
  5. <title>Test for the Reflow Activity</title>
  6. <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  7. <script type="text/javascript;version=1.8" src="common.js"></script>
  8. <!-- Any copyright is dedicated to the Public Domain.
  9. - http://creativecommons.org/publicdomain/zero/1.0/ -->
  10. </head>
  11. <body>
  12. <p>Test for reflow events</p>
  13. <script class="testbody" type="text/javascript;version=1.8">
  14. SimpleTest.waitForExplicitFinish();
  15. let client;
  16. function generateReflow()
  17. {
  18. top.document.documentElement.style.display = "none";
  19. top.document.documentElement.getBoundingClientRect();
  20. top.document.documentElement.style.display = "block";
  21. }
  22. function startTest()
  23. {
  24. removeEventListener("load", startTest);
  25. attachConsoleToTab(["ReflowActivity"], onAttach);
  26. }
  27. function onAttach(aState, aResponse)
  28. {
  29. client = aState.dbgClient;
  30. onReflowActivity = onReflowActivity.bind(null, aState);
  31. client.addListener("reflowActivity", onReflowActivity);
  32. generateReflow();
  33. }
  34. // We are expecting 3 reflow events.
  35. let expectedEvents = [
  36. {
  37. interruptible: false,
  38. sourceURL: "chrome://mochitests/content/chrome/devtools/shared/webconsole/test/test_reflow.html",
  39. functionName: "generateReflow"
  40. },
  41. {
  42. interruptible: true,
  43. sourceURL: null,
  44. functionName: null
  45. },
  46. {
  47. interruptible: true,
  48. sourceURL: null,
  49. functionName: null
  50. },
  51. ];
  52. let receivedEvents = [];
  53. function onReflowActivity(aState, aType, aPacket)
  54. {
  55. info("packet: " + aPacket.message);
  56. receivedEvents.push(aPacket);
  57. if (receivedEvents.length == expectedEvents.length) {
  58. checkEvents();
  59. finish(aState);
  60. }
  61. }
  62. function checkEvents() {
  63. for (let i = 0; i < expectedEvents.length; i++) {
  64. let a = expectedEvents[i];
  65. let b = receivedEvents[i];
  66. for (let key in a) {
  67. is(a[key], b[key], "field " + key + " is valid");
  68. }
  69. }
  70. }
  71. function finish(aState) {
  72. client.removeListener("reflowActivity", onReflowActivity);
  73. closeDebugger(aState, function() {
  74. SimpleTest.finish();
  75. });
  76. }
  77. addEventListener("load", startTest);
  78. </script>
  79. </body>
  80. </html>