[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 2 | // 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 Roger | 5179764 | 2018-03-20 13:29:16 | [diff] [blame] | 7 | #include "base/bind_helpers.h" |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 9 | #include "base/mac/scoped_nsobject.h" |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 10 | #include "base/run_loop.h" |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 12 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 13 | #import "chrome/browser/app_controller_mac.h" |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 14 | #include "chrome/browser/browser_process.h" |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 15 | #include "chrome/browser/profiles/profile_manager.h" |
| 16 | #include "chrome/common/chrome_constants.h" |
| 17 | #include "chrome/common/pref_names.h" |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 18 | #include "chrome/test/base/testing_browser_process.h" |
| 19 | #include "chrome/test/base/testing_profile.h" |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 20 | #include "chrome/test/base/testing_profile_manager.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 21 | #include "content/public/test/browser_task_environment.h" |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 22 | #include "testing/platform_test.h" |
| 23 | |
| 24 | class AppControllerTest : public PlatformTest { |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 25 | protected: |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 26 | 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] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 35 | |
dcheng | 8ae9dbf | 2015-01-09 19:50:22 | [diff] [blame] | 36 | void TearDown() override { |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 37 | TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 38 | base::RunLoop().RunUntilIdle(); |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 39 | PlatformTest::TearDown(); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 40 | } |
| 41 | |
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 42 | content::BrowserTaskEnvironment task_environment_; |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 43 | TestingProfileManager profile_manager_; |
| 44 | TestingProfile* profile_; |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | TEST_F(AppControllerTest, DockMenu) { |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 48 | base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 49 | 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] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 56 | EXPECT_EQ(ac.get(), [item target]); |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 57 | EXPECT_EQ(@selector(commandFromDock:), [item action]); |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 58 | } |
| 59 | } |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 60 | |
| 61 | TEST_F(AppControllerTest, LastProfile) { |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 62 | // Create a second profile. |
| 63 | base::FilePath dest_path1 = profile_->GetPath(); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 64 | base::FilePath dest_path2 = |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 65 | 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] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 68 | |
| 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. |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 76 | profile_manager_.profile_manager()->ScheduleProfileForDeletion( |
David Roger | 5179764 | 2018-03-20 13:29:16 | [diff] [blame] | 77 | dest_path1, base::DoNothing()); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 78 | |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 79 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 80 | |
| 81 | EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); |
| 82 | } |