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 "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"
19 #include "content/public/test/test_utils.h"
22 using apps::AppWindow;
26 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer {
28 explicit TestAppWindowRegistryObserver(Profile* profile)
29 : profile_(profile), icon_updates_(0) {
30 apps::AppWindowRegistry::Get(profile_)->AddObserver(this);
32 virtual ~TestAppWindowRegistryObserver() {
33 apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this);
36 // Overridden from AppWindowRegistry::Observer:
37 virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE {}
38 virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {
41 virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE {}
43 int icon_updates() { return icon_updates_; }
49 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
54 namespace extensions {
56 // Flaky, http://crbug.com/164735 .
57 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DISABLED_WindowsApiBounds) {
58 ExtensionTestMessageListener background_listener("background_ok", false);
59 ExtensionTestMessageListener ready_listener("ready", true /* will_reply */);
60 ExtensionTestMessageListener success_listener("success", false);
62 LoadAndLaunchPlatformApp("windows_api_bounds");
63 ASSERT_TRUE(background_listener.WaitUntilSatisfied());
64 ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
65 AppWindow* window = GetFirstAppWindow();
67 gfx::Rect new_bounds(100, 200, 300, 400);
68 new_bounds.Inset(-window->GetBaseWindow()->GetFrameInsets());
69 window->GetBaseWindow()->SetBounds(new_bounds);
71 // TODO(jeremya/asargent) figure out why in GTK the window doesn't end up
72 // with exactly the bounds we set. Is it a bug in our app window
73 // implementation? crbug.com/160252
78 #endif // !TOOLKIT_GTK
80 ready_listener.Reply(base::IntToString(slop));
83 // TODO(asargent)- this is here to help track down the root cause of
86 gfx::Rect last_bounds;
87 while (!success_listener.was_satisfied()) {
88 gfx::Rect current_bounds = window->GetBaseWindow()->GetBounds();
89 if (current_bounds != last_bounds) {
90 LOG(INFO) << "new bounds: " << current_bounds.ToString();
92 last_bounds = current_bounds;
93 content::RunAllPendingInMessageLoop();
98 ASSERT_TRUE(success_listener.WaitUntilSatisfied());
101 // Tests chrome.app.window.setIcon.
102 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
103 scoped_ptr<TestAppWindowRegistryObserver> test_observer(
104 new TestAppWindowRegistryObserver(browser()->profile()));
105 ExtensionTestMessageListener listener("IconSet", false);
106 LoadAndLaunchPlatformApp("windows_api_set_icon");
107 EXPECT_EQ(0, test_observer->icon_updates());
108 // Wait until the icon load has been requested.
109 ASSERT_TRUE(listener.WaitUntilSatisfied());
110 // Now wait until the WebContent has decoded the icon and chrome has
111 // processed it. This needs to be in a loop since the renderer runs in a
112 // different process.
113 while (test_observer->icon_updates() < 1) {
114 base::RunLoop run_loop;
115 run_loop.RunUntilIdle();
117 AppWindow* app_window = GetFirstAppWindow();
118 ASSERT_TRUE(app_window);
119 EXPECT_NE(std::string::npos,
120 app_window->app_icon_url().spec().find("icon.png"));
121 EXPECT_EQ(1, test_observer->icon_updates());
124 // TODO(asargent) - Figure out what to do about the fact that minimize events
125 // don't work under ubuntu unity.
126 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
127 // TODO(linux_aura) http://crbug.com/163931
128 // Flaky on Mac, http://crbug.com/232330
129 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
131 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
133 RunExtensionTest("platform_apps/windows_api_properties")) << message_;
136 #endif // defined(TOOLKIT_VIEWS)
138 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
139 WindowsApiAlwaysOnTopWithPermissions) {
140 EXPECT_TRUE(RunPlatformAppTest(
141 "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
144 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
145 WindowsApiAlwaysOnTopNoPermissions) {
146 EXPECT_TRUE(RunPlatformAppTest(
147 "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
150 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
151 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
155 } // namespace extensions