| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
| 6 #import <Cocoa/Cocoa.h> | 6 #import <Cocoa/Cocoa.h> |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #import <Foundation/NSAppleEventDescriptor.h> | 8 #import <Foundation/NSAppleEventDescriptor.h> |
| 9 #import <objc/message.h> | 9 #import <objc/message.h> |
| 10 #import <objc/runtime.h> | 10 #import <objc/runtime.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 17 #import "chrome/browser/app_controller_mac.h" | 17 #import "chrome/browser/app_controller_mac.h" |
| 18 #include "chrome/browser/apps/app_browsertest_util.h" | 18 #include "chrome/browser/apps/app_browsertest_util.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 24 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" | |
| 25 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/browser/ui/user_manager.h" |
| 27 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "components/signin/core/common/profile_management_switches.h" | 33 #include "components/signin/core/common/profile_management_switches.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "extensions/browser/app_window/app_window_registry.h" | 35 #include "extensions/browser/app_window/app_window_registry.h" |
| 36 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 // Test that for a regular last profile, a reopen event opens a browser. | 216 // Test that for a regular last profile, a reopen event opens a browser. |
| 217 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, | 217 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, |
| 218 RegularProfileReopenWithNoWindows) { | 218 RegularProfileReopenWithNoWindows) { |
| 219 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | 219 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
| 220 EXPECT_EQ(1u, active_browser_list_->size()); | 220 EXPECT_EQ(1u, active_browser_list_->size()); |
| 221 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | 221 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
| 222 | 222 |
| 223 EXPECT_FALSE(result); | 223 EXPECT_FALSE(result); |
| 224 EXPECT_EQ(2u, active_browser_list_->size()); | 224 EXPECT_EQ(2u, active_browser_list_->size()); |
| 225 EXPECT_FALSE(UserManagerMac::IsShowing()); | 225 EXPECT_FALSE(UserManager::IsShowing()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Test that for a locked last profile, a reopen event opens the User Manager. | 228 // Test that for a locked last profile, a reopen event opens the User Manager. |
| 229 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, | 229 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, |
| 230 LockedProfileReopenWithNoWindows) { | 230 LockedProfileReopenWithNoWindows) { |
| 231 // The User Manager uses the guest profile as its underlying profile. To | 231 // The User Manager uses the guest profile as its underlying profile. To |
| 232 // minimize flakiness due to the scheduling/descheduling of tasks on the | 232 // minimize flakiness due to the scheduling/descheduling of tasks on the |
| 233 // different threads, pre-initialize the guest profile before it is needed. | 233 // different threads, pre-initialize the guest profile before it is needed. |
| 234 CreateAndWaitForGuestProfile(); | 234 CreateAndWaitForGuestProfile(); |
| 235 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | 235 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
| 236 | 236 |
| 237 // Lock the active profile. | 237 // Lock the active profile. |
| 238 Profile* profile = [ac lastProfile]; | 238 Profile* profile = [ac lastProfile]; |
| 239 ProfileInfoCache& cache = | 239 ProfileInfoCache& cache = |
| 240 g_browser_process->profile_manager()->GetProfileInfoCache(); | 240 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 241 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 241 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 242 cache.SetProfileSigninRequiredAtIndex(profile_index, true); | 242 cache.SetProfileSigninRequiredAtIndex(profile_index, true); |
| 243 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index)); | 243 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index)); |
| 244 | 244 |
| 245 EXPECT_EQ(1u, active_browser_list_->size()); | 245 EXPECT_EQ(1u, active_browser_list_->size()); |
| 246 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | 246 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
| 247 EXPECT_FALSE(result); | 247 EXPECT_FALSE(result); |
| 248 | 248 |
| 249 base::RunLoop().RunUntilIdle(); | 249 base::RunLoop().RunUntilIdle(); |
| 250 EXPECT_EQ(1u, active_browser_list_->size()); | 250 EXPECT_EQ(1u, active_browser_list_->size()); |
| 251 EXPECT_TRUE(UserManagerMac::IsShowing()); | 251 EXPECT_TRUE(UserManager::IsShowing()); |
| 252 UserManagerMac::Hide(); | 252 UserManager::Hide(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Test that for a guest last profile, a reopen event opens the User Manager. | 255 // Test that for a guest last profile, a reopen event opens the User Manager. |
| 256 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, | 256 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, |
| 257 GuestProfileReopenWithNoWindows) { | 257 GuestProfileReopenWithNoWindows) { |
| 258 // Create the guest profile, and set it as the last used profile so the | 258 // Create the guest profile, and set it as the last used profile so the |
| 259 // app controller can use it on init. | 259 // app controller can use it on init. |
| 260 CreateAndWaitForGuestProfile(); | 260 CreateAndWaitForGuestProfile(); |
| 261 PrefService* local_state = g_browser_process->local_state(); | 261 PrefService* local_state = g_browser_process->local_state(); |
| 262 local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir); | 262 local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir); |
| 263 | 263 |
| 264 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | 264 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
| 265 | 265 |
| 266 Profile* profile = [ac lastProfile]; | 266 Profile* profile = [ac lastProfile]; |
| 267 EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath()); | 267 EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath()); |
| 268 EXPECT_TRUE(profile->IsGuestSession()); | 268 EXPECT_TRUE(profile->IsGuestSession()); |
| 269 | 269 |
| 270 EXPECT_EQ(1u, active_browser_list_->size()); | 270 EXPECT_EQ(1u, active_browser_list_->size()); |
| 271 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | 271 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
| 272 EXPECT_FALSE(result); | 272 EXPECT_FALSE(result); |
| 273 | 273 |
| 274 base::RunLoop().RunUntilIdle(); | 274 base::RunLoop().RunUntilIdle(); |
| 275 | 275 |
| 276 EXPECT_EQ(1u, active_browser_list_->size()); | 276 EXPECT_EQ(1u, active_browser_list_->size()); |
| 277 EXPECT_TRUE(UserManagerMac::IsShowing()); | 277 EXPECT_TRUE(UserManager::IsShowing()); |
| 278 UserManagerMac::Hide(); | 278 UserManager::Hide(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 class AppControllerOpenShortcutBrowserTest : public InProcessBrowserTest { | 281 class AppControllerOpenShortcutBrowserTest : public InProcessBrowserTest { |
| 282 protected: | 282 protected: |
| 283 AppControllerOpenShortcutBrowserTest() { | 283 AppControllerOpenShortcutBrowserTest() { |
| 284 } | 284 } |
| 285 | 285 |
| 286 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 286 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 287 // In order to mimic opening shortcut during browser startup, we need to | 287 // In order to mimic opening shortcut during browser startup, we need to |
| 288 // send the event before -applicationDidFinishLaunching is called, but | 288 // send the event before -applicationDidFinishLaunching is called, but |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 IN_PROC_BROWSER_TEST_F(AppControllerOpenShortcutBrowserTest, | 325 IN_PROC_BROWSER_TEST_F(AppControllerOpenShortcutBrowserTest, |
| 326 OpenShortcutOnStartup) { | 326 OpenShortcutOnStartup) { |
| 327 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 327 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 328 EXPECT_EQ(g_open_shortcut_url, | 328 EXPECT_EQ(g_open_shortcut_url, |
| 329 browser()->tab_strip_model()->GetActiveWebContents() | 329 browser()->tab_strip_model()->GetActiveWebContents() |
| 330 ->GetLastCommittedURL()); | 330 ->GetLastCommittedURL()); |
| 331 } | 331 } |
| 332 | 332 |
| 333 } // namespace | 333 } // namespace |
| OLD | NEW |