OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/popup_message.h" | 5 #include "ash/popup_message.h" |
6 | 6 |
7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
11 | 11 |
12 namespace ash { | 12 namespace ash { |
13 | 13 |
14 using PopupMessageTest = test::AshTestBase; | 14 using PopupMessageTest = test::AshTestBase; |
15 | 15 |
16 // Verifies the layout of the popup, especially it does not crop the caption and | 16 // Verifies the layout of the popup, especially it does not crop the caption and |
17 // message text. See http://crbug.com/468494. | 17 // message text. See http://crbug.com/468494. |
18 TEST_F(PopupMessageTest, Layout) { | 18 TEST_F(PopupMessageTest, Layout) { |
19 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 19 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
20 nullptr, CurrentContext(), gfx::Rect(0, 0, 100, 100)); | 20 nullptr, CurrentContext(), gfx::Rect(0, 0, 100, 100)); |
21 PopupMessage message(base::ASCIIToUTF16("caption text"), | 21 PopupMessage message( |
22 base::ASCIIToUTF16( | 22 base::ASCIIToUTF16("caption text"), |
23 "Message text, which will be usually longer than " | 23 base::ASCIIToUTF16("Message text, which will be usually longer than " |
24 "the caption, so that it's wrapped at some width"), | 24 "the caption, so that it's wrapped at some width"), |
25 PopupMessage::ICON_WARNING, | 25 PopupMessage::ICON_WARNING, widget->GetContentsView() /* anchor */, |
26 widget->GetContentsView() /* anchor */, | 26 views::BubbleBorder::TOP_LEFT, gfx::Size(), 10); |
27 views::BubbleBorder::TOP_LEFT, gfx::Size(), 10); | |
28 | 27 |
29 views::View* contents_view = message.widget_->GetContentsView(); | 28 views::View* contents_view = message.widget_->GetContentsView(); |
30 views::View* caption_label = | 29 views::View* caption_label = |
31 contents_view->GetViewByID(PopupMessage::kCaptionLabelID); | 30 contents_view->GetViewByID(PopupMessage::kCaptionLabelID); |
32 views::View* message_label = | 31 views::View* message_label = |
33 contents_view->GetViewByID(PopupMessage::kMessageLabelID); | 32 contents_view->GetViewByID(PopupMessage::kMessageLabelID); |
34 ASSERT_TRUE(caption_label); | 33 ASSERT_TRUE(caption_label); |
35 ASSERT_TRUE(message_label); | 34 ASSERT_TRUE(message_label); |
36 | 35 |
37 // The bubble should have enough heights to show both of the labels. | 36 // The bubble should have enough heights to show both of the labels. |
38 EXPECT_GE(contents_view->height(), | 37 EXPECT_GE(contents_view->height(), |
39 caption_label->height() + message_label->height()); | 38 caption_label->height() + message_label->height()); |
40 | 39 |
41 // The labels are not cropped -- the assigned height has enough height to show | 40 // The labels are not cropped -- the assigned height has enough height to show |
42 // the full text. | 41 // the full text. |
43 EXPECT_GE(caption_label->height(), | 42 EXPECT_GE(caption_label->height(), |
44 caption_label->GetHeightForWidth(caption_label->width())); | 43 caption_label->GetHeightForWidth(caption_label->width())); |
45 EXPECT_GE(message_label->height(), | 44 EXPECT_GE(message_label->height(), |
46 message_label->GetHeightForWidth(message_label->width())); | 45 message_label->GetHeightForWidth(message_label->width())); |
47 | 46 |
48 message.Close(); | 47 message.Close(); |
49 widget->Close(); | 48 widget->Close(); |
50 } | 49 } |
51 | 50 |
52 } // namespace ash | 51 } // namespace ash |
OLD | NEW |