Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/app_controller_mac_browsertest.mm

Issue 129333002: [Mac] Check if a profile is locked before allowing a new window to be opened. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/MessageLoop/RunLoop/g Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Called when the ProfileManager has created a profile.
123 void CreateProfileCallback(const base::Closure& quit_closure,
124 Profile* profile,
125 Profile::CreateStatus status) {
126 EXPECT_TRUE(profile);
127 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status);
128 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status);
129 // This will be called multiple times. Wait until the profile is initialized
130 // fully to quit the loop.
131 if (status == Profile::CREATE_STATUS_INITIALIZED)
132 quit_closure.Run();
133 }
134
135 void CreateAndWaitForGuestProfile() {
136 ProfileManager::CreateCallback create_callback =
137 base::Bind(&CreateProfileCallback,
138 base::MessageLoop::current()->QuitClosure());
139 g_browser_process->profile_manager()->CreateProfileAsync(
140 ProfileManager::GetGuestProfilePath(),
141 create_callback,
142 base::string16(),
143 base::string16(),
144 std::string());
145 base::RunLoop().Run();
146 }
147
148 class AppControllerNewProfileManagementBrowserTest
149 : public InProcessBrowserTest {
150 protected:
151 AppControllerNewProfileManagementBrowserTest()
152 : active_browser_list_(BrowserList::GetInstance(
153 chrome::GetActiveDesktop())) {
154 }
155
156 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
157 command_line->AppendSwitch(switches::kNewProfileManagement);
158 }
159
160 const BrowserList* active_browser_list_;
161 };
162
163 // Test that for a regular last profile, a reopen event opens a browser.
164 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
165 RegularProfileReopenWithNoWindows) {
166 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
167 EXPECT_EQ(1u, active_browser_list_->size());
168 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
169
170 EXPECT_FALSE(result);
171 EXPECT_EQ(2u, active_browser_list_->size());
172 EXPECT_FALSE(UserManagerMac::IsShowing());
173 }
174
175 // Test that for a locked last profile, a reopen event opens the User Manager.
176 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
177 LockedProfileReopenWithNoWindows) {
178 // The User Manager uses the guest profile as its underlying profile. To
179 // minimize flakiness due to the scheduling/descheduling of tasks on the
180 // different threads, pre-initialize the guest profile before it is needed.
181 CreateAndWaitForGuestProfile();
182 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
183
184 // Lock the active profile.
185 Profile* profile = [ac lastProfile];
186 ProfileInfoCache& cache =
187 g_browser_process->profile_manager()->GetProfileInfoCache();
188 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
189 cache.SetProfileSigninRequiredAtIndex(profile_index, true);
190 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index));
191
192 EXPECT_EQ(1u, active_browser_list_->size());
193 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
194 EXPECT_FALSE(result);
195
196 base::RunLoop().RunUntilIdle();
197 EXPECT_EQ(1u, active_browser_list_->size());
198 EXPECT_TRUE(UserManagerMac::IsShowing());
199 UserManagerMac::Hide();
200 }
201
202 // Test that for a guest last profile, a reopen event opens the User Manager.
203 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
204 GuestProfileReopenWithNoWindows) {
205 // Create the guest profile, and set it as the last used profile so the
206 // app controller can use it on init.
207 CreateAndWaitForGuestProfile();
208 PrefService* local_state = g_browser_process->local_state();
209 local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir);
210
211 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
212
213 Profile* profile = [ac lastProfile];
214 EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath());
215 EXPECT_TRUE(profile->IsGuestSession());
216
217 EXPECT_EQ(1u, active_browser_list_->size());
218 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
219 EXPECT_FALSE(result);
220
221 base::RunLoop().RunUntilIdle();
222
223 EXPECT_EQ(1u, active_browser_list_->size());
224 EXPECT_TRUE(UserManagerMac::IsShowing());
225 UserManagerMac::Hide();
226 }
227
116 } // namespace 228 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698