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/shell_window.h"
6 #include "apps/shell_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/test/base/testing_profile.h"
14 #include "ui/base/base_window.h"
15 #include "ui/gfx/rect.h"
18 #include "content/public/test/test_utils.h"
21 using apps::ShellWindow;
25 class TestShellWindowRegistryObserver
26 : public apps::ShellWindowRegistry::Observer {
28 explicit TestShellWindowRegistryObserver(Profile* profile)
31 apps::ShellWindowRegistry::Get(profile_)->AddObserver(this);
33 virtual ~TestShellWindowRegistryObserver() {
34 apps::ShellWindowRegistry::Get(profile_)->RemoveObserver(this);
37 // Overridden from ShellWindowRegistry::Observer:
38 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {}
39 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {
42 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE {
45 int icon_updates() { return icon_updates_; }
51 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver);
56 namespace extensions {
58 // Flaky, http://crbug.com/164735 .
59 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DISABLED_WindowsApiBounds) {
60 ExtensionTestMessageListener background_listener("background_ok", false);
61 ExtensionTestMessageListener ready_listener("ready", true /* will_reply */);
62 ExtensionTestMessageListener success_listener("success", false);
64 LoadAndLaunchPlatformApp("windows_api_bounds");
65 ASSERT_TRUE(background_listener.WaitUntilSatisfied());
66 ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
67 ShellWindow* window = GetFirstShellWindow();
69 gfx::Rect new_bounds(100, 200, 300, 400);
70 new_bounds.Inset(-window->GetBaseWindow()->GetFrameInsets());
71 window->GetBaseWindow()->SetBounds(new_bounds);
73 // TODO(jeremya/asargent) figure out why in GTK the window doesn't end up
74 // with exactly the bounds we set. Is it a bug in our shell window
75 // implementation? crbug.com/160252
80 #endif // !TOOLKIT_GTK
82 ready_listener.Reply(base::IntToString(slop));
85 // TODO(asargent)- this is here to help track down the root cause of
88 gfx::Rect last_bounds;
89 while (!success_listener.was_satisfied()) {
90 gfx::Rect current_bounds = window->GetBaseWindow()->GetBounds();
91 if (current_bounds != last_bounds) {
92 LOG(INFO) << "new bounds: " << current_bounds.ToString();
94 last_bounds = current_bounds;
95 content::RunAllPendingInMessageLoop();
100 ASSERT_TRUE(success_listener.WaitUntilSatisfied());
103 // Tests chrome.app.window.setIcon.
104 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
105 scoped_ptr<TestShellWindowRegistryObserver> test_observer(
106 new TestShellWindowRegistryObserver(browser()->profile()));
107 ExtensionTestMessageListener listener("IconSet", false);
108 LoadAndLaunchPlatformApp("windows_api_set_icon");
109 EXPECT_EQ(0, test_observer->icon_updates());
110 // Wait until the icon load has been requested.
111 ASSERT_TRUE(listener.WaitUntilSatisfied());
112 // Now wait until the WebContent has decoded the icon and chrome has
113 // processed it. This needs to be in a loop since the renderer runs in a
114 // different process.
115 while (test_observer->icon_updates() < 1) {
116 base::RunLoop run_loop;
117 run_loop.RunUntilIdle();
119 ShellWindow* shell_window = GetFirstShellWindow();
120 ASSERT_TRUE(shell_window);
121 EXPECT_NE(std::string::npos,
122 shell_window->app_icon_url().spec().find("icon.png"));
123 EXPECT_EQ(1, test_observer->icon_updates());
126 // TODO(asargent) - Figure out what to do about the fact that minimize events
127 // don't work under ubuntu unity.
128 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
129 // TODO(linux_aura) http://crbug.com/163931
130 // Flaky on Mac, http://crbug.com/232330
131 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
133 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
135 RunExtensionTest("platform_apps/windows_api_properties")) << message_;
138 #endif // defined(TOOLKIT_VIEWS)
140 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlwaysOnTop) {
141 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_always_on_top"))
145 } // namespace extensions