Upstream version 7.36.149.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 using apps::AppWindow;
19
20 namespace {
21
22 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer {
23  public:
24   explicit TestAppWindowRegistryObserver(Profile* profile)
25       : profile_(profile), icon_updates_(0) {
26     apps::AppWindowRegistry::Get(profile_)->AddObserver(this);
27   }
28   virtual ~TestAppWindowRegistryObserver() {
29     apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this);
30   }
31
32   // Overridden from AppWindowRegistry::Observer:
33   virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {
34     ++icon_updates_;
35   }
36
37   int icon_updates() { return icon_updates_; }
38
39  private:
40   Profile* profile_;
41   int icon_updates_;
42
43   DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
44 };
45
46 }  // namespace
47
48 namespace extensions {
49
50 // Tests chrome.app.window.setIcon.
51 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
52   scoped_ptr<TestAppWindowRegistryObserver> test_observer(
53       new TestAppWindowRegistryObserver(browser()->profile()));
54   ExtensionTestMessageListener listener("IconSet", false);
55   LoadAndLaunchPlatformApp("windows_api_set_icon");
56   EXPECT_EQ(0, test_observer->icon_updates());
57   // Wait until the icon load has been requested.
58   ASSERT_TRUE(listener.WaitUntilSatisfied());
59   // Now wait until the WebContent has decoded the icon and chrome has
60   // processed it. This needs to be in a loop since the renderer runs in a
61   // different process.
62   while (test_observer->icon_updates() < 1) {
63     base::RunLoop run_loop;
64     run_loop.RunUntilIdle();
65   }
66   AppWindow* app_window = GetFirstAppWindow();
67   ASSERT_TRUE(app_window);
68   EXPECT_NE(std::string::npos,
69             app_window->app_icon_url().spec().find("icon.png"));
70   EXPECT_EQ(1, test_observer->icon_updates());
71 }
72
73 // TODO(asargent) - Figure out what to do about the fact that minimize events
74 // don't work under ubuntu unity.
75 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
76 // TODO(linux_aura) http://crbug.com/163931
77 // Flaky on Mac, http://crbug.com/232330
78 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
79
80 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
81   EXPECT_TRUE(
82       RunExtensionTest("platform_apps/windows_api_properties")) << message_;
83 }
84
85 #endif  // defined(TOOLKIT_VIEWS)
86
87 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
88                        WindowsApiAlwaysOnTopWithPermissions) {
89   EXPECT_TRUE(RunPlatformAppTest(
90       "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
91 }
92
93 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
94                        WindowsApiAlwaysOnTopWithOldPermissions) {
95   EXPECT_TRUE(RunPlatformAppTest(
96       "platform_apps/windows_api_always_on_top/has_old_permissions"))
97       << message_;
98 }
99
100 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
101                        WindowsApiAlwaysOnTopNoPermissions) {
102   EXPECT_TRUE(RunPlatformAppTest(
103       "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
104 }
105
106 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
107   EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
108       << message_;
109 }
110
111 }  // namespace extensions