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

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

Issue 10514008: Add WebNotificationTray (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
« no previous file with comments | « ash/system/web_notification/web_notification_tray.cc ('k') | ash/wm/shelf_layout_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 WebNotificationTray* tray = new WebNotificationTray(widget);
25 widget->AddWebNotificationTray(tray);
26 widget->Show();
27 return tray;
28 }
29
30 class TestDelegate : public WebNotificationTray::Delegate {
31 public:
32 TestDelegate() {}
33 virtual ~TestDelegate() {}
34
35 // WebNotificationTray::Delegate overrides.
36 virtual void NotificationRemoved(const std::string& notifcation_id) {
37 notification_ids_.erase(notifcation_id);
38 }
39
40 virtual void DisableExtension(const std::string& notifcation_id) {
41 }
42
43 virtual void DisableNotificationsFromSource(
44 const std::string& notifcation_id) {
45 }
46
47 virtual void ShowSettings(const std::string& notifcation_id) {
48 }
49
50 void AddNotification(WebNotificationTray* tray, const std::string& id) {
51 notification_ids_.insert(id);
52 tray->AddNotification(id,
53 ASCIIToUTF16("Test Web Notification"),
54 ASCIIToUTF16("Notification message body."),
55 ASCIIToUTF16("www.test.org"),
56 "" /* extension id */);
57 }
58
59 void RemoveNotification(WebNotificationTray* tray, const std::string& id) {
60 tray->RemoveNotification(id);
61 }
62
63 bool HasNotificationId(const std::string& id) {
64 return notification_ids_.find(id) != notification_ids_.end();
65 }
66
67 private:
68 std::set<std::string> notification_ids_;
69
70 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
71 };
72
73 } // namespace
74
75 typedef test::AshTestBase WebNotificationTrayTest;
76
77 TEST_F(WebNotificationTrayTest, WebNotifications) {
78 scoped_ptr<WebNotificationTray> tray(CreateWebNotificationTray());
79 scoped_ptr<TestDelegate> delegate(new TestDelegate);
80 tray->SetDelegate(delegate.get());
81
82 ASSERT_TRUE(tray->GetWidget());
83
84 // Adding a notification should show the bubble.
85 delegate->AddNotification(tray.get(), "test_id1");
86 EXPECT_TRUE(tray->bubble() != NULL);
87 EXPECT_EQ(1, tray->GetNotificationCount());
88 delegate->AddNotification(tray.get(), "test_id2");
89 delegate->AddNotification(tray.get(), "test_id2");
90 EXPECT_EQ(2, tray->GetNotificationCount());
91 // Ensure that removing a notification removes it from the tray, and signals
92 // the delegate.
93 EXPECT_TRUE(delegate->HasNotificationId("test_id2"));
94 delegate->RemoveNotification(tray.get(), "test_id2");
95 EXPECT_FALSE(delegate->HasNotificationId("test_id2"));
96 EXPECT_EQ(1, tray->GetNotificationCount());
97
98 // Removing the last notification should hide the bubble.
99 delegate->RemoveNotification(tray.get(), "test_id1");
100 EXPECT_EQ(0, tray->GetNotificationCount());
101 EXPECT_TRUE(tray->bubble() == NULL);
102 }
103
104 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/web_notification/web_notification_tray.cc ('k') | ash/wm/shelf_layout_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698