Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / 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 "apps/app_window.h"
6 #include "apps/app_window_registry.h"
7 #include "apps/ui/native_app_window.h"
8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/extensions/extension_test_message_listener.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/common/extensions/features/feature_channel.h"
14 #include "chrome/test/base/testing_profile.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 using apps::AppWindow;
23
24 namespace {
25
26 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer {
27  public:
28   explicit TestAppWindowRegistryObserver(Profile* profile)
29       : profile_(profile), icon_updates_(0) {
30     apps::AppWindowRegistry::Get(profile_)->AddObserver(this);
31   }
32   virtual ~TestAppWindowRegistryObserver() {
33     apps::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 namespace extensions {
53
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);
59
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("");
64
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();
71   }
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());
77 }
78
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))
85
86 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
87   EXPECT_TRUE(
88       RunExtensionTest("platform_apps/windows_api_properties")) << message_;
89 }
90
91 #endif  // defined(TOOLKIT_VIEWS)
92
93 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
94                        WindowsApiAlwaysOnTopWithPermissions) {
95   EXPECT_TRUE(RunPlatformAppTest(
96       "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
97 }
98
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_;
104 }
105
106 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
107                        WindowsApiAlwaysOnTopNoPermissions) {
108   EXPECT_TRUE(RunPlatformAppTest(
109       "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
110 }
111
112 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
113   EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
114       << message_;
115 }
116
117 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShape) {
118   EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_shape"))
119       << message_;
120 }
121
122 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
123                        WindowsApiAlphaEnabledHasPermissions) {
124   const char* no_alpha_dir =
125       "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
126   const char* test_dir = no_alpha_dir;
127
128 #if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX))
129   test_dir =
130       "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
131 #if defined(OS_WIN)
132   if (!ui::win::IsAeroGlassEnabled()) {
133     test_dir = no_alpha_dir;
134   }
135 #endif  // OS_WIN
136 #endif  // USE_AURA && (OS_CHROMEOS || !OS_LINUX)
137
138   EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_;
139 }
140
141 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
142                        WindowsApiAlphaEnabledNoPermissions) {
143   EXPECT_TRUE(RunPlatformAppTest(
144       "platform_apps/windows_api_alpha_enabled/no_permissions"))
145       << message_;
146 }
147
148 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) {
149   extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
150   EXPECT_TRUE(RunPlatformAppTestWithFlags(
151       "platform_apps/windows_api_alpha_enabled/in_stable",
152       // Ignore manifest warnings because the extension will not load at all
153       // in stable.
154       kFlagIgnoreManifestWarnings))
155       << message_;
156 }
157
158 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
159                        WindowsApiAlphaEnabledWrongFrameType) {
160   EXPECT_TRUE(RunPlatformAppTest(
161       "platform_apps/windows_api_alpha_enabled/wrong_frame_type"))
162       << message_;
163 }
164
165 }  // namespace extensions