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

Unified Diff: chrome/browser/ui/views/download/download_item_view_unittest.cc

Issue 2556573002: Fix SizeLabelToMinWidth() function such that no unnecessary space (Closed)
Patch Set: change to static function Created 4 years 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: chrome/browser/ui/views/download/download_item_view_unittest.cc
diff --git a/chrome/browser/ui/views/download/download_item_view_unittest.cc b/chrome/browser/ui/views/download/download_item_view_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f401cb10b87edeed5a1de6d03b31fac2e2e0d3e7
--- /dev/null
+++ b/chrome/browser/ui/views/download/download_item_view_unittest.cc
@@ -0,0 +1,49 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/download/download_item_view.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/controls/label.h"
+
+typedef testing::Test DownloadItemViewDangerousDownloadLabelTest;
Peter Kasting 2016/12/08 21:53:53 Nit: Prefer type alias ("using") to typedef.
Jialiu Lin 2016/12/08 22:44:03 Done.
+
+// For very short label that can fit in a single line, no need to do any
+// adjustment, return it directly.
+TEST_F(DownloadItemViewDangerousDownloadLabelTest,
+ AdjustTextAndGetSize_VeryShortText) {
+ base::string16 label_text = base::ASCIIToUTF16("very short label");
Peter Kasting 2016/12/08 21:53:53 Nit: I suggest just "short", to minimize the chanc
Jialiu Lin 2016/12/08 22:44:03 Done.
+ views::Label label(label_text);
+ label.SetMultiLine(true);
+ DownloadItemView::AdjustTextAndGetSize(&label);
+ EXPECT_EQ(label_text, label.text());
+}
+
+// When we have multiple linebreaks that result in the same minimum width, we
+// should place as much text as possible on the first line.
+TEST_F(DownloadItemViewDangerousDownloadLabelTest,
+ AdjustTextAndGetSize_MoreTextOnFirstLine) {
+ base::string16 label_text = base::ASCIIToUTF16(
+ "aaaa aaaa aaaa aaaa aaaa aaaa bb aaaa aaaa aaaa aaaa aaaa aaaa");
+ base::string16 expected_text = base::ASCIIToUTF16(
+ "aaaa aaaa aaaa aaaa aaaa aaaa bb\n"
+ "aaaa aaaa aaaa aaaa aaaa aaaa");
+ views::Label label(label_text);
+ label.SetMultiLine(true);
+ DownloadItemView::AdjustTextAndGetSize(&label);
+ EXPECT_EQ(expected_text, label.text());
+}
+
+// If the label is a single word and extremely long, we should not break it into
+// 2 lines.
+TEST_F(DownloadItemViewDangerousDownloadLabelTest,
+ AdjustTextAndGetSize_VeryLongTextWithoutSpace) {
+ base::string16 label_text = base::ASCIIToUTF16(
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ views::Label label(label_text);
+ label.SetMultiLine(true);
+ DownloadItemView::AdjustTextAndGetSize(&label);
+ EXPECT_EQ(label_text, label.text());
+}

Powered by Google App Engine
This is Rietveld 408576698