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