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

Side by Side 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: fix win 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/background/background_contents_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
10 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h" 12 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/background/background_contents_service.h" 14 #include "chrome/browser/background/background_contents_service.h"
14 #include "chrome/browser/background/background_contents_service_factory.h" 15 #include "chrome/browser/background/background_contents_service_factory.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/tab_contents/background_contents.h" 17 #include "chrome/browser/tab_contents/background_contents.h"
17 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/common/extensions/extension_test_util.h"
18 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/browser_with_test_window_test.h"
19 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "chrome/test/base/testing_profile_manager.h"
21 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/test/test_browser_thread.h"
27 #include "extensions/common/extension.h"
22 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
23 #include "testing/platform_test.h" 29 #include "testing/platform_test.h"
24 #include "url/gurl.h" 30 #include "url/gurl.h"
25 31
32 #if defined(ENABLE_NOTIFICATIONS)
33 #include "chrome/browser/notifications/notification.h"
34 #include "chrome/browser/notifications/notification_ui_manager.h"
35 #include "ui/message_center/message_center.h"
36 #include "ui/message_center/message_center_observer.h"
37 #endif
38
39 #if defined(USE_ASH)
40 #include "ash/test/ash_test_helper.h"
41 #endif
42
26 class BackgroundContentsServiceTest : public testing::Test { 43 class BackgroundContentsServiceTest : public testing::Test {
27 public: 44 public:
28 BackgroundContentsServiceTest() {} 45 BackgroundContentsServiceTest() {}
29 virtual ~BackgroundContentsServiceTest() {} 46 virtual ~BackgroundContentsServiceTest() {}
30 virtual void SetUp() { 47 virtual void SetUp() {
31 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); 48 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
32 } 49 }
33 50
34 const base::DictionaryValue* GetPrefs(Profile* profile) { 51 const base::DictionaryValue* GetPrefs(Profile* profile) {
35 return profile->GetPrefs()->GetDictionary( 52 return profile->GetPrefs()->GetDictionary(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 private: 114 private:
98 GURL url_; 115 GURL url_;
99 116
100 // The ID of our parent application 117 // The ID of our parent application
101 base::string16 appid_; 118 base::string16 appid_;
102 119
103 // Parent profile 120 // Parent profile
104 Profile* profile_; 121 Profile* profile_;
105 }; 122 };
106 123
124 #if defined(ENABLE_NOTIFICATIONS)
125 // Wait for the notification created.
126 class NotificationWaiter : public message_center::MessageCenterObserver {
127 public:
128 explicit NotificationWaiter(const std::string& target_id)
129 : target_id_(target_id) {}
130 virtual ~NotificationWaiter() {}
131
132 void WaitForNotificationAdded() {
133 message_center::MessageCenter* message_center =
134 message_center::MessageCenter::Get();
135 if (message_center->HasNotification(target_id_))
136 return;
137
138 message_center->AddObserver(this);
139 base::MessageLoop::current()->Run();
140 message_center->RemoveObserver(this);
141 }
142
143 private:
144 // message_center::MessageCenterObserver overrides:
145 virtual void OnNotificationAdded(
146 const std::string& notification_id) OVERRIDE {
147 if (notification_id == target_id_)
148 base::MessageLoop::current()->Quit();
149 }
150
151 std::string target_id_;
152
153 DISALLOW_COPY_AND_ASSIGN(NotificationWaiter);
154 };
155
156 class BackgroundContentsServiceNotificationTest
157 : public BrowserWithTestWindowTest {
158 public:
159 BackgroundContentsServiceNotificationTest()
160 : profile_(NULL) {}
161 virtual ~BackgroundContentsServiceNotificationTest() {}
162
163 // Overridden from testing::Test
164 virtual void SetUp() {
165 BrowserWithTestWindowTest::SetUp();
166 // In ChromeOS environment, BrowserWithTestWindowTest initializes
167 // MessageCenter.
168 #if !defined(OS_CHROMEOS)
169 message_center::MessageCenter::Initialize();
170 #endif
171 profile_manager_.reset(new TestingProfileManager(
172 TestingBrowserProcess::GetGlobal()));
173 ASSERT_TRUE(profile_manager_->SetUp());
174 profile_ = profile_manager_->CreateTestingProfile("Default");
175 }
176
177 virtual void TearDown() {
178 profile_manager_.reset();
179 profile_ = NULL;
180 #if !defined(OS_CHROMEOS)
181 message_center::MessageCenter::Shutdown();
182 #endif
183 BrowserWithTestWindowTest::TearDown();
184 }
185
186 protected:
187 Profile* profile() { return profile_; }
188
189 // Creates crash notification for the specified extension and returns
190 // the created one.
191 const Notification* CreateCrashNotification(
192 scoped_refptr<extensions::Extension> extension) {
193 std::string notification_id =
194 BackgroundContentsService::GetNotificationIdForExtensionForTesting(
195 extension->id());
196 NotificationWaiter waiter(notification_id);
197 BackgroundContentsService::ShowBalloonForTesting(extension.get(), profile_);
198 waiter.WaitForNotificationAdded();
199
200 return g_browser_process->notification_ui_manager()->FindById(
201 notification_id);
202 }
203
204 private:
205 scoped_ptr<TestingProfileManager> profile_manager_;
206 TestingProfile* profile_;
207
208 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsServiceNotificationTest);
209 };
210 #endif // ENABLE_NOTIFICATIONS
211
107 TEST_F(BackgroundContentsServiceTest, Create) { 212 TEST_F(BackgroundContentsServiceTest, Create) {
108 // Check for creation and leaks. 213 // Check for creation and leaks.
109 TestingProfile profile; 214 TestingProfile profile;
110 BackgroundContentsService service(&profile, command_line_.get()); 215 BackgroundContentsService service(&profile, command_line_.get());
111 } 216 }
112 217
113 TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) { 218 TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
114 TestingProfile profile; 219 TestingProfile profile;
115 BackgroundContentsService service(&profile, command_line_.get()); 220 BackgroundContentsService service(&profile, command_line_.get());
116 MockBackgroundContents* contents = new MockBackgroundContents(&profile); 221 MockBackgroundContents* contents = new MockBackgroundContents(&profile);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_EQ(1U, GetPrefs(&profile)->size()); 333 EXPECT_EQ(1U, GetPrefs(&profile)->size());
229 contents2->Navigate(url2); 334 contents2->Navigate(url2);
230 EXPECT_EQ(2U, GetPrefs(&profile)->size()); 335 EXPECT_EQ(2U, GetPrefs(&profile)->size());
231 service.ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16("appid")); 336 service.ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16("appid"));
232 EXPECT_FALSE(service.IsTracked(contents)); 337 EXPECT_FALSE(service.IsTracked(contents));
233 EXPECT_EQ(NULL, 338 EXPECT_EQ(NULL,
234 service.GetAppBackgroundContents(base::ASCIIToUTF16("appid"))); 339 service.GetAppBackgroundContents(base::ASCIIToUTF16("appid")));
235 EXPECT_EQ(1U, GetPrefs(&profile)->size()); 340 EXPECT_EQ(1U, GetPrefs(&profile)->size());
236 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); 341 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid()));
237 } 342 }
343
344 #if defined(ENABLE_NOTIFICATIONS)
345 // Test fails because of NOTIMPLEMENTED in fullscreen_aura.cc used by the
346 // notification system.
347 // TODO(mukai): Fix in notification side.
348 #if defined(OS_CHROMEOS) || !defined(OS_LINUX)
349 #define MAYBE_TestShowBalloon TestShowBalloon
350 #define MAYBE_TestShowBalloonNoIcon TestShowBalloonNoIcon
351 #else
352 #define MAYBE_TestShowBalloon DISABLED_TestShowBalloon
353 #define MAYBE_TestShowBalloonNoIcon DISABLED_TestShowBalloonNoIcon
354 #endif
355
356 TEST_F(BackgroundContentsServiceNotificationTest, MAYBE_TestShowBalloon) {
357 scoped_refptr<extensions::Extension> extension =
358 extension_test_util::LoadManifest("image_loading_tracker", "app.json");
359 ASSERT_TRUE(extension.get());
360 ASSERT_TRUE(extension->GetManifestData("icons"));
361
362 const Notification* notification = CreateCrashNotification(extension);
363 EXPECT_FALSE(notification->icon().IsEmpty());
364 }
365
366 // Verify if a test notification can show the default extension icon for
367 // a crash notification for an extension without icon.
368 TEST_F(BackgroundContentsServiceNotificationTest, MAYBE_TestShowBalloonNoIcon) {
369 // Extension manifest file with no 'icon' field.
370 scoped_refptr<extensions::Extension> extension =
371 extension_test_util::LoadManifest("app", "manifest.json");
372 ASSERT_TRUE(extension.get());
373 ASSERT_FALSE(extension->GetManifestData("icons"));
374
375 const Notification* notification = CreateCrashNotification(extension);
376 EXPECT_FALSE(notification->icon().IsEmpty());
377 }
378 #endif
OLDNEW
« no previous file with comments | « chrome/browser/background/background_contents_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698