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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "apps/shell_window_registry.h" | 7 #include "apps/shell_window_registry.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/prefs/pref_service.h" | |
10 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
11 #import "chrome/browser/app_controller_mac.h" | 12 #import "chrome/browser/app_controller_mac.h" |
12 #include "chrome/browser/apps/app_browsertest_util.h" | 13 #include "chrome/browser/apps/app_browsertest_util.h" |
13 #include "chrome/browser/extensions/extension_test_message_listener.h" | 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | |
14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/browser/browser_process.h" | |
16 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
20 #import "chrome/browser/ui/cocoa/user_manager_mac.h" | |
17 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #import "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_switches.h" | |
25 #include "chrome/common/pref_names.h" | |
20 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
23 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
24 | 30 |
25 namespace { | 31 namespace { |
26 | 32 |
27 class AppControllerPlatformAppBrowserTest | 33 class AppControllerPlatformAppBrowserTest |
28 : public extensions::PlatformAppBrowserTest { | 34 : public extensions::PlatformAppBrowserTest { |
29 protected: | 35 protected: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 | 112 |
107 EXPECT_FALSE(result); | 113 EXPECT_FALSE(result); |
108 EXPECT_EQ(2u, active_browser_list_->size()); | 114 EXPECT_EQ(2u, active_browser_list_->size()); |
109 | 115 |
110 Browser* browser = active_browser_list_->get(0); | 116 Browser* browser = active_browser_list_->get(0); |
111 GURL current_url = | 117 GURL current_url = |
112 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); | 118 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); |
113 EXPECT_EQ(GetAppURL(), current_url.spec()); | 119 EXPECT_EQ(GetAppURL(), current_url.spec()); |
114 } | 120 } |
115 | 121 |
122 class AppControllerNewProfileManagementBrowserTest | |
123 : public InProcessBrowserTest { | |
124 protected: | |
125 AppControllerNewProfileManagementBrowserTest() | |
126 : active_browser_list_(BrowserList::GetInstance( | |
127 chrome::GetActiveDesktop())) { | |
128 } | |
129 | |
130 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
131 command_line->AppendSwitch(switches::kNewProfileManagement); | |
132 } | |
133 | |
134 const BrowserList* active_browser_list_; | |
135 }; | |
136 | |
137 // Test that for a regular last profile, a reopen event opens a browser. | |
138 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, | |
139 RegularProfileReopenWithNoWindows) { | |
140 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | |
141 EXPECT_EQ(1u, active_browser_list_->size()); | |
142 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | |
143 | |
144 EXPECT_FALSE(result); | |
145 EXPECT_EQ(2u, active_browser_list_->size()); | |
146 EXPECT_FALSE(UserManagerMac::IsShowing()); | |
147 } | |
148 | |
149 // Test that for a locked last profile, a reopen event opens the user manager. | |
150 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, | |
151 LockedProfileReopenWithNoWindows) { | |
152 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | |
153 | |
154 // Lock the active profile. | |
155 Profile* profile = [ac lastProfile]; | |
156 ProfileInfoCache& cache = | |
157 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
158 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
159 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
| |
160 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index)); | |
161 | |
162 EXPECT_EQ(1u, active_browser_list_->size()); | |
163 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | |
164 | |
165 base::MessageLoop::current()->RunUntilIdle(); | |
166 | |
167 // Opening the user manager requires creating a guest profile, which is | |
168 // asynchronous. | |
169 if (!UserManagerMac::IsShowing()) | |
170 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
| |
171 | |
172 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
| |
173 EXPECT_EQ(1u, active_browser_list_->size()); | |
174 EXPECT_TRUE(UserManagerMac::IsShowing()); | |
175 UserManagerMac::Hide(); | |
176 } | |
177 | |
178 // Test that for a guest last profile, a reopen event opens the user manager. | |
179 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, | |
180 GuestProfileReopenWithNoWindows) { | |
181 // Create the guest profile, and set it as the last used profile so the | |
182 // app controller can use it on init. | |
183 scoped_ptr<Profile> guest_profile(Profile::CreateProfile( | |
184 ProfileManager::GetGuestProfilePath(), | |
185 NULL, Profile::CREATE_MODE_SYNCHRONOUS)); | |
186 PrefService* local_state = g_browser_process->local_state(); | |
187 local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir); | |
188 | |
189 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | |
190 | |
191 Profile* profile = [ac lastProfile]; | |
192 EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath()); | |
193 EXPECT_TRUE(profile->IsGuestSession()); | |
194 | |
195 EXPECT_EQ(1u, active_browser_list_->size()); | |
196 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | |
197 | |
198 base::MessageLoop::current()->RunUntilIdle(); | |
199 // Opening the user manager requires creating a guest profile, which is | |
200 // asynchronous. | |
201 if (!UserManagerMac::IsShowing()) | |
202 base::MessageLoop::current()->RunUntilIdle(); | |
203 | |
204 EXPECT_FALSE(result); | |
205 EXPECT_EQ(1u, active_browser_list_->size()); | |
206 EXPECT_TRUE(UserManagerMac::IsShowing()); | |
207 UserManagerMac::Hide(); | |
208 } | |
209 | |
116 } // namespace | 210 } // namespace |
OLD | NEW |