summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormukai <mukai@chromium.org>2015-03-24 22:15:21 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-25 05:16:02 +0000
commitb4838b40d1a3d0a5b889c57e96c00b61ad022d8c (patch)
tree61906bd4092761e205165ef6e7e35ea69756b10b
parent2a2b00ffa76a85f9a6586d19191218edaf429591 (diff)
downloadchromium_src-b4838b40d1a3d0a5b889c57e96c00b61ad022d8c.zip
chromium_src-b4838b40d1a3d0a5b889c57e96c00b61ad022d8c.tar.gz
chromium_src-b4838b40d1a3d0a5b889c57e96c00b61ad022d8c.tar.bz2
Add the layout test case of ash/popup_message.
BUG=468494 R=oshima@chromium.org TEST=the new test case fails before r321652, but succeeds on ToT. Review URL: https://codereview.chromium.org/1026943002 Cr-Commit-Position: refs/heads/master@{#322115}
-rw-r--r--ash/ash.gyp1
-rw-r--r--ash/popup_message.cc6
-rw-r--r--ash/popup_message.h6
-rw-r--r--ash/popup_message_unittest.cc52
4 files changed, 65 insertions, 0 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index bb44467..bead4a6 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -787,6 +787,7 @@
'keyboard_overlay/keyboard_overlay_delegate_unittest.cc',
'keyboard_overlay/keyboard_overlay_view_unittest.cc',
'magnifier/magnification_controller_unittest.cc',
+ 'popup_message_unittest.cc',
'root_window_controller_unittest.cc',
'screen_util_unittest.cc',
'shelf/scoped_observer_with_duplicated_sources_unittest.cc',
diff --git a/ash/popup_message.cc b/ash/popup_message.cc
index 6256659..bdde23b 100644
--- a/ash/popup_message.cc
+++ b/ash/popup_message.cc
@@ -63,6 +63,10 @@ class PopupMessage::MessageBubble : public views::BubbleDelegateView {
DISALLOW_COPY_AND_ASSIGN(MessageBubble);
};
+// static
+const int PopupMessage::kCaptionLabelID = 1000;
+const int PopupMessage::kMessageLabelID = 1001;
+
PopupMessage::MessageBubble::MessageBubble(const base::string16& caption,
const base::string16& message,
IconType message_type,
@@ -128,6 +132,7 @@ PopupMessage::MessageBubble::MessageBubble(const base::string16& caption,
// The caption label.
if (!caption.empty()) {
views::Label* caption_label = new views::Label(caption);
+ caption_label->set_id(kCaptionLabelID);
caption_label->SetMultiLine(true);
caption_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
caption_label->SetFontList(
@@ -139,6 +144,7 @@ PopupMessage::MessageBubble::MessageBubble(const base::string16& caption,
// The message label.
if (!message.empty()) {
views::Label* message_label = new views::Label(message);
+ message_label->set_id(kMessageLabelID);
message_label->SetMultiLine(true);
message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
message_label->SetEnabledColor(kMessageTextColor);
diff --git a/ash/popup_message.h b/ash/popup_message.h
index 8731536..c2b160f 100644
--- a/ash/popup_message.h
+++ b/ash/popup_message.h
@@ -7,6 +7,7 @@
#include "ash/ash_export.h"
#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
#include "base/strings/string16.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/bubble/bubble_border.h"
@@ -62,8 +63,13 @@ class ASH_EXPORT PopupMessage {
void Close();
private:
+ FRIEND_TEST_ALL_PREFIXES(PopupMessageTest, Layout);
+
class MessageBubble;
+ static const int kCaptionLabelID;
+ static const int kMessageLabelID;
+
void CancelHidingAnimation();
MessageBubble* view_;
diff --git a/ash/popup_message_unittest.cc b/ash/popup_message_unittest.cc
new file mode 100644
index 0000000..374e0aa
--- /dev/null
+++ b/ash/popup_message_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2015 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 "ash/popup_message.h"
+
+#include "ash/test/ash_test_base.h"
+#include "base/strings/utf_string_conversions.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+
+typedef test::AshTestBase PopupMessageTest;
+
+// Verifies the layout of the popup, especially it does not crop the caption and
+// message text. See http://crbug.com/468494.
+TEST_F(PopupMessageTest, Layout) {
+ views::Widget* widget =
+ views::Widget::CreateWindowWithBounds(nullptr, gfx::Rect(0, 0, 100, 100));
+ PopupMessage message(base::ASCIIToUTF16("caption text"),
+ base::ASCIIToUTF16(
+ "Message text, which will be usually longer than "
+ "the caption, so that it's wrapped at some width"),
+ PopupMessage::ICON_WARNING,
+ widget->GetContentsView() /* anchor */,
+ views::BubbleBorder::TOP_LEFT, gfx::Size(), 10);
+
+ views::View* contents_view = message.widget_->GetContentsView();
+ views::View* caption_label =
+ contents_view->GetViewByID(PopupMessage::kCaptionLabelID);
+ views::View* message_label =
+ contents_view->GetViewByID(PopupMessage::kMessageLabelID);
+ ASSERT_TRUE(caption_label);
+ ASSERT_TRUE(message_label);
+
+ // The bubble should have enough heights to show both of the labels.
+ EXPECT_GE(contents_view->height(),
+ caption_label->height() + message_label->height());
+
+ // The labels are not cropped -- the assigned height has enough height to show
+ // the full text.
+ EXPECT_GE(caption_label->height(),
+ caption_label->GetHeightForWidth(caption_label->width()));
+ EXPECT_GE(message_label->height(),
+ message_label->GetHeightForWidth(message_label->width()));
+
+ message.Close();
+ widget->Close();
+}
+
+} // namespace ash