Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / api / app_window / app_window_apitest.cc
blobfc9003a1709e240cc14e1216c15a33cbd13dba6e
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/chrome_switches.h"
10 #include "chrome/common/extensions/features/feature_channel.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "components/version_info/version_info.h"
13 #include "extensions/browser/app_window/app_window.h"
14 #include "extensions/browser/app_window/app_window_registry.h"
15 #include "extensions/browser/app_window/native_app_window.h"
16 #include "extensions/test/extension_test_message_listener.h"
17 #include "ui/base/base_window.h"
18 #include "ui/gfx/geometry/rect.h"
20 #if defined(OS_WIN)
21 #include "ui/base/win/shell.h"
22 #endif
24 namespace extensions {
26 namespace {
28 class TestAppWindowRegistryObserver : public AppWindowRegistry::Observer {
29 public:
30 explicit TestAppWindowRegistryObserver(Profile* profile)
31 : profile_(profile), icon_updates_(0) {
32 AppWindowRegistry::Get(profile_)->AddObserver(this);
34 ~TestAppWindowRegistryObserver() override {
35 AppWindowRegistry::Get(profile_)->RemoveObserver(this);
38 // Overridden from AppWindowRegistry::Observer:
39 void OnAppWindowIconChanged(AppWindow* app_window) override {
40 ++icon_updates_;
43 int icon_updates() { return icon_updates_; }
45 private:
46 Profile* profile_;
47 int icon_updates_;
49 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
52 } // namespace
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());
63 listener.Reply("");
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
67 // different process.
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) {
87 EXPECT_TRUE(
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"))
103 << message_;
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"))
114 << message_;
117 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShapeHasPerm) {
118 EXPECT_TRUE(
119 RunPlatformAppTest("platform_apps/windows_api_shape/has_permission"))
120 << message_;
123 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShapeNoPerm) {
124 EXPECT_TRUE(
125 RunPlatformAppTest("platform_apps/windows_api_shape/no_permission"))
126 << message_;
129 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
130 WindowsApiAlphaEnabledHasPermissions) {
131 const char* no_alpha_dir =
132 "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
133 const char* test_dir = no_alpha_dir;
135 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
136 test_dir =
137 "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
138 #if defined(OS_WIN)
139 if (!ui::win::IsAeroGlassEnabled()) {
140 test_dir = no_alpha_dir;
142 #endif // OS_WIN
143 #endif // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
145 EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
148 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
149 WindowsApiAlphaEnabledNoPermissions) {
150 EXPECT_TRUE(RunPlatformAppTest(
151 "platform_apps/windows_api_alpha_enabled/no_permissions"))
152 << message_;
155 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) {
156 extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE);
157 EXPECT_TRUE(RunPlatformAppTestWithFlags(
158 "platform_apps/windows_api_alpha_enabled/in_stable",
159 // Ignore manifest warnings because the extension will not load at all
160 // in stable.
161 kFlagIgnoreManifestWarnings))
162 << message_;
165 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
166 WindowsApiAlphaEnabledWrongFrameType) {
167 EXPECT_TRUE(RunPlatformAppTest(
168 "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
169 << message_;
172 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
173 WindowsApiVisibleOnAllWorkspacesInStable) {
174 extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE);
175 EXPECT_TRUE(RunPlatformAppTest(
176 "platform_apps/windows_api_visible_on_all_workspaces/in_stable"))
177 << message_;
180 #if defined(OS_CHROMEOS)
181 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
182 WindowsApiImeWindowHasPermissions) {
183 EXPECT_TRUE(RunComponentExtensionTest(
184 "platform_apps/windows_api_ime/has_permissions_whitelisted"))
185 << message_;
187 EXPECT_TRUE(RunPlatformAppTestWithFlags(
188 "platform_apps/windows_api_ime/has_permissions_platform_app",
189 kFlagIgnoreManifestWarnings))
190 << message_;
193 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
194 WindowsApiImeWindowNoPermissions) {
195 EXPECT_TRUE(RunComponentExtensionTest(
196 "platform_apps/windows_api_ime/no_permissions_whitelisted"))
197 << message_;
199 EXPECT_TRUE(RunPlatformAppTest(
200 "platform_apps/windows_api_ime/no_permissions_platform_app"))
201 << message_;
204 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
205 WindowsApiImeWindowNotFullscreen) {
206 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
207 command_line->AppendSwitch(switches::kForceAppMode);
208 command_line->AppendSwitchASCII(switches::kAppId,
209 "jkghodnilhceideoidjikpgommlajknk");
211 EXPECT_TRUE(RunComponentExtensionTest(
212 "platform_apps/windows_api_ime/forced_app_mode_not_fullscreen"))
213 << message_;
215 #endif // OS_CHROMEOS
217 } // namespace extensions