app_list_service_views_browsertest.cc revision 010d83a9304c5a91596085d917d248abff47903a
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/run_loop.h"
8#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
9#include "chrome/browser/ui/browser.h"
10#include "chrome/test/base/in_process_browser_test.h"
11#include "ui/views/widget/widget.h"
12
13// Browser Test for AppListService on Views platforms.
14typedef InProcessBrowserTest AppListServiceViewsBrowserTest;
15
16// Test closing the native app list window as if via a request from the OS.
17IN_PROC_BROWSER_TEST_F(AppListServiceViewsBrowserTest, NativeClose) {
18  AppListService* service = test::GetAppListService();
19  EXPECT_FALSE(service->GetAppListWindow());
20
21  // Since the profile is loaded, this will create a view immediately. This is
22  // important, because anything asynchronous would need an interactive_uitest
23  // due to the possibility of the app list being dismissed, and
24  // AppListService::GetAppListWindow returning NULL.
25  service->ShowForProfile(browser()->profile());
26  gfx::NativeWindow window = service->GetAppListWindow();
27  EXPECT_TRUE(window);
28
29  views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
30  EXPECT_TRUE(widget);
31  widget->Close();
32
33  // Close is asynchronous (dismiss is not) so sink the message queue.
34  base::RunLoop().RunUntilIdle();
35  EXPECT_FALSE(service->GetAppListWindow());
36
37  // Show again to get some code coverage for possibly stale pointers.
38  service->ShowForProfile(browser()->profile());
39  EXPECT_TRUE(service->GetAppListWindow());
40  service->DismissAppList();  // Note: in Ash, this will invalidate the window.
41
42  // Note: no need to sink message queue.
43  EXPECT_FALSE(service->GetAppListWindow());
44}
45