// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #import #include "base/files/file_path.h" #include "base/mac/scoped_nsobject.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #import "chrome/browser/app_controller_mac.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/pref_names.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "components/signin/core/browser/fake_auth_status_provider.h" #include "components/signin/core/browser/signin_error_controller.h" #include "components/signin/core/browser/signin_manager.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/platform_test.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_mac.h" class AppControllerTest : public PlatformTest { protected: AppControllerTest() : profile_manager_(TestingBrowserProcess::GetGlobal()), profile_(nullptr) {} void SetUp() override { PlatformTest::SetUp(); ASSERT_TRUE(profile_manager_.SetUp()); profile_ = profile_manager_.CreateTestingProfile("New Profile 1"); } void TearDown() override { TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); base::RunLoop().RunUntilIdle(); PlatformTest::TearDown(); } content::TestBrowserThreadBundle thread_bundle_; TestingProfileManager profile_manager_; TestingProfile* profile_; }; TEST_F(AppControllerTest, DockMenu) { base::scoped_nsobject ac([[AppController alloc] init]); NSMenu* menu = [ac applicationDockMenu:NSApp]; NSMenuItem* item; EXPECT_TRUE(menu); EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]); EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]); for (item in [menu itemArray]) { EXPECT_EQ(ac.get(), [item target]); EXPECT_EQ(@selector(commandFromDock:), [item action]); } } TEST_F(AppControllerTest, LastProfile) { // Create a second profile. base::FilePath dest_path1 = profile_->GetPath(); base::FilePath dest_path2 = profile_manager_.CreateTestingProfile("New Profile 2")->GetPath(); ASSERT_EQ(2U, profile_manager_.profile_manager()->GetNumberOfProfiles()); ASSERT_EQ(2U, profile_manager_.profile_manager()->GetLoadedProfiles().size()); PrefService* local_state = g_browser_process->local_state(); local_state->SetString(prefs::kProfileLastUsed, dest_path1.BaseName().MaybeAsASCII()); base::scoped_nsobject ac([[AppController alloc] init]); // Delete the active profile. profile_manager_.profile_manager()->ScheduleProfileForDeletion( dest_path1, ProfileManager::CreateCallback()); base::RunLoop().RunUntilIdle(); EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); }