| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/browser/ui/app_list/app_list_util.h" | 11 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 | 17 |
| 18 | |
| 19 // Browser Test for AppListController that runs on all platforms supporting | 18 // Browser Test for AppListController that runs on all platforms supporting |
| 20 // app_list. | 19 // app_list. |
| 21 class AppListControllerBrowserTest : public InProcessBrowserTest { | 20 class AppListControllerBrowserTest : public InProcessBrowserTest { |
| 22 public: | 21 public: |
| 23 AppListControllerBrowserTest() | 22 AppListControllerBrowserTest() |
| 24 : profile2_(NULL) {} | 23 : profile2_(NULL) {} |
| 25 | 24 |
| 26 void OnProfileCreated(Profile* profile, Profile::CreateStatus status) { | 25 void OnProfileCreated(Profile* profile, Profile::CreateStatus status) { |
| 27 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 26 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
| 28 profile2_ = profile; | 27 profile2_ = profile; |
| 29 MessageLoop::current()->Quit(); | 28 MessageLoop::current()->Quit(); |
| 30 } | 29 } |
| 31 } | 30 } |
| 32 | 31 |
| 33 protected: | 32 protected: |
| 34 base::ScopedTempDir temp_profile_dir_; | 33 base::ScopedTempDir temp_profile_dir_; |
| 35 Profile* profile2_; | 34 Profile* profile2_; |
| 36 | 35 |
| 37 private: | 36 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(AppListControllerBrowserTest); | 37 DISALLOW_COPY_AND_ASSIGN(AppListControllerBrowserTest); |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 #if defined(OS_WIN) && !defined(USE_AURA) | 40 // TODO(tapted): This should work on OS_CHROMEOS as well, but DismissAppList |
| 41 // does not affect IsAppListVisible immediately. |
| 42 #if defined(OS_WIN) |
| 42 // Show the app list, then dismiss it. | 43 // Show the app list, then dismiss it. |
| 43 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, ShowAndDismiss) { | 44 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, ShowAndDismiss) { |
| 44 ASSERT_FALSE(chrome::IsAppListVisible()); | 45 AppListService* service = AppListService::Get(); |
| 45 chrome::ShowAppList(browser()->profile()); | 46 ASSERT_FALSE(service->IsAppListVisible()); |
| 46 ASSERT_TRUE(chrome::IsAppListVisible()); | 47 service->ShowAppList(browser()->profile()); |
| 47 chrome::DismissAppList(); | 48 ASSERT_TRUE(service->IsAppListVisible()); |
| 48 ASSERT_FALSE(chrome::IsAppListVisible()); | 49 service->DismissAppList(); |
| 50 ASSERT_FALSE(service->IsAppListVisible()); |
| 49 } | 51 } |
| 52 #endif // defined(OS_WIN) |
| 50 | 53 |
| 54 #if defined(OS_WIN) |
| 51 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, SwitchAppListProfiles) { | 55 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, SwitchAppListProfiles) { |
| 52 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 56 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 53 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); | 57 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); |
| 54 profile_manager->CreateProfileAsync( | 58 profile_manager->CreateProfileAsync( |
| 55 temp_profile_dir_.path(), | 59 temp_profile_dir_.path(), |
| 56 base::Bind(&AppListControllerBrowserTest::OnProfileCreated, | 60 base::Bind(&AppListControllerBrowserTest::OnProfileCreated, |
| 57 this), | 61 this), |
| 58 string16(), string16(), false); | 62 string16(), string16(), false); |
| 59 content::RunMessageLoop(); // Will stop in OnProfileCreated(). | 63 content::RunMessageLoop(); // Will stop in OnProfileCreated(). |
| 60 | 64 |
| 61 ASSERT_FALSE(chrome::IsAppListVisible()); | 65 AppListService* service = AppListService::Get(); |
| 62 chrome::ShowAppList(browser()->profile()); | 66 ASSERT_FALSE(service->IsAppListVisible()); |
| 63 ASSERT_TRUE(chrome::IsAppListVisible()); | 67 service->ShowAppList(browser()->profile()); |
| 64 ASSERT_EQ(browser()->profile(), chrome::GetCurrentAppListProfile()); | 68 ASSERT_TRUE(service->IsAppListVisible()); |
| 65 chrome::ShowAppList(profile2_); | 69 ASSERT_EQ(browser()->profile(), service->GetCurrentAppListProfile()); |
| 66 ASSERT_TRUE(chrome::IsAppListVisible()); | 70 service->ShowAppList(profile2_); |
| 67 ASSERT_EQ(profile2_, chrome::GetCurrentAppListProfile()); | 71 ASSERT_TRUE(service->IsAppListVisible()); |
| 68 chrome::DismissAppList(); | 72 ASSERT_EQ(profile2_, service->GetCurrentAppListProfile()); |
| 69 ASSERT_FALSE(chrome::IsAppListVisible()); | 73 service->DismissAppList(); |
| 74 ASSERT_FALSE(service->IsAppListVisible()); |
| 70 } | 75 } |
| 71 | 76 |
| 72 class ShowAppListBrowserTest : public InProcessBrowserTest { | 77 class ShowAppListBrowserTest : public InProcessBrowserTest { |
| 73 public: | 78 public: |
| 74 ShowAppListBrowserTest() {} | 79 ShowAppListBrowserTest() {} |
| 75 | 80 |
| 76 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 81 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 77 command_line->AppendSwitch(switches::kShowAppList); | 82 command_line->AppendSwitch(switches::kShowAppList); |
| 78 } | 83 } |
| 79 | 84 |
| 80 private: | 85 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(ShowAppListBrowserTest); | 86 DISALLOW_COPY_AND_ASSIGN(ShowAppListBrowserTest); |
| 82 }; | 87 }; |
| 83 | 88 |
| 84 IN_PROC_BROWSER_TEST_F(ShowAppListBrowserTest, ShowAppListFlag) { | 89 IN_PROC_BROWSER_TEST_F(ShowAppListBrowserTest, ShowAppListFlag) { |
| 90 AppListService* service = AppListService::Get(); |
| 85 // The app list should already be shown because we passed | 91 // The app list should already be shown because we passed |
| 86 // switches::kShowAppList. | 92 // switches::kShowAppList. |
| 87 ASSERT_TRUE(chrome::IsAppListVisible()); | 93 ASSERT_TRUE(service->IsAppListVisible()); |
| 88 | 94 |
| 89 // Create a browser to prevent shutdown when we dismiss the app list. We | 95 // Create a browser to prevent shutdown when we dismiss the app list. We |
| 90 // need to do this because switches::kShowAppList suppresses the creation of | 96 // need to do this because switches::kShowAppList suppresses the creation of |
| 91 // any browsers. | 97 // any browsers. |
| 92 CreateBrowser(chrome::GetCurrentAppListProfile()); | 98 CreateBrowser(service->GetCurrentAppListProfile()); |
| 93 chrome::DismissAppList(); | 99 service->DismissAppList(); |
| 94 } | 100 } |
| 95 #endif // defined(OS_WIN) && !defined(USE_AURA) | 101 #endif // defined(OS_WIN) |
| OLD | NEW |