Index: chrome/browser/app_controller_mac_browsertest.mm |
diff --git a/chrome/browser/app_controller_mac_browsertest.mm b/chrome/browser/app_controller_mac_browsertest.mm |
index 4493a6f0f908f1818855d9f5dc8333e3c67b4d13..bd8dd9ebf4c945bc5d60692816f45274f6d10046 100644 |
--- a/chrome/browser/app_controller_mac_browsertest.mm |
+++ b/chrome/browser/app_controller_mac_browsertest.mm |
@@ -7,16 +7,22 @@ |
#include "apps/shell_window_registry.h" |
#include "base/command_line.h" |
#include "base/mac/scoped_nsobject.h" |
+#include "base/prefs/pref_service.h" |
#include "chrome/app/chrome_command_ids.h" |
#import "chrome/browser/app_controller_mac.h" |
#include "chrome/browser/apps/app_browsertest_util.h" |
#include "chrome/browser/extensions/extension_test_message_listener.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/ui/browser_window.h" |
+#import "chrome/browser/ui/cocoa/user_manager_mac.h" |
#include "chrome/browser/ui/host_desktop.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
-#import "chrome/common/chrome_switches.h" |
+#include "chrome/common/chrome_constants.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/pref_names.h" |
#include "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/ui_test_utils.h" |
#include "content/public/browser/web_contents.h" |
@@ -113,4 +119,92 @@ IN_PROC_BROWSER_TEST_F(AppControllerWebAppBrowserTest, |
EXPECT_EQ(GetAppURL(), current_url.spec()); |
} |
+class AppControllerNewProfileManagementBrowserTest |
+ : public InProcessBrowserTest { |
+ protected: |
+ AppControllerNewProfileManagementBrowserTest() |
+ : active_browser_list_(BrowserList::GetInstance( |
+ chrome::GetActiveDesktop())) { |
+ } |
+ |
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
+ command_line->AppendSwitch(switches::kNewProfileManagement); |
+ } |
+ |
+ const BrowserList* active_browser_list_; |
+}; |
+ |
+// Test that for a regular last profile, a reopen event opens a browser. |
+IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, |
+ RegularProfileReopenWithNoWindows) { |
+ base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
+ EXPECT_EQ(1u, active_browser_list_->size()); |
+ BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
+ |
+ EXPECT_FALSE(result); |
+ EXPECT_EQ(2u, active_browser_list_->size()); |
+ EXPECT_FALSE(UserManagerMac::IsShowing()); |
+} |
+ |
+// Test that for a locked last profile, a reopen event opens the user manager. |
+IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, |
+ LockedProfileReopenWithNoWindows) { |
+ base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
+ |
+ // Lock the active profile. |
+ Profile* profile = [ac lastProfile]; |
+ ProfileInfoCache& cache = |
+ g_browser_process->profile_manager()->GetProfileInfoCache(); |
+ size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
+ cache.SetProfileSigninRequiredAtIndex(profile_index, true); |
Nico
2014/01/14 02:16:04
This is an in-memory thing and doesn't need to be
noms (inactive)
2014/01/14 17:59:50
Correct. The browser process gets cleaned up at th
|
+ EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index)); |
+ |
+ EXPECT_EQ(1u, active_browser_list_->size()); |
+ BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
+ |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ |
+ // Opening the user manager requires creating a guest profile, which is |
+ // asynchronous. |
+ if (!UserManagerMac::IsShowing()) |
+ base::MessageLoop::current()->RunUntilIdle(); |
Nico
2014/01/14 02:16:04
Huh, you're doing RunUntilIdle() twice in successi
noms (inactive)
2014/01/14 17:59:50
IsShowing() doesn't do anything, but without the e
Nico
2014/01/23 21:15:40
As far as I understand (after patching this in, pl
|
+ |
+ EXPECT_FALSE(result); |
Nico
2014/01/14 02:16:04
Maybe check this right after you assign something
noms (inactive)
2014/01/14 17:59:50
Oops. Bad copy paste. Done.
On 2014/01/14 02:16:04
|
+ EXPECT_EQ(1u, active_browser_list_->size()); |
+ EXPECT_TRUE(UserManagerMac::IsShowing()); |
+ UserManagerMac::Hide(); |
+} |
+ |
+// Test that for a guest last profile, a reopen event opens the user manager. |
+IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, |
+ GuestProfileReopenWithNoWindows) { |
+ // Create the guest profile, and set it as the last used profile so the |
+ // app controller can use it on init. |
+ scoped_ptr<Profile> guest_profile(Profile::CreateProfile( |
+ ProfileManager::GetGuestProfilePath(), |
+ NULL, Profile::CREATE_MODE_SYNCHRONOUS)); |
+ PrefService* local_state = g_browser_process->local_state(); |
+ local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir); |
+ |
+ base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
+ |
+ Profile* profile = [ac lastProfile]; |
+ EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath()); |
+ EXPECT_TRUE(profile->IsGuestSession()); |
+ |
+ EXPECT_EQ(1u, active_browser_list_->size()); |
+ BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
+ |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ // Opening the user manager requires creating a guest profile, which is |
+ // asynchronous. |
+ if (!UserManagerMac::IsShowing()) |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ |
+ EXPECT_FALSE(result); |
+ EXPECT_EQ(1u, active_browser_list_->size()); |
+ EXPECT_TRUE(UserManagerMac::IsShowing()); |
+ UserManagerMac::Hide(); |
+} |
+ |
} // namespace |