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"
18 using apps::AppWindow;
22 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer {
24 explicit TestAppWindowRegistryObserver(Profile* profile)
25 : profile_(profile), icon_updates_(0) {
26 apps::AppWindowRegistry::Get(profile_)->AddObserver(this);
28 virtual ~TestAppWindowRegistryObserver() {
29 apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this);
32 // Overridden from AppWindowRegistry::Observer:
33 virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {
37 int icon_updates() { return icon_updates_; }
43 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver);
48 namespace extensions {
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
62 while (test_observer->icon_updates() < 1) {
63 base::RunLoop run_loop;
64 run_loop.RunUntilIdle();
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());
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))
80 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) {
82 RunExtensionTest("platform_apps/windows_api_properties")) << message_;
85 #endif // defined(TOOLKIT_VIEWS)
87 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
88 WindowsApiAlwaysOnTopWithPermissions) {
89 EXPECT_TRUE(RunPlatformAppTest(
90 "platform_apps/windows_api_always_on_top/has_permissions")) << message_;
93 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
94 WindowsApiAlwaysOnTopWithOldPermissions) {
95 EXPECT_TRUE(RunPlatformAppTest(
96 "platform_apps/windows_api_always_on_top/has_old_permissions"))
100 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
101 WindowsApiAlwaysOnTopNoPermissions) {
102 EXPECT_TRUE(RunPlatformAppTest(
103 "platform_apps/windows_api_always_on_top/no_permissions")) << message_;
106 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
107 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get"))
111 } // namespace extensions