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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/web_notification/web_notification_tray_unittest.cc
diff --git a/ash/system/web_notification/web_notification_tray_unittest.cc b/ash/system/web_notification/web_notification_tray_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..80a64caddeedb0b8b8294326c4f36ec8641273aa
--- /dev/null
+++ b/ash/system/web_notification/web_notification_tray_unittest.cc
@@ -0,0 +1,104 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/web_notification/web_notification_tray.h"
+
+#include <vector>
+
+#include "ash/system/status_area_widget.h"
+#include "ash/system/tray/system_tray_item.h"
+#include "ash/test/ash_test_base.h"
+#include "base/utf_string_conversions.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/fill_layout.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+
+namespace {
+
+WebNotificationTray* CreateWebNotificationTray() {
+ internal::StatusAreaWidget* widget = new internal::StatusAreaWidget;
+ WebNotificationTray* tray = new WebNotificationTray(widget);
+ widget->AddWebNotificationTray(tray);
+ widget->Show();
+ return tray;
+}
+
+class TestDelegate : public WebNotificationTray::Delegate {
+ public:
+ TestDelegate() {}
+ virtual ~TestDelegate() {}
+
+ // WebNotificationTray::Delegate overrides.
+ virtual void NotificationRemoved(const std::string& notifcation_id) {
+ notification_ids_.erase(notifcation_id);
+ }
+
+ virtual void DisableExtension(const std::string& notifcation_id) {
+ }
+
+ virtual void DisableNotificationsFromSource(
+ const std::string& notifcation_id) {
+ }
+
+ virtual void ShowSettings(const std::string& notifcation_id) {
+ }
+
+ void AddNotification(WebNotificationTray* tray, const std::string& id) {
+ notification_ids_.insert(id);
+ tray->AddNotification(id,
+ ASCIIToUTF16("Test Web Notification"),
+ ASCIIToUTF16("Notification message body."),
+ ASCIIToUTF16("www.test.org"),
+ "" /* extension id */);
+ }
+
+ void RemoveNotification(WebNotificationTray* tray, const std::string& id) {
+ tray->RemoveNotification(id);
+ }
+
+ bool HasNotificationId(const std::string& id) {
+ return notification_ids_.find(id) != notification_ids_.end();
+ }
+
+ private:
+ std::set<std::string> notification_ids_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDelegate);
+};
+
+} // namespace
+
+typedef test::AshTestBase WebNotificationTrayTest;
+
+TEST_F(WebNotificationTrayTest, WebNotifications) {
+ scoped_ptr<WebNotificationTray> tray(CreateWebNotificationTray());
+ scoped_ptr<TestDelegate> delegate(new TestDelegate);
+ tray->SetDelegate(delegate.get());
+
+ ASSERT_TRUE(tray->GetWidget());
+
+ // Adding a notification should show the bubble.
+ delegate->AddNotification(tray.get(), "test_id1");
+ EXPECT_TRUE(tray->bubble() != NULL);
+ EXPECT_EQ(1, tray->GetNotificationCount());
+ delegate->AddNotification(tray.get(), "test_id2");
+ delegate->AddNotification(tray.get(), "test_id2");
+ EXPECT_EQ(2, tray->GetNotificationCount());
+ // Ensure that removing a notification removes it from the tray, and signals
+ // the delegate.
+ EXPECT_TRUE(delegate->HasNotificationId("test_id2"));
+ delegate->RemoveNotification(tray.get(), "test_id2");
+ EXPECT_FALSE(delegate->HasNotificationId("test_id2"));
+ EXPECT_EQ(1, tray->GetNotificationCount());
+
+ // Removing the last notification should hide the bubble.
+ delegate->RemoveNotification(tray.get(), "test_id1");
+ EXPECT_EQ(0, tray->GetNotificationCount());
+ EXPECT_TRUE(tray->bubble() == NULL);
+}
+
+} // namespace ash
« 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