OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../http/tests/inspector/console-test.js"></script> |
| 5 <script> |
| 6 function addMessages(count) |
| 7 { |
| 8 for (var i = 0; i < count; ++i) |
| 9 console.log("Message #" + i); |
| 10 } |
| 11 |
| 12 function addRepeatingMessages(count) |
| 13 { |
| 14 for (var i = 0; i < count; ++i) |
| 15 console.log("Repeating message"); |
| 16 } |
| 17 |
| 18 //# sourceURL=console-viewport-control.html |
| 19 </script> |
| 20 |
| 21 <script> |
| 22 |
| 23 function test() |
| 24 { |
| 25 const viewportHeight = 200; |
| 26 InspectorTest.fixConsoleViewportDimensions(600, viewportHeight); |
| 27 var consoleView = Console.ConsoleView.instance(); |
| 28 var viewport = consoleView._viewport; |
| 29 const smallCount = 3; |
| 30 const rowHeight = viewportHeight / consoleView.minimumRowHeight(); |
| 31 const maxVisibleCount = Math.ceil(rowHeight); |
| 32 const maxActiveCount = Math.ceil(rowHeight * 2); |
| 33 var wasShown = []; |
| 34 var willHide = []; |
| 35 |
| 36 InspectorTest.addResult("Max visible messages count: " + maxVisibleCount + "
, active count: " + maxActiveCount); |
| 37 |
| 38 function onMessageShown() { |
| 39 wasShown.push(this); |
| 40 } |
| 41 |
| 42 function onMessageHidden() { |
| 43 willHide.push(this); |
| 44 } |
| 45 |
| 46 function printAndResetCounts(next) { |
| 47 InspectorTest.addResult("Messages shown: " + wasShown.length + ", hidden
: " + willHide.length); |
| 48 resetShowHideCounts(); |
| 49 next(); |
| 50 } |
| 51 |
| 52 function resetShowHideCounts() { |
| 53 wasShown = []; |
| 54 willHide = []; |
| 55 } |
| 56 |
| 57 function logMessages(count, repeating, callback) |
| 58 { |
| 59 var awaitingMessagesCount = count; |
| 60 function messageAdded() |
| 61 { |
| 62 if (!--awaitingMessagesCount) { |
| 63 viewport.invalidate(); |
| 64 callback(); |
| 65 } else { |
| 66 InspectorTest.addConsoleSniffer(messageAdded, false); |
| 67 } |
| 68 } |
| 69 InspectorTest.addConsoleSniffer(messageAdded, false); |
| 70 if (!repeating) |
| 71 InspectorTest.evaluateInPage(String.sprintf("addMessages(%d)", count
)); |
| 72 else |
| 73 InspectorTest.evaluateInPage(String.sprintf("addRepeatingMessages(%d
)", count)); |
| 74 } |
| 75 |
| 76 function printStuckToBottom() { |
| 77 InspectorTest.addResult("Is at bottom: " + viewport.element.isScrolledTo
Bottom() + ", should stick: " + viewport.stickToBottom()); |
| 78 } |
| 79 |
| 80 function clearConsoleAndReset() { |
| 81 Console.ConsoleView.clearConsole(); |
| 82 resetShowHideCounts(); |
| 83 } |
| 84 |
| 85 InspectorTest.addSniffer(Console.ConsoleViewMessage.prototype, "wasShown", o
nMessageShown, true); |
| 86 InspectorTest.addSniffer(Console.ConsoleViewMessage.prototype, "willHide", o
nMessageHidden, true); |
| 87 |
| 88 InspectorTest.runTestSuite([ |
| 89 function addSmallCount(next) { |
| 90 clearConsoleAndReset(); |
| 91 logMessages(smallCount, false, () => printAndResetCounts(next)); |
| 92 }, |
| 93 |
| 94 function addMaxVisibleCount(next) { |
| 95 clearConsoleAndReset(); |
| 96 logMessages(maxVisibleCount, false, () => printAndResetCounts(next))
; |
| 97 }, |
| 98 |
| 99 function addMaxActiveCount(next) { |
| 100 clearConsoleAndReset(); |
| 101 logMessages(maxActiveCount, false, () => printAndResetCounts(next)); |
| 102 printStuckToBottom(); |
| 103 }, |
| 104 |
| 105 function addMoreThanMaxActiveCount(next) { |
| 106 clearConsoleAndReset(); |
| 107 logMessages(maxActiveCount, false, step2); |
| 108 function step2() { |
| 109 logMessages(smallCount, false, () => printAndResetCounts(next)); |
| 110 printStuckToBottom(); |
| 111 } |
| 112 }, |
| 113 |
| 114 function scrollUpWithinActiveWindow(next) { |
| 115 clearConsoleAndReset(); |
| 116 logMessages(maxActiveCount, false, step2); |
| 117 printStuckToBottom(); |
| 118 function step2() { |
| 119 resetShowHideCounts(); |
| 120 viewport.forceScrollItemToBeFirst(0); |
| 121 printAndResetCounts(next); |
| 122 } |
| 123 }, |
| 124 |
| 125 function scrollUpToPositionOutsideOfActiveWindow(next) { |
| 126 clearConsoleAndReset(); |
| 127 logMessages(maxActiveCount + smallCount, false, step2); |
| 128 printStuckToBottom(); |
| 129 function step2() { |
| 130 resetShowHideCounts(); |
| 131 viewport.forceScrollItemToBeFirst(0); |
| 132 printAndResetCounts(next); |
| 133 } |
| 134 }, |
| 135 |
| 136 function logRepeatingMessages(next) { |
| 137 clearConsoleAndReset(); |
| 138 logMessages(maxVisibleCount, true, () => printAndResetCounts(next)); |
| 139 }, |
| 140 |
| 141 function reorderingMessages(next) { |
| 142 clearConsoleAndReset(); |
| 143 InspectorTest.addResult("Logging " + smallCount + " messages"); |
| 144 logMessages(smallCount, false, () => printAndResetCounts(step2)); |
| 145 function step2() { |
| 146 resetShowHideCounts(); |
| 147 InspectorTest.addResult("Swapping messages 0 and 1"); |
| 148 var temp = consoleView._visibleViewMessages[0]; |
| 149 consoleView._visibleViewMessages[0] = consoleView._visibleViewMe
ssages[1]; |
| 150 consoleView._visibleViewMessages[1] = temp; |
| 151 viewport.invalidate(); |
| 152 printAndResetCounts(next); |
| 153 } |
| 154 } |
| 155 ]); |
| 156 } |
| 157 </script> |
| 158 </head> |
| 159 <body onload="runTest()"> |
| 160 <p> |
| 161 Verifies viewport correctly shows and hides messages while logging and scrol
ling. |
| 162 </p> |
| 163 </body> |
| 164 </html> |
OLD | NEW |