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

Side by Side Diff: ui/message_center/views/message_popup_collection_unittest.cc

Issue 14139014: Reposition toasts to align the closed one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/message_center/views/message_popup_collection.h"
6
7 #include <list>
8
9 #include "base/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/message_center/fake_message_center.h"
13 #include "ui/views/test/views_test_base.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace message_center {
17 namespace test {
18
19 class MessagePopupCollectionTest : public views::ViewsTestBase {
20 public:
21 virtual void SetUp() OVERRIDE {
22 views::ViewsTestBase::SetUp();
23 collection_.reset(new MessagePopupCollection(NULL, &message_center_));
24 collection_->SetWorkAreaForTest(gfx::Rect(0, 0, 200, 200));
25 }
26
27 virtual void TearDown() OVERRIDE {
28 collection_->CloseAllWidgets();
29 views::ViewsTestBase::TearDown();
30 }
31
32 protected:
33 void CreateWidgets(const std::vector<gfx::Rect>& rects) {
34 for (std::vector<gfx::Rect>::const_iterator iter = rects.begin();
35 iter != rects.end(); ++iter) {
36 views::Widget* widget = new views::Widget();
37 views::Widget::InitParams params = CreateParams(
38 views::Widget::InitParams::TYPE_POPUP);
39 params.keep_on_top = true;
40 params.top_level = true;
41 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
42 widget->Init(params);
43 widget->SetBounds(*iter);
44 collection_->widgets_.push_back(widget);
45 }
46 }
47
48 void RepositionWidgets() {
49 collection_->RepositionWidgets();
50 }
51
52 void RepositionWidgetsWithTarget(const gfx::Rect& target_rect) {
53 collection_->RepositionWidgetsWithTarget(target_rect);
54 }
55
56 gfx::Rect GetWidgetRectAt(size_t index) {
57 size_t i = 0;
58 for (std::list<views::Widget*>::const_iterator iter =
59 collection_->widgets_.begin();
60 iter != collection_->widgets_.end(); ++iter) {
61 if (i++ == index)
62 return (*iter)->GetWindowBoundsInScreen();
63 }
64 return gfx::Rect();
65 }
66
67 private:
68 FakeMessageCenter message_center_;
69 scoped_ptr<MessagePopupCollection> collection_;
70 };
71
72 TEST_F(MessagePopupCollectionTest, RepositionWidgets) {
73 std::vector<gfx::Rect> rects;
74 std::list<views::Widget*> widgets;
75 rects.push_back(gfx::Rect(0, 0, 10, 10));
76 rects.push_back(gfx::Rect(0, 0, 10, 20));
77 rects.push_back(gfx::Rect(0, 0, 10, 30));
78 rects.push_back(gfx::Rect(0, 0, 10, 40));
79 CreateWidgets(rects);
80 RepositionWidgets();
81
82 EXPECT_EQ("0,180 10x10", GetWidgetRectAt(0).ToString());
83 EXPECT_EQ("0,150 10x20", GetWidgetRectAt(1).ToString());
84 EXPECT_EQ("0,110 10x30", GetWidgetRectAt(2).ToString());
85 EXPECT_EQ("0,60 10x40", GetWidgetRectAt(3).ToString());
86 }
87
88 TEST_F(MessagePopupCollectionTest, RepositionWidgetsWithTargetDown) {
89 std::vector<gfx::Rect> rects;
90 std::list<views::Widget*> widgets;
91 rects.push_back(gfx::Rect(0, 180, 10, 10));
92 rects.push_back(gfx::Rect(0, 150, 10, 20));
93 rects.push_back(gfx::Rect(0, 60, 10, 40));
94 CreateWidgets(rects);
95 RepositionWidgetsWithTarget(gfx::Rect(0, 110, 10, 30));
96
97 EXPECT_EQ("0,180 10x10", GetWidgetRectAt(0).ToString());
98 EXPECT_EQ("0,150 10x20", GetWidgetRectAt(1).ToString());
99 EXPECT_EQ("0,110 10x40", GetWidgetRectAt(2).ToString());
100 }
101
102 TEST_F(MessagePopupCollectionTest, RepositionWidgetsWithTargetDownAll) {
103 std::vector<gfx::Rect> rects;
104 std::list<views::Widget*> widgets;
105 rects.push_back(gfx::Rect(0, 150, 10, 20));
106 rects.push_back(gfx::Rect(0, 110, 10, 30));
107 rects.push_back(gfx::Rect(0, 60, 10, 40));
108 CreateWidgets(rects);
109 RepositionWidgetsWithTarget(gfx::Rect(0, 180, 10, 10));
110
111 EXPECT_EQ("0,180 10x20", GetWidgetRectAt(0).ToString());
112 EXPECT_EQ("0,140 10x30", GetWidgetRectAt(1).ToString());
113 EXPECT_EQ("0,90 10x40", GetWidgetRectAt(2).ToString());
114 }
115
116 TEST_F(MessagePopupCollectionTest, RepositionWidgetsWithTargetUp) {
117 std::vector<gfx::Rect> rects;
118 std::list<views::Widget*> widgets;
119 rects.push_back(gfx::Rect(0, 180, 10, 10));
120 rects.push_back(gfx::Rect(0, 150, 10, 20));
121 rects.push_back(gfx::Rect(0, 110, 10, 30));
122 CreateWidgets(rects);
123 RepositionWidgetsWithTarget(gfx::Rect(0, 60, 10, 40));
124
125 EXPECT_EQ("0,130 10x10", GetWidgetRectAt(0).ToString());
126 EXPECT_EQ("0,100 10x20", GetWidgetRectAt(1).ToString());
127 EXPECT_EQ("0,60 10x30", GetWidgetRectAt(2).ToString());
128 }
129
130 } // namespace test
131 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698