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

Side by Side Diff: chrome/browser/app_controller_mac_browsertest.mm

Issue 1102833002: Reland: AppControllerMac updates the window when a Profile is deleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | 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 #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
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
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_TRUE([ac historyMenuBridge]->service());
467 EXPECT_EQ([ac historyMenuBridge]->service(),
468 HistoryServiceFactory::GetForProfile(profile1,
469 ServiceAccessType::EXPLICIT_ACCESS));
470
471 // Load profile2's History Service backend so it will be assigned to the
472 // HistoryMenuBridge when windowChangedToProfile is called, or else this test
473 // will fail flaky.
474 ui_test_utils::WaitForHistoryToLoad(
475 HistoryServiceFactory::GetForProfile(profile2,
476 ServiceAccessType::EXPLICIT_ACCESS));
477 // Switch the controller to profile2.
478 [ac windowChangedToProfile:profile2];
479 base::RunLoop().RunUntilIdle();
480
481 // Verify the controller's History Menu has changed.
482 EXPECT_TRUE([ac historyMenuBridge]->service());
483 EXPECT_EQ([ac historyMenuBridge]->service(),
484 HistoryServiceFactory::GetForProfile(profile2,
485 ServiceAccessType::EXPLICIT_ACCESS));
486 EXPECT_NE(
487 HistoryServiceFactory::GetForProfile(profile1,
488 ServiceAccessType::EXPLICIT_ACCESS),
489 HistoryServiceFactory::GetForProfile(profile2,
490 ServiceAccessType::EXPLICIT_ACCESS));
491
492 // Delete profile2.
493 profile_manager->ScheduleProfileForDeletion(
494 profile2->GetPath(), ProfileManager::CreateCallback());
495 base::RunLoop().RunUntilIdle();
496
497 // Verify the controller's history is back to profile1.
498 EXPECT_EQ([ac historyMenuBridge]->service(),
499 HistoryServiceFactory::GetForProfile(profile1,
500 ServiceAccessType::EXPLICIT_ACCESS));
501 }
502
503 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
430 BookmarksMenuIsRestoredAfterProfileSwitch) { 504 BookmarksMenuIsRestoredAfterProfileSwitch) {
431 ProfileManager* profile_manager = g_browser_process->profile_manager(); 505 ProfileManager* profile_manager = g_browser_process->profile_manager();
432 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); 506 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
433 [ac awakeFromNib]; 507 [ac awakeFromNib];
434 508
435 // Constants for bookmarks that we will create later. 509 // Constants for bookmarks that we will create later.
436 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics")); 510 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics"));
437 const GURL url1("http://qwantz.com//"); 511 const GURL url1("http://qwantz.com//");
438 512
439 const base::string16 title2(base::ASCIIToUTF16("XKCD")); 513 const base::string16 title2(base::ASCIIToUTF16("XKCD"));
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 ui_test_utils::NavigateToURL(browser3, test_url1); 689 ui_test_utils::NavigateToURL(browser3, test_url1);
616 EXPECT_EQ(g_handoff_url, GURL()); 690 EXPECT_EQ(g_handoff_url, GURL());
617 691
618 // Activate the original browser window. 692 // Activate the original browser window.
619 Browser* browser1 = active_browser_list->get(0); 693 Browser* browser1 = active_browser_list->get(0);
620 browser1->window()->Show(); 694 browser1->window()->Show();
621 EXPECT_EQ(g_handoff_url, test_url2); 695 EXPECT_EQ(g_handoff_url, test_url2);
622 } 696 }
623 697
624 } // namespace 698 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698