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

Unified Diff: chrome/browser/background/background_contents_service_unittest.cc

Issue 160923002: Fixes a typo: use the default image if the extension doesn't have icon. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-upload Created 6 years, 10 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
Index: chrome/browser/background/background_contents_service_unittest.cc
diff --git a/chrome/browser/background/background_contents_service_unittest.cc b/chrome/browser/background/background_contents_service_unittest.cc
index 014825498f00c8099ffa182f769e32c350f32bfd..3162d2aa99d500ca88e7f6d7a570da466e14801c 100644
--- a/chrome/browser/background/background_contents_service_unittest.cc
+++ b/chrome/browser/background/background_contents_service_unittest.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/strings/utf_string_conversions.h"
@@ -15,14 +16,29 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/ui/browser_list.h"
+#include "chrome/common/extensions/extension_test_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/test/test_browser_thread.h"
+#include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "url/gurl.h"
+#if defined(ENABLE_NOTIFICATIONS)
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "ui/message_center/message_center.h"
+#include "ui/message_center/message_center_observer.h"
+#endif
+
+#if defined(USE_ASH)
+#include "ash/test/ash_test_helper.h"
+#endif
+
class BackgroundContentsServiceTest : public testing::Test {
public:
BackgroundContentsServiceTest() {}
@@ -104,6 +120,103 @@ class MockBackgroundContents : public BackgroundContents {
Profile* profile_;
};
+#if defined(ENABLE_NOTIFICATIONS)
+// Wait for the notification created.
+class NotificationWaiter : public message_center::MessageCenterObserver {
+ public:
+ explicit NotificationWaiter(const std::string& target_id)
+ : target_id_(target_id) {}
+ virtual ~NotificationWaiter() {}
+
+ void WaitForNotificationAdded() {
+ message_center::MessageCenter* message_center =
+ message_center::MessageCenter::Get();
+ if (message_center->HasNotification(target_id_))
+ return;
+
+ message_center->AddObserver(this);
+ base::MessageLoop::current()->Run();
+ message_center->RemoveObserver(this);
+ }
+
+ private:
+ // message_center::MessageCenterObserver overrides:
+ virtual void OnNotificationAdded(
+ const std::string& notification_id) OVERRIDE {
+ if (notification_id == target_id_)
+ base::MessageLoop::current()->Quit();
+ }
+
+ std::string target_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationWaiter);
+};
+
+class BackgroundContentsServiceNotificationTest : public testing::Test {
+ public:
+ BackgroundContentsServiceNotificationTest()
+ : ui_thread_(content::BrowserThread::UI, &ui_loop_),
+#if defined(USE_ASH)
+ ash_helper_(&ui_loop_),
+#endif
+ profile_(NULL) {}
+ virtual ~BackgroundContentsServiceNotificationTest() {}
+
+ // Overridden from testing::Test
+ virtual void SetUp() {
+ // In Ash environment, ash_helper_ can initialize MessageCenter.
+#if defined(USE_ASH)
+ ash_helper_.SetUp(true);
+#else
+ message_center::MessageCenter::Initialize();
+#endif
+ profile_manager_.reset(new TestingProfileManager(
+ TestingBrowserProcess::GetGlobal()));
+ ASSERT_TRUE(profile_manager_->SetUp());
+ profile_ = profile_manager_->CreateTestingProfile("Default");
+ }
+
+ virtual void TearDown() {
+ profile_manager_.reset();
+ profile_ = NULL;
+#if defined(USE_ASH)
+ ash_helper_.TearDown();
+#else
+ message_center::MessageCenter::Shutdown();
+#endif
+ }
+
+ protected:
+ Profile* profile() { return profile_; }
+
+ // Creates crash notification for the specified extension and returns
+ // the created one.
+ const Notification* CreateCrashNotification(
+ scoped_refptr<extensions::Extension> extension) {
+ std::string notification_id =
+ BackgroundContentsService::GetNotificationIdForExtension(
+ extension->id());
+ NotificationWaiter waiter(notification_id);
+ BackgroundContentsService::ShowBalloon(extension.get(), profile_);
+ waiter.WaitForNotificationAdded();
+
+ return g_browser_process->notification_ui_manager()->FindById(
+ notification_id);
+ }
+
+ private:
+ base::MessageLoopForUI ui_loop_;
+ content::TestBrowserThread ui_thread_;
+#if defined(USE_ASH)
+ ash::test::AshTestHelper ash_helper_;
+#endif
+ scoped_ptr<TestingProfileManager> profile_manager_;
+ TestingProfile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundContentsServiceNotificationTest);
+};
+#endif // ENABLE_NOTIFICATIONS
+
TEST_F(BackgroundContentsServiceTest, Create) {
// Check for creation and leaks.
TestingProfile profile;
@@ -235,3 +348,28 @@ TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) {
EXPECT_EQ(1U, GetPrefs(&profile)->size());
EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid()));
}
+
+#if defined(ENABLE_NOTIFICATIONS)
+TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloon) {
+ scoped_refptr<extensions::Extension> extension =
+ extension_test_util::LoadManifest("image_loading_tracker", "app.json");
+ ASSERT_TRUE(extension.get());
+ ASSERT_TRUE(extension->GetManifestData("icons"));
+
+ const Notification* notification = CreateCrashNotification(extension);
+ EXPECT_FALSE(notification->icon().IsEmpty());
+}
+
+// Verify if a test notification can show the default extension icon for
+// a crash notification for an extension without icon.
+TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloonNoIcon) {
+ // Extension manifest file with no 'icon' field.
+ scoped_refptr<extensions::Extension> extension =
+ extension_test_util::LoadManifest("app", "manifest.json");
+ ASSERT_TRUE(extension.get());
+ ASSERT_FALSE(extension->GetManifestData("icons"));
+
+ const Notification* notification = CreateCrashNotification(extension);
+ EXPECT_FALSE(notification->icon().IsEmpty());
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698