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

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

Issue 8802013: Fixing background mode manager to correctly display the name of the profile in the status icon. P... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/background/background_mode_manager.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) 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/background/background_mode_manager.h" 8 #include "chrome/browser/background/background_mode_manager.h"
8 #include "chrome/browser/profiles/profile_info_cache.h" 9 #include "chrome/browser/profiles/profile_info_cache.h"
9 #include "chrome/browser/ui/browser_list.h" 10 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/base/testing_browser_process.h" 12 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
13 #include "chrome/test/base/testing_profile_manager.h" 14 #include "chrome/test/base/testing_profile_manager.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/image/image_unittest_util.h"
15 18
16 class BackgroundModeManagerTest : public testing::Test { 19 class BackgroundModeManagerTest : public testing::Test {
17 public: 20 public:
18 BackgroundModeManagerTest() 21 BackgroundModeManagerTest()
19 : profile_manager_( 22 : profile_manager_(
20 static_cast<TestingBrowserProcess*>(g_browser_process)) {} 23 static_cast<TestingBrowserProcess*>(g_browser_process)) {}
21 ~BackgroundModeManagerTest() {} 24 ~BackgroundModeManagerTest() {}
22 void SetUp() { 25 void SetUp() {
23 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); 26 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
24 ASSERT_TRUE(profile_manager_.SetUp()); 27 ASSERT_TRUE(profile_manager_.SetUp());
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 manager.SetBackgroundAppCountForProfile(0); 244 manager.SetBackgroundAppCountForProfile(0);
242 manager.OnApplicationListChanged(profile2); 245 manager.OnApplicationListChanged(profile2);
243 246
244 size_t p2_index = cache->GetIndexOfProfileWithPath(profile1->GetPath()); 247 size_t p2_index = cache->GetIndexOfProfileWithPath(profile1->GetPath());
245 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(p2_index)); 248 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(p2_index));
246 249
247 // Even though neither has background status on, there should still be two 250 // Even though neither has background status on, there should still be two
248 // profiles in the cache. 251 // profiles in the cache.
249 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); 252 EXPECT_EQ(2u, cache->GetNumberOfProfiles());
250 } 253 }
254 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) {
255 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1");
256 TestBackgroundModeManager manager(
257 command_line_.get(), profile_manager_.profile_info_cache());
258 manager.RegisterProfile(profile1);
259 EXPECT_FALSE(BrowserList::WillKeepAlive());
260
261 ProfileInfoCache* cache = profile_manager_.profile_info_cache();
262
263 // Install app, should show status tray icon.
264 manager.OnBackgroundAppInstalled(NULL);
265 manager.SetBackgroundAppCount(1);
266 manager.SetBackgroundAppCountForProfile(1);
267 manager.OnApplicationListChanged(profile1);
268
269 string16 p1name = cache->GetNameOfProfileAtIndex(0);
270 manager.OnProfileNameChanged(p1name, UTF8ToUTF16("p1new"));
271
272 EXPECT_EQ(UTF8ToUTF16("p1new"),
273 manager.GetBackgroundModeData(profile1)->name());
274
275 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2");
276 manager.RegisterProfile(profile2);
277 EXPECT_EQ(2, manager.NumberOfBackgroundModeData());
278
279 gfx::Image gaia_image(gfx::test::CreateImage());
280 manager.OnProfileAdded(UTF8ToUTF16("p2new"),
281 profile2->GetPath().BaseName().LossyDisplayName(),
282 profile2->GetPath(),
283 &gaia_image);
284 EXPECT_EQ(UTF8ToUTF16("p2new"),
285 manager.GetBackgroundModeData(profile2)->name());
286
287 manager.OnProfileRemoved(UTF8ToUTF16("p2new"));
288 EXPECT_EQ(1, manager.NumberOfBackgroundModeData());
289
290 // Check that the background mode data we think is in the map actually is.
291 EXPECT_EQ(UTF8ToUTF16("p1new"),
292 manager.GetBackgroundModeData(profile1)->name());
293 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698