1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_autoscroll.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Bug 863102 - Automatically scroll down upon new network requests. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + requestLongerTimeout(2); 1.13 + let monitor, debuggee, requestsContainer, scrollTop; 1.14 + 1.15 + initNetMonitor(INFINITE_GET_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.16 + monitor = aMonitor; 1.17 + debuggee = aDebuggee; 1.18 + let win = monitor.panelWin; 1.19 + let topNode = win.document.getElementById("requests-menu-contents"); 1.20 + requestsContainer = topNode.getElementsByTagName("scrollbox")[0]; 1.21 + ok(!!requestsContainer, "Container element exists as expected."); 1.22 + }) 1.23 + 1.24 + // (1) Check that the scroll position is maintained at the bottom 1.25 + // when the requests overflow the vertical size of the container. 1.26 + .then(() => { 1.27 + return waitForRequestsToOverflowContainer(monitor, requestsContainer); 1.28 + }) 1.29 + .then(() => { 1.30 + ok(scrolledToBottom(requestsContainer), "Scrolled to bottom on overflow."); 1.31 + }) 1.32 + 1.33 + // (2) Now set the scroll position somewhere in the middle and check 1.34 + // that additional requests do not change the scroll position. 1.35 + .then(() => { 1.36 + let children = requestsContainer.childNodes; 1.37 + let middleNode = children.item(children.length / 2); 1.38 + middleNode.scrollIntoView(); 1.39 + ok(!scrolledToBottom(requestsContainer), "Not scrolled to bottom."); 1.40 + scrollTop = requestsContainer.scrollTop; // save for comparison later 1.41 + return waitForNetworkEvents(monitor, 8); 1.42 + }) 1.43 + .then(() => { 1.44 + is(requestsContainer.scrollTop, scrollTop, "Did not scroll."); 1.45 + }) 1.46 + 1.47 + // (3) Now set the scroll position back at the bottom and check that 1.48 + // additional requests *do* cause the container to scroll down. 1.49 + .then(() => { 1.50 + requestsContainer.scrollTop = requestsContainer.scrollHeight; 1.51 + ok(scrolledToBottom(requestsContainer), "Set scroll position to bottom."); 1.52 + return waitForNetworkEvents(monitor, 8); 1.53 + }) 1.54 + .then(() => { 1.55 + ok(scrolledToBottom(requestsContainer), "Still scrolled to bottom."); 1.56 + }) 1.57 + 1.58 + // (4) Now select an item in the list and check that additional requests 1.59 + // do not change the scroll position. 1.60 + .then(() => { 1.61 + monitor.panelWin.NetMonitorView.RequestsMenu.selectedIndex = 0; 1.62 + return waitForNetworkEvents(monitor, 8); 1.63 + }) 1.64 + .then(() => { 1.65 + is(requestsContainer.scrollTop, 0, "Did not scroll."); 1.66 + }) 1.67 + 1.68 + // Done; clean up. 1.69 + .then(() => { 1.70 + return teardown(monitor).then(finish); 1.71 + }) 1.72 + 1.73 + // Handle exceptions in the chain of promises. 1.74 + .then(null, (err) => { 1.75 + ok(false, err); 1.76 + finish(); 1.77 + }); 1.78 + 1.79 + function waitForRequestsToOverflowContainer (aMonitor, aContainer) { 1.80 + return waitForNetworkEvents(aMonitor, 1).then(() => { 1.81 + if (aContainer.scrollHeight > aContainer.clientHeight) { 1.82 + // Wait for some more just for good measure. 1.83 + return waitForNetworkEvents(aMonitor, 8); 1.84 + } else { 1.85 + return waitForRequestsToOverflowContainer(aMonitor, aContainer); 1.86 + } 1.87 + }); 1.88 + } 1.89 + 1.90 + function scrolledToBottom(aElement) { 1.91 + return aElement.scrollTop + aElement.clientHeight >= aElement.scrollHeight; 1.92 + } 1.93 +}