michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Bug 863102 - Automatically scroll down upon new network requests. michael@0: */ michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: let monitor, debuggee, requestsContainer, scrollTop; michael@0: michael@0: initNetMonitor(INFINITE_GET_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: monitor = aMonitor; michael@0: debuggee = aDebuggee; michael@0: let win = monitor.panelWin; michael@0: let topNode = win.document.getElementById("requests-menu-contents"); michael@0: requestsContainer = topNode.getElementsByTagName("scrollbox")[0]; michael@0: ok(!!requestsContainer, "Container element exists as expected."); michael@0: }) michael@0: michael@0: // (1) Check that the scroll position is maintained at the bottom michael@0: // when the requests overflow the vertical size of the container. michael@0: .then(() => { michael@0: return waitForRequestsToOverflowContainer(monitor, requestsContainer); michael@0: }) michael@0: .then(() => { michael@0: ok(scrolledToBottom(requestsContainer), "Scrolled to bottom on overflow."); michael@0: }) michael@0: michael@0: // (2) Now set the scroll position somewhere in the middle and check michael@0: // that additional requests do not change the scroll position. michael@0: .then(() => { michael@0: let children = requestsContainer.childNodes; michael@0: let middleNode = children.item(children.length / 2); michael@0: middleNode.scrollIntoView(); michael@0: ok(!scrolledToBottom(requestsContainer), "Not scrolled to bottom."); michael@0: scrollTop = requestsContainer.scrollTop; // save for comparison later michael@0: return waitForNetworkEvents(monitor, 8); michael@0: }) michael@0: .then(() => { michael@0: is(requestsContainer.scrollTop, scrollTop, "Did not scroll."); michael@0: }) michael@0: michael@0: // (3) Now set the scroll position back at the bottom and check that michael@0: // additional requests *do* cause the container to scroll down. michael@0: .then(() => { michael@0: requestsContainer.scrollTop = requestsContainer.scrollHeight; michael@0: ok(scrolledToBottom(requestsContainer), "Set scroll position to bottom."); michael@0: return waitForNetworkEvents(monitor, 8); michael@0: }) michael@0: .then(() => { michael@0: ok(scrolledToBottom(requestsContainer), "Still scrolled to bottom."); michael@0: }) michael@0: michael@0: // (4) Now select an item in the list and check that additional requests michael@0: // do not change the scroll position. michael@0: .then(() => { michael@0: monitor.panelWin.NetMonitorView.RequestsMenu.selectedIndex = 0; michael@0: return waitForNetworkEvents(monitor, 8); michael@0: }) michael@0: .then(() => { michael@0: is(requestsContainer.scrollTop, 0, "Did not scroll."); michael@0: }) michael@0: michael@0: // Done; clean up. michael@0: .then(() => { michael@0: return teardown(monitor).then(finish); michael@0: }) michael@0: michael@0: // Handle exceptions in the chain of promises. michael@0: .then(null, (err) => { michael@0: ok(false, err); michael@0: finish(); michael@0: }); michael@0: michael@0: function waitForRequestsToOverflowContainer (aMonitor, aContainer) { michael@0: return waitForNetworkEvents(aMonitor, 1).then(() => { michael@0: if (aContainer.scrollHeight > aContainer.clientHeight) { michael@0: // Wait for some more just for good measure. michael@0: return waitForNetworkEvents(aMonitor, 8); michael@0: } else { michael@0: return waitForRequestsToOverflowContainer(aMonitor, aContainer); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: function scrolledToBottom(aElement) { michael@0: return aElement.scrollTop + aElement.clientHeight >= aElement.scrollHeight; michael@0: } michael@0: }