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" | |
26 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
29 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
30 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 29 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
31 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" | |
32 #include "chrome/browser/ui/host_desktop.h" | 30 #include "chrome/browser/ui/host_desktop.h" |
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
34 #include "chrome/browser/ui/user_manager.h" | 32 #include "chrome/browser/ui/user_manager.h" |
35 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
36 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
38 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
39 #include "chrome/test/base/in_process_browser_test.h" | 37 #include "chrome/test/base/in_process_browser_test.h" |
40 #include "chrome/test/base/ui_test_utils.h" | 38 #include "chrome/test/base/ui_test_utils.h" |
41 #include "components/bookmarks/test/bookmark_test_helpers.h" | 39 #include "components/bookmarks/test/bookmark_test_helpers.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 Method get_url = | 72 Method get_url = |
75 class_getInstanceMethod([controller class], @selector(getUrl:withReply:)); | 73 class_getInstanceMethod([controller class], @selector(getUrl:withReply:)); |
76 | 74 |
77 ASSERT_TRUE(get_url); | 75 ASSERT_TRUE(get_url); |
78 | 76 |
79 NSAppleEventDescriptor* shortcut_event = AppleEventToOpenUrl(url); | 77 NSAppleEventDescriptor* shortcut_event = AppleEventToOpenUrl(url); |
80 | 78 |
81 method_invoke(controller, get_url, shortcut_event, NULL); | 79 method_invoke(controller, get_url, shortcut_event, NULL); |
82 } | 80 } |
83 | 81 |
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 | |
91 } // namespace | 82 } // namespace |
92 | 83 |
93 @interface TestOpenShortcutOnStartup : NSObject | 84 @interface TestOpenShortcutOnStartup : NSObject |
94 - (void)applicationWillFinishLaunching:(NSNotification*)notification; | 85 - (void)applicationWillFinishLaunching:(NSNotification*)notification; |
95 @end | 86 @end |
96 | 87 |
97 @implementation TestOpenShortcutOnStartup | 88 @implementation TestOpenShortcutOnStartup |
98 | 89 |
99 - (void)applicationWillFinishLaunching:(NSNotification*)notification { | 90 - (void)applicationWillFinishLaunching:(NSNotification*)notification { |
100 if (!g_open_shortcut_url.is_valid()) | 91 if (!g_open_shortcut_url.is_valid()) |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 ->GetLastCommittedURL()); | 420 ->GetLastCommittedURL()); |
430 } | 421 } |
431 | 422 |
432 class AppControllerMainMenuBrowserTest : public InProcessBrowserTest { | 423 class AppControllerMainMenuBrowserTest : public InProcessBrowserTest { |
433 protected: | 424 protected: |
434 AppControllerMainMenuBrowserTest() { | 425 AppControllerMainMenuBrowserTest() { |
435 } | 426 } |
436 }; | 427 }; |
437 | 428 |
438 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, | 429 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, | |
496 BookmarksMenuIsRestoredAfterProfileSwitch) { | 430 BookmarksMenuIsRestoredAfterProfileSwitch) { |
497 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 431 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
498 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | 432 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
499 [ac awakeFromNib]; | 433 [ac awakeFromNib]; |
500 | 434 |
501 // Constants for bookmarks that we will create later. | 435 // Constants for bookmarks that we will create later. |
502 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics")); | 436 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics")); |
503 const GURL url1("http://qwantz.com//"); | 437 const GURL url1("http://qwantz.com//"); |
504 | 438 |
505 const base::string16 title2(base::ASCIIToUTF16("XKCD")); | 439 const base::string16 title2(base::ASCIIToUTF16("XKCD")); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 ui_test_utils::NavigateToURL(browser3, test_url1); | 615 ui_test_utils::NavigateToURL(browser3, test_url1); |
682 EXPECT_EQ(g_handoff_url, GURL()); | 616 EXPECT_EQ(g_handoff_url, GURL()); |
683 | 617 |
684 // Activate the original browser window. | 618 // Activate the original browser window. |
685 Browser* browser1 = active_browser_list->get(0); | 619 Browser* browser1 = active_browser_list->get(0); |
686 browser1->window()->Show(); | 620 browser1->window()->Show(); |
687 EXPECT_EQ(g_handoff_url, test_url2); | 621 EXPECT_EQ(g_handoff_url, test_url2); |
688 } | 622 } |
689 | 623 |
690 } // namespace | 624 } // namespace |
OLD | NEW |