| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 class NotificationWaiter : public message_center::MessageCenterObserver { | 124 class NotificationWaiter : public message_center::MessageCenterObserver { |
| 125 public: | 125 public: |
| 126 explicit NotificationWaiter(const std::string& target_id) | 126 explicit NotificationWaiter(const std::string& target_id) |
| 127 : target_id_(target_id) {} | 127 : target_id_(target_id) {} |
| 128 virtual ~NotificationWaiter() {} | 128 virtual ~NotificationWaiter() {} |
| 129 | 129 |
| 130 void WaitForNotificationAdded() { | 130 void WaitForNotificationAdded() { |
| 131 DCHECK(!run_loop_.running()); | 131 DCHECK(!run_loop_.running()); |
| 132 message_center::MessageCenter* message_center = | 132 message_center::MessageCenter* message_center = |
| 133 message_center::MessageCenter::Get(); | 133 message_center::MessageCenter::Get(); |
| 134 if (message_center->HasNotification(target_id_)) | |
| 135 return; | |
| 136 | 134 |
| 137 message_center->AddObserver(this); | 135 message_center->AddObserver(this); |
| 138 run_loop_.Run(); | 136 run_loop_.Run(); |
| 139 message_center->RemoveObserver(this); | 137 message_center->RemoveObserver(this); |
| 140 } | 138 } |
| 141 | 139 |
| 142 private: | 140 private: |
| 143 // message_center::MessageCenterObserver overrides: | 141 // message_center::MessageCenterObserver overrides: |
| 144 virtual void OnNotificationAdded( | 142 virtual void OnNotificationAdded( |
| 145 const std::string& notification_id) OVERRIDE { | 143 const std::string& notification_id) OVERRIDE { |
| 146 if (notification_id == target_id_) | 144 if (notification_id == target_id_) |
| 147 run_loop_.Quit(); | 145 run_loop_.Quit(); |
| 148 } | 146 } |
| 149 | 147 |
| 148 virtual void OnNotificationUpdated( |
| 149 const std::string& notification_id) OVERRIDE { |
| 150 if (notification_id == target_id_) |
| 151 run_loop_.Quit(); |
| 152 } |
| 153 |
| 150 std::string target_id_; | 154 std::string target_id_; |
| 151 base::RunLoop run_loop_; | 155 base::RunLoop run_loop_; |
| 152 | 156 |
| 153 DISALLOW_COPY_AND_ASSIGN(NotificationWaiter); | 157 DISALLOW_COPY_AND_ASSIGN(NotificationWaiter); |
| 154 }; | 158 }; |
| 155 | 159 |
| 156 class BackgroundContentsServiceNotificationTest | 160 class BackgroundContentsServiceNotificationTest |
| 157 : public BrowserWithTestWindowTest { | 161 : public BrowserWithTestWindowTest { |
| 158 public: | 162 public: |
| 159 BackgroundContentsServiceNotificationTest() {} | 163 BackgroundContentsServiceNotificationTest() {} |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloonNoIcon) { | 363 TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloonNoIcon) { |
| 360 // Extension manifest file with no 'icon' field. | 364 // Extension manifest file with no 'icon' field. |
| 361 scoped_refptr<extensions::Extension> extension = | 365 scoped_refptr<extensions::Extension> extension = |
| 362 extension_test_util::LoadManifest("app", "manifest.json"); | 366 extension_test_util::LoadManifest("app", "manifest.json"); |
| 363 ASSERT_TRUE(extension.get()); | 367 ASSERT_TRUE(extension.get()); |
| 364 ASSERT_FALSE(extension->GetManifestData("icons")); | 368 ASSERT_FALSE(extension->GetManifestData("icons")); |
| 365 | 369 |
| 366 const Notification* notification = CreateCrashNotification(extension); | 370 const Notification* notification = CreateCrashNotification(extension); |
| 367 EXPECT_FALSE(notification->icon().IsEmpty()); | 371 EXPECT_FALSE(notification->icon().IsEmpty()); |
| 368 } | 372 } |
| 373 |
| 374 TEST_F(BackgroundContentsServiceNotificationTest, TestShowTwoBalloons) { |
| 375 TestingProfile profile; |
| 376 scoped_refptr<extensions::Extension> extension = |
| 377 extension_test_util::LoadManifest("app", "manifest.json"); |
| 378 ASSERT_TRUE(extension.get()); |
| 379 CreateCrashNotification(extension); |
| 380 CreateCrashNotification(extension); |
| 381 |
| 382 message_center::MessageCenter* message_center = |
| 383 message_center::MessageCenter::Get(); |
| 384 message_center::NotificationList::Notifications notifications = |
| 385 message_center->GetVisibleNotifications(); |
| 386 ASSERT_EQ(1u, notifications.size()); |
| 387 } |
| 369 #endif | 388 #endif |
| OLD | NEW |