[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 | |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 7 | #include "base/files/file_path.h" |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 8 | #include "base/mac/scoped_nsobject.h" |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 9 | #include "base/run_loop.h" |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 10 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 11 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 12 | #import "chrome/browser/app_controller_mac.h" |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 13 | #include "chrome/browser/browser_process.h" |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile_manager.h" |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 15 | #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 16 | #include "chrome/browser/signin/signin_manager_factory.h" |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 17 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 18 | #include "chrome/common/chrome_constants.h" |
| 19 | #include "chrome/common/pref_names.h" |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 20 | #include "chrome/test/base/testing_browser_process.h" |
| 21 | #include "chrome/test/base/testing_profile.h" |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 22 | #include "chrome/test/base/testing_profile_manager.h" |
maxbogue | 26f4022 | 2016-09-16 20:22:18 | [diff] [blame] | 23 | #include "components/browser_sync/profile_sync_service.h" |
| 24 | #include "components/browser_sync/profile_sync_service_mock.h" |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 25 | #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] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 28 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 29 | #include "testing/platform_test.h" |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 30 | |
| 31 | class AppControllerTest : public PlatformTest { |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 32 | protected: |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 33 | 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] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 42 | |
dcheng | 8ae9dbf | 2015-01-09 19:50:22 | [diff] [blame] | 43 | void TearDown() override { |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 44 | TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 45 | base::RunLoop().RunUntilIdle(); |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 46 | PlatformTest::TearDown(); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 49 | content::TestBrowserThreadBundle thread_bundle_; |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 50 | TestingProfileManager profile_manager_; |
| 51 | TestingProfile* profile_; |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | TEST_F(AppControllerTest, DockMenu) { |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 55 | base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 56 | 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] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 63 | EXPECT_EQ(ac.get(), [item target]); |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 64 | EXPECT_EQ(@selector(commandFromDock:), [item action]); |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 65 | } |
| 66 | } |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 67 | |
| 68 | TEST_F(AppControllerTest, LastProfile) { |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 69 | // Create a second profile. |
| 70 | base::FilePath dest_path1 = profile_->GetPath(); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 71 | base::FilePath dest_path2 = |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 72 | 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] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 75 | |
| 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. |
andresantoso | 55fd251 | 2015-04-01 21:07:04 | [diff] [blame] | 83 | profile_manager_.profile_manager()->ScheduleProfileForDeletion( |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 84 | dest_path1, ProfileManager::CreateCallback()); |
| 85 | |
[email protected] | de6b8ecf | 2013-09-16 21:47:31 | [diff] [blame] | 86 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 87 | |
| 88 | EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); |
| 89 | } |