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