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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/app_controller_mac_unittest.mm
diff --git a/chrome/browser/app_controller_mac_unittest.mm b/chrome/browser/app_controller_mac_unittest.mm
index b391fd76b12af0adec2ac091ccfaa44cfec9f5e5..cb4173c8242e808d42bdfc0a1ade118287ef3325 100644
--- a/chrome/browser/app_controller_mac_unittest.mm
+++ b/chrome/browser/app_controller_mac_unittest.mm
@@ -4,12 +4,59 @@
#import <Cocoa/Cocoa.h>
+#import "chrome/browser/app_controller_mac.h"
+
+#include "base/files/file_path.h"
#include "base/memory/scoped_nsobject.h"
#include "chrome/app/chrome_command_ids.h"
-#import "chrome/browser/app_controller_mac.h"
+#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_profile_manager.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "testing/platform_test.h"
-class AppControllerTest : public PlatformTest {
+namespace {
+class ProfileRemovalObserver : public ProfileInfoCacheObserver {
sail 2013/06/12 21:16:49 new line above
+ public:
+ ProfileRemovalObserver(ProfileManager* profile_manager,
+ AppController* app_controller,
+ base::FilePath& path)
+ : profile_manager_(profile_manager),
+ app_controller_(app_controller),
+ next_active_profile_path_(path) {
+ profile_manager_->GetProfileInfoCache().AddObserver(this);
+ }
+
+ virtual ~ProfileRemovalObserver() {
+ profile_manager_->GetProfileInfoCache().RemoveObserver(this);
+ }
+ private:
sail 2013/06/12 21:16:49 new line above
+ // ProfileInfoCacheObserver implementation:
+ virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE {}
+ virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
+ const string16& profile_name) OVERRIDE {
+ base::FilePath lastProfilePath = [app_controller_ lastProfile]->GetPath();
+ EXPECT_EQ(lastProfilePath, next_active_profile_path_);
+ }
+ virtual void OnProfileWillBeRemoved(
+ const base::FilePath& profile_path) OVERRIDE {}
+ virtual void OnProfileNameChanged(const base::FilePath& profile_path,
+ const string16& old_profile_name)
+ OVERRIDE {}
+ virtual void OnProfileAvatarChanged(
+ const base::FilePath& profile_path) OVERRIDE {}
+
+ ProfileManager* profile_manager_;
+ AppController* app_controller_; // Weak; owns us.
+ base::FilePath& next_active_profile_path_;
+ DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver);
+};
+
+}
+
+class AppControllerTest : public CocoaProfileTest {
};
TEST_F(AppControllerTest, DockMenu) {
@@ -25,3 +72,31 @@ TEST_F(AppControllerTest, DockMenu) {
EXPECT_EQ(@selector(commandFromDock:), [item action]);
}
}
+
+TEST_F(AppControllerTest, LastProfile) {
+ TestingProfileManager* manager = testing_profile_manager();
+
+ // Create two additional profiles.
+ // Since profiles are loaded alphabetically, prefix them with A to make sure
+ // that the default testing profile is not loaded instead.
+ base::FilePath dest_path1 =
+ manager->CreateTestingProfile("A New Profile 1")->GetPath();
+ base::FilePath dest_path2 =
+ manager->CreateTestingProfile("A New Profile 2")->GetPath();
+ ASSERT_EQ(3U, manager->profile_manager()->GetNumberOfProfiles());
+ ASSERT_EQ(3U, manager->profile_manager()->GetLoadedProfiles().size());
+
+ PrefService* local_state = g_browser_process->local_state();
+ local_state->SetString(prefs::kProfileLastUsed,
+ dest_path1.BaseName().MaybeAsASCII());
+
+ scoped_nsobject<AppController> ac([[AppController alloc] init]);
+ 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.
+ ac,
+ dest_path2);
+
+ // Delete the active profile. The ProfileRemovalObserver will check the
+ // next active profile is set correctly.
+ manager->profile_manager()->ScheduleProfileForDeletion(
+ dest_path1, ProfileManager::CreateCallback());
+}

Powered by Google App Engine
This is Rietveld 408576698