Chromium Code Reviews| Index: chrome/browser/app_controller_mac_browsertest.mm |
| diff --git a/chrome/browser/app_controller_mac_browsertest.mm b/chrome/browser/app_controller_mac_browsertest.mm |
| index 52fa358be367f07ac4379687bdb787fef7de07ba..3dd644cccfdb707532c58c20cc67124c43acb3d4 100644 |
| --- a/chrome/browser/app_controller_mac_browsertest.mm |
| +++ b/chrome/browser/app_controller_mac_browsertest.mm |
| @@ -22,11 +22,13 @@ |
| #include "chrome/browser/apps/app_browsertest_util.h" |
| #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/history/history_service_factory.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
| +#include "chrome/browser/ui/cocoa/history_menu_bridge.h" |
| #include "chrome/browser/ui/host_desktop.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/user_manager.h" |
| @@ -37,6 +39,8 @@ |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "components/bookmarks/test/bookmark_test_helpers.h" |
| +#include "components/history/core/browser/history_db_task.h" |
| +#include "components/history/core/browser/history_service.h" |
| #include "components/signin/core/common/profile_management_switches.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/test/browser_test_utils.h" |
| @@ -79,6 +83,39 @@ void SendAppleEventToOpenUrlToAppController(const GURL& url) { |
| method_invoke(controller, get_url, shortcut_event, NULL); |
| } |
| +void RunClosureWhenProfileInitialized(const base::Closure& closure, |
| + Profile* profile, |
| + Profile::CreateStatus status) { |
| + if (status == Profile::CREATE_STATUS_INITIALIZED) |
| + closure.Run(); |
| +} |
| + |
| +class WaitForHistoryTask : public history::HistoryDBTask { |
| + public: |
| + WaitForHistoryTask() {} |
| + |
| + bool RunOnDBThread(history::HistoryBackend* backend, |
| + history::HistoryDatabase* db) override { |
| + return true; |
| + } |
| + |
| + void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); } |
| + |
| + private: |
| + ~WaitForHistoryTask() override {} |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); |
| +}; |
| + |
| +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
|
| + base::CancelableTaskTracker task_tracker; |
| + scoped_ptr<history::HistoryDBTask> task(new WaitForHistoryTask()); |
| + history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
| + profile, ServiceAccessType::EXPLICIT_ACCESS); |
| + history->ScheduleDBTask(task.Pass(), &task_tracker); |
| + content::RunMessageLoop(); |
| +} |
| + |
| } // namespace |
| @interface TestOpenShortcutOnStartup : NSObject |
| @@ -427,6 +464,65 @@ class AppControllerMainMenuBrowserTest : public InProcessBrowserTest { |
| }; |
| IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, |
| + HistoryMenuResetAfterProfileDeletion) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + AppController* ac = [NSApp delegate]; |
| + |
| + // Use the existing profile as profile 1. |
| + Profile* profile1 = browser()->profile(); |
| + |
| + // // Create profile 2. |
|
Robert Sesek
2015/04/21 18:02:42
nit: extra //
Mike Lerman
2015/04/21 19:33:16
Done.
|
| + base::FilePath profile2_path = |
| + profile_manager->GenerateNextProfileDirectoryPath(); |
| + base::RunLoop run_loop; |
| + 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.
|
| + profile2_path, |
| + base::Bind(&RunClosureWhenProfileInitialized, |
| + run_loop.QuitClosure()), |
| + base::string16(), |
| + base::string16(), |
| + std::string()); |
| + run_loop.Run(); |
| + Profile* profile2 = profile_manager->GetProfileByPath(profile2_path); |
| + DCHECK(profile2); |
| + |
| + // Switch the controller to profile1. |
| + [ac windowChangedToProfile:profile1]; |
| + WaitForHistoryBackendToRun(profile1); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Verify the controller's History Menu corresponds to profile1. |
| + DCHECK_EQ([ac historyMenuBridge]->service(), |
| + HistoryServiceFactory::GetForProfile(profile1, |
| + ServiceAccessType::EXPLICIT_ACCESS)); |
| + |
| + // Switch the controller to profile2. |
| + [ac windowChangedToProfile:profile2]; |
| + WaitForHistoryBackendToRun(profile2); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Verify the controller's History Menu has changed. |
| + DCHECK_EQ([ac historyMenuBridge]->service(), |
| + HistoryServiceFactory::GetForProfile(profile2, |
| + ServiceAccessType::EXPLICIT_ACCESS)); |
| + DCHECK_NE( |
| + HistoryServiceFactory::GetForProfile(profile1, |
| + ServiceAccessType::EXPLICIT_ACCESS), |
| + HistoryServiceFactory::GetForProfile(profile2, |
| + ServiceAccessType::EXPLICIT_ACCESS)); |
| + |
| + // Delete profile2. |
| + profile_manager->ScheduleProfileForDeletion( |
| + profile2->GetPath(), ProfileManager::CreateCallback()); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Verify the controller's history is back to profile1. |
| + DCHECK_EQ([ac historyMenuBridge]->service(), |
| + HistoryServiceFactory::GetForProfile(profile1, |
| + ServiceAccessType::EXPLICIT_ACCESS)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, |
| BookmarksMenuIsRestoredAfterProfileSwitch) { |
| ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |