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

Side by Side Diff: chrome/browser/app_controller_mac_unittest.mm

Issue 14923004: [Mac] AppController needs to update its "last profile" pointer when the active profile is deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase & fixed comments Created 7 years, 6 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) 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/app_controller_mac.h"
8
9 #include "base/files/file_path.h"
7 #include "base/memory/scoped_nsobject.h" 10 #include "base/memory/scoped_nsobject.h"
8 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
9 #import "chrome/browser/app_controller_mac.h" 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile_manager.h"
17 #include "chrome/test/base/ui_test_utils.h"
10 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
11 19
12 class AppControllerTest : public PlatformTest { 20 namespace {
21 class ProfileRemovalObserver : public ProfileInfoCacheObserver {
sail 2013/06/12 21:16:49 new line above
22 public:
23 ProfileRemovalObserver(ProfileManager* profile_manager,
24 AppController* app_controller,
25 base::FilePath& path)
26 : profile_manager_(profile_manager),
27 app_controller_(app_controller),
28 next_active_profile_path_(path) {
29 profile_manager_->GetProfileInfoCache().AddObserver(this);
30 }
31
32 virtual ~ProfileRemovalObserver() {
33 profile_manager_->GetProfileInfoCache().RemoveObserver(this);
34 }
35 private:
sail 2013/06/12 21:16:49 new line above
36 // ProfileInfoCacheObserver implementation:
37 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE {}
38 virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
39 const string16& profile_name) OVERRIDE {
40 base::FilePath lastProfilePath = [app_controller_ lastProfile]->GetPath();
41 EXPECT_EQ(lastProfilePath, next_active_profile_path_);
42 }
43 virtual void OnProfileWillBeRemoved(
44 const base::FilePath& profile_path) OVERRIDE {}
45 virtual void OnProfileNameChanged(const base::FilePath& profile_path,
46 const string16& old_profile_name)
47 OVERRIDE {}
48 virtual void OnProfileAvatarChanged(
49 const base::FilePath& profile_path) OVERRIDE {}
50
51 ProfileManager* profile_manager_;
52 AppController* app_controller_; // Weak; owns us.
53 base::FilePath& next_active_profile_path_;
54 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver);
55 };
56
57 }
58
59 class AppControllerTest : public CocoaProfileTest {
13 }; 60 };
14 61
15 TEST_F(AppControllerTest, DockMenu) { 62 TEST_F(AppControllerTest, DockMenu) {
16 scoped_nsobject<AppController> ac([[AppController alloc] init]); 63 scoped_nsobject<AppController> ac([[AppController alloc] init]);
17 NSMenu* menu = [ac applicationDockMenu:NSApp]; 64 NSMenu* menu = [ac applicationDockMenu:NSApp];
18 NSMenuItem* item; 65 NSMenuItem* item;
19 66
20 EXPECT_TRUE(menu); 67 EXPECT_TRUE(menu);
21 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]); 68 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]);
22 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]); 69 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]);
23 for (item in [menu itemArray]) { 70 for (item in [menu itemArray]) {
24 EXPECT_EQ(ac.get(), [item target]); 71 EXPECT_EQ(ac.get(), [item target]);
25 EXPECT_EQ(@selector(commandFromDock:), [item action]); 72 EXPECT_EQ(@selector(commandFromDock:), [item action]);
26 } 73 }
27 } 74 }
75
76 TEST_F(AppControllerTest, LastProfile) {
77 TestingProfileManager* manager = testing_profile_manager();
78
79 // Create two additional profiles.
80 // Since profiles are loaded alphabetically, prefix them with A to make sure
81 // that the default testing profile is not loaded instead.
82 base::FilePath dest_path1 =
83 manager->CreateTestingProfile("A New Profile 1")->GetPath();
84 base::FilePath dest_path2 =
85 manager->CreateTestingProfile("A New Profile 2")->GetPath();
86 ASSERT_EQ(3U, manager->profile_manager()->GetNumberOfProfiles());
87 ASSERT_EQ(3U, manager->profile_manager()->GetLoadedProfiles().size());
88
89 PrefService* local_state = g_browser_process->local_state();
90 local_state->SetString(prefs::kProfileLastUsed,
91 dest_path1.BaseName().MaybeAsASCII());
92
93 scoped_nsobject<AppController> ac([[AppController alloc] init]);
94 ProfileRemovalObserver observer(manager->profile_manager(),
sail 2013/06/12 21:16:49 do you need this observer? Could you just do a che
noms (inactive) 2013/06/13 20:56:25 Done.
95 ac,
96 dest_path2);
97
98 // Delete the active profile. The ProfileRemovalObserver will check the
99 // next active profile is set correctly.
100 manager->profile_manager()->ScheduleProfileForDeletion(
101 dest_path1, ProfileManager::CreateCallback());
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698