app_list_service_views_browsertest.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
1// Copyright 2014 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 "chrome/browser/ui/app_list/app_list_service_views.h" 6 7#include "base/path_service.h" 8#include "base/run_loop.h" 9#include "chrome/browser/extensions/extension_browsertest.h" 10#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 11#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h" 12#include "chrome/browser/ui/browser.h" 13#include "chrome/common/chrome_paths.h" 14#include "chrome/test/base/in_process_browser_test.h" 15#include "ui/app_list/app_list_switches.h" 16#include "ui/app_list/views/app_list_view.h" 17#include "ui/views/widget/widget.h" 18 19#if defined(OS_CHROMEOS) 20#include "ash/shell.h" 21#include "ash/test/app_list_controller_test_api.h" 22#endif 23 24// Browser Test for AppListService on Views platforms. 25typedef InProcessBrowserTest AppListServiceViewsBrowserTest; 26 27// Test closing the native app list window as if via a request from the OS. 28IN_PROC_BROWSER_TEST_F(AppListServiceViewsBrowserTest, NativeClose) { 29 AppListService* service = test::GetAppListService(); 30 EXPECT_FALSE(service->GetAppListWindow()); 31 32 // Since the profile is loaded, this will create a view immediately. This is 33 // important, because anything asynchronous would need an interactive_uitest 34 // due to the possibility of the app list being dismissed, and 35 // AppListService::GetAppListWindow returning NULL. 36 service->ShowForProfile(browser()->profile()); 37 gfx::NativeWindow window = service->GetAppListWindow(); 38 EXPECT_TRUE(window); 39 40 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 41 EXPECT_TRUE(widget); 42 widget->Close(); 43 44 // Close is asynchronous (dismiss is not) so sink the message queue. 45 base::RunLoop().RunUntilIdle(); 46 EXPECT_FALSE(service->GetAppListWindow()); 47 48 // Show again to get some code coverage for possibly stale pointers. 49 service->ShowForProfile(browser()->profile()); 50 EXPECT_TRUE(service->GetAppListWindow()); 51 service->DismissAppList(); // Note: in Ash, this will invalidate the window. 52 53 // Note: no need to sink message queue. 54 EXPECT_FALSE(service->GetAppListWindow()); 55} 56 57// Browser Test for AppListController that ensures the App Info dialog opens 58// correctly. 59class AppListControllerAppInfoDialogBrowserTest : public ExtensionBrowserTest { 60 public: 61 AppListControllerAppInfoDialogBrowserTest() {} 62 virtual ~AppListControllerAppInfoDialogBrowserTest() {} 63 64 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { 65 ExtensionBrowserTest::SetUpCommandLine(command_line); 66 } 67 68 private: 69 DISALLOW_COPY_AND_ASSIGN(AppListControllerAppInfoDialogBrowserTest); 70}; 71 72// Test the DoShowAppInfoFlow function of the controller delegate. 73// Crashes on all platforms some of the time (flaky). http://crbug.com/378251 74IN_PROC_BROWSER_TEST_F(AppListControllerAppInfoDialogBrowserTest, 75 DISABLED_DoShowAppInfoFlow) { 76 // Install an extension to open the dialog for. 77 test::SigninProfile(browser()->profile()); 78 base::FilePath test_extension_path; 79 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path)); 80 test_extension_path = test_extension_path.AppendASCII("extensions") 81 .AppendASCII("platform_apps") 82 .AppendASCII("minimal"); 83 const extensions::Extension* extension = InstallExtension( 84 test_extension_path, 1 /* expected_change: new install */); 85 ASSERT_TRUE(extension); 86 87 // Open the app list window. 88 AppListService* service = test::GetAppListService(); 89 EXPECT_FALSE(service->GetAppListWindow()); 90 91 service->ShowForProfile(browser()->profile()); 92 gfx::NativeWindow window = service->GetAppListWindow(); 93 EXPECT_TRUE(window); 94 95 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 96 ASSERT_TRUE(widget); 97 98 // Open the app info dialog. 99 views::Widget::Widgets owned_widgets; 100 widget->GetAllOwnedWidgets(window, &owned_widgets); 101 EXPECT_EQ(0U, owned_widgets.size()); 102 103 AppListControllerDelegate* controller = service->GetControllerDelegate(); 104 ASSERT_TRUE(controller); 105 controller->DoShowAppInfoFlow(browser()->profile(), extension->id()); 106 base::RunLoop().RunUntilIdle(); 107 108 owned_widgets.clear(); 109 widget->GetAllOwnedWidgets(window, &owned_widgets); 110 EXPECT_EQ(1U, owned_widgets.size()); 111 112 // Close the app info dialog. 113 views::Widget* app_info_dialog = *owned_widgets.begin(); 114 app_info_dialog->Close(); 115 base::RunLoop().RunUntilIdle(); 116 117 owned_widgets.clear(); 118 widget->GetAllOwnedWidgets(window, &owned_widgets); 119 EXPECT_EQ(0U, owned_widgets.size()); 120} 121