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

Side by Side Diff: ash/system/web_notification/web_notification_tray_unittest.cc

Issue 10546125: Add WebNotificationTray to the status area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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) 2012 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 "ash/system/web_notification/web_notification_tray.h"
6
7 #include <vector>
8
9 #include "ash/system/status_area_widget.h"
10 #include "ash/system/tray/system_tray_item.h"
11 #include "ash/test/ash_test_base.h"
12 #include "base/utf_string_conversions.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/fill_layout.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h"
17
18 namespace ash {
19
20 namespace {
21
22 WebNotificationTray* CreateWebNotificationTray() {
23 internal::StatusAreaWidget* widget = new internal::StatusAreaWidget;
24 widget->CreateTrayViews(NULL);
25 widget->Show();
26 return widget->web_notification_tray();
27 }
28
29 class TestDelegate : public WebNotificationTray::Delegate {
30 public:
31 TestDelegate() {}
32 virtual ~TestDelegate() {}
33
34 // WebNotificationTray::Delegate overrides.
35 virtual void NotificationRemoved(const std::string& notifcation_id) {
36 notification_ids_.erase(notifcation_id);
37 }
38
39 virtual void DisableExtension(const std::string& notifcation_id) {
40 }
41
42 virtual void DisableNotificationsFromSource(
43 const std::string& notifcation_id) {
44 }
45
46 virtual void ShowSettings(const std::string& notifcation_id) {
47 }
48
49 virtual void OnClicked(const std::string& notifcation_id) {
50 }
51
52 void AddNotification(WebNotificationTray* tray, const std::string& id) {
53 notification_ids_.insert(id);
54 tray->AddNotification(id,
55 ASCIIToUTF16("Test Web Notification"),
56 ASCIIToUTF16("Notification message body."),
57 ASCIIToUTF16("www.test.org"),
58 "" /* extension id */);
59 }
60
61 void RemoveNotification(WebNotificationTray* tray, const std::string& id) {
62 tray->RemoveNotification(id);
63 }
64
65 bool HasNotificationId(const std::string& id) {
66 return notification_ids_.find(id) != notification_ids_.end();
67 }
68
69 private:
70 std::set<std::string> notification_ids_;
71
72 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
73 };
74
75 } // namespace
76
77 typedef test::AshTestBase WebNotificationTrayTest;
78
79 TEST_F(WebNotificationTrayTest, WebNotifications) {
80 scoped_ptr<WebNotificationTray> tray(CreateWebNotificationTray());
81 scoped_ptr<TestDelegate> delegate(new TestDelegate);
82 tray->SetDelegate(delegate.get());
83
84 ASSERT_TRUE(tray->GetWidget());
85
86 // Adding a notification should show the bubble.
87 delegate->AddNotification(tray.get(), "test_id1");
88 EXPECT_TRUE(tray->bubble() != NULL);
89 EXPECT_EQ(1, tray->GetNotificationCount());
90 delegate->AddNotification(tray.get(), "test_id2");
91 delegate->AddNotification(tray.get(), "test_id2");
92 EXPECT_EQ(2, tray->GetNotificationCount());
93 // Ensure that removing a notification removes it from the tray, and signals
94 // the delegate.
95 EXPECT_TRUE(delegate->HasNotificationId("test_id2"));
96 delegate->RemoveNotification(tray.get(), "test_id2");
97 EXPECT_FALSE(delegate->HasNotificationId("test_id2"));
98 EXPECT_EQ(1, tray->GetNotificationCount());
99
100 // Removing the last notification should hide the bubble.
101 delegate->RemoveNotification(tray.get(), "test_id1");
102 EXPECT_EQ(0, tray->GetNotificationCount());
103 EXPECT_TRUE(tray->bubble() == NULL);
104 }
105
106 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698