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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

Issue 13468005: Show only the settings pages for new managed users (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 7 years, 8 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
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 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "chrome/test/base/in_process_browser_test.h" 33 #include "chrome/test/base/in_process_browser_test.h"
34 #include "chrome/test/base/ui_test_utils.h" 34 #include "chrome/test/base/ui_test_utils.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 37
38 using extensions::Extension; 38 using extensions::Extension;
39 39
40 namespace {
41
42 // Check that there are two browsers. Find the one that is not |browser|.
43 void FindOneOtherBrowser(Browser* browser, Browser** out_other_browser) {
Bernhard Bauer 2013/04/03 17:55:20 Could you simply return the other browser here?
Sergiu 2013/04/04 09:02:55 Well, there is a comment below that says: // Hel
Bernhard Bauer 2013/04/04 09:08:40 Well, yeah, an ASSERT expands to something that re
44 // There should only be one other browser.
45 ASSERT_EQ(2u, chrome::GetBrowserCount(browser->profile(),
46 browser->host_desktop_type()));
47
48 // Find the new browser.
49 Browser* other_browser = NULL;
50 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) {
51 if (*it != browser)
52 other_browser = *it;
53 }
54 ASSERT_TRUE(other_browser);
55 ASSERT_TRUE(other_browser != browser);
Bernhard Bauer 2013/04/03 17:55:20 This check isn't really necessary (that's the exac
Sergiu 2013/04/04 09:02:55 Done.
56 *out_other_browser = other_browser;
57 }
58
59 } // namespace
60
40 class StartupBrowserCreatorTest : public ExtensionBrowserTest { 61 class StartupBrowserCreatorTest : public ExtensionBrowserTest {
41 protected: 62 protected:
42 virtual bool SetUpUserDataDirectory() OVERRIDE { 63 virtual bool SetUpUserDataDirectory() OVERRIDE {
43 // Make sure the first run sentinel file exists before running these tests, 64 // Make sure the first run sentinel file exists before running these tests,
44 // since some of them customize the session startup pref whose value can 65 // since some of them customize the session startup pref whose value can
45 // be different than the default during the first run. 66 // be different than the default during the first run.
46 // TODO(bauerb): set the first run flag instead of creating a sentinel file. 67 // TODO(bauerb): set the first run flag instead of creating a sentinel file.
47 first_run::CreateSentinel(); 68 first_run::CreateSentinel();
48 return ExtensionBrowserTest::SetUpUserDataDirectory(); 69 return ExtensionBrowserTest::SetUpUserDataDirectory();
49 } 70 }
(...skipping 27 matching lines...) Expand all
77 browser()->host_desktop_type())); 98 browser()->host_desktop_type()));
78 } 99 }
79 100
80 void SetAppLaunchPref(const std::string& app_id, 101 void SetAppLaunchPref(const std::string& app_id,
81 extensions::ExtensionPrefs::LaunchType launch_type) { 102 extensions::ExtensionPrefs::LaunchType launch_type) {
82 ExtensionService* service = extensions::ExtensionSystem::Get( 103 ExtensionService* service = extensions::ExtensionSystem::Get(
83 browser()->profile())->extension_service(); 104 browser()->profile())->extension_service();
84 service->extension_prefs()->SetLaunchType(app_id, launch_type); 105 service->extension_prefs()->SetLaunchType(app_id, launch_type);
85 } 106 }
86 107
87 // Check that there are two browsers. Find the one that is not |browser()|.
88 void FindOneOtherBrowser(Browser** out_other_browser) {
89 // There should only be one other browser.
90 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(),
91 browser()->host_desktop_type()));
92
93 // Find the new browser.
94 Browser* other_browser = NULL;
95 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) {
96 if (*it != browser())
97 other_browser = *it;
98 }
99 ASSERT_TRUE(other_browser);
100 ASSERT_TRUE(other_browser != browser());
101 *out_other_browser = other_browser;
102 }
103
104 Browser* FindOneOtherBrowserForProfile(Profile* profile, 108 Browser* FindOneOtherBrowserForProfile(Profile* profile,
105 Browser* not_this_browser) { 109 Browser* not_this_browser) {
106 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 110 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
107 if (*it != not_this_browser && it->profile() == profile) 111 if (*it != not_this_browser && it->profile() == profile)
108 return *it; 112 return *it;
109 } 113 }
110 return NULL; 114 return NULL;
111 } 115 }
112 }; 116 };
113 117
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Do a simple non-process-startup browser launch. 186 // Do a simple non-process-startup browser launch.
183 CommandLine dummy(CommandLine::NO_PROGRAM); 187 CommandLine dummy(CommandLine::NO_PROGRAM);
184 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 188 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
185 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 189 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
186 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); 190 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
187 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 191 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
188 192
189 // This should have created a new browser window. |browser()| is still 193 // This should have created a new browser window. |browser()| is still
190 // around at this point, even though we've closed its window. 194 // around at this point, even though we've closed its window.
191 Browser* new_browser = NULL; 195 Browser* new_browser = NULL;
192 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 196 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
193 197
194 // The new browser should have one tab for each URL. 198 // The new browser should have one tab for each URL.
195 TabStripModel* tab_strip = new_browser->tab_strip_model(); 199 TabStripModel* tab_strip = new_browser->tab_strip_model();
196 ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count()); 200 ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count());
197 for (size_t i=0; i < urls.size(); i++) { 201 for (size_t i=0; i < urls.size(); i++) {
198 EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); 202 EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL());
199 } 203 }
200 204
201 // The two tabs, despite having the same site, should be in different 205 // The two tabs, despite having the same site, should be in different
202 // SiteInstances. 206 // SiteInstances.
(...skipping 22 matching lines...) Expand all
225 229
226 // Do a simple non-process-startup browser launch. 230 // Do a simple non-process-startup browser launch.
227 CommandLine dummy(CommandLine::NO_PROGRAM); 231 CommandLine dummy(CommandLine::NO_PROGRAM);
228 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 232 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
229 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 233 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
230 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); 234 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
231 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 235 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
232 236
233 // This should have created a new browser window. 237 // This should have created a new browser window.
234 Browser* new_browser = NULL; 238 Browser* new_browser = NULL;
235 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 239 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
236 240
237 // The new browser should have exactly one tab (not the startup URLs). 241 // The new browser should have exactly one tab (not the startup URLs).
238 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); 242 ASSERT_EQ(1, new_browser->tab_strip_model()->count());
239 } 243 }
240 244
241 // App shortcuts are not implemented on mac os. 245 // App shortcuts are not implemented on mac os.
242 #if !defined(OS_MACOSX) 246 #if !defined(OS_MACOSX)
243 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { 247 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) {
244 // Load an app with launch.container = 'tab'. 248 // Load an app with launch.container = 'tab'.
245 const Extension* extension_app = NULL; 249 const Extension* extension_app = NULL;
246 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); 250 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
247 251
248 // Add --app-id=<extension->id()> to the command line. 252 // Add --app-id=<extension->id()> to the command line.
249 CommandLine command_line(CommandLine::NO_PROGRAM); 253 CommandLine command_line(CommandLine::NO_PROGRAM);
250 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); 254 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
251 255
252 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 256 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
253 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 257 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
254 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); 258 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
255 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 259 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
256 260
257 // No pref was set, so the app should have opened in a window. 261 // No pref was set, so the app should have opened in a window.
258 // The launch should have created a new browser. 262 // The launch should have created a new browser.
259 Browser* new_browser = NULL; 263 Browser* new_browser = NULL;
260 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 264 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
261 265
262 // Expect an app window. 266 // Expect an app window.
263 EXPECT_TRUE(new_browser->is_app()); 267 EXPECT_TRUE(new_browser->is_app());
264 268
265 // The browser's app_name should include the app's ID. 269 // The browser's app_name should include the app's ID.
266 EXPECT_NE( 270 EXPECT_NE(
267 new_browser->app_name_.find(extension_app->id()), 271 new_browser->app_name_.find(extension_app->id()),
268 std::string::npos) << new_browser->app_name_; 272 std::string::npos) << new_browser->app_name_;
269 } 273 }
270 274
271 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { 275 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) {
272 const Extension* extension_app = NULL; 276 const Extension* extension_app = NULL;
273 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); 277 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
274 278
275 // Set a pref indicating that the user wants to open this app in a window. 279 // Set a pref indicating that the user wants to open this app in a window.
276 SetAppLaunchPref(extension_app->id(), 280 SetAppLaunchPref(extension_app->id(),
277 extensions::ExtensionPrefs::LAUNCH_WINDOW); 281 extensions::ExtensionPrefs::LAUNCH_WINDOW);
278 282
279 CommandLine command_line(CommandLine::NO_PROGRAM); 283 CommandLine command_line(CommandLine::NO_PROGRAM);
280 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); 284 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
281 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 285 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
282 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 286 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
283 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); 287 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
284 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 288 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
285 289
286 // Pref was set to open in a window, so the app should have opened in a 290 // Pref was set to open in a window, so the app should have opened in a
287 // window. The launch should have created a new browser. Find the new 291 // window. The launch should have created a new browser. Find the new
288 // browser. 292 // browser.
289 Browser* new_browser = NULL; 293 Browser* new_browser = NULL;
290 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 294 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
291 295
292 // Expect an app window. 296 // Expect an app window.
293 EXPECT_TRUE(new_browser->is_app()); 297 EXPECT_TRUE(new_browser->is_app());
294 298
295 // The browser's app_name should include the app's ID. 299 // The browser's app_name should include the app's ID.
296 EXPECT_NE( 300 EXPECT_NE(
297 new_browser->app_name_.find(extension_app->id()), 301 new_browser->app_name_.find(extension_app->id()),
298 std::string::npos) << new_browser->app_name_; 302 std::string::npos) << new_browser->app_name_;
299 } 303 }
300 304
(...skipping 12 matching lines...) Expand all
313 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 317 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
314 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); 318 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
315 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 319 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
316 320
317 // When an app shortcut is open and the pref indicates a tab should 321 // When an app shortcut is open and the pref indicates a tab should
318 // open, the tab is open in a new browser window. Expect a new window. 322 // open, the tab is open in a new browser window. Expect a new window.
319 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), 323 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(),
320 browser()->host_desktop_type())); 324 browser()->host_desktop_type()));
321 325
322 Browser* new_browser = NULL; 326 Browser* new_browser = NULL;
323 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 327 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
324 328
325 // The tab should be in a tabbed window. 329 // The tab should be in a tabbed window.
326 EXPECT_TRUE(new_browser->is_type_tabbed()); 330 EXPECT_TRUE(new_browser->is_type_tabbed());
327 331
328 // The browser's app_name should not include the app's ID: It is in a 332 // The browser's app_name should not include the app's ID: It is in a
329 // normal browser. 333 // normal browser.
330 EXPECT_EQ( 334 EXPECT_EQ(
331 new_browser->app_name_.find(extension_app->id()), 335 new_browser->app_name_.find(extension_app->id()),
332 std::string::npos) << new_browser->app_name_; 336 std::string::npos) << new_browser->app_name_;
333 } 337 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html")); 370 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html"));
367 371
368 // Do a simple non-process-startup browser launch. 372 // Do a simple non-process-startup browser launch.
369 CommandLine dummy(CommandLine::NO_PROGRAM); 373 CommandLine dummy(CommandLine::NO_PROGRAM);
370 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, 374 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
371 chrome::startup::IS_FIRST_RUN); 375 chrome::startup::IS_FIRST_RUN);
372 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 376 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
373 377
374 // This should have created a new browser window. 378 // This should have created a new browser window.
375 Browser* new_browser = NULL; 379 Browser* new_browser = NULL;
376 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 380 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
377 381
378 TabStripModel* tab_strip = new_browser->tab_strip_model(); 382 TabStripModel* tab_strip = new_browser->tab_strip_model();
379 EXPECT_EQ(2, tab_strip->count()); 383 EXPECT_EQ(2, tab_strip->count());
380 384
381 EXPECT_EQ("title1.html", 385 EXPECT_EQ("title1.html",
382 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); 386 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
383 EXPECT_EQ("title2.html", 387 EXPECT_EQ("title2.html",
384 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); 388 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
385 } 389 }
386 390
387 // Test hard-coded special first run tabs (defined in 391 // Test hard-coded special first run tabs (defined in
388 // StartupBrowserCreatorImpl::AddStartupURLs()). 392 // StartupBrowserCreatorImpl::AddStartupURLs()).
389 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, AddCustomFirstRunTab) { 393 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, AddCustomFirstRunTab) {
390 StartupBrowserCreator browser_creator; 394 StartupBrowserCreator browser_creator;
391 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); 395 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
392 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); 396 browser_creator.AddFirstRunTab(GURL("http://new_tab_page"));
393 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html")); 397 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html"));
394 browser_creator.AddFirstRunTab(GURL("http://welcome_page")); 398 browser_creator.AddFirstRunTab(GURL("http://welcome_page"));
395 399
396 // Do a simple non-process-startup browser launch. 400 // Do a simple non-process-startup browser launch.
397 CommandLine dummy(CommandLine::NO_PROGRAM); 401 CommandLine dummy(CommandLine::NO_PROGRAM);
398 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, 402 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
399 chrome::startup::IS_FIRST_RUN); 403 chrome::startup::IS_FIRST_RUN);
400 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 404 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
401 405
402 // This should have created a new browser window. 406 // This should have created a new browser window.
403 Browser* new_browser = NULL; 407 Browser* new_browser = NULL;
404 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 408 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
405 409
406 TabStripModel* tab_strip = new_browser->tab_strip_model(); 410 TabStripModel* tab_strip = new_browser->tab_strip_model();
407 EXPECT_EQ(4, tab_strip->count()); 411 EXPECT_EQ(4, tab_strip->count());
408 412
409 EXPECT_EQ("title1.html", 413 EXPECT_EQ("title1.html",
410 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); 414 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
411 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 415 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
412 tab_strip->GetWebContentsAt(1)->GetURL()); 416 tab_strip->GetWebContentsAt(1)->GetURL());
413 EXPECT_EQ("title2.html", 417 EXPECT_EQ("title2.html",
414 tab_strip->GetWebContentsAt(2)->GetURL().ExtractFileName()); 418 tab_strip->GetWebContentsAt(2)->GetURL().ExtractFileName());
415 EXPECT_EQ(internals::GetWelcomePageURL(), 419 EXPECT_EQ(internals::GetWelcomePageURL(),
416 tab_strip->GetWebContentsAt(3)->GetURL()); 420 tab_strip->GetWebContentsAt(3)->GetURL());
417 } 421 }
418 422
419 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) { 423 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) {
420 // Trick this test into thinking the promo has been shown for this profile; so 424 // Trick this test into thinking the promo has been shown for this profile; so
421 // that it will show it again (otherwise it skips showing it since 425 // that it will show it again (otherwise it skips showing it since
422 // --no-first-run is specified in browser tests). 426 // --no-first-run is specified in browser tests).
423 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); 427 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile());
424 428
425 // Do a simple non-process-startup browser launch. 429 // Do a simple non-process-startup browser launch.
426 CommandLine dummy(CommandLine::NO_PROGRAM); 430 CommandLine dummy(CommandLine::NO_PROGRAM);
427 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, 431 StartupBrowserCreatorImpl launch(base::FilePath(), dummy,
428 chrome::startup::IS_FIRST_RUN); 432 chrome::startup::IS_FIRST_RUN);
429 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 433 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
430 434
431 // This should have created a new browser window. 435 // This should have created a new browser window.
432 Browser* new_browser = NULL; 436 Browser* new_browser = NULL;
433 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 437 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
434 438
435 TabStripModel* tab_strip = new_browser->tab_strip_model(); 439 TabStripModel* tab_strip = new_browser->tab_strip_model();
436 EXPECT_EQ(1, tab_strip->count()); 440 EXPECT_EQ(1, tab_strip->count());
437 441
438 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { 442 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) {
439 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); 443 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host());
440 } else { 444 } else {
441 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 445 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
442 tab_strip->GetWebContentsAt(0)->GetURL()); 446 tab_strip->GetWebContentsAt(0)->GetURL());
443 } 447 }
444 } 448 }
445 449
446 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) { 450 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) {
447 // Trick this test into thinking the promo has been shown for this profile; so 451 // Trick this test into thinking the promo has been shown for this profile; so
448 // that it will show it again (otherwise it skips showing it since 452 // that it will show it again (otherwise it skips showing it since
449 // --no-first-run is specified in browser tests). 453 // --no-first-run is specified in browser tests).
450 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); 454 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile());
451 first_run::SetShouldShowWelcomePage(); 455 first_run::SetShouldShowWelcomePage();
452 456
453 // Do a simple non-process-startup browser launch. 457 // Do a simple non-process-startup browser launch.
454 CommandLine dummy(CommandLine::NO_PROGRAM); 458 CommandLine dummy(CommandLine::NO_PROGRAM);
455 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, 459 StartupBrowserCreatorImpl launch(base::FilePath(), dummy,
456 chrome::startup::IS_FIRST_RUN); 460 chrome::startup::IS_FIRST_RUN);
457 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 461 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
458 462
459 // This should have created a new browser window. 463 // This should have created a new browser window.
460 Browser* new_browser = NULL; 464 Browser* new_browser = NULL;
461 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 465 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
462 466
463 TabStripModel* tab_strip = new_browser->tab_strip_model(); 467 TabStripModel* tab_strip = new_browser->tab_strip_model();
464 EXPECT_EQ(2, tab_strip->count()); 468 EXPECT_EQ(2, tab_strip->count());
465 469
466 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { 470 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) {
467 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); 471 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host());
468 } else { 472 } else {
469 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 473 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
470 tab_strip->GetWebContentsAt(0)->GetURL()); 474 tab_strip->GetWebContentsAt(0)->GetURL());
471 } 475 }
(...skipping 16 matching lines...) Expand all
488 first_run::SetShouldShowWelcomePage(); 492 first_run::SetShouldShowWelcomePage();
489 493
490 // Do a simple non-process-startup browser launch. 494 // Do a simple non-process-startup browser launch.
491 CommandLine dummy(CommandLine::NO_PROGRAM); 495 CommandLine dummy(CommandLine::NO_PROGRAM);
492 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, 496 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
493 chrome::startup::IS_FIRST_RUN); 497 chrome::startup::IS_FIRST_RUN);
494 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 498 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
495 499
496 // This should have created a new browser window. 500 // This should have created a new browser window.
497 Browser* new_browser = NULL; 501 Browser* new_browser = NULL;
498 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 502 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
499 503
500 TabStripModel* tab_strip = new_browser->tab_strip_model(); 504 TabStripModel* tab_strip = new_browser->tab_strip_model();
501 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { 505 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) {
502 EXPECT_EQ(2, tab_strip->count()); 506 EXPECT_EQ(2, tab_strip->count());
503 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); 507 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host());
504 EXPECT_EQ("title1.html", 508 EXPECT_EQ("title1.html",
505 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); 509 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
506 } else { 510 } else {
507 EXPECT_EQ(1, tab_strip->count()); 511 EXPECT_EQ(1, tab_strip->count());
508 EXPECT_EQ("title1.html", 512 EXPECT_EQ("title1.html",
(...skipping 15 matching lines...) Expand all
524 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); 528 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile());
525 529
526 // Do a simple non-process-startup browser launch. 530 // Do a simple non-process-startup browser launch.
527 CommandLine dummy(CommandLine::NO_PROGRAM); 531 CommandLine dummy(CommandLine::NO_PROGRAM);
528 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, 532 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
529 chrome::startup::IS_FIRST_RUN); 533 chrome::startup::IS_FIRST_RUN);
530 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 534 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
531 535
532 // This should have created a new browser window. 536 // This should have created a new browser window.
533 Browser* new_browser = NULL; 537 Browser* new_browser = NULL;
534 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 538 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
535 539
536 TabStripModel* tab_strip = new_browser->tab_strip_model(); 540 TabStripModel* tab_strip = new_browser->tab_strip_model();
537 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { 541 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) {
538 EXPECT_EQ(3, tab_strip->count()); 542 EXPECT_EQ(3, tab_strip->count());
539 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); 543 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host());
540 EXPECT_EQ("title1.html", 544 EXPECT_EQ("title1.html",
541 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); 545 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
542 EXPECT_EQ(internals::GetWelcomePageURL(), 546 EXPECT_EQ(internals::GetWelcomePageURL(),
543 tab_strip->GetWebContentsAt(2)->GetURL()); 547 tab_strip->GetWebContentsAt(2)->GetURL());
544 } else { 548 } else {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 browser()->host_desktop_type())); 889 browser()->host_desktop_type()));
886 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); 890 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL);
887 ASSERT_TRUE(new_browser); 891 ASSERT_TRUE(new_browser);
888 tab_strip = new_browser->tab_strip_model(); 892 tab_strip = new_browser->tab_strip_model();
889 ASSERT_EQ(1, tab_strip->count()); 893 ASSERT_EQ(1, tab_strip->count());
890 web_contents = tab_strip->GetWebContentsAt(0); 894 web_contents = tab_strip->GetWebContentsAt(0);
891 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); 895 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL());
892 EXPECT_EQ(1U, 896 EXPECT_EQ(1U,
893 InfoBarService::FromWebContents(web_contents)->GetInfoBarCount()); 897 InfoBarService::FromWebContents(web_contents)->GetInfoBarCount());
894 } 898 }
899
900 class ManagedModeBrowserCreatorTest : public InProcessBrowserTest {
901 protected:
902 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
903 InProcessBrowserTest::SetUpCommandLine(command_line);
904 command_line->AppendSwitch(switches::kEnableManagedUsers);
905 }
906 };
907
908 IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest,
909 StartupManagedModeProfile) {
910 // Make this a managed profile.
911 browser()->profile()->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true);
912 StartupBrowserCreator browser_creator;
913
914 // Do a simple non-process-startup browser launch.
915 CommandLine dummy(CommandLine::NO_PROGRAM);
916 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
917 chrome::startup::IS_FIRST_RUN);
918 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
919
920 // This should have created a new browser window.
921 Browser* new_browser = NULL;
922 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(browser(), &new_browser));
923
924 TabStripModel* tab_strip = new_browser->tab_strip_model();
925 // There should be only one tab.
926 EXPECT_EQ(1, tab_strip->count());
927
928 // And it should point to the managed user settings page.
929 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0);
930 GURL expected(GURL(std::string(chrome::kChromeUISettingsURL) +
931 chrome::kManagedUserSettingsSubPage));
932 EXPECT_EQ(GURL(expected), web_contents->GetURL());
933 }
Bernhard Bauer 2013/04/03 17:55:20 Nit: a newline after this line would be nice.
Sergiu 2013/04/04 09:02:55 Done.
895 #endif // !OS_CHROMEOS 934 #endif // !OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698