1 // Copyright (c) 2012 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.
5 #include "apps/app_window.h"
6 #include "apps/app_window_registry.h"
7 #include "apps/ui/native_app_window.h"
8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/extensions/extension_test_message_listener.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/common/extensions/features/feature_channel.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "ui/base/base_window.h"
16 #include "ui/gfx/rect.h"
19 #include "ui/base/win/shell.h"
22 using apps::AppWindow;
26 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer {
28 explicit TestAppWindowRegistryObserver(Profile* profile)
29 : profile_(profile), icon_updates_(0) {
30 apps::AppWindowRegistry::Get(profile_)->AddObserver(this);
32 virtual ~TestAppWindowRegistryObserver() {
33 apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this);
36 // Overridden from AppWindowRegistry::Observer:
37 virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {
41 int icon_updates() { return icon_updates_; }
47 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
52 namespace extensions {
54 // Tests chrome.app.window.setIcon.
55 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
56 scoped_ptr<TestAppWindowRegistryObserver> test_observer(
57 new TestAppWindowRegistryObserver(browser()->profile()));
58 ExtensionTestMessageListener listener("ready", true);
60 // Launch the app and wait for it to be ready.
61 LoadAndLaunchPlatformApp("windows_api_set_icon", &listener);
62 EXPECT_EQ(0, test_observer->icon_updates());
65 // Now wait until the WebContent has decoded the icon and chrome has
66 // processed it. This needs to be in a loop since the renderer runs in a
68 while (test_observer->icon_updates() < 1) {
69 base::RunLoop run_loop;
70 run_loop.RunUntilIdle();
72 AppWindow* app_window = GetFirstAppWindow();
73 ASSERT_TRUE(app_window);
74 EXPECT_NE(std::string::npos,
75 app_window->app_icon_url().spec().find("icon.png"));
76 EXPECT_EQ(1, test_observer->icon_updates());
79 // TODO(asargent) - Figure out what to do about the fact that minimize events
80 // don't work under ubuntu unity.
81 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
82 // TODO(linux_aura) http://crbug.com/163931
83 // Flaky on Mac, http://crbug.com/232330
84 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
86 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
88 RunExtensionTest("platform_apps/windows_api_properties")) << message_;
91 #endif // defined(TOOLKIT_VIEWS)
93 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
94 WindowsApiAlwaysOnTopWithPermissions) {
95 EXPECT_TRUE(RunPlatformAppTest(
96 "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
99 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
100 WindowsApiAlwaysOnTopWithOldPermissions) {
101 EXPECT_TRUE(RunPlatformAppTest(
102 "platform_apps/windows_api_always_on_top/has_old_permissions"))
106 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
107 WindowsApiAlwaysOnTopNoPermissions) {
108 EXPECT_TRUE(RunPlatformAppTest(
109 "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
112 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
113 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
117 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShape) {
118 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_shape"))
122 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
123 WindowsApiAlphaEnabledHasPermissions) {
124 const char* no_alpha_dir =
125 "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
126 const char* test_dir = no_alpha_dir;
128 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
130 "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
132 if (!ui::win::IsAeroGlassEnabled()) {
133 test_dir = no_alpha_dir;
136 #endif // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
138 EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
141 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
142 WindowsApiAlphaEnabledNoPermissions) {
143 EXPECT_TRUE(RunPlatformAppTest(
144 "platform_apps/windows_api_alpha_enabled/no_permissions"))
148 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) {
149 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
150 EXPECT_TRUE(RunPlatformAppTestWithFlags(
151 "platform_apps/windows_api_alpha_enabled/in_stable",
152 // Ignore manifest warnings because the extension will not load at all
154 kFlagIgnoreManifestWarnings))
158 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
159 WindowsApiAlphaEnabledWrongFrameType) {
160 EXPECT_TRUE(RunPlatformAppTest(
161 "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
165 } // namespace extensions