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

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: Test fixes + better tests. 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
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/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_init.h" 17 #include "chrome/browser/ui/browser_init.h"
18 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 class BrowserInitTest : public ExtensionBrowserTest { 28 class BrowserInitTest : public ExtensionBrowserTest {
28 protected: 29 protected:
29 virtual void SetUpCommandLine(CommandLine* command_line) { 30 virtual void SetUpCommandLine(CommandLine* command_line) {
30 ExtensionBrowserTest::SetUpCommandLine(command_line); 31 ExtensionBrowserTest::SetUpCommandLine(command_line);
31 command_line->AppendSwitch(switches::kEnablePanels); 32 command_line->AppendSwitch(switches::kEnablePanels);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 SessionStartupPref::SetStartupPref(other_profile, pref2); 369 SessionStartupPref::SetStartupPref(other_profile, pref2);
369 370
370 // Close the browser. 371 // Close the browser.
371 browser()->window()->Close(); 372 browser()->window()->Close();
372 373
373 // Do a simple non-process-startup browser launch. 374 // Do a simple non-process-startup browser launch.
374 CommandLine dummy(CommandLine::NO_PROGRAM); 375 CommandLine dummy(CommandLine::NO_PROGRAM);
375 376
376 int return_code; 377 int return_code;
377 BrowserInit browser_init; 378 BrowserInit browser_init;
378 std::vector<Profile*> other_profiles(1, other_profile); 379 std::vector<Profile*> last_opened_profiles;
380 last_opened_profiles.push_back(default_profile);
381 last_opened_profiles.push_back(other_profile);
379 browser_init.Start(dummy, profile_manager->user_data_dir(), default_profile, 382 browser_init.Start(dummy, profile_manager->user_data_dir(), default_profile,
380 other_profiles, &return_code); 383 last_opened_profiles, &return_code);
381 384
382 // urls1 were opened in a browser for default_profile, and urls2 were opened 385 // urls1 were opened in a browser for default_profile, and urls2 were opened
383 // in a browser for other_profile. 386 // in a browser for other_profile.
384 Browser* new_browser = NULL; 387 Browser* new_browser = NULL;
385 // |browser()| is still around at this point, even though we've closed it's 388 // |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. 389 // window. Thus the browser count for default_profile is 2.
387 ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile)); 390 ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile));
388 new_browser = FindOneOtherBrowserForProfile(default_profile, 391 new_browser = FindOneOtherBrowserForProfile(default_profile, browser());
389 browser());
390 ASSERT_TRUE(new_browser); 392 ASSERT_TRUE(new_browser);
391 ASSERT_EQ(1, new_browser->tab_count()); 393 ASSERT_EQ(1, new_browser->tab_count());
392 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL()); 394 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL());
393 395
394 ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile)); 396 ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile));
395 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL); 397 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL);
396 ASSERT_TRUE(new_browser); 398 ASSERT_TRUE(new_browser);
397 ASSERT_EQ(1, new_browser->tab_count()); 399 ASSERT_EQ(1, new_browser->tab_count());
398 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL()); 400 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL());
399 } 401 }
402
403 IN_PROC_BROWSER_TEST_F(BrowserInitTest, UpdateWithTwoProfiles) {
404 ProfileManager* profile_manager = g_browser_process->profile_manager();
405
406 // Create two profiles.
407 FilePath dest_path = profile_manager->user_data_dir();
408
409 Profile* profile1 = profile_manager->GetProfile(
410 dest_path.Append(FILE_PATH_LITERAL("New Profile 1")));
411 ASSERT_TRUE(profile1);
412
413 Profile* profile2 = profile_manager->GetProfile(
414 dest_path.Append(FILE_PATH_LITERAL("New Profile 2")));
415 ASSERT_TRUE(profile2);
416
417 // Use a couple arbitrary URLs.
418 std::vector<GURL> urls1;
419 urls1.push_back(ui_test_utils::GetTestUrl(
420 FilePath(FilePath::kCurrentDirectory),
421 FilePath(FILE_PATH_LITERAL("title1.html"))));
422 std::vector<GURL> urls2;
423 urls2.push_back(ui_test_utils::GetTestUrl(
424 FilePath(FilePath::kCurrentDirectory),
425 FilePath(FILE_PATH_LITERAL("title2.html"))));
426
427 // Set different startup preferences for the 2 profiles.
428 SessionStartupPref pref1(SessionStartupPref::URLS);
429 pref1.urls = urls1;
430 SessionStartupPref::SetStartupPref(profile1, pref1);
431 SessionStartupPref pref2(SessionStartupPref::URLS);
432 pref2.urls = urls2;
433 SessionStartupPref::SetStartupPref(profile2, pref2);
434
435 // Simulate a launch after a browser update.
436 CommandLine command_line(FilePath(FILE_PATH_LITERAL("dummy_prog")));
437 command_line.AppendSwitch(switches::kRestoreLastSession);
438
439 int return_code;
440 BrowserInit browser_init;
441 std::vector<Profile*> last_opened_profiles;
442 last_opened_profiles.push_back(profile1);
443 last_opened_profiles.push_back(profile2);
444 browser_init.Start(command_line, profile_manager->user_data_dir(), profile1,
445 last_opened_profiles, &return_code);
446
447 // The startup URLs are ignored, and instead the last open URLs (in this case,
448 // none) are opened.
449 Browser* new_browser = NULL;
450 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile1));
451 new_browser = FindOneOtherBrowserForProfile(profile1, NULL);
452 ASSERT_TRUE(new_browser);
453 ASSERT_EQ(1, new_browser->tab_count());
454 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
455 new_browser->GetWebContentsAt(0)->GetURL());
456
457 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile2));
458 new_browser = FindOneOtherBrowserForProfile(profile2, NULL);
459 ASSERT_TRUE(new_browser);
460 ASSERT_EQ(1, new_browser->tab_count());
461 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
462 new_browser->GetWebContentsAt(0)->GetURL());
463 }
OLDNEW
« chrome/browser/ui/browser_init.cc ('K') | « chrome/browser/ui/browser_init.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698