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