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

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

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 7 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 (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"
11 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
12 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
13 #include "base/run_loop.h" 12 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/background/background_contents.h" 14 #include "chrome/browser/background/background_contents.h"
16 #include "chrome/browser/background/background_contents_service.h" 15 #include "chrome/browser/background/background_contents_service.h"
17 #include "chrome/browser/background/background_contents_service_factory.h" 16 #include "chrome/browser/background/background_contents_service_factory.h"
18 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/common/extensions/extension_test_util.h" 19 #include "chrome/common/extensions/extension_test_util.h"
21 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/browser_with_test_window_test.h" 21 #include "chrome/test/base/browser_with_test_window_test.h"
23 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
24 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
25 #include "chrome/test/base/testing_profile_manager.h" 24 #include "chrome/test/base/testing_profile_manager.h"
26 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
27 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
27 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "testing/platform_test.h" 30 #include "testing/platform_test.h"
31 #include "url/gurl.h" 31 #include "url/gurl.h"
32 32
33 #if defined(ENABLE_NOTIFICATIONS) 33 #if defined(ENABLE_NOTIFICATIONS)
34 #include "chrome/browser/notifications/message_center_notification_manager.h" 34 #include "chrome/browser/notifications/message_center_notification_manager.h"
35 #include "chrome/browser/notifications/notification.h" 35 #include "chrome/browser/notifications/notification.h"
36 #include "ui/message_center/fake_message_center_tray_delegate.h" 36 #include "ui/message_center/fake_message_center_tray_delegate.h"
37 #include "ui/message_center/message_center.h" 37 #include "ui/message_center/message_center.h"
38 #include "ui/message_center/message_center_observer.h" 38 #include "ui/message_center/message_center_observer.h"
39 #endif 39 #endif
40 40
41 class BackgroundContentsServiceTest : public testing::Test { 41 class BackgroundContentsServiceTest : public testing::Test {
42 public: 42 public:
43 BackgroundContentsServiceTest() {} 43 BackgroundContentsServiceTest() {}
44 ~BackgroundContentsServiceTest() override {} 44 ~BackgroundContentsServiceTest() override {}
45 void SetUp() override { 45 void SetUp() override {
46 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); 46 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM));
47 BackgroundContentsService::DisableCloseBalloonForTesting(true);
48 }
49
50 void TearDown() override {
51 BackgroundContentsService::DisableCloseBalloonForTesting(false);
47 } 52 }
48 53
49 const base::DictionaryValue* GetPrefs(Profile* profile) { 54 const base::DictionaryValue* GetPrefs(Profile* profile) {
50 return profile->GetPrefs()->GetDictionary( 55 return profile->GetPrefs()->GetDictionary(
51 prefs::kRegisteredBackgroundContents); 56 prefs::kRegisteredBackgroundContents);
52 } 57 }
53 58
54 // Returns the stored pref URL for the passed app id. 59 // Returns the stored pref URL for the passed app id.
55 std::string GetPrefURLForApp(Profile* profile, const base::string16& appid) { 60 std::string GetPrefURLForApp(Profile* profile, const base::string16& appid) {
56 const base::DictionaryValue* pref = GetPrefs(profile); 61 const base::DictionaryValue* pref = GetPrefs(profile);
57 EXPECT_TRUE(pref->HasKey(base::UTF16ToUTF8(appid))); 62 EXPECT_TRUE(pref->HasKey(base::UTF16ToUTF8(appid)));
58 const base::DictionaryValue* value; 63 const base::DictionaryValue* value;
59 pref->GetDictionaryWithoutPathExpansion(base::UTF16ToUTF8(appid), &value); 64 pref->GetDictionaryWithoutPathExpansion(base::UTF16ToUTF8(appid), &value);
60 std::string url; 65 std::string url;
61 value->GetString("url", &url); 66 value->GetString("url", &url);
62 return url; 67 return url;
63 } 68 }
64 69
70 content::TestBrowserThreadBundle thread_bundle_;
65 scoped_ptr<base::CommandLine> command_line_; 71 scoped_ptr<base::CommandLine> command_line_;
66 }; 72 };
67 73
68 class MockBackgroundContents : public BackgroundContents { 74 class MockBackgroundContents : public BackgroundContents {
69 public: 75 public:
70 explicit MockBackgroundContents(Profile* profile) 76 explicit MockBackgroundContents(Profile* profile)
71 : appid_(base::ASCIIToUTF16("app_id")), 77 : appid_(base::ASCIIToUTF16("app_id")),
72 profile_(profile) { 78 profile_(profile) {
73 } 79 }
74 MockBackgroundContents(Profile* profile, const std::string& id) 80 MockBackgroundContents(Profile* profile, const std::string& id)
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 CreateCrashNotification(extension); 391 CreateCrashNotification(extension);
386 CreateCrashNotification(extension); 392 CreateCrashNotification(extension);
387 393
388 message_center::MessageCenter* message_center = 394 message_center::MessageCenter* message_center =
389 message_center::MessageCenter::Get(); 395 message_center::MessageCenter::Get();
390 message_center::NotificationList::Notifications notifications = 396 message_center::NotificationList::Notifications notifications =
391 message_center->GetVisibleNotifications(); 397 message_center->GetVisibleNotifications();
392 ASSERT_EQ(1u, notifications.size()); 398 ASSERT_EQ(1u, notifications.size());
393 } 399 }
394 #endif 400 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698