app_list_controller_browsertest.cc revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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/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 base::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->ShowForProfile(browser()->profile()); 46 ASSERT_TRUE(service->IsAppListVisible()); 47 service->DismissAppList(); 48 ASSERT_FALSE(service->IsAppListVisible()); 49} 50 51IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, SwitchAppListProfiles) { 52 ProfileManager* profile_manager = g_browser_process->profile_manager(); 53 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); 54 profile_manager->CreateProfileAsync( 55 temp_profile_dir_.path(), 56 base::Bind(&AppListControllerBrowserTest::OnProfileCreated, 57 this), 58 string16(), string16(), false); 59 content::RunMessageLoop(); // Will stop in OnProfileCreated(). 60 61 AppListService* service = AppListService::Get(); 62 ASSERT_FALSE(service->IsAppListVisible()); 63 service->ShowForProfile(browser()->profile()); 64 ASSERT_TRUE(service->IsAppListVisible()); 65 ASSERT_EQ(browser()->profile(), service->GetCurrentAppListProfile()); 66 service->ShowForProfile(profile2_); 67 ASSERT_TRUE(service->IsAppListVisible()); 68 ASSERT_EQ(profile2_, service->GetCurrentAppListProfile()); 69 service->DismissAppList(); 70 ASSERT_FALSE(service->IsAppListVisible()); 71} 72 73class ShowAppListBrowserTest : public InProcessBrowserTest { 74 public: 75 ShowAppListBrowserTest() {} 76 77 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 78 command_line->AppendSwitch(switches::kShowAppList); 79 } 80 81 private: 82 DISALLOW_COPY_AND_ASSIGN(ShowAppListBrowserTest); 83}; 84 85IN_PROC_BROWSER_TEST_F(ShowAppListBrowserTest, ShowAppListFlag) { 86 AppListService* service = AppListService::Get(); 87 // The app list should already be shown because we passed 88 // switches::kShowAppList. 89 ASSERT_TRUE(service->IsAppListVisible()); 90 91 // Create a browser to prevent shutdown when we dismiss the app list. We 92 // need to do this because switches::kShowAppList suppresses the creation of 93 // any browsers. 94 CreateBrowser(service->GetCurrentAppListProfile()); 95 service->DismissAppList(); 96} 97#endif // !defined(OS_CHROMEOS) && !defined(USE_AURA) 98