blob: 3cc40c8448563118ba01ff92b721366ae9de0f69 [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
David Roger51797642018-03-20 13:29:167#include "base/bind_helpers.h"
[email protected]1c62b2f2013-06-28 00:15:008#include "base/files/file_path.h"
[email protected]a8522032013-06-24 22:51:469#include "base/mac/scoped_nsobject.h"
[email protected]de6b8ecf2013-09-16 21:47:3110#include "base/run_loop.h"
andresantoso55fd2512015-04-01 21:07:0411#include "base/strings/utf_string_conversions.h"
[email protected]1a3aba82010-11-08 23:52:5412#include "chrome/app/chrome_command_ids.h"
[email protected]288bfcd32009-09-14 18:14:4613#import "chrome/browser/app_controller_mac.h"
[email protected]de6b8ecf2013-09-16 21:47:3114#include "chrome/browser/browser_process.h"
[email protected]1c62b2f2013-06-28 00:15:0015#include "chrome/browser/profiles/profile_manager.h"
16#include "chrome/common/chrome_constants.h"
17#include "chrome/common/pref_names.h"
[email protected]de6b8ecf2013-09-16 21:47:3118#include "chrome/test/base/testing_browser_process.h"
19#include "chrome/test/base/testing_profile.h"
[email protected]1c62b2f2013-06-28 00:15:0020#include "chrome/test/base/testing_profile_manager.h"
Gabriel Charettec7108742019-08-23 03:31:4021#include "content/public/test/browser_task_environment.h"
[email protected]288bfcd32009-09-14 18:14:4622#include "testing/platform_test.h"
23
24class AppControllerTest : public PlatformTest {
[email protected]1c62b2f2013-06-28 00:15:0025 protected:
andresantoso55fd2512015-04-01 21:07:0426 AppControllerTest()
27 : profile_manager_(TestingBrowserProcess::GetGlobal()),
28 profile_(nullptr) {}
29
30 void SetUp() override {
31 PlatformTest::SetUp();
32 ASSERT_TRUE(profile_manager_.SetUp());
33 profile_ = profile_manager_.CreateTestingProfile("New Profile 1");
34 }
[email protected]1c62b2f2013-06-28 00:15:0035
dcheng8ae9dbf2015-01-09 19:50:2236 void TearDown() override {
[email protected]1c62b2f2013-06-28 00:15:0037 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
[email protected]de6b8ecf2013-09-16 21:47:3138 base::RunLoop().RunUntilIdle();
andresantoso55fd2512015-04-01 21:07:0439 PlatformTest::TearDown();
[email protected]1c62b2f2013-06-28 00:15:0040 }
41
Gabriel Charette798fde72019-08-20 22:24:0442 content::BrowserTaskEnvironment task_environment_;
andresantoso55fd2512015-04-01 21:07:0443 TestingProfileManager profile_manager_;
44 TestingProfile* profile_;
[email protected]288bfcd32009-09-14 18:14:4645};
46
47TEST_F(AppControllerTest, DockMenu) {
[email protected]a8522032013-06-24 22:51:4648 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
[email protected]288bfcd32009-09-14 18:14:4649 NSMenu* menu = [ac applicationDockMenu:NSApp];
50 NSMenuItem* item;
51
52 EXPECT_TRUE(menu);
53 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]);
54 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]);
55 for (item in [menu itemArray]) {
[email protected]018a3962009-09-17 22:23:4456 EXPECT_EQ(ac.get(), [item target]);
[email protected]93b59fc2010-12-21 20:00:4757 EXPECT_EQ(@selector(commandFromDock:), [item action]);
[email protected]288bfcd32009-09-14 18:14:4658 }
59}
[email protected]1c62b2f2013-06-28 00:15:0060
61TEST_F(AppControllerTest, LastProfile) {
andresantoso55fd2512015-04-01 21:07:0462 // Create a second profile.
63 base::FilePath dest_path1 = profile_->GetPath();
[email protected]1c62b2f2013-06-28 00:15:0064 base::FilePath dest_path2 =
andresantoso55fd2512015-04-01 21:07:0465 profile_manager_.CreateTestingProfile("New Profile 2")->GetPath();
66 ASSERT_EQ(2U, profile_manager_.profile_manager()->GetNumberOfProfiles());
67 ASSERT_EQ(2U, profile_manager_.profile_manager()->GetLoadedProfiles().size());
[email protected]1c62b2f2013-06-28 00:15:0068
69 PrefService* local_state = g_browser_process->local_state();
70 local_state->SetString(prefs::kProfileLastUsed,
71 dest_path1.BaseName().MaybeAsASCII());
72
73 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
74
75 // Delete the active profile.
andresantoso55fd2512015-04-01 21:07:0476 profile_manager_.profile_manager()->ScheduleProfileForDeletion(
David Roger51797642018-03-20 13:29:1677 dest_path1, base::DoNothing());
[email protected]1c62b2f2013-06-28 00:15:0078
[email protected]de6b8ecf2013-09-16 21:47:3179 base::RunLoop().RunUntilIdle();
[email protected]1c62b2f2013-06-28 00:15:0080
81 EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath());
82}