Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / app_window / app_window_apitest.cc
blob6aa666df536cf4719784de863b2312977ff3e5b9
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 "extensions/browser/app_window/app_window.h"
13 #include "extensions/browser/app_window/app_window_registry.h"
14 #include "extensions/browser/app_window/native_app_window.h"
15 #include "extensions/test/extension_test_message_listener.h"
16 #include "ui/base/base_window.h"
17 #include "ui/gfx/geometry/rect.h"
19 #if defined(OS_WIN)
20 #include "ui/base/win/shell.h"
21 #endif
23 namespace extensions {
25 namespace {
27 class TestAppWindowRegistryObserver : public AppWindowRegistry::Observer {
28 public:
29 explicit TestAppWindowRegistryObserver(Profile* profile)
30 : profile_(profile), icon_updates_(0) {
31 AppWindowRegistry::Get(profile_)->AddObserver(this);
33 ~TestAppWindowRegistryObserver() override {
34 AppWindowRegistry::Get(profile_)->RemoveObserver(this);
37 // Overridden from AppWindowRegistry::Observer:
38 void OnAppWindowIconChanged(AppWindow* app_window) override {
39 ++icon_updates_;
42 int icon_updates() { return icon_updates_; }
44 private:
45 Profile* profile_;
46 int icon_updates_;
48 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
51 } // namespace
53 // Tests chrome.app.window.setIcon.
54 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
55 scoped_ptr<TestAppWindowRegistryObserver> test_observer(
56 new TestAppWindowRegistryObserver(browser()->profile()));
57 ExtensionTestMessageListener listener("ready", true);
59 // Launch the app and wait for it to be ready.
60 LoadAndLaunchPlatformApp("windows_api_set_icon", &listener);
61 EXPECT_EQ(0, test_observer->icon_updates());
62 listener.Reply("");
64 // Now wait until the WebContent has decoded the icon and chrome has
65 // processed it. This needs to be in a loop since the renderer runs in a
66 // different process.
67 while (test_observer->icon_updates() < 1) {
68 base::RunLoop run_loop;
69 run_loop.RunUntilIdle();
71 AppWindow* app_window = GetFirstAppWindow();
72 ASSERT_TRUE(app_window);
73 EXPECT_NE(std::string::npos,
74 app_window->app_icon_url().spec().find("icon.png"));
75 EXPECT_EQ(1, test_observer->icon_updates());
78 // TODO(asargent) - Figure out what to do about the fact that minimize events
79 // don't work under ubuntu unity.
80 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
81 // TODO(linux_aura) http://crbug.com/163931
82 // Flaky on Mac, http://crbug.com/232330
83 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
85 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
86 EXPECT_TRUE(
87 RunExtensionTest("platform_apps/windows_api_properties")) << message_;
90 #endif // defined(TOOLKIT_VIEWS)
92 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
93 WindowsApiAlwaysOnTopWithPermissions) {
94 EXPECT_TRUE(RunPlatformAppTest(
95 "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
98 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
99 WindowsApiAlwaysOnTopWithOldPermissions) {
100 EXPECT_TRUE(RunPlatformAppTest(
101 "platform_apps/windows_api_always_on_top/has_old_permissions"))
102 << message_;
105 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
106 WindowsApiAlwaysOnTopNoPermissions) {
107 EXPECT_TRUE(RunPlatformAppTest(
108 "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
111 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
112 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
113 << message_;
116 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShapeHasPerm) {
117 EXPECT_TRUE(
118 RunPlatformAppTest("platform_apps/windows_api_shape/has_permission"))
119 << message_;
122 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShapeNoPerm) {
123 EXPECT_TRUE(
124 RunPlatformAppTest("platform_apps/windows_api_shape/no_permission"))
125 << message_;
128 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
129 WindowsApiAlphaEnabledHasPermissions) {
130 const char* no_alpha_dir =
131 "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
132 const char* test_dir = no_alpha_dir;
134 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
135 test_dir =
136 "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
137 #if defined(OS_WIN)
138 if (!ui::win::IsAeroGlassEnabled()) {
139 test_dir = no_alpha_dir;
141 #endif // OS_WIN
142 #endif // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
144 EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
147 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
148 WindowsApiAlphaEnabledNoPermissions) {
149 EXPECT_TRUE(RunPlatformAppTest(
150 "platform_apps/windows_api_alpha_enabled/no_permissions"))
151 << message_;
154 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) {
155 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
156 EXPECT_TRUE(RunPlatformAppTestWithFlags(
157 "platform_apps/windows_api_alpha_enabled/in_stable",
158 // Ignore manifest warnings because the extension will not load at all
159 // in stable.
160 kFlagIgnoreManifestWarnings))
161 << message_;
164 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
165 WindowsApiAlphaEnabledWrongFrameType) {
166 EXPECT_TRUE(RunPlatformAppTest(
167 "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
168 << message_;
171 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
172 WindowsApiVisibleOnAllWorkspacesInStable) {
173 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
174 EXPECT_TRUE(RunPlatformAppTest(
175 "platform_apps/windows_api_visible_on_all_workspaces/in_stable"))
176 << message_;
179 #if defined(OS_CHROMEOS)
180 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
181 WindowsApiImeWindowHasPermissions) {
182 EXPECT_TRUE(RunComponentExtensionTest(
183 "platform_apps/windows_api_ime/has_permissions_whitelisted"))
184 << message_;
186 EXPECT_TRUE(RunPlatformAppTestWithFlags(
187 "platform_apps/windows_api_ime/has_permissions_platform_app",
188 kFlagIgnoreManifestWarnings))
189 << message_;
192 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
193 WindowsApiImeWindowNoPermissions) {
194 EXPECT_TRUE(RunComponentExtensionTest(
195 "platform_apps/windows_api_ime/no_permissions_whitelisted"))
196 << message_;
198 EXPECT_TRUE(RunPlatformAppTest(
199 "platform_apps/windows_api_ime/no_permissions_platform_app"))
200 << message_;
203 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
204 WindowsApiImeWindowNotFullscreen) {
205 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
206 command_line->AppendSwitch(switches::kForceAppMode);
207 command_line->AppendSwitchASCII(switches::kAppId,
208 "jkghodnilhceideoidjikpgommlajknk");
210 EXPECT_TRUE(RunComponentExtensionTest(
211 "platform_apps/windows_api_ime/forced_app_mode_not_fullscreen"))
212 << message_;
214 #endif // OS_CHROMEOS
216 } // namespace extensions