1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "base/files/file_path.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/run_loop.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #import "chrome/browser/app_controller_mac.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_browser_process.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/testing_profile_manager.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "testing/platform_test.h"
23 class AppControllerTest : public PlatformTest {
25 AppControllerTest() {}
27 virtual void TearDown() {
28 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
29 base::RunLoop().RunUntilIdle();
32 content::TestBrowserThreadBundle thread_bundle_;
35 TEST_F(AppControllerTest, DockMenu) {
36 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
37 NSMenu* menu = [ac applicationDockMenu:NSApp];
41 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]);
42 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]);
43 for (item in [menu itemArray]) {
44 EXPECT_EQ(ac.get(), [item target]);
45 EXPECT_EQ(@selector(commandFromDock:), [item action]);
49 TEST_F(AppControllerTest, LastProfile) {
50 TestingProfileManager manager(TestingBrowserProcess::GetGlobal());
51 ASSERT_TRUE(manager.SetUp());
53 // Create two profiles.
54 base::FilePath dest_path1 =
55 manager.CreateTestingProfile("New Profile 1")->GetPath();
56 base::FilePath dest_path2 =
57 manager.CreateTestingProfile("New Profile 2")->GetPath();
58 ASSERT_EQ(2U, manager.profile_manager()->GetNumberOfProfiles());
59 ASSERT_EQ(2U, manager.profile_manager()->GetLoadedProfiles().size());
61 PrefService* local_state = g_browser_process->local_state();
62 local_state->SetString(prefs::kProfileLastUsed,
63 dest_path1.BaseName().MaybeAsASCII());
65 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
67 // Delete the active profile.
68 manager.profile_manager()->ScheduleProfileForDeletion(
69 dest_path1, ProfileManager::CreateCallback());
71 base::RunLoop().RunUntilIdle();
73 EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath());