15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/web_notification/web_notification_tray.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ash/ash_switches.h"
10558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "ash/display/display_manager.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/root_window_controller.h"
12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/shell.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/status_area_widget.h"
16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_item.h"
18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ash/system/web_notification/ash_popup_alignment_delegate.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h"
20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/test/status_area_widget_test_helper.h"
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ash/test/test_system_tray_delegate.h"
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/wm/window_state.h"
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/command_line.h"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h"
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/aura/client/aura_constants.h"
273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/aura/window.h"
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/events/event.h"
295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/events/test/event_generator.h"
303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/gfx/display.h"
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/gfx/point.h"
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/gfx/rect.h"
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/gfx/screen.h"
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/message_center/message_center_style.h"
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/message_center_tray.h"
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_list.h"
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_types.h"
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/views/message_center_bubble.h"
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/views/message_popup_collection.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/label.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/fill_layout.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/view.h"
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)WebNotificationTray* GetTray() {
50a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->
51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      web_notification_tray();
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
54558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochWebNotificationTray* GetSecondaryTray() {
55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  StatusAreaWidget* status_area_widget =
56a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget();
57a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (status_area_widget)
58a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return status_area_widget->web_notification_tray();
59558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  return NULL;
60558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch}
61558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)message_center::MessageCenter* GetMessageCenter() {
63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return GetTray()->message_center();
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)SystemTray* GetSystemTray() {
67a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray();
68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Trivial item implementation for testing PopupAndSystemTray test case.
71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class TestItem : public SystemTrayItem {
72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) public:
73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  TestItem() : SystemTrayItem(GetSystemTray()) {}
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE {
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    views::View* default_view = new views::View;
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    default_view->SetLayoutManager(new views::FillLayout);
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    default_view->AddChildView(new views::Label(base::UTF8ToUTF16("Default")));
79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return default_view;
80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual views::View* CreateNotificationView(
83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      user::LoginStatus status) OVERRIDE {
84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return new views::View;
85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) private:
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestItem);
89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}  // namespace
92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class WebNotificationTrayTest : public test::AshTestBase {
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  WebNotificationTrayTest() {}
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual ~WebNotificationTrayTest() {}
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void SetUp() OVERRIDE {
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    CommandLine::ForCurrentProcess()->AppendSwitch(
1001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        switches::kAshEnableTouchViewTouchFeedback);
1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    test::AshTestBase::SetUp();
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void TearDown() OVERRIDE {
105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    GetMessageCenter()->RemoveAllNotifications(false);
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    test::AshTestBase::TearDown();
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected:
110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void AddNotification(const std::string& id) {
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    scoped_ptr<message_center::Notification> notification;
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    notification.reset(new message_center::Notification(
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        message_center::NOTIFICATION_TYPE_SIMPLE,
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        id,
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::ASCIIToUTF16("Test Web Notification"),
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::ASCIIToUTF16("Notification message body."),
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        gfx::Image(),
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::ASCIIToUTF16("www.test.org"),
119424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        message_center::NotifierId(),
1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        message_center::RichNotificationData(),
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        NULL /* delegate */));
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    GetMessageCenter()->AddNotification(notification.Pass());
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void UpdateNotification(const std::string& old_id,
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          const std::string& new_id) {
127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    scoped_ptr<message_center::Notification> notification;
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    notification.reset(new message_center::Notification(
129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        message_center::NOTIFICATION_TYPE_SIMPLE,
13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        new_id,
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::ASCIIToUTF16("Updated Web Notification"),
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::ASCIIToUTF16("Updated message body."),
133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        gfx::Image(),
1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::ASCIIToUTF16("www.test.org"),
135424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        message_center::NotifierId(),
1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        message_center::RichNotificationData(),
137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        NULL /* delegate */));
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    GetMessageCenter()->UpdateNotification(old_id, notification.Pass());
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void RemoveNotification(const std::string& id) {
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    GetMessageCenter()->RemoveNotification(id, false);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  views::Widget* GetWidget() {
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return GetTray()->GetWidget();
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int GetPopupWorkAreaBottom() {
150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return GetPopupWorkAreaBottomForTray(GetTray());
151a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
152a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
153116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) {
154116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return tray->popup_alignment_delegate_->GetWorkAreaBottom();
155a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
156a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bool IsPopupVisible() {
1583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return GetTray()->IsPopupVisible();
1593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
1603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest);
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(WebNotificationTrayTest, WebNotifications) {
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(mukai): move this test case to ui/message_center.
167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(GetWidget());
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add a notification.
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AddNotification("test_id1");
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1u, GetMessageCenter()->NotificationCount());
172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(GetMessageCenter()->FindVisibleNotificationById("test_id1"));
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AddNotification("test_id2");
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AddNotification("test_id2");
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(2u, GetMessageCenter()->NotificationCount());
176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(GetMessageCenter()->FindVisibleNotificationById("test_id2"));
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ensure that updating a notification does not affect the count.
179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateNotification("test_id2", "test_id3");
180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateNotification("test_id3", "test_id3");
181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(2u, GetMessageCenter()->NotificationCount());
182f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(GetMessageCenter()->FindVisibleNotificationById("test_id2"));
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ensure that Removing the first notification removes it from the tray.
185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RemoveNotification("test_id1");
186f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(GetMessageCenter()->FindVisibleNotificationById("test_id1"));
187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1u, GetMessageCenter()->NotificationCount());
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Remove the remianing notification.
190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RemoveNotification("test_id3");
191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0u, GetMessageCenter()->NotificationCount());
192f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(GetMessageCenter()->FindVisibleNotificationById("test_id3"));
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) {
196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(mukai): move this test case to ui/message_center.
197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(GetWidget());
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adding a notification should show the popup bubble.
200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AddNotification("test_id1");
201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updating a notification should not hide the popup bubble.
204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AddNotification("test_id2");
205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateNotification("test_id2", "test_id3");
206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removing the first notification should not hide the popup bubble.
209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RemoveNotification("test_id1");
210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removing the visible notification should hide the popup bubble.
213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RemoveNotification("test_id3");
214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(GetTray()->IsPopupVisible());
215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Now test that we can show multiple popups and then show the message center.
217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AddNotification("test_id4");
218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AddNotification("test_id5");
219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  GetTray()->message_center_tray_->ShowMessageCenterBubble();
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  GetTray()->message_center_tray_->HideMessageCenterBubble();
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_FALSE(GetTray()->IsPopupVisible());
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using message_center::NotificationList;
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Flakily fails. http://crbug.com/229791
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) {
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add the max visible notifications +1, ensure the correct visible number.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t notifications_to_add =
234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      message_center::kMaxVisibleMessageCenterNotifications + 1;
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < notifications_to_add; ++i) {
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    AddNotification(id);
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool shown = GetTray()->message_center_tray_->ShowMessageCenterBubble();
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shown);
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RunAllPendingInMessageLoop();
242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(GetTray()->message_center_bubble() != NULL);
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(notifications_to_add,
244c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            GetMessageCenter()->NotificationCount());
245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(message_center::kMaxVisibleMessageCenterNotifications,
246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            GetTray()->GetMessageCenterBubbleForTest()->
247c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                NumMessageViewsForTest());
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Flakily times out. http://crbug.com/229792
251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) {
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add the max visible popup notifications +1, ensure the correct num visible.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t notifications_to_add =
254c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      message_center::kMaxVisiblePopupNotifications + 1;
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < notifications_to_add; ++i) {
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
257c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    AddNotification(id);
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
259a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetTray()->ShowPopups();
260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(notifications_to_add,
262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            GetMessageCenter()->NotificationCount());
2637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  NotificationList::PopupNotifications popups =
2647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetMessageCenter()->GetPopupNotifications();
2657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size());
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
268558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_CHROMEOS)
269558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Display notification is ChromeOS only.
270558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays
271a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define MAYBE_PopupAndSystemTrayMultiDisplay PopupAndSystemTrayMultiDisplay
272558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#else
273558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#define MAYBE_PopupShownOnBothDisplays DISABLED_PopupShownOnBothDisplays
274a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define MAYBE_PopupAndSystemTrayMultiDisplay \
275a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  DISABLED_PopupAndSystemTrayMultiDisplay
276558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif
277558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
278558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Verifies if the notification appears on both displays when extended mode.
279558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochTEST_F(WebNotificationTrayTest, MAYBE_PopupShownOnBothDisplays) {
280558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  if (!SupportsMultipleDisplays())
281558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch    return;
282558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
283558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Enables to appear the notification for display changes.
284558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  test::TestSystemTrayDelegate* tray_delegate =
285558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch      static_cast<test::TestSystemTrayDelegate*>(
286558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch          Shell::GetInstance()->system_tray_delegate());
287558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  tray_delegate->set_should_show_display_notification(true);
288558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
289558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  UpdateDisplay("400x400,200x200");
290558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // UpdateDisplay() creates the display notifications, so popup is visible.
291558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(GetTray()->IsPopupVisible());
292558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  WebNotificationTray* secondary_tray = GetSecondaryTray();
293558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  ASSERT_TRUE(secondary_tray);
294558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(secondary_tray->IsPopupVisible());
295558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
296558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Transition to mirroring and then back to extended display, which recreates
297558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // root window controller and shelf with having notifications. This code
298558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // verifies it doesn't cause crash and popups are still visible. See
299558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // http://crbug.com/263664
300c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
301558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
302c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  display_manager->SetSecondDisplayMode(DisplayManager::MIRRORING);
303558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  UpdateDisplay("400x400,200x200");
304558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(GetTray()->IsPopupVisible());
305558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_FALSE(GetSecondaryTray());
306558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
307c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  display_manager->SetSecondDisplayMode(DisplayManager::EXTENDED);
308558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  UpdateDisplay("400x400,200x200");
309558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(GetTray()->IsPopupVisible());
310558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  secondary_tray = GetSecondaryTray();
311558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  ASSERT_TRUE(secondary_tray);
312558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(secondary_tray->IsPopupVisible());
313558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch}
314558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
315a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#if defined(OS_CHROMEOS)
316a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// PopupAndSystemTray may fail in platforms other than ChromeOS because the
317a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// RootWindow's bound can be bigger than gfx::Display's work area so that
318a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// openingsystem tray doesn't affect at all the work area of popups.
319a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define MAYBE_PopupAndSystemTray PopupAndSystemTray
3203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define MAYBE_PopupAndAutoHideShelf PopupAndAutoHideShelf
3213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define MAYBE_PopupAndFullscreen PopupAndFullscreen
322a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#else
323a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#define MAYBE_PopupAndSystemTray DISABLED_PopupAndSystemTray
3243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define MAYBE_PopupAndAutoHideShelf DISABLED_PopupAndAutoHideShelf
3253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define MAYBE_PopupAndFullscreen DISABLED_PopupAndFullscreen
326a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
327a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
328a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) {
329a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  TestItem* test_item = new TestItem;
330a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->AddTrayItem(test_item);
331a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
332a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  AddNotification("test_id");
333a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
334116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom = GetPopupWorkAreaBottom();
335a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
336a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // System tray is created, the popup's work area should be narrowed but still
337a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // visible.
338a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
339a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
340116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_with_tray = GetPopupWorkAreaBottom();
341116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom, bottom_with_tray);
342a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
343a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // System tray notification is also created, the popup's work area is narrowed
344a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // even more, but still visible.
345a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->ShowNotificationView(test_item);
346a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
347116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_with_tray_notification = GetPopupWorkAreaBottom();
348116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom, bottom_with_tray_notification);
349116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom_with_tray, bottom_with_tray_notification);
350a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
351a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Close system tray, only system tray notifications.
352a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->ClickedOutsideBubble();
353a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
354116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_with_notification = GetPopupWorkAreaBottom();
355116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom, bottom_with_notification);
356116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_LT(bottom_with_tray_notification, bottom_with_notification);
357a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
3583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Close the system tray notifications.
359a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->HideNotificationView(test_item);
360a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
361116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(bottom, GetPopupWorkAreaBottom());
362a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
363a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
3643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) {
365a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  AddNotification("test_id");
3663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
367116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom = GetPopupWorkAreaBottom();
368a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
3693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Shelf's auto-hide state won't be HIDDEN unless window exists.
3703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<aura::Window> window(
3713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
372c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfLayoutManager* shelf =
3733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
3743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
3753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
377116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_auto_hidden = GetPopupWorkAreaBottom();
378116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_LT(bottom, bottom_auto_hidden);
3793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Close the window, which shows the shelf.
3813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  window.reset();
3823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
383116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_auto_shown = GetPopupWorkAreaBottom();
384116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(bottom, bottom_auto_shown);
3853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Create the system tray during auto-hide.
3873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
3883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  TestItem* test_item = new TestItem;
3893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  GetSystemTray()->AddTrayItem(test_item);
390a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
3913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
3933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(GetTray()->IsPopupVisible());
394116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_with_tray = GetPopupWorkAreaBottom();
395116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom_auto_shown, bottom_with_tray);
3963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Create tray notification.
3983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  GetSystemTray()->ShowNotificationView(test_item);
3993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
400116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_with_tray_notification = GetPopupWorkAreaBottom();
401116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom_with_tray, bottom_with_tray_notification);
4023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Close the system tray.
4043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  GetSystemTray()->ClickedOutsideBubble();
4053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  shelf->UpdateAutoHideState();
4063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  RunAllPendingInMessageLoop();
4073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
408116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_hidden_with_tray_notification = GetPopupWorkAreaBottom();
409116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_LT(bottom_with_tray_notification,
410116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            bottom_hidden_with_tray_notification);
411116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom_auto_hidden, bottom_hidden_with_tray_notification);
4123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Close the window again, which shows the shelf.
4143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  window.reset();
4153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
416116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_shown_with_tray_notification = GetPopupWorkAreaBottom();
417116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom_hidden_with_tray_notification,
418116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            bottom_shown_with_tray_notification);
419116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom_auto_shown, bottom_shown_with_tray_notification);
4203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
4213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) {
4233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  AddNotification("test_id");
4243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(IsPopupVisible());
425116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom = GetPopupWorkAreaBottom();
4263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Checks the work area for normal auto-hidden state.
4283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<aura::Window> window(
4293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
430c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfLayoutManager* shelf =
4313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
4323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
4333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
434116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_auto_hidden = GetPopupWorkAreaBottom();
4353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
4363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Put |window| into fullscreen without forcing the shelf to hide. Currently,
4381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // this is used by immersive fullscreen and forces the shelf to be auto
4391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // hidden.
4401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  wm::GetWindowState(window.get())->set_hide_shelf_when_fullscreen(false);
4413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
4423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  RunAllPendingInMessageLoop();
4433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // The work area for auto-hidden status of fullscreen is a bit larger
4453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // since it doesn't even have the 3-pixel width.
4463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
447116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_fullscreen_hidden = GetPopupWorkAreaBottom();
448116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(bottom_auto_hidden, bottom_fullscreen_hidden);
4493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Move the mouse cursor at the bottom, which shows the shelf.
4515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
4523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  gfx::Point bottom_right =
4533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom_right();
4543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bottom_right.Offset(-1, -1);
4553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  generator.MoveMouseTo(bottom_right);
4563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  shelf->UpdateAutoHideStateNow();
4573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
458116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(bottom, GetPopupWorkAreaBottom());
4593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
460116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  generator.MoveMouseTo(
461116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      Shell::GetScreen()->GetPrimaryDisplay().bounds().CenterPoint());
4623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  shelf->UpdateAutoHideStateNow();
4633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
464116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(bottom_auto_hidden, GetPopupWorkAreaBottom());
465a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
466a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
467a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) {
468a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  UpdateDisplay("800x600,600x400");
469a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
470a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  AddNotification("test_id");
471116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom = GetPopupWorkAreaBottom();
472116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int bottom_second = GetPopupWorkAreaBottomForTray(GetSecondaryTray());
473a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
474a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // System tray is created on the primary display. The popups in the secondary
475a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // tray aren't affected.
476a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
477116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_GT(bottom, GetPopupWorkAreaBottom());
478116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray()));
479a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
480a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
4811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(jonross): This test is failing on ASAN bots, fix the failure and
4821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// re-enable. (crbug.com/411881)
4831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(jonross): Replace manually creating TouchEvent with
4841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// EventGenerator.PressTouch/ReleaseTouch. Currently they set a width on the
4851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// touch event causing the gesture recognizer to target a different view.
4861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_CHROMEOS)
4871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Tests that there is visual feedback for touch presses.
4881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(WebNotificationTrayTest, DISABLED_TouchFeedback) {
4891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AddNotification("test_id");
4901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
4911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  WebNotificationTray* tray = GetTray();
4921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(tray->visible());
4931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
4951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  const int touch_id = 0;
4961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint();
4971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id,
4991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                       generator.Now());
5001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.Dispatch(&press);
5011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(tray->draw_background_as_active());
5031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center_point, touch_id,
5051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
5061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.Dispatch(&release);
5071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(tray->draw_background_as_active());
5091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(tray->IsMessageCenterBubbleVisible());
5101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.GestureTapAt(center_point);
5121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(tray->draw_background_as_active());
5141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
5151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
5161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(jonross): This test is failing on ASAN bots, fix the failure and
5181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// re-enable. (crbug.com/411881)
5191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Tests that while touch presses trigger visual feedback, that subsequent non
5201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// tap gestures cancel the feedback without triggering the message center.
5211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(WebNotificationTrayTest, DISABLED_TouchFeedbackCancellation) {
5221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AddNotification("test_id");
5231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  WebNotificationTray* tray = GetTray();
5251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(tray->visible());
5261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
5281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  const int touch_id = 0;
5291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::Rect bounds = tray->GetBoundsInScreen();
5301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::Point center_point = bounds.CenterPoint();
5311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id,
5331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                       generator.Now());
5341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.Dispatch(&press);
5351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(tray->draw_background_as_active());
5371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::Point out_of_bounds(bounds.x() - 1, center_point.y());
5391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::TouchEvent move(ui::ET_TOUCH_MOVED, out_of_bounds, touch_id,
5401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                      press.time_stamp()+base::TimeDelta::FromMilliseconds(50));
5411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.Dispatch(&move);
5421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(tray->draw_background_as_active());
5441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id,
5461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      move.time_stamp()+base::TimeDelta::FromMilliseconds(50));
5471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.Dispatch(&release);
5481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
5491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(tray->draw_background_as_active());
5501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
5511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
5521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // OS_CHROMEOS
5541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
556