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