Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / extensions / browser / api / app_window / app_window_apitest.cc
blob9fb442213c1a660f0bca55e0410884c07976a3bc
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/geometry/rect.h"
18 #if defined(OS_WIN)
19 #include "ui/base/win/shell.h"
20 #endif
22 namespace extensions {
24 namespace {
26 class TestAppWindowRegistryObserver : public AppWindowRegistry::Observer {
27 public:
28 explicit TestAppWindowRegistryObserver(Profile* profile)
29 : profile_(profile), icon_updates_(0) {
30 AppWindowRegistry::Get(profile_)->AddObserver(this);
32 ~TestAppWindowRegistryObserver() override {
33 AppWindowRegistry::Get(profile_)->RemoveObserver(this);
36 // Overridden from AppWindowRegistry::Observer:
37 void OnAppWindowIconChanged(AppWindow* app_window) override {
38 ++icon_updates_;
41 int icon_updates() { return icon_updates_; }
43 private:
44 Profile* profile_;
45 int icon_updates_;
47 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
50 } // namespace
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());
61 listener.Reply("");
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
65 // different process.
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) {
85 EXPECT_TRUE(
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"))
101 << message_;
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"))
112 << message_;
115 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShapeHasPerm) {
116 EXPECT_TRUE(
117 RunPlatformAppTest("platform_apps/windows_api_shape/has_permission"))
118 << message_;
121 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShapeNoPerm) {
122 EXPECT_TRUE(
123 RunPlatformAppTest("platform_apps/windows_api_shape/no_permission"))
124 << message_;
127 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
128 WindowsApiAlphaEnabledHasPermissions) {
129 const char* no_alpha_dir =
130 "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
131 const char* test_dir = no_alpha_dir;
133 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
134 test_dir =
135 "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
136 #if defined(OS_WIN)
137 if (!ui::win::IsAeroGlassEnabled()) {
138 test_dir = no_alpha_dir;
140 #endif // OS_WIN
141 #endif // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
143 EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
146 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
147 WindowsApiAlphaEnabledNoPermissions) {
148 EXPECT_TRUE(RunPlatformAppTest(
149 "platform_apps/windows_api_alpha_enabled/no_permissions"))
150 << message_;
153 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) {
154 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
155 EXPECT_TRUE(RunPlatformAppTestWithFlags(
156 "platform_apps/windows_api_alpha_enabled/in_stable",
157 // Ignore manifest warnings because the extension will not load at all
158 // in stable.
159 kFlagIgnoreManifestWarnings))
160 << message_;
163 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
164 WindowsApiAlphaEnabledWrongFrameType) {
165 EXPECT_TRUE(RunPlatformAppTest(
166 "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
167 << message_;
170 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
171 WindowsApiVisibleOnAllWorkspacesInStable) {
172 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
173 EXPECT_TRUE(RunPlatformAppTest(
174 "platform_apps/windows_api_visible_on_all_workspaces/in_stable"))
175 << message_;
178 #if defined(OS_CHROMEOS)
179 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
180 WindowsApiImeWindowHasPermissions) {
181 EXPECT_TRUE(RunComponentExtensionTest(
182 "platform_apps/windows_api_ime/has_permissions_whitelisted"))
183 << message_;
185 EXPECT_TRUE(RunPlatformAppTestWithFlags(
186 "platform_apps/windows_api_ime/has_permissions_platform_app",
187 kFlagIgnoreManifestWarnings))
188 << message_;
191 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
192 WindowsApiImeWindowNoPermissions) {
193 EXPECT_TRUE(RunComponentExtensionTest(
194 "platform_apps/windows_api_ime/no_permissions_whitelisted"))
195 << message_;
197 EXPECT_TRUE(RunPlatformAppTest(
198 "platform_apps/windows_api_ime/no_permissions_platform_app"))
199 << message_;
201 #endif // OS_CHROMEOS
203 } // namespace extensions