blob: 8a011920d2c8828241ae0178a44dd45dfd1bfee1 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]288bfcd32009-09-14 18:14:462// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import <Cocoa/Cocoa.h>
6
[email protected]1c62b2f2013-06-28 00:15:007#include "base/files/file_path.h"
[email protected]a8522032013-06-24 22:51:468#include "base/mac/scoped_nsobject.h"
[email protected]de6b8ecf2013-09-16 21:47:319#include "base/run_loop.h"
andresantoso55fd2512015-04-01 21:07:0410#include "base/strings/utf_string_conversions.h"
[email protected]1a3aba82010-11-08 23:52:5411#include "chrome/app/chrome_command_ids.h"
[email protected]288bfcd32009-09-14 18:14:4612#import "chrome/browser/app_controller_mac.h"
[email protected]de6b8ecf2013-09-16 21:47:3113#include "chrome/browser/browser_process.h"
[email protected]1c62b2f2013-06-28 00:15:0014#include "chrome/browser/profiles/profile_manager.h"
andresantoso55fd2512015-04-01 21:07:0415#include "chrome/browser/signin/signin_error_controller_factory.h"
16#include "chrome/browser/signin/signin_manager_factory.h"
andresantoso55fd2512015-04-01 21:07:0417#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]1c62b2f2013-06-28 00:15:0018#include "chrome/common/chrome_constants.h"
19#include "chrome/common/pref_names.h"
[email protected]de6b8ecf2013-09-16 21:47:3120#include "chrome/test/base/testing_browser_process.h"
21#include "chrome/test/base/testing_profile.h"
[email protected]1c62b2f2013-06-28 00:15:0022#include "chrome/test/base/testing_profile_manager.h"
maxbogue26f40222016-09-16 20:22:1823#include "components/browser_sync/profile_sync_service.h"
24#include "components/browser_sync/profile_sync_service_mock.h"
andresantoso55fd2512015-04-01 21:07:0425#include "components/signin/core/browser/fake_auth_status_provider.h"
26#include "components/signin/core/browser/signin_error_controller.h"
27#include "components/signin/core/browser/signin_manager.h"
[email protected]de6b8ecf2013-09-16 21:47:3128#include "content/public/test/test_browser_thread_bundle.h"
[email protected]288bfcd32009-09-14 18:14:4629#include "testing/platform_test.h"
[email protected]288bfcd32009-09-14 18:14:4630
31class AppControllerTest : public PlatformTest {
[email protected]1c62b2f2013-06-28 00:15:0032 protected:
andresantoso55fd2512015-04-01 21:07:0433 AppControllerTest()
34 : profile_manager_(TestingBrowserProcess::GetGlobal()),
35 profile_(nullptr) {}
36
37 void SetUp() override {
38 PlatformTest::SetUp();
39 ASSERT_TRUE(profile_manager_.SetUp());
40 profile_ = profile_manager_.CreateTestingProfile("New Profile 1");
41 }
[email protected]1c62b2f2013-06-28 00:15:0042
dcheng8ae9dbf2015-01-09 19:50:2243 void TearDown() override {
[email protected]1c62b2f2013-06-28 00:15:0044 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
[email protected]de6b8ecf2013-09-16 21:47:3145 base::RunLoop().RunUntilIdle();
andresantoso55fd2512015-04-01 21:07:0446 PlatformTest::TearDown();
[email protected]1c62b2f2013-06-28 00:15:0047 }
48
[email protected]de6b8ecf2013-09-16 21:47:3149 content::TestBrowserThreadBundle thread_bundle_;
andresantoso55fd2512015-04-01 21:07:0450 TestingProfileManager profile_manager_;
51 TestingProfile* profile_;
[email protected]288bfcd32009-09-14 18:14:4652};
53
54TEST_F(AppControllerTest, DockMenu) {
[email protected]a8522032013-06-24 22:51:4655 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
[email protected]288bfcd32009-09-14 18:14:4656 NSMenu* menu = [ac applicationDockMenu:NSApp];
57 NSMenuItem* item;
58
59 EXPECT_TRUE(menu);
60 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]);
61 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]);
62 for (item in [menu itemArray]) {
[email protected]018a3962009-09-17 22:23:4463 EXPECT_EQ(ac.get(), [item target]);
[email protected]93b59fc2010-12-21 20:00:4764 EXPECT_EQ(@selector(commandFromDock:), [item action]);
[email protected]288bfcd32009-09-14 18:14:4665 }
66}
[email protected]1c62b2f2013-06-28 00:15:0067
68TEST_F(AppControllerTest, LastProfile) {
andresantoso55fd2512015-04-01 21:07:0469 // Create a second profile.
70 base::FilePath dest_path1 = profile_->GetPath();
[email protected]1c62b2f2013-06-28 00:15:0071 base::FilePath dest_path2 =
andresantoso55fd2512015-04-01 21:07:0472 profile_manager_.CreateTestingProfile("New Profile 2")->GetPath();
73 ASSERT_EQ(2U, profile_manager_.profile_manager()->GetNumberOfProfiles());
74 ASSERT_EQ(2U, profile_manager_.profile_manager()->GetLoadedProfiles().size());
[email protected]1c62b2f2013-06-28 00:15:0075
76 PrefService* local_state = g_browser_process->local_state();
77 local_state->SetString(prefs::kProfileLastUsed,
78 dest_path1.BaseName().MaybeAsASCII());
79
80 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
81
82 // Delete the active profile.
andresantoso55fd2512015-04-01 21:07:0483 profile_manager_.profile_manager()->ScheduleProfileForDeletion(
[email protected]1c62b2f2013-06-28 00:15:0084 dest_path1, ProfileManager::CreateCallback());
85
[email protected]de6b8ecf2013-09-16 21:47:3186 base::RunLoop().RunUntilIdle();
[email protected]1c62b2f2013-06-28 00:15:0087
88 EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath());
89}