Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / extensions / browser / api / app_window / app_window_apitest.cc
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.
4
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"
17
18 #if defined(OS_WIN)
19 #include "ui/base/win/shell.h"
20 #endif
21
22 namespace extensions {
23
24 namespace {
25
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);
31   }
32   virtual ~TestAppWindowRegistryObserver() {
33     AppWindowRegistry::Get(profile_)->RemoveObserver(this);
34   }
35
36   // Overridden from AppWindowRegistry::Observer:
37   virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {
38     ++icon_updates_;
39   }
40
41   int icon_updates() { return icon_updates_; }
42
43  private:
44   Profile* profile_;
45   int icon_updates_;
46
47   DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
48 };
49
50 }  // namespace
51
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);
57
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("");
62
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();
69   }
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());
75 }
76
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))
83
84 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
85   EXPECT_TRUE(
86       RunExtensionTest("platform_apps/windows_api_properties")) << message_;
87 }
88
89 #endif  // defined(TOOLKIT_VIEWS)
90
91 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
92                        WindowsApiAlwaysOnTopWithPermissions) {
93   EXPECT_TRUE(RunPlatformAppTest(
94       "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
95 }
96
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_;
102 }
103
104 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
105                        WindowsApiAlwaysOnTopNoPermissions) {
106   EXPECT_TRUE(RunPlatformAppTest(
107       "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
108 }
109
110 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
111   EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
112       << message_;
113 }
114
115 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShape) {
116   EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_shape"))
117       << message_;
118 }
119
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;
125
126 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
127   test_dir =
128       "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
129 #if defined(OS_WIN)
130   if (!ui::win::IsAeroGlassEnabled()) {
131     test_dir = no_alpha_dir;
132   }
133 #endif  // OS_WIN
134 #endif  // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
135
136   EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
137 }
138
139 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
140                        WindowsApiAlphaEnabledNoPermissions) {
141   EXPECT_TRUE(RunPlatformAppTest(
142       "platform_apps/windows_api_alpha_enabled/no_permissions"))
143       << message_;
144 }
145
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
151       // in stable.
152       kFlagIgnoreManifestWarnings))
153       << message_;
154 }
155
156 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
157                        WindowsApiAlphaEnabledWrongFrameType) {
158   EXPECT_TRUE(RunPlatformAppTest(
159       "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
160       << message_;
161 }
162
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"))
168       << message_;
169 }
170
171 }  // namespace extensions