1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/widgets/test_popupreflows.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?> 1.7 + 1.8 +<window title="Popup Reflow Tests" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.10 + 1.11 + <panel id="testPanel" 1.12 + type="arrow" 1.13 + noautohide="true"> 1.14 + </panel> 1.15 + 1.16 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.17 + 1.18 +<script> 1.19 +<![CDATA[ 1.20 +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; 1.21 + 1.22 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.23 +Cu.import("resource://gre/modules/Promise.jsm"); 1.24 + 1.25 +let panel, anchor, arrow; 1.26 + 1.27 +// A reflow observer - it just remembers the stack trace of all sync reflows 1.28 +// done by the panel. 1.29 +let observer = { 1.30 + reflows: [], 1.31 + reflow: function (start, end) { 1.32 + this.reflows.push(new Error().stack); 1.33 + }, 1.34 + 1.35 + reflowInterruptible: function (start, end) { 1.36 + // We're not interested in interruptible reflows. Why, you ask? Because 1.37 + // we've simply cargo-culted this test from browser_tabopen_reflows.js! 1.38 + }, 1.39 + 1.40 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIReflowObserver, 1.41 + Ci.nsISupportsWeakReference]) 1.42 +}; 1.43 + 1.44 +// A test utility that counts the reflows caused by a test function. If the 1.45 +// count of reflows isn't what is expected, it causes a test failure and logs 1.46 +// the stack trace of all seen reflows. 1.47 +function countReflows(testfn, expected) { 1.48 + let deferred = Promise.defer(); 1.49 + observer.reflows = []; 1.50 + let docShell = panel.ownerDocument.defaultView 1.51 + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) 1.52 + .getInterface(Components.interfaces.nsIWebNavigation) 1.53 + .QueryInterface(Components.interfaces.nsIDocShell); 1.54 + docShell.addWeakReflowObserver(observer); 1.55 + testfn().then(() => { 1.56 + docShell.removeWeakReflowObserver(observer); 1.57 + SimpleTest.is(observer.reflows.length, expected, "correct number of reflows"); 1.58 + if (observer.reflows.length != expected) { 1.59 + SimpleTest.info("stack traces of reflows:\n" + observer.reflows.join("\n") + "\n"); 1.60 + } 1.61 + deferred.resolve(); 1.62 + }); 1.63 + return deferred.promise 1.64 +} 1.65 + 1.66 +function openPopup() { 1.67 + let deferred = Promise.defer(); 1.68 + panel.addEventListener("popupshown", function popupshown() { 1.69 + panel.removeEventListener("popupshown", popupshown); 1.70 + deferred.resolve(); 1.71 + }); 1.72 + panel.openPopup(anchor, "before_start"); 1.73 + return deferred.promise 1.74 +} 1.75 + 1.76 +// ******************** 1.77 +// The actual tests... 1.78 +// We only have one atm - simply open a popup. 1.79 +// 1.80 +function testSimplePanel() { 1.81 + return openPopup(); 1.82 +} 1.83 + 1.84 +// ******************** 1.85 +// The test harness... 1.86 +// 1.87 +SimpleTest.waitForExplicitFinish(); 1.88 + 1.89 +addEventListener("load", function() { 1.90 + anchor = document.getElementById("anchor"); 1.91 + panel = document.getElementById("testPanel"); 1.92 + arrow = document.getAnonymousElementByAttribute(panel, "anonid", "arrow"); 1.93 + 1.94 + // Cancel the arrow panel slide-in transition (bug 767133) - we are only 1.95 + // testing reflows in the core panel implementation and not reflows that may 1.96 + // or may not be caused by transitioning.... 1.97 + arrow.style.transition = "none"; 1.98 + 1.99 + // and off we go... 1.100 + countReflows(testSimplePanel, 1).then(SimpleTest.finish); 1.101 +}); 1.102 +]]> 1.103 +</script> 1.104 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.105 + <p>The anchor --> <span id="anchor">v</span> <--</p> 1.106 +</body> 1.107 +</window>