OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ui/message_center/views/message_popup_collection.h" | 5 #include "ui/message_center/views/message_popup_collection.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/base/events/event.h" |
| 14 #include "ui/base/events/event_constants.h" |
13 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
14 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
15 #include "ui/message_center/fake_message_center.h" | 17 #include "ui/message_center/fake_message_center.h" |
16 #include "ui/message_center/views/toast_contents_view.h" | 18 #include "ui/message_center/views/toast_contents_view.h" |
17 #include "ui/views/test/views_test_base.h" | 19 #include "ui/views/test/views_test_base.h" |
18 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" |
19 | 22 |
20 namespace message_center { | 23 namespace message_center { |
21 namespace test { | 24 namespace test { |
22 | 25 |
23 class MessagePopupCollectionTest : public views::ViewsTestBase { | 26 class MessagePopupCollectionTest : public views::ViewsTestBase { |
24 public: | 27 public: |
25 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() OVERRIDE { |
26 views::ViewsTestBase::SetUp(); | 29 views::ViewsTestBase::SetUp(); |
27 MessageCenter::Initialize(); | 30 MessageCenter::Initialize(); |
28 collection_.reset(new MessagePopupCollection( | 31 collection_.reset(new MessagePopupCollection( |
(...skipping 15 matching lines...) Expand all Loading... |
44 views::ViewsTestBase::TearDown(); | 47 views::ViewsTestBase::TearDown(); |
45 } | 48 } |
46 | 49 |
47 protected: | 50 protected: |
48 MessagePopupCollection* collection() { return collection_.get(); } | 51 MessagePopupCollection* collection() { return collection_.get(); } |
49 | 52 |
50 size_t GetToastCounts() { | 53 size_t GetToastCounts() { |
51 return collection_->toasts_.size(); | 54 return collection_->toasts_.size(); |
52 } | 55 } |
53 | 56 |
| 57 bool MouseInCollection() { |
| 58 return collection_->latest_toast_entered_ != NULL; |
| 59 } |
| 60 |
54 bool IsToastShown(const std::string& id) { | 61 bool IsToastShown(const std::string& id) { |
55 views::Widget* widget = collection_->GetWidgetForTest(id); | 62 views::Widget* widget = collection_->GetWidgetForTest(id); |
56 return widget && widget->IsVisible(); | 63 return widget && widget->IsVisible(); |
57 } | 64 } |
58 | 65 |
59 views::Widget* GetWidget(const std::string& id) { | 66 views::Widget* GetWidget(const std::string& id) { |
60 return collection_->GetWidgetForTest(id); | 67 return collection_->GetWidgetForTest(id); |
61 } | 68 } |
62 | 69 |
63 gfx::Rect GetWorkArea() { | 70 gfx::Rect GetWorkArea() { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 EXPECT_LT(r1.x(), GetWorkArea().CenterPoint().x()); | 335 EXPECT_LT(r1.x(), GetWorkArea().CenterPoint().x()); |
329 | 336 |
330 CloseAllToastsAndWait(); | 337 CloseAllToastsAndWait(); |
331 EXPECT_EQ(0u, GetToastCounts()); | 338 EXPECT_EQ(0u, GetToastCounts()); |
332 | 339 |
333 // Restore simulated taskbar position to bottom. | 340 // Restore simulated taskbar position to bottom. |
334 collection()->SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | 341 collection()->SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. |
335 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | 342 gfx::Rect(0, 0, 600, 400)); // Display-bounds. |
336 } | 343 } |
337 | 344 |
| 345 TEST_F(MessagePopupCollectionTest, DetectMouseHover) { |
| 346 std::string id0 = AddNotification(); |
| 347 std::string id1 = AddNotification(); |
| 348 WaitForTransitionsDone(); |
| 349 |
| 350 views::WidgetDelegateView* toast0 = GetToast(id0); |
| 351 EXPECT_TRUE(toast0 != NULL); |
| 352 views::WidgetDelegateView* toast1 = GetToast(id1); |
| 353 EXPECT_TRUE(toast1 != NULL); |
| 354 |
| 355 ui::MouseEvent event(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 0); |
| 356 |
| 357 // Test that mouse detection logic works in presence of out-of-order events. |
| 358 toast0->OnMouseEntered(event); |
| 359 EXPECT_TRUE(MouseInCollection()); |
| 360 toast1->OnMouseEntered(event); |
| 361 EXPECT_TRUE(MouseInCollection()); |
| 362 toast0->OnMouseExited(event); |
| 363 EXPECT_TRUE(MouseInCollection()); |
| 364 toast1->OnMouseExited(event); |
| 365 EXPECT_FALSE(MouseInCollection()); |
| 366 |
| 367 // Test that mouse detection logic works in presence of WindowClosing events. |
| 368 toast0->OnMouseEntered(event); |
| 369 EXPECT_TRUE(MouseInCollection()); |
| 370 toast1->OnMouseEntered(event); |
| 371 EXPECT_TRUE(MouseInCollection()); |
| 372 toast0->WindowClosing(); |
| 373 EXPECT_TRUE(MouseInCollection()); |
| 374 toast1->WindowClosing(); |
| 375 EXPECT_FALSE(MouseInCollection()); |
| 376 } |
| 377 |
338 // TODO(dimich): Test repositioning - both normal one and when user is closing | 378 // TODO(dimich): Test repositioning - both normal one and when user is closing |
339 // the toasts. | 379 // the toasts. |
340 | 380 |
341 } // namespace test | 381 } // namespace test |
342 } // namespace message_center | 382 } // namespace message_center |
OLD | NEW |