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

Side by Side Diff: chrome/browser/background/background_contents_service_unittest.cc

Issue 2555833002: Remove enable_notifications build flag and define (Closed)
Patch Set: Merge Created 4 years 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
OLDNEW
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 "chrome/browser/background/background_contents_service.h" 5 #include "chrome/browser/background/background_contents_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/background/background_contents.h" 15 #include "chrome/browser/background/background_contents.h"
16 #include "chrome/browser/background/background_contents_service_factory.h" 16 #include "chrome/browser/background/background_contents_service_factory.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/notifications/message_center_notification_manager.h"
19 #include "chrome/browser/notifications/notification.h"
18 #include "chrome/browser/ui/browser_list.h" 20 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/common/extensions/extension_test_util.h" 21 #include "chrome/common/extensions/extension_test_util.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/browser_with_test_window_test.h" 23 #include "chrome/test/base/browser_with_test_window_test.h"
22 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
23 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
24 #include "chrome/test/base/testing_profile_manager.h" 26 #include "chrome/test/base/testing_profile_manager.h"
25 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
26 #include "components/prefs/scoped_user_pref_update.h" 28 #include "components/prefs/scoped_user_pref_update.h"
27 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
28 #include "content/public/test/test_browser_thread.h" 30 #include "content/public/test/test_browser_thread.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "extensions/common/extension.h" 32 #include "extensions/common/extension.h"
31 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
32 #include "testing/platform_test.h" 34 #include "testing/platform_test.h"
33 #include "url/gurl.h"
34
35 #if defined(ENABLE_NOTIFICATIONS)
36 #include "chrome/browser/notifications/message_center_notification_manager.h"
37 #include "chrome/browser/notifications/notification.h"
38 #include "ui/message_center/fake_message_center_tray_delegate.h" 35 #include "ui/message_center/fake_message_center_tray_delegate.h"
39 #include "ui/message_center/message_center.h" 36 #include "ui/message_center/message_center.h"
40 #include "ui/message_center/message_center_observer.h" 37 #include "ui/message_center/message_center_observer.h"
41 #endif 38 #include "url/gurl.h"
42 39
43 class BackgroundContentsServiceTest : public testing::Test { 40 class BackgroundContentsServiceTest : public testing::Test {
44 public: 41 public:
45 BackgroundContentsServiceTest() {} 42 BackgroundContentsServiceTest() {}
46 ~BackgroundContentsServiceTest() override {} 43 ~BackgroundContentsServiceTest() override {}
47 void SetUp() override { 44 void SetUp() override {
48 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); 45 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM));
49 BackgroundContentsService::DisableCloseBalloonForTesting(true); 46 BackgroundContentsService::DisableCloseBalloonForTesting(true);
50 } 47 }
51 48
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 private: 116 private:
120 GURL url_; 117 GURL url_;
121 118
122 // The ID of our parent application 119 // The ID of our parent application
123 base::string16 appid_; 120 base::string16 appid_;
124 121
125 // Parent profile 122 // Parent profile
126 Profile* profile_; 123 Profile* profile_;
127 }; 124 };
128 125
129 #if defined(ENABLE_NOTIFICATIONS)
130 // Wait for the notification created. 126 // Wait for the notification created.
131 class NotificationWaiter : public message_center::MessageCenterObserver { 127 class NotificationWaiter : public message_center::MessageCenterObserver {
132 public: 128 public:
133 explicit NotificationWaiter(const std::string& target_id, Profile* profile) 129 explicit NotificationWaiter(const std::string& target_id, Profile* profile)
134 : target_id_(target_id), profile_(profile) {} 130 : target_id_(target_id), profile_(profile) {}
135 ~NotificationWaiter() override {} 131 ~NotificationWaiter() override {}
136 132
137 void WaitForNotificationAdded() { 133 void WaitForNotificationAdded() {
138 DCHECK(!run_loop_.running()); 134 DCHECK(!run_loop_.running());
139 message_center::MessageCenter* message_center = 135 message_center::MessageCenter* message_center =
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 215
220 return g_browser_process->notification_ui_manager()->FindById( 216 return g_browser_process->notification_ui_manager()->FindById(
221 notification_id, profile()); 217 notification_id, profile());
222 } 218 }
223 219
224 private: 220 private:
225 std::unique_ptr<TestingProfileManager> profile_manager_; 221 std::unique_ptr<TestingProfileManager> profile_manager_;
226 222
227 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsServiceNotificationTest); 223 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsServiceNotificationTest);
228 }; 224 };
229 #endif // ENABLE_NOTIFICATIONS
230 225
231 TEST_F(BackgroundContentsServiceTest, Create) { 226 TEST_F(BackgroundContentsServiceTest, Create) {
232 // Check for creation and leaks. 227 // Check for creation and leaks.
233 TestingProfile profile; 228 TestingProfile profile;
234 BackgroundContentsService service(&profile, command_line_.get()); 229 BackgroundContentsService service(&profile, command_line_.get());
235 } 230 }
236 231
237 TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) { 232 TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
238 TestingProfile profile; 233 TestingProfile profile;
239 BackgroundContentsService service(&profile, command_line_.get()); 234 BackgroundContentsService service(&profile, command_line_.get());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 contents2->Navigate(url2); 348 contents2->Navigate(url2);
354 EXPECT_EQ(2U, GetPrefs(&profile)->size()); 349 EXPECT_EQ(2U, GetPrefs(&profile)->size());
355 service.ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16("appid")); 350 service.ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16("appid"));
356 EXPECT_FALSE(service.IsTracked(contents)); 351 EXPECT_FALSE(service.IsTracked(contents));
357 EXPECT_EQ(NULL, 352 EXPECT_EQ(NULL,
358 service.GetAppBackgroundContents(base::ASCIIToUTF16("appid"))); 353 service.GetAppBackgroundContents(base::ASCIIToUTF16("appid")));
359 EXPECT_EQ(1U, GetPrefs(&profile)->size()); 354 EXPECT_EQ(1U, GetPrefs(&profile)->size());
360 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); 355 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid()));
361 } 356 }
362 357
363 #if defined(ENABLE_NOTIFICATIONS)
364 TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloon) { 358 TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloon) {
365 scoped_refptr<extensions::Extension> extension = 359 scoped_refptr<extensions::Extension> extension =
366 extension_test_util::LoadManifest("image_loading_tracker", "app.json"); 360 extension_test_util::LoadManifest("image_loading_tracker", "app.json");
367 ASSERT_TRUE(extension.get()); 361 ASSERT_TRUE(extension.get());
368 ASSERT_TRUE(extension->GetManifestData("icons")); 362 ASSERT_TRUE(extension->GetManifestData("icons"));
369 363
370 const Notification* notification = CreateCrashNotification(extension); 364 const Notification* notification = CreateCrashNotification(extension);
371 EXPECT_FALSE(notification->icon().IsEmpty()); 365 EXPECT_FALSE(notification->icon().IsEmpty());
372 } 366 }
373 367
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 ASSERT_TRUE(extension.get()); 407 ASSERT_TRUE(extension.get());
414 CreateCrashNotification(extension); 408 CreateCrashNotification(extension);
415 CreateCrashNotification(extension); 409 CreateCrashNotification(extension);
416 410
417 message_center::MessageCenter* message_center = 411 message_center::MessageCenter* message_center =
418 message_center::MessageCenter::Get(); 412 message_center::MessageCenter::Get();
419 message_center::NotificationList::Notifications notifications = 413 message_center::NotificationList::Notifications notifications =
420 message_center->GetVisibleNotifications(); 414 message_center->GetVisibleNotifications();
421 ASSERT_EQ(1u, notifications.size()); 415 ASSERT_EQ(1u, notifications.size());
422 } 416 }
423 #endif
OLDNEW
« no previous file with comments | « chrome/browser/background/background_contents_service.cc ('k') | chrome/browser/browser_process_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698