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

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

Issue 1097553002: [Mac] AppControllerMac updates the window when a Profile is deleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A different type of test. I call it 'working'. 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
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"
42 #include "components/history/core/browser/history_db_task.h"
43 #include "components/history/core/browser/history_service.h"
40 #include "components/signin/core/common/profile_management_switches.h" 44 #include "components/signin/core/common/profile_management_switches.h"
41 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
42 #include "content/public/test/browser_test_utils.h" 46 #include "content/public/test/browser_test_utils.h"
43 #include "content/public/test/test_navigation_observer.h" 47 #include "content/public/test/test_navigation_observer.h"
44 #include "extensions/browser/app_window/app_window_registry.h" 48 #include "extensions/browser/app_window/app_window_registry.h"
45 #include "extensions/common/extension.h" 49 #include "extensions/common/extension.h"
46 #include "extensions/test/extension_test_message_listener.h" 50 #include "extensions/test/extension_test_message_listener.h"
47 #include "net/test/embedded_test_server/embedded_test_server.h" 51 #include "net/test/embedded_test_server/embedded_test_server.h"
48 52
49 namespace { 53 namespace {
(...skipping 22 matching lines...) Expand all
72 Method get_url = 76 Method get_url =
73 class_getInstanceMethod([controller class], @selector(getUrl:withReply:)); 77 class_getInstanceMethod([controller class], @selector(getUrl:withReply:));
74 78
75 ASSERT_TRUE(get_url); 79 ASSERT_TRUE(get_url);
76 80
77 NSAppleEventDescriptor* shortcut_event = AppleEventToOpenUrl(url); 81 NSAppleEventDescriptor* shortcut_event = AppleEventToOpenUrl(url);
78 82
79 method_invoke(controller, get_url, shortcut_event, NULL); 83 method_invoke(controller, get_url, shortcut_event, NULL);
80 } 84 }
81 85
86 void RunClosureWhenProfileInitialized(const base::Closure& closure,
87 Profile* profile,
88 Profile::CreateStatus status) {
89 if (status == Profile::CREATE_STATUS_INITIALIZED)
90 closure.Run();
91 }
92
93 class WaitForHistoryTask : public history::HistoryDBTask {
94 public:
95 WaitForHistoryTask() {}
96
97 bool RunOnDBThread(history::HistoryBackend* backend,
98 history::HistoryDatabase* db) override {
99 return true;
100 }
101
102 void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); }
103
104 private:
105 ~WaitForHistoryTask() override {}
106
107 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask);
108 };
109
110 void WaitForHistoryBackendToRun(Profile* profile) {
Robert Sesek 2015/04/21 18:02:42 Can you use base::RunLoop run_loop; HistoryServic
Mike Lerman 2015/04/21 19:33:16 We actually don't need to load the Backend at all
111 base::CancelableTaskTracker task_tracker;
112 scoped_ptr<history::HistoryDBTask> task(new WaitForHistoryTask());
113 history::HistoryService* history = HistoryServiceFactory::GetForProfile(
114 profile, ServiceAccessType::EXPLICIT_ACCESS);
115 history->ScheduleDBTask(task.Pass(), &task_tracker);
116 content::RunMessageLoop();
117 }
118
82 } // namespace 119 } // namespace
83 120
84 @interface TestOpenShortcutOnStartup : NSObject 121 @interface TestOpenShortcutOnStartup : NSObject
85 - (void)applicationWillFinishLaunching:(NSNotification*)notification; 122 - (void)applicationWillFinishLaunching:(NSNotification*)notification;
86 @end 123 @end
87 124
88 @implementation TestOpenShortcutOnStartup 125 @implementation TestOpenShortcutOnStartup
89 126
90 - (void)applicationWillFinishLaunching:(NSNotification*)notification { 127 - (void)applicationWillFinishLaunching:(NSNotification*)notification {
91 if (!g_open_shortcut_url.is_valid()) 128 if (!g_open_shortcut_url.is_valid())
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ->GetLastCommittedURL()); 457 ->GetLastCommittedURL());
421 } 458 }
422 459
423 class AppControllerMainMenuBrowserTest : public InProcessBrowserTest { 460 class AppControllerMainMenuBrowserTest : public InProcessBrowserTest {
424 protected: 461 protected:
425 AppControllerMainMenuBrowserTest() { 462 AppControllerMainMenuBrowserTest() {
426 } 463 }
427 }; 464 };
428 465
429 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, 466 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
467 HistoryMenuResetAfterProfileDeletion) {
468 ProfileManager* profile_manager = g_browser_process->profile_manager();
469 AppController* ac = [NSApp delegate];
470
471 // Use the existing profile as profile 1.
472 Profile* profile1 = browser()->profile();
473
474 // // Create profile 2.
Robert Sesek 2015/04/21 18:02:42 nit: extra //
Mike Lerman 2015/04/21 19:33:16 Done.
475 base::FilePath profile2_path =
476 profile_manager->GenerateNextProfileDirectoryPath();
477 base::RunLoop run_loop;
478 profile_manager->CreateProfileAsync(
Robert Sesek 2015/04/21 18:02:42 Can you create the profile synchronously, like on
Mike Lerman 2015/04/21 19:33:16 The command on line 545 doesn't do all the same th
Robert Sesek 2015/04/21 20:12:30 Got it. Thanks for the explanation.
479 profile2_path,
480 base::Bind(&RunClosureWhenProfileInitialized,
481 run_loop.QuitClosure()),
482 base::string16(),
483 base::string16(),
484 std::string());
485 run_loop.Run();
486 Profile* profile2 = profile_manager->GetProfileByPath(profile2_path);
487 DCHECK(profile2);
488
489 // Switch the controller to profile1.
490 [ac windowChangedToProfile:profile1];
491 WaitForHistoryBackendToRun(profile1);
492 base::RunLoop().RunUntilIdle();
493
494 // Verify the controller's History Menu corresponds to profile1.
495 DCHECK_EQ([ac historyMenuBridge]->service(),
496 HistoryServiceFactory::GetForProfile(profile1,
497 ServiceAccessType::EXPLICIT_ACCESS));
498
499 // Switch the controller to profile2.
500 [ac windowChangedToProfile:profile2];
501 WaitForHistoryBackendToRun(profile2);
502 base::RunLoop().RunUntilIdle();
503
504 // Verify the controller's History Menu has changed.
505 DCHECK_EQ([ac historyMenuBridge]->service(),
506 HistoryServiceFactory::GetForProfile(profile2,
507 ServiceAccessType::EXPLICIT_ACCESS));
508 DCHECK_NE(
509 HistoryServiceFactory::GetForProfile(profile1,
510 ServiceAccessType::EXPLICIT_ACCESS),
511 HistoryServiceFactory::GetForProfile(profile2,
512 ServiceAccessType::EXPLICIT_ACCESS));
513
514 // Delete profile2.
515 profile_manager->ScheduleProfileForDeletion(
516 profile2->GetPath(), ProfileManager::CreateCallback());
517 base::RunLoop().RunUntilIdle();
518
519 // Verify the controller's history is back to profile1.
520 DCHECK_EQ([ac historyMenuBridge]->service(),
521 HistoryServiceFactory::GetForProfile(profile1,
522 ServiceAccessType::EXPLICIT_ACCESS));
523 }
524
525 IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
430 BookmarksMenuIsRestoredAfterProfileSwitch) { 526 BookmarksMenuIsRestoredAfterProfileSwitch) {
431 ProfileManager* profile_manager = g_browser_process->profile_manager(); 527 ProfileManager* profile_manager = g_browser_process->profile_manager();
432 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); 528 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
433 [ac awakeFromNib]; 529 [ac awakeFromNib];
434 530
435 // Constants for bookmarks that we will create later. 531 // Constants for bookmarks that we will create later.
436 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics")); 532 const base::string16 title1(base::ASCIIToUTF16("Dinosaur Comics"));
437 const GURL url1("http://qwantz.com//"); 533 const GURL url1("http://qwantz.com//");
438 534
439 const base::string16 title2(base::ASCIIToUTF16("XKCD")); 535 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); 711 ui_test_utils::NavigateToURL(browser3, test_url1);
616 EXPECT_EQ(g_handoff_url, GURL()); 712 EXPECT_EQ(g_handoff_url, GURL());
617 713
618 // Activate the original browser window. 714 // Activate the original browser window.
619 Browser* browser1 = active_browser_list->get(0); 715 Browser* browser1 = active_browser_list->get(0);
620 browser1->window()->Show(); 716 browser1->window()->Show();
621 EXPECT_EQ(g_handoff_url, test_url2); 717 EXPECT_EQ(g_handoff_url, test_url2);
622 } 718 }
623 719
624 } // namespace 720 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698