| 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 #import <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
| 6 #import <Cocoa/Cocoa.h> | 6 #import <Cocoa/Cocoa.h> |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #import <Foundation/NSAppleEventDescriptor.h> | 8 #import <Foundation/NSAppleEventDescriptor.h> |
| 9 #import <objc/message.h> | 9 #import <objc/message.h> |
| 10 #import <objc/runtime.h> | 10 #import <objc/runtime.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #import "chrome/browser/app_controller_mac.h" | 21 #import "chrome/browser/app_controller_mac.h" |
| 22 #include "chrome/browser/apps/app_browsertest_util.h" | 22 #include "chrome/browser/apps/app_browsertest_util.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
| 29 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 30 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
| 31 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" |
| 30 #include "chrome/browser/ui/host_desktop.h" | 32 #include "chrome/browser/ui/host_desktop.h" |
| 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 32 #include "chrome/browser/ui/user_manager.h" | 34 #include "chrome/browser/ui/user_manager.h" |
| 33 #include "chrome/common/chrome_constants.h" | 35 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 37 #include "chrome/test/base/in_process_browser_test.h" | 39 #include "chrome/test/base/in_process_browser_test.h" |
| 38 #include "chrome/test/base/ui_test_utils.h" | 40 #include "chrome/test/base/ui_test_utils.h" |
| 39 #include "components/bookmarks/test/bookmark_test_helpers.h" | 41 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 Method get_url = | 74 Method get_url = |
| 73 class_getInstanceMethod([controller class], @selector(getUrl:withReply:)); | 75 class_getInstanceMethod([controller class], @selector(getUrl:withReply:)); |
| 74 | 76 |
| 75 ASSERT_TRUE(get_url); | 77 ASSERT_TRUE(get_url); |
| 76 | 78 |
| 77 NSAppleEventDescriptor* shortcut_event = AppleEventToOpenUrl(url); | 79 NSAppleEventDescriptor* shortcut_event = AppleEventToOpenUrl(url); |
| 78 | 80 |
| 79 method_invoke(controller, get_url, shortcut_event, NULL); | 81 method_invoke(controller, get_url, shortcut_event, NULL); |
| 80 } | 82 } |
| 81 | 83 |
| 84 void RunClosureWhenProfileInitialized(const base::Closure& closure, |
| 85 Profile* profile, |
| 86 Profile::CreateStatus status) { |
| 87 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 88 closure.Run(); |
| 89 } |
| 90 |
| 82 } // namespace | 91 } // namespace |
| 83 | 92 |
| 84 @interface TestOpenShortcutOnStartup : NSObject | 93 @interface TestOpenShortcutOnStartup : NSObject |
| 85 - (void)applicationWillFinishLaunching:(NSNotification*)notification; | 94 - (void)applicationWillFinishLaunching:(NSNotification*)notification; |
| 86 @end | 95 @end |
| 87 | 96 |
| 88 @implementation TestOpenShortcutOnStartup | 97 @implementation TestOpenShortcutOnStartup |
| 89 | 98 |
| 90 - (void)applicationWillFinishLaunching:(NSNotification*)notification { | 99 - (void)applicationWillFinishLaunching:(NSNotification*)notification { |
| 91 if (!g_open_shortcut_url.is_valid()) | 100 if (!g_open_shortcut_url.is_valid()) |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 ->GetLastCommittedURL()); | 429 ->GetLastCommittedURL()); |
| 421 } | 430 } |
| 422 | 431 |
| 423 class AppControllerMainMenuBrowserTest : public InProcessBrowserTest { | 432 class AppControllerMainMenuBrowserTest : public InProcessBrowserTest { |
| 424 protected: | 433 protected: |
| 425 AppControllerMainMenuBrowserTest() { | 434 AppControllerMainMenuBrowserTest() { |
| 426 } | 435 } |
| 427 }; | 436 }; |
| 428 | 437 |
| 429 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, | 438 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, |
| 439 HistoryMenuResetAfterProfileDeletion) { |
| 440 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 441 AppController* ac = [NSApp delegate]; |
| 442 |
| 443 // Use the existing profile as profile 1. |
| 444 Profile* profile1 = browser()->profile(); |
| 445 |
| 446 // Create profile 2. |
| 447 base::FilePath profile2_path = |
| 448 profile_manager->GenerateNextProfileDirectoryPath(); |
| 449 base::RunLoop run_loop; |
| 450 profile_manager->CreateProfileAsync( |
| 451 profile2_path, |
| 452 base::Bind(&RunClosureWhenProfileInitialized, |
| 453 run_loop.QuitClosure()), |
| 454 base::string16(), |
| 455 base::string16(), |
| 456 std::string()); |
| 457 run_loop.Run(); |
| 458 Profile* profile2 = profile_manager->GetProfileByPath(profile2_path); |
| 459 ASSERT_TRUE(profile2); |
| 460 |
| 461 // Switch the controller to profile1. |
| 462 [ac windowChangedToProfile:profile1]; |
| 463 base::RunLoop().RunUntilIdle(); |
| 464 |
| 465 // Verify the controller's History Menu corresponds to profile1. |
| 466 EXPECT_EQ([ac historyMenuBridge]->service(), |
| 467 HistoryServiceFactory::GetForProfile(profile1, |
| 468 ServiceAccessType::EXPLICIT_ACCESS)); |
| 469 |
| 470 // Switch the controller to profile2. |
| 471 [ac windowChangedToProfile:profile2]; |
| 472 base::RunLoop().RunUntilIdle(); |
| 473 |
| 474 // Verify the controller's History Menu has changed. |
| 475 EXPECT_EQ([ac historyMenuBridge]->service(), |
| 476 HistoryServiceFactory::GetForProfile(profile2, |
| 477 ServiceAccessType::EXPLICIT_ACCESS)); |
| 478 EXPECT_NE( |
| 479 HistoryServiceFactory::GetForProfile(profile1, |
| 480 ServiceAccessType::EXPLICIT_ACCESS), |
| 481 HistoryServiceFactory::GetForProfile(profile2, |
| 482 ServiceAccessType::EXPLICIT_ACCESS)); |
| 483 |
| 484 // Delete profile2. |
| 485 profile_manager->ScheduleProfileForDeletion( |
| 486 profile2->GetPath(), ProfileManager::CreateCallback()); |
| 487 base::RunLoop().RunUntilIdle(); |
| 488 |
| 489 // Verify the controller's history is back to profile1. |
| 490 EXPECT_EQ([ac historyMenuBridge]->service(), |
| 491 HistoryServiceFactory::GetForProfile(profile1, |
| 492 ServiceAccessType::EXPLICIT_ACCESS)); |
| 493 } |
| 494 |
| 495 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, |
| 430 BookmarksMenuIsRestoredAfterProfileSwitch) { | 496 BookmarksMenuIsRestoredAfterProfileSwitch) { |
| 431 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 497 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 432 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | 498 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
| 433 [ac awakeFromNib]; | 499 [ac awakeFromNib]; |
| 434 | 500 |
| 435 // Constants for bookmarks that we will create later. | 501 // Constants for bookmarks that we will create later. |
| 436 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics")); | 502 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics")); |
| 437 const GURL url1("http://qwantz.com//"); | 503 const GURL url1("http://qwantz.com//"); |
| 438 | 504 |
| 439 const base::string16 title2(base::ASCIIToUTF16("XKCD")); | 505 const base::string16 title2(base::ASCIIToUTF16("XKCD")); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 ui_test_utils::NavigateToURL(browser3, test_url1); | 681 ui_test_utils::NavigateToURL(browser3, test_url1); |
| 616 EXPECT_EQ(g_handoff_url, GURL()); | 682 EXPECT_EQ(g_handoff_url, GURL()); |
| 617 | 683 |
| 618 // Activate the original browser window. | 684 // Activate the original browser window. |
| 619 Browser* browser1 = active_browser_list->get(0); | 685 Browser* browser1 = active_browser_list->get(0); |
| 620 browser1->window()->Show(); | 686 browser1->window()->Show(); |
| 621 EXPECT_EQ(g_handoff_url, test_url2); | 687 EXPECT_EQ(g_handoff_url, test_url2); |
| 622 } | 688 } |
| 623 | 689 |
| 624 } // namespace | 690 } // namespace |
| OLD | NEW |