Skip to content

Commit

Permalink
DevTools: add console viewport visibility test cleanup
Browse files Browse the repository at this point in the history
Besides minor cleanup, in this CL:
- Viewport selection.js and stick-to-bottom.js tests no longer
  do "verifyViewportIsTallEnough". This sort of test is now covered
  by "console-viewport-indices.js"
- The actual visible indices can be determined in tests with a
  helper that uses getBoundingClientRect()

Bug: 803537
Change-Id: I7642051b6a5eb358c536ae29568ec9de91a02a8b
Reviewed-on: https://chromium-review.googlesource.com/874778
Reviewed-by: Joel Einbinder <[email protected]>
Reviewed-by: Andrey Lushnikov <[email protected]>
Commit-Queue: Erik Luo <[email protected]>
Cr-Commit-Position: refs/heads/master@{#531158}
  • Loading branch information
psybuzz authored and Commit Bot committed Jan 23, 2018
1 parent a36b6c4 commit 455651f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions front_end/console_test_runner/ConsoleTestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,32 @@ ConsoleTestRunner.dumpStackTraces = function() {
}
}
};

/**
* Returns actual visible indices. Messages in the margin are treated as NOT visible.
* @return {!{first: number, last: number, count: number}}
*/
ConsoleTestRunner.visibleIndices = function() {
var consoleView = Console.ConsoleView.instance();
var viewport = consoleView._viewport;
var viewportRect = viewport.element.getBoundingClientRect();
var viewportPadding = parseFloat(window.getComputedStyle(viewport.element).paddingTop);
var first = -1;
var last = -1;
var count = 0;
for (var i = 0; i < consoleView._visibleViewMessages.length; i++) {
// Created message elements may have a bounding rect, but not be connected to DOM.
var item = consoleView._visibleViewMessages[i];
if (!item._element || !item._element.isConnected)
continue;
var itemRect = item._element.getBoundingClientRect();
var isVisible = (itemRect.bottom > viewportRect.top + viewportPadding + 1) &&
(itemRect.top <= viewportRect.bottom - viewportPadding - 1);
if (isVisible) {
first = first === -1 ? i : first;
last = i;
count++;
}
}
return {first, last, count};
};

0 comments on commit 455651f

Please sign in to comment.