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

Unified Diff: ui/file_manager/file_manager/foreground/js/ui/file_table_unittest.js

Issue 2172173002: Avoid generating negative width of columns when the view is too small. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test for testSetWidthAndkeepTotal. Created 4 years, 5 months 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
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/ui/file_table.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/ui/file_table_unittest.js
diff --git a/ui/file_manager/file_manager/foreground/js/ui/file_table_unittest.js b/ui/file_manager/file_manager/foreground/js/ui/file_table_unittest.js
index a2f67ce29a4f7b349c7aefb0ec050e3e201ae714..dc28e2c555cd067545a8c86beb9e2904b0f14b09 100644
--- a/ui/file_manager/file_manager/foreground/js/ui/file_table_unittest.js
+++ b/ui/file_manager/file_manager/foreground/js/ui/file_table_unittest.js
@@ -183,3 +183,44 @@ function testExportAndRestoreColumnConfigWithHidingColumn() {
assertArrayEquals(expectedWidths, getColumnWidths(newModel));
assertEquals(expectedTotalWidth, newModel.totalWidth);
}
+
+function testNormalizeWidth() {
+ var newContentWidth = 150;
+ var expectedWidths = [10, 20, 30, 40, 50];
+
+ for (var i = 0; i < model.size; i++) {
+ model.setWidth(i, expectedWidths[i] * 17);
+ }
+
+ // Resizes columns proportionally
+ model.normalizeWidths(newContentWidth);
+
+ assertArrayEquals(expectedWidths, getColumnWidths(model));
+ assertEquals(newContentWidth, model.totalWidth);
+}
+
+function testNormalizeWidthWithSmallWidth() {
+ model.normalizeWidths(10); // not enough width to contain all columns
+
+ // Should keep the minimum width.
+ getColumnWidths(model).map(function(width) {
+ assertEquals(FileTableColumnModel.MIN_WIDTH_, width);
+ });
+}
+
+function testSetWidthAndKeepTotal() {
+ // Make sure to take column snapshot. Required for setWidthAndKeepTotal.
+ model.initializeColumnPos();
+
+ // Attempt to expand the 3rd column exceeding the window.
+ model.setWidthAndKeepTotal(2, 400);
+
+ // Should keep the minimum width.
+ getColumnWidths(model).map(function(width) {
+ assertTrue(width >= FileTableColumnModel.MIN_WIDTH_);
+ });
+ var minWidth = FileTableColumnModel.MIN_WIDTH_;
+ // Total width = 500.
+ expectedWidths = [100, 100, 500 - 100 * 2 - minWidth * 2, minWidth, minWidth];
+ assertArrayEquals(expectedWidths, getColumnWidths(model));
+}
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/ui/file_table.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698