Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Bug 863102 - Automatically scroll down upon new network requests. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | requestLongerTimeout(2); |
michael@0 | 10 | let monitor, debuggee, requestsContainer, scrollTop; |
michael@0 | 11 | |
michael@0 | 12 | initNetMonitor(INFINITE_GET_URL).then(([aTab, aDebuggee, aMonitor]) => { |
michael@0 | 13 | monitor = aMonitor; |
michael@0 | 14 | debuggee = aDebuggee; |
michael@0 | 15 | let win = monitor.panelWin; |
michael@0 | 16 | let topNode = win.document.getElementById("requests-menu-contents"); |
michael@0 | 17 | requestsContainer = topNode.getElementsByTagName("scrollbox")[0]; |
michael@0 | 18 | ok(!!requestsContainer, "Container element exists as expected."); |
michael@0 | 19 | }) |
michael@0 | 20 | |
michael@0 | 21 | // (1) Check that the scroll position is maintained at the bottom |
michael@0 | 22 | // when the requests overflow the vertical size of the container. |
michael@0 | 23 | .then(() => { |
michael@0 | 24 | return waitForRequestsToOverflowContainer(monitor, requestsContainer); |
michael@0 | 25 | }) |
michael@0 | 26 | .then(() => { |
michael@0 | 27 | ok(scrolledToBottom(requestsContainer), "Scrolled to bottom on overflow."); |
michael@0 | 28 | }) |
michael@0 | 29 | |
michael@0 | 30 | // (2) Now set the scroll position somewhere in the middle and check |
michael@0 | 31 | // that additional requests do not change the scroll position. |
michael@0 | 32 | .then(() => { |
michael@0 | 33 | let children = requestsContainer.childNodes; |
michael@0 | 34 | let middleNode = children.item(children.length / 2); |
michael@0 | 35 | middleNode.scrollIntoView(); |
michael@0 | 36 | ok(!scrolledToBottom(requestsContainer), "Not scrolled to bottom."); |
michael@0 | 37 | scrollTop = requestsContainer.scrollTop; // save for comparison later |
michael@0 | 38 | return waitForNetworkEvents(monitor, 8); |
michael@0 | 39 | }) |
michael@0 | 40 | .then(() => { |
michael@0 | 41 | is(requestsContainer.scrollTop, scrollTop, "Did not scroll."); |
michael@0 | 42 | }) |
michael@0 | 43 | |
michael@0 | 44 | // (3) Now set the scroll position back at the bottom and check that |
michael@0 | 45 | // additional requests *do* cause the container to scroll down. |
michael@0 | 46 | .then(() => { |
michael@0 | 47 | requestsContainer.scrollTop = requestsContainer.scrollHeight; |
michael@0 | 48 | ok(scrolledToBottom(requestsContainer), "Set scroll position to bottom."); |
michael@0 | 49 | return waitForNetworkEvents(monitor, 8); |
michael@0 | 50 | }) |
michael@0 | 51 | .then(() => { |
michael@0 | 52 | ok(scrolledToBottom(requestsContainer), "Still scrolled to bottom."); |
michael@0 | 53 | }) |
michael@0 | 54 | |
michael@0 | 55 | // (4) Now select an item in the list and check that additional requests |
michael@0 | 56 | // do not change the scroll position. |
michael@0 | 57 | .then(() => { |
michael@0 | 58 | monitor.panelWin.NetMonitorView.RequestsMenu.selectedIndex = 0; |
michael@0 | 59 | return waitForNetworkEvents(monitor, 8); |
michael@0 | 60 | }) |
michael@0 | 61 | .then(() => { |
michael@0 | 62 | is(requestsContainer.scrollTop, 0, "Did not scroll."); |
michael@0 | 63 | }) |
michael@0 | 64 | |
michael@0 | 65 | // Done; clean up. |
michael@0 | 66 | .then(() => { |
michael@0 | 67 | return teardown(monitor).then(finish); |
michael@0 | 68 | }) |
michael@0 | 69 | |
michael@0 | 70 | // Handle exceptions in the chain of promises. |
michael@0 | 71 | .then(null, (err) => { |
michael@0 | 72 | ok(false, err); |
michael@0 | 73 | finish(); |
michael@0 | 74 | }); |
michael@0 | 75 | |
michael@0 | 76 | function waitForRequestsToOverflowContainer (aMonitor, aContainer) { |
michael@0 | 77 | return waitForNetworkEvents(aMonitor, 1).then(() => { |
michael@0 | 78 | if (aContainer.scrollHeight > aContainer.clientHeight) { |
michael@0 | 79 | // Wait for some more just for good measure. |
michael@0 | 80 | return waitForNetworkEvents(aMonitor, 8); |
michael@0 | 81 | } else { |
michael@0 | 82 | return waitForRequestsToOverflowContainer(aMonitor, aContainer); |
michael@0 | 83 | } |
michael@0 | 84 | }); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function scrolledToBottom(aElement) { |
michael@0 | 88 | return aElement.scrollTop + aElement.clientHeight >= aElement.scrollHeight; |
michael@0 | 89 | } |
michael@0 | 90 | } |