OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
| 7 #import "chrome/browser/app_controller_mac.h" |
| 8 |
| 9 #include "base/files/file_path.h" |
7 #include "base/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
| 11 #include "chrome/browser/extensions/event_router_forwarder.h" |
8 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
9 #import "chrome/browser/app_controller_mac.h" | 13 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" |
10 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
11 | 20 |
12 class AppControllerTest : public PlatformTest { | 21 class AppControllerTest : public PlatformTest { |
| 22 protected: |
| 23 AppControllerTest() |
| 24 : extension_event_router_forwarder_(new extensions::EventRouterForwarder), |
| 25 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 26 db_thread_(content::BrowserThread::DB, &message_loop_), |
| 27 file_thread_(content::BrowserThread::FILE, &message_loop_) { |
| 28 } |
| 29 |
| 30 virtual void TearDown() { |
| 31 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
| 32 message_loop_.RunUntilIdle(); |
| 33 } |
| 34 |
| 35 scoped_refptr<extensions::EventRouterForwarder> |
| 36 extension_event_router_forwarder_; |
| 37 base::MessageLoopForUI message_loop_; |
| 38 content::TestBrowserThread ui_thread_; |
| 39 content::TestBrowserThread db_thread_; |
| 40 content::TestBrowserThread file_thread_; |
13 }; | 41 }; |
14 | 42 |
15 TEST_F(AppControllerTest, DockMenu) { | 43 TEST_F(AppControllerTest, DockMenu) { |
16 scoped_nsobject<AppController> ac([[AppController alloc] init]); | 44 scoped_nsobject<AppController> ac([[AppController alloc] init]); |
17 NSMenu* menu = [ac applicationDockMenu:NSApp]; | 45 NSMenu* menu = [ac applicationDockMenu:NSApp]; |
18 NSMenuItem* item; | 46 NSMenuItem* item; |
19 | 47 |
20 EXPECT_TRUE(menu); | 48 EXPECT_TRUE(menu); |
21 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]); | 49 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]); |
22 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]); | 50 EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]); |
23 for (item in [menu itemArray]) { | 51 for (item in [menu itemArray]) { |
24 EXPECT_EQ(ac.get(), [item target]); | 52 EXPECT_EQ(ac.get(), [item target]); |
25 EXPECT_EQ(@selector(commandFromDock:), [item action]); | 53 EXPECT_EQ(@selector(commandFromDock:), [item action]); |
26 } | 54 } |
27 } | 55 } |
| 56 |
| 57 TEST_F(AppControllerTest, LastProfile) { |
| 58 TestingProfileManager manager(TestingBrowserProcess::GetGlobal()); |
| 59 ASSERT_TRUE(manager.SetUp()); |
| 60 |
| 61 // Create two profiles. |
| 62 base::FilePath dest_path1 = |
| 63 manager.CreateTestingProfile("New Profile 1")->GetPath(); |
| 64 base::FilePath dest_path2 = |
| 65 manager.CreateTestingProfile("New Profile 2")->GetPath(); |
| 66 ASSERT_EQ(2U, manager.profile_manager()->GetNumberOfProfiles()); |
| 67 ASSERT_EQ(2U, manager.profile_manager()->GetLoadedProfiles().size()); |
| 68 |
| 69 PrefService* local_state = g_browser_process->local_state(); |
| 70 local_state->SetString(prefs::kProfileLastUsed, |
| 71 dest_path1.BaseName().MaybeAsASCII()); |
| 72 |
| 73 scoped_nsobject<AppController> ac([[AppController alloc] init]); |
| 74 |
| 75 // Delete the active profile. |
| 76 manager.profile_manager()->ScheduleProfileForDeletion( |
| 77 dest_path1, ProfileManager::CreateCallback()); |
| 78 |
| 79 message_loop_.RunUntilIdle(); |
| 80 |
| 81 EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); |
| 82 } |
OLD | NEW |