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 #include "chrome/browser/ui/browser_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/command_updater.h" | |
9 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/browser_window_state.h" | 13 #include "chrome/browser/ui/browser_window_state.h" |
14 #include "chrome/common/pref_names.h" | |
13 #include "chrome/test/base/browser_with_test_window_test.h" | 15 #include "chrome/test/base/browser_with_test_window_test.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
16 #include "content/public/browser/native_web_keyboard_event.h" | 18 #include "content/public/browser/native_web_keyboard_event.h" |
17 #include "ui/base/keycodes/keyboard_codes.h" | 19 #include "ui/base/keycodes/keyboard_codes.h" |
18 | 20 |
19 typedef BrowserWithTestWindowTest BrowserCommandControllerTest; | 21 typedef BrowserWithTestWindowTest BrowserCommandControllerTest; |
20 | 22 |
21 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { | 23 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { |
22 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 testing_profile_manager.CreateTestingProfile("p2"); | 172 testing_profile_manager.CreateTestingProfile("p2"); |
171 ASSERT_EQ(2U, profile_manager->GetNumberOfProfiles()); | 173 ASSERT_EQ(2U, profile_manager->GetNumberOfProfiles()); |
172 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 174 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
173 | 175 |
174 testing_profile_manager.DeleteTestingProfile("p1"); | 176 testing_profile_manager.DeleteTestingProfile("p1"); |
175 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); | 177 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); |
176 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 178 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
177 | 179 |
178 testing_profile_manager.DeleteTestingProfile("p2"); | 180 testing_profile_manager.DeleteTestingProfile("p2"); |
179 } | 181 } |
182 | |
183 TEST_F(BrowserCommandControllerTest, | |
184 IncognitoModeOnSigninAllowedPrefChange) { | |
185 TestingProfileManager testing_profile_manager( | |
186 TestingBrowserProcess::GetGlobal()); | |
187 ASSERT_TRUE(testing_profile_manager.SetUp()); | |
188 | |
189 // Set up a profile with an off the record profile. | |
190 TestingProfile* profile1 = | |
191 testing_profile_manager.CreateTestingProfile("p1"); | |
192 TestingProfile* profile2 = new TestingProfile(); | |
193 profile2->set_incognito(true); | |
Andrew T Wilson (Slow)
2013/02/07 10:08:11
nit: This is the wrong way to create an incognito
Adrian Kuegel
2013/02/07 11:09:21
Done.
| |
194 profile2->SetOriginalProfile(profile1); | |
195 EXPECT_EQ(profile2->GetOriginalProfile(), profile1); | |
196 profile1->SetOffTheRecordProfile(profile2); | |
197 | |
198 // Create a new browser based on the off the record profile. | |
199 scoped_ptr<Browser> browser2( | |
200 chrome::CreateBrowserWithTestWindowForProfile(profile2)); | |
201 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | |
202 chrome::BrowserCommandController* command_controller = | |
203 new chrome::BrowserCommandController(browser2.get(), profile_manager); | |
204 const CommandUpdater* command_updater = command_controller->command_updater(); | |
205 | |
206 // Check that the SYNC_SETUP command is updated on preference change. | |
207 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | |
208 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | |
209 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | |
210 delete command_controller; | |
211 browser2.reset(); | |
212 testing_profile_manager.DeleteTestingProfile("p1"); | |
213 } | |
214 | |
215 TEST_F(BrowserCommandControllerTest, | |
216 OnSigninAllowedPrefChange) { | |
217 TestingProfileManager testing_profile_manager( | |
218 TestingBrowserProcess::GetGlobal()); | |
219 ASSERT_TRUE(testing_profile_manager.SetUp()); | |
220 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | |
221 chrome::BrowserCommandController command_controller(browser(), | |
222 profile_manager); | |
223 const CommandUpdater* command_updater = command_controller.command_updater(); | |
224 | |
225 // Check that the SYNC_SETUP command is updated on preference change. | |
226 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | |
227 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | |
228 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | |
229 } | |
OLD | NEW |