Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/inspector-unit/static-viewport-control.js

Issue 2513423003: DevTools: Convert inspector-unit tests to use reusable test harness (Closed)
Patch Set: address CL feedback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/inspector-unit/static-viewport-control.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-unit/static-viewport-control.js b/third_party/WebKit/LayoutTests/http/tests/inspector-unit/static-viewport-control.js
new file mode 100644
index 0000000000000000000000000000000000000000..35285801e19e076ac815c8377fdc1ace582174ad
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/inspector-unit/static-viewport-control.js
@@ -0,0 +1,50 @@
+UnitTest.addResult("This tests if the StaticViewportControl works properly.");
+
+var items = [];
+var heights = [];
+for (var i = 0; i < 100; i++){
+ items[i] = document.createElement("div");
+ items[i].style.height = (heights[i] = (i % 4) ? 50 : 28) + "px";
+ items[i].textContent = i;
+}
+var viewport = new UI.StaticViewportControl({
+ fastItemHeight: i => heights[i],
+ itemCount: _ => items.length,
+ itemElement: i => items[i]
+});
+viewport.element.style.height = "300px";
+UI.inspectorView.element.appendChild(viewport.element);
+
+viewport.refresh();
+dumpViewport();
+
+viewport.forceScrollItemToBeFirst(26);
+dumpViewport();
+
+viewport.scrollItemIntoView(33);
+dumpViewport();
+
+viewport.scrollItemIntoView(30);
+dumpViewport();
+
+viewport.forceScrollItemToBeFirst(30);
+dumpViewport();
+
+viewport.forceScrollItemToBeLast(88);
+dumpViewport();
+
+for (var i = 0; i < 100; i++)
+ items[i].style.height = (heights[i] = (i % 2) ? 55 : 63) + "px";
+viewport.refresh();
+viewport.forceScrollItemToBeLast(88);
+dumpViewport();
+
+UnitTest.completeTest();
+
+function dumpViewport()
+{
+ UnitTest.addResult("First:" + viewport.firstVisibleIndex());
+ UnitTest.addResult("Last:" + viewport.lastVisibleIndex());
+ UnitTest.addResult("Active Items:" + viewport._innerElement.children.length);
+ UnitTest.addResult("");
+}

Powered by Google App Engine
This is Rietveld 408576698