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 "base/run_loop.h"
6 #include "base/strings/string_number_conversions.h"
7 #include "chrome/browser/apps/app_browsertest_util.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/common/extensions/features/feature_channel.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "extensions/browser/app_window/app_window.h"
12 #include "extensions/browser/app_window/app_window_registry.h"
13 #include "extensions/browser/app_window/native_app_window.h"
14 #include "extensions/test/extension_test_message_listener.h"
15 #include "ui/base/base_window.h"
16 #include "ui/gfx/rect.h"
19 #include "ui/base/win/shell.h"
22 namespace extensions {
26 class TestAppWindowRegistryObserver : public AppWindowRegistry::Observer {
28 explicit TestAppWindowRegistryObserver(Profile* profile)
29 : profile_(profile), icon_updates_(0) {
30 AppWindowRegistry::Get(profile_)->AddObserver(this);
32 virtual ~TestAppWindowRegistryObserver() {
33 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 // Tests chrome.app.window.setIcon.
53 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
54 scoped_ptr<TestAppWindowRegistryObserver> test_observer(
55 new TestAppWindowRegistryObserver(browser()->profile()));
56 ExtensionTestMessageListener listener("ready", true);
58 // Launch the app and wait for it to be ready.
59 LoadAndLaunchPlatformApp("windows_api_set_icon", &listener);
60 EXPECT_EQ(0, test_observer->icon_updates());
63 // Now wait until the WebContent has decoded the icon and chrome has
64 // processed it. This needs to be in a loop since the renderer runs in a
66 while (test_observer->icon_updates() < 1) {
67 base::RunLoop run_loop;
68 run_loop.RunUntilIdle();
70 AppWindow* app_window = GetFirstAppWindow();
71 ASSERT_TRUE(app_window);
72 EXPECT_NE(std::string::npos,
73 app_window->app_icon_url().spec().find("icon.png"));
74 EXPECT_EQ(1, test_observer->icon_updates());
77 // TODO(asargent) - Figure out what to do about the fact that minimize events
78 // don't work under ubuntu unity.
79 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
80 // TODO(linux_aura) http://crbug.com/163931
81 // Flaky on Mac, http://crbug.com/232330
82 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
84 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
86 RunExtensionTest("platform_apps/windows_api_properties")) << message_;
89 #endif // defined(TOOLKIT_VIEWS)
91 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
92 WindowsApiAlwaysOnTopWithPermissions) {
93 EXPECT_TRUE(RunPlatformAppTest(
94 "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
97 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
98 WindowsApiAlwaysOnTopWithOldPermissions) {
99 EXPECT_TRUE(RunPlatformAppTest(
100 "platform_apps/windows_api_always_on_top/has_old_permissions"))
104 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
105 WindowsApiAlwaysOnTopNoPermissions) {
106 EXPECT_TRUE(RunPlatformAppTest(
107 "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
110 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
111 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
115 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShape) {
116 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_shape"))
120 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
121 WindowsApiAlphaEnabledHasPermissions) {
122 const char* no_alpha_dir =
123 "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
124 const char* test_dir = no_alpha_dir;
126 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
128 "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
130 if (!ui::win::IsAeroGlassEnabled()) {
131 test_dir = no_alpha_dir;
134 #endif // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
136 EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
139 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
140 WindowsApiAlphaEnabledNoPermissions) {
141 EXPECT_TRUE(RunPlatformAppTest(
142 "platform_apps/windows_api_alpha_enabled/no_permissions"))
146 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) {
147 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
148 EXPECT_TRUE(RunPlatformAppTestWithFlags(
149 "platform_apps/windows_api_alpha_enabled/in_stable",
150 // Ignore manifest warnings because the extension will not load at all
152 kFlagIgnoreManifestWarnings))
156 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
157 WindowsApiAlphaEnabledWrongFrameType) {
158 EXPECT_TRUE(RunPlatformAppTest(
159 "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
163 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
164 WindowsApiVisibleOnAllWorkspacesInStable) {
165 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
166 EXPECT_TRUE(RunPlatformAppTest(
167 "platform_apps/windows_api_visible_on_all_workspaces/in_stable"))
171 } // namespace extensions