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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/background/background_contents_service.h" 11 #include "chrome/browser/background/background_contents_service.h"
12 #include "chrome/browser/background/background_contents_service_factory.h" 12 #include "chrome/browser/background/background_contents_service_factory.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/tab_contents/background_contents.h" 15 #include "chrome/browser/tab_contents/background_contents.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/testing_browser_process.h" 19 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/browser/notification_service.h"
21 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "testing/platform_test.h" 24 #include "testing/platform_test.h"
24 25
25 class BackgroundContentsServiceTest : public testing::Test { 26 class BackgroundContentsServiceTest : public testing::Test {
26 public: 27 public:
27 BackgroundContentsServiceTest() {} 28 BackgroundContentsServiceTest() {}
28 ~BackgroundContentsServiceTest() {} 29 ~BackgroundContentsServiceTest() {}
29 void SetUp() { 30 void SetUp() {
30 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); 31 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 void SendOpenedNotification(BackgroundContentsService* service) { 64 void SendOpenedNotification(BackgroundContentsService* service) {
64 string16 frame_name = ASCIIToUTF16("background"); 65 string16 frame_name = ASCIIToUTF16("background");
65 BackgroundContentsOpenedDetails details = { 66 BackgroundContentsOpenedDetails details = {
66 this, frame_name, appid_ }; 67 this, frame_name, appid_ };
67 service->BackgroundContentsOpened(&details); 68 service->BackgroundContentsOpened(&details);
68 } 69 }
69 70
70 virtual void Navigate(GURL url) { 71 virtual void Navigate(GURL url) {
71 url_ = url; 72 url_ = url;
72 NotificationService::current()->Notify( 73 content::NotificationService::current()->Notify(
73 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 74 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
74 content::Source<Profile>(profile_), 75 content::Source<Profile>(profile_),
75 content::Details<BackgroundContents>(this)); 76 content::Details<BackgroundContents>(this));
76 } 77 }
77 virtual const GURL& GetURL() const { return url_; } 78 virtual const GURL& GetURL() const { return url_; }
78 79
79 void MockClose(Profile* profile) { 80 void MockClose(Profile* profile) {
80 NotificationService::current()->Notify( 81 content::NotificationService::current()->Notify(
81 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, 82 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED,
82 content::Source<Profile>(profile), 83 content::Source<Profile>(profile),
83 content::Details<BackgroundContents>(this)); 84 content::Details<BackgroundContents>(this));
84 delete this; 85 delete this;
85 } 86 }
86 87
87 ~MockBackgroundContents() { 88 ~MockBackgroundContents() {
88 NotificationService::current()->Notify( 89 content::NotificationService::current()->Notify(
89 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 90 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
90 content::Source<Profile>(profile_), 91 content::Source<Profile>(profile_),
91 content::Details<BackgroundContents>(this)); 92 content::Details<BackgroundContents>(this));
92 } 93 }
93 94
94 const string16& appid() { return appid_; } 95 const string16& appid() { return appid_; }
95 96
96 private: 97 private:
97 GURL url_; 98 GURL url_;
98 99
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 contents->Navigate(url); 226 contents->Navigate(url);
226 EXPECT_EQ(1U, GetPrefs(&profile)->size()); 227 EXPECT_EQ(1U, GetPrefs(&profile)->size());
227 contents2->Navigate(url2); 228 contents2->Navigate(url2);
228 EXPECT_EQ(2U, GetPrefs(&profile)->size()); 229 EXPECT_EQ(2U, GetPrefs(&profile)->size());
229 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); 230 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid"));
230 EXPECT_FALSE(service.IsTracked(contents)); 231 EXPECT_FALSE(service.IsTracked(contents));
231 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); 232 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid")));
232 EXPECT_EQ(1U, GetPrefs(&profile)->size()); 233 EXPECT_EQ(1U, GetPrefs(&profile)->size());
233 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); 234 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid()));
234 } 235 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_contents_service.cc ('k') | chrome/browser/background/background_mode_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698