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

Side by Side Diff: chrome/browser/notifications/extension_welcome_notification_unittest.cc

Issue 2342523002: Forcibly clear worker ref counts on shutdown. (Closed)
Patch Set: more bundles Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/notifications/extension_welcome_notification.h" 5 #include "chrome/browser/notifications/extension_welcome_notification.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "chrome/browser/notifications/notification.h" 17 #include "chrome/browser/notifications/notification.h"
18 #include "chrome/browser/prefs/pref_service_syncable_util.h" 18 #include "chrome/browser/prefs/pref_service_syncable_util.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/testing_browser_process.h" 20 #include "chrome/test/base/testing_browser_process.h"
21 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "components/pref_registry/pref_registry_syncable.h" 22 #include "components/pref_registry/pref_registry_syncable.h"
23 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "components/sync/api/fake_sync_change_processor.h" 24 #include "components/sync/api/fake_sync_change_processor.h"
25 #include "components/sync/api/sync_error_factory_mock.h" 25 #include "components/sync/api/sync_error_factory_mock.h"
26 #include "components/syncable_prefs/testing_pref_service_syncable.h" 26 #include "components/syncable_prefs/testing_pref_service_syncable.h"
27 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "extensions/browser/quota_service.h" 28 #include "extensions/browser/quota_service.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/message_center/fake_message_center.h" 30 #include "ui/message_center/fake_message_center.h"
30 #include "ui/message_center/notification.h" 31 #include "ui/message_center/notification.h"
31 32
32 class MockMessageCenter : public message_center::FakeMessageCenter { 33 class MockMessageCenter : public message_center::FakeMessageCenter {
33 public: 34 public:
34 MockMessageCenter() 35 MockMessageCenter()
35 : add_notification_calls_(0), 36 : add_notification_calls_(0),
36 remove_notification_calls_(0), 37 remove_notification_calls_(0),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 class ExtensionWelcomeNotificationTest : public testing::Test { 130 class ExtensionWelcomeNotificationTest : public testing::Test {
130 protected: 131 protected:
131 ExtensionWelcomeNotificationTest() { 132 ExtensionWelcomeNotificationTest() {
132 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry( 133 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
133 new user_prefs::PrefRegistrySyncable()); 134 new user_prefs::PrefRegistrySyncable());
134 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get()); 135 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
135 } 136 }
136 137
137 void SetUp() override { 138 void SetUp() override {
138 task_runner_ = new base::TestSimpleTaskRunner(); 139 task_runner_ = new base::TestSimpleTaskRunner();
139 thread_task_runner_handle_.reset( 140 base::MessageLoop::current()->SetTaskRunner(task_runner_);
140 new base::ThreadTaskRunnerHandle(task_runner_));
141 profile_.reset(new TestingProfile()); 141 profile_.reset(new TestingProfile());
142 delegate_ = new WelcomeNotificationDelegate(); 142 delegate_ = new WelcomeNotificationDelegate();
143 welcome_notification_.reset( 143 welcome_notification_.reset(
144 ExtensionWelcomeNotification::Create(profile_.get(), delegate_)); 144 ExtensionWelcomeNotification::Create(profile_.get(), delegate_));
145 } 145 }
146 146
147 void TearDown() override { 147 void TearDown() override {
148 delegate_ = NULL; 148 delegate_ = NULL;
149 welcome_notification_.reset(); 149 welcome_notification_.reset();
150 profile_.reset(); 150 profile_.reset();
151 TestingBrowserProcess::DeleteInstance(); 151 TestingBrowserProcess::DeleteInstance();
152 thread_task_runner_handle_.reset();
153 task_runner_ = NULL; 152 task_runner_ = NULL;
154 } 153 }
155 154
156 void StartPreferenceSyncing() const { 155 void StartPreferenceSyncing() const {
157 PrefServiceSyncableFromProfile(profile_.get()) 156 PrefServiceSyncableFromProfile(profile_.get())
158 ->GetSyncableService(syncer::PREFERENCES) 157 ->GetSyncableService(syncer::PREFERENCES)
159 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 158 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(),
160 std::unique_ptr<syncer::SyncChangeProcessor>( 159 std::unique_ptr<syncer::SyncChangeProcessor>(
161 new syncer::FakeSyncChangeProcessor), 160 new syncer::FakeSyncChangeProcessor),
162 std::unique_ptr<syncer::SyncErrorFactory>( 161 std::unique_ptr<syncer::SyncErrorFactory>(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 rich_notification_data.priority = 0; 226 rich_notification_data.priority = 0;
228 Notification notification( 227 Notification notification(
229 message_center::NOTIFICATION_TYPE_BASE_FORMAT, 228 message_center::NOTIFICATION_TYPE_BASE_FORMAT,
230 base::UTF8ToUTF16("Title"), base::UTF8ToUTF16("Body"), gfx::Image(), 229 base::UTF8ToUTF16("Title"), base::UTF8ToUTF16("Body"), gfx::Image(),
231 notifier_id, base::UTF8ToUTF16("Source"), GURL("http://tests.url"), 230 notifier_id, base::UTF8ToUTF16("Source"), GURL("http://tests.url"),
232 notification_id, rich_notification_data, 231 notification_id, rich_notification_data,
233 new TestNotificationDelegate("TestNotification")); 232 new TestNotificationDelegate("TestNotification"));
234 welcome_notification_->ShowWelcomeNotificationIfNecessary(notification); 233 welcome_notification_->ShowWelcomeNotificationIfNecessary(notification);
235 } 234 }
236 235
236 content::TestBrowserThreadBundle thread_bundle_;
237 extensions::QuotaService::ScopedDisablePurgeForTesting 237 extensions::QuotaService::ScopedDisablePurgeForTesting
238 disable_purge_for_testing_; 238 disable_purge_for_testing_;
239 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 239 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
240 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
241 std::unique_ptr<TestingProfile> profile_; 240 std::unique_ptr<TestingProfile> profile_;
242 // Weak Ref owned by welcome_notification_ 241 // Weak Ref owned by welcome_notification_
243 WelcomeNotificationDelegate* delegate_; 242 WelcomeNotificationDelegate* delegate_;
244 std::unique_ptr<ExtensionWelcomeNotification> welcome_notification_; 243 std::unique_ptr<ExtensionWelcomeNotification> welcome_notification_;
245 244
246 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest); 245 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest);
247 }; 246 };
248 247
249 // Show a regular notification. Expect that WelcomeNotification will 248 // Show a regular notification. Expect that WelcomeNotification will
250 // not show a welcome notification. 249 // not show a welcome notification.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 529
531 EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); 530 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
532 EXPECT_EQ(message_center()->add_notification_calls(), 0); 531 EXPECT_EQ(message_center()->add_notification_calls(), 0);
533 EXPECT_EQ(message_center()->remove_notification_calls(), 0); 532 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
534 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); 533 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
535 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); 534 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
536 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); 535 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
537 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); 536 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
538 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); 537 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
539 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698