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

Side by Side Diff: chrome/browser/ui/browser_init_browsertest.cc

Issue 9232007: Fix: after updating, restore tabs from all profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK fix. Created 8 years, 11 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/ui/browser_init.cc ('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 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.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"
11 #include "chrome/browser/first_run/first_run.h" 11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/session_startup_pref.h" 13 #include "chrome/browser/prefs/session_startup_pref.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/sessions/session_restore.h"
16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_init.h" 18 #include "chrome/browser/ui/browser_init.h"
18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
25 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
26 28
27 class BrowserInitTest : public ExtensionBrowserTest { 29 class BrowserInitTest : public ExtensionBrowserTest {
28 protected: 30 protected:
29 virtual void SetUpCommandLine(CommandLine* command_line) { 31 virtual void SetUpCommandLine(CommandLine* command_line) {
30 ExtensionBrowserTest::SetUpCommandLine(command_line); 32 ExtensionBrowserTest::SetUpCommandLine(command_line);
31 command_line->AppendSwitch(switches::kEnablePanels); 33 command_line->AppendSwitch(switches::kEnablePanels);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 EXPECT_NE( 316 EXPECT_NE(
315 new_browser->app_name_.find(extension_app->id()), 317 new_browser->app_name_.find(extension_app->id()),
316 std::string::npos) << new_browser->app_name_; 318 std::string::npos) << new_browser->app_name_;
317 } 319 }
318 320
319 #endif // !defined(OS_MACOSX) 321 #endif // !defined(OS_MACOSX)
320 322
321 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) { 323 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) {
322 // Tests that BrowserInit::WasRestarted reads and resets the preference 324 // Tests that BrowserInit::WasRestarted reads and resets the preference
323 // kWasRestarted correctly. 325 // kWasRestarted correctly.
326 BrowserInit::was_restarted_read_ = false;
324 PrefService* pref_service = g_browser_process->local_state(); 327 PrefService* pref_service = g_browser_process->local_state();
325 pref_service->SetBoolean(prefs::kWasRestarted, true); 328 pref_service->SetBoolean(prefs::kWasRestarted, true);
326 EXPECT_TRUE(BrowserInit::WasRestarted()); 329 EXPECT_TRUE(BrowserInit::WasRestarted());
327 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); 330 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
328 EXPECT_TRUE(BrowserInit::WasRestarted()); 331 EXPECT_TRUE(BrowserInit::WasRestarted());
329 } 332 }
330 333
331 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) { 334 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) {
332 // Tests that BrowserInit::WasRestarted reads and resets the preference 335 // Tests that BrowserInit::WasRestarted reads and resets the preference
333 // kWasRestarted correctly. 336 // kWasRestarted correctly.
337 BrowserInit::was_restarted_read_ = false;
334 PrefService* pref_service = g_browser_process->local_state(); 338 PrefService* pref_service = g_browser_process->local_state();
335 pref_service->SetBoolean(prefs::kWasRestarted, false); 339 pref_service->SetBoolean(prefs::kWasRestarted, false);
336 EXPECT_FALSE(BrowserInit::WasRestarted()); 340 EXPECT_FALSE(BrowserInit::WasRestarted());
337 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); 341 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
338 EXPECT_FALSE(BrowserInit::WasRestarted()); 342 EXPECT_FALSE(BrowserInit::WasRestarted());
339 } 343 }
340 344
341 IN_PROC_BROWSER_TEST_F(BrowserInitTest, StartupURLsForTwoProfiles) { 345 IN_PROC_BROWSER_TEST_F(BrowserInitTest, StartupURLsForTwoProfiles) {
342 Profile* default_profile = browser()->profile(); 346 Profile* default_profile = browser()->profile();
343 347
(...skipping 24 matching lines...) Expand all
368 SessionStartupPref::SetStartupPref(other_profile, pref2); 372 SessionStartupPref::SetStartupPref(other_profile, pref2);
369 373
370 // Close the browser. 374 // Close the browser.
371 browser()->window()->Close(); 375 browser()->window()->Close();
372 376
373 // Do a simple non-process-startup browser launch. 377 // Do a simple non-process-startup browser launch.
374 CommandLine dummy(CommandLine::NO_PROGRAM); 378 CommandLine dummy(CommandLine::NO_PROGRAM);
375 379
376 int return_code; 380 int return_code;
377 BrowserInit browser_init; 381 BrowserInit browser_init;
378 std::vector<Profile*> other_profiles(1, other_profile); 382 std::vector<Profile*> last_opened_profiles;
383 last_opened_profiles.push_back(default_profile);
384 last_opened_profiles.push_back(other_profile);
379 browser_init.Start(dummy, profile_manager->user_data_dir(), default_profile, 385 browser_init.Start(dummy, profile_manager->user_data_dir(), default_profile,
380 other_profiles, &return_code); 386 last_opened_profiles, &return_code);
381 387
382 // urls1 were opened in a browser for default_profile, and urls2 were opened 388 // urls1 were opened in a browser for default_profile, and urls2 were opened
383 // in a browser for other_profile. 389 // in a browser for other_profile.
384 Browser* new_browser = NULL; 390 Browser* new_browser = NULL;
385 // |browser()| is still around at this point, even though we've closed it's 391 // |browser()| is still around at this point, even though we've closed it's
386 // window. Thus the browser count for default_profile is 2. 392 // window. Thus the browser count for default_profile is 2.
387 ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile)); 393 ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile));
388 new_browser = FindOneOtherBrowserForProfile(default_profile, 394 new_browser = FindOneOtherBrowserForProfile(default_profile, browser());
389 browser());
390 ASSERT_TRUE(new_browser); 395 ASSERT_TRUE(new_browser);
391 ASSERT_EQ(1, new_browser->tab_count()); 396 ASSERT_EQ(1, new_browser->tab_count());
392 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL()); 397 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL());
393 398
394 ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile)); 399 ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile));
395 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL); 400 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL);
396 ASSERT_TRUE(new_browser); 401 ASSERT_TRUE(new_browser);
397 ASSERT_EQ(1, new_browser->tab_count()); 402 ASSERT_EQ(1, new_browser->tab_count());
398 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL()); 403 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL());
399 } 404 }
405
406 IN_PROC_BROWSER_TEST_F(BrowserInitTest, UpdateWithTwoProfiles) {
407 // Make BrowserInit::WasRestarted() return true.
408 BrowserInit::was_restarted_read_ = false;
409 PrefService* pref_service = g_browser_process->local_state();
410 pref_service->SetBoolean(prefs::kWasRestarted, true);
411
412 ProfileManager* profile_manager = g_browser_process->profile_manager();
413
414 // Create two profiles.
415 FilePath dest_path = profile_manager->user_data_dir();
416
417 Profile* profile1 = profile_manager->GetProfile(
418 dest_path.Append(FILE_PATH_LITERAL("New Profile 1")));
419 ASSERT_TRUE(profile1);
420
421 Profile* profile2 = profile_manager->GetProfile(
422 dest_path.Append(FILE_PATH_LITERAL("New Profile 2")));
423 ASSERT_TRUE(profile2);
424
425 // Use a couple arbitrary URLs.
426 std::vector<GURL> urls1;
427 urls1.push_back(ui_test_utils::GetTestUrl(
428 FilePath(FilePath::kCurrentDirectory),
429 FilePath(FILE_PATH_LITERAL("title1.html"))));
430 std::vector<GURL> urls2;
431 urls2.push_back(ui_test_utils::GetTestUrl(
432 FilePath(FilePath::kCurrentDirectory),
433 FilePath(FILE_PATH_LITERAL("title2.html"))));
434
435 // Set different startup preferences for the 2 profiles.
436 SessionStartupPref pref1(SessionStartupPref::URLS);
437 pref1.urls = urls1;
438 SessionStartupPref::SetStartupPref(profile1, pref1);
439 SessionStartupPref pref2(SessionStartupPref::URLS);
440 pref2.urls = urls2;
441 SessionStartupPref::SetStartupPref(profile2, pref2);
442
443 // Simulate a launch after a browser update.
444 CommandLine dummy(CommandLine::NO_PROGRAM);
445 int return_code;
446 BrowserInit browser_init;
447 std::vector<Profile*> last_opened_profiles;
448 last_opened_profiles.push_back(profile1);
449 last_opened_profiles.push_back(profile2);
450 browser_init.Start(dummy, profile_manager->user_data_dir(), profile1,
451 last_opened_profiles, &return_code);
452
453 while (SessionRestore::IsRestoring())
454 MessageLoop::current()->RunAllPending();
455
456 // The startup URLs are ignored, and instead the last open sessions are
457 // restored.
458 EXPECT_TRUE(profile1->restored_last_session());
459 EXPECT_TRUE(profile2->restored_last_session());
460
461 Browser* new_browser = NULL;
462 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile1));
463 new_browser = FindOneOtherBrowserForProfile(profile1, NULL);
464 ASSERT_TRUE(new_browser);
465 ASSERT_EQ(1, new_browser->tab_count());
466 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
467 new_browser->GetWebContentsAt(0)->GetURL());
468
469 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile2));
470 new_browser = FindOneOtherBrowserForProfile(profile2, NULL);
471 ASSERT_TRUE(new_browser);
472 ASSERT_EQ(1, new_browser->tab_count());
473 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
474 new_browser->GetWebContentsAt(0)->GetURL());
475 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_init.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698