OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "apps/shell_window.h" | 5 #include "apps/app_window.h" |
6 #include "apps/shell_window_registry.h" | 6 #include "apps/app_window_registry.h" |
7 #include "apps/ui/native_app_window.h" | 7 #include "apps/ui/native_app_window.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/common/extensions/features/feature_channel.h" | 13 #include "chrome/common/extensions/features/feature_channel.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "ui/base/base_window.h" | 15 #include "ui/base/base_window.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
17 | 17 |
18 #ifdef TOOLKIT_GTK | 18 #ifdef TOOLKIT_GTK |
19 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
20 #endif | 20 #endif |
21 | 21 |
22 using apps::ShellWindow; | 22 using apps::AppWindow; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class TestShellWindowRegistryObserver | 26 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer { |
27 : public apps::ShellWindowRegistry::Observer { | |
28 public: | 27 public: |
29 explicit TestShellWindowRegistryObserver(Profile* profile) | 28 explicit TestAppWindowRegistryObserver(Profile* profile) |
30 : profile_(profile), | 29 : profile_(profile), icon_updates_(0) { |
31 icon_updates_(0) { | 30 apps::AppWindowRegistry::Get(profile_)->AddObserver(this); |
32 apps::ShellWindowRegistry::Get(profile_)->AddObserver(this); | |
33 } | 31 } |
34 virtual ~TestShellWindowRegistryObserver() { | 32 virtual ~TestAppWindowRegistryObserver() { |
35 apps::ShellWindowRegistry::Get(profile_)->RemoveObserver(this); | 33 apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this); |
36 } | 34 } |
37 | 35 |
38 // Overridden from ShellWindowRegistry::Observer: | 36 // Overridden from AppWindowRegistry::Observer: |
39 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {} | 37 virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE {} |
40 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE { | 38 virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE { |
41 ++icon_updates_; | 39 ++icon_updates_; |
42 } | 40 } |
43 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE { | 41 virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE {} |
44 } | |
45 | 42 |
46 int icon_updates() { return icon_updates_; } | 43 int icon_updates() { return icon_updates_; } |
47 | 44 |
48 private: | 45 private: |
49 Profile* profile_; | 46 Profile* profile_; |
50 int icon_updates_; | 47 int icon_updates_; |
51 | 48 |
52 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver); | 49 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver); |
53 }; | 50 }; |
54 | 51 |
55 } // namespace | 52 } // namespace |
56 | 53 |
57 namespace extensions { | 54 namespace extensions { |
58 | 55 |
59 // Flaky, http://crbug.com/164735 . | 56 // Flaky, http://crbug.com/164735 . |
60 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DISABLED_WindowsApiBounds) { | 57 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DISABLED_WindowsApiBounds) { |
61 ExtensionTestMessageListener background_listener("background_ok", false); | 58 ExtensionTestMessageListener background_listener("background_ok", false); |
62 ExtensionTestMessageListener ready_listener("ready", true /* will_reply */); | 59 ExtensionTestMessageListener ready_listener("ready", true /* will_reply */); |
63 ExtensionTestMessageListener success_listener("success", false); | 60 ExtensionTestMessageListener success_listener("success", false); |
64 | 61 |
65 LoadAndLaunchPlatformApp("windows_api_bounds"); | 62 LoadAndLaunchPlatformApp("windows_api_bounds"); |
66 ASSERT_TRUE(background_listener.WaitUntilSatisfied()); | 63 ASSERT_TRUE(background_listener.WaitUntilSatisfied()); |
67 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 64 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
68 ShellWindow* window = GetFirstShellWindow(); | 65 AppWindow* window = GetFirstAppWindow(); |
69 | 66 |
70 gfx::Rect new_bounds(100, 200, 300, 400); | 67 gfx::Rect new_bounds(100, 200, 300, 400); |
71 new_bounds.Inset(-window->GetBaseWindow()->GetFrameInsets()); | 68 new_bounds.Inset(-window->GetBaseWindow()->GetFrameInsets()); |
72 window->GetBaseWindow()->SetBounds(new_bounds); | 69 window->GetBaseWindow()->SetBounds(new_bounds); |
73 | 70 |
74 // TODO(jeremya/asargent) figure out why in GTK the window doesn't end up | 71 // TODO(jeremya/asargent) figure out why in GTK the window doesn't end up |
75 // with exactly the bounds we set. Is it a bug in our shell window | 72 // with exactly the bounds we set. Is it a bug in our app window |
76 // implementation? crbug.com/160252 | 73 // implementation? crbug.com/160252 |
77 #ifdef TOOLKIT_GTK | 74 #ifdef TOOLKIT_GTK |
78 int slop = 50; | 75 int slop = 50; |
79 #else | 76 #else |
80 int slop = 0; | 77 int slop = 0; |
81 #endif // !TOOLKIT_GTK | 78 #endif // !TOOLKIT_GTK |
82 | 79 |
83 ready_listener.Reply(base::IntToString(slop)); | 80 ready_listener.Reply(base::IntToString(slop)); |
84 | 81 |
85 #ifdef TOOLKIT_GTK | 82 #ifdef TOOLKIT_GTK |
86 // TODO(asargent)- this is here to help track down the root cause of | 83 // TODO(asargent)- this is here to help track down the root cause of |
87 // crbug.com/164735. | 84 // crbug.com/164735. |
88 { | 85 { |
89 gfx::Rect last_bounds; | 86 gfx::Rect last_bounds; |
90 while (!success_listener.was_satisfied()) { | 87 while (!success_listener.was_satisfied()) { |
91 gfx::Rect current_bounds = window->GetBaseWindow()->GetBounds(); | 88 gfx::Rect current_bounds = window->GetBaseWindow()->GetBounds(); |
92 if (current_bounds != last_bounds) { | 89 if (current_bounds != last_bounds) { |
93 LOG(INFO) << "new bounds: " << current_bounds.ToString(); | 90 LOG(INFO) << "new bounds: " << current_bounds.ToString(); |
94 } | 91 } |
95 last_bounds = current_bounds; | 92 last_bounds = current_bounds; |
96 content::RunAllPendingInMessageLoop(); | 93 content::RunAllPendingInMessageLoop(); |
97 } | 94 } |
98 } | 95 } |
99 #endif | 96 #endif |
100 | 97 |
101 ASSERT_TRUE(success_listener.WaitUntilSatisfied()); | 98 ASSERT_TRUE(success_listener.WaitUntilSatisfied()); |
102 } | 99 } |
103 | 100 |
104 // Tests chrome.app.window.setIcon. | 101 // Tests chrome.app.window.setIcon. |
105 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) { | 102 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) { |
106 scoped_ptr<TestShellWindowRegistryObserver> test_observer( | 103 scoped_ptr<TestAppWindowRegistryObserver> test_observer( |
107 new TestShellWindowRegistryObserver(browser()->profile())); | 104 new TestAppWindowRegistryObserver(browser()->profile())); |
108 ExtensionTestMessageListener listener("IconSet", false); | 105 ExtensionTestMessageListener listener("IconSet", false); |
109 LoadAndLaunchPlatformApp("windows_api_set_icon"); | 106 LoadAndLaunchPlatformApp("windows_api_set_icon"); |
110 EXPECT_EQ(0, test_observer->icon_updates()); | 107 EXPECT_EQ(0, test_observer->icon_updates()); |
111 // Wait until the icon load has been requested. | 108 // Wait until the icon load has been requested. |
112 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 109 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
113 // Now wait until the WebContent has decoded the icon and chrome has | 110 // Now wait until the WebContent has decoded the icon and chrome has |
114 // processed it. This needs to be in a loop since the renderer runs in a | 111 // processed it. This needs to be in a loop since the renderer runs in a |
115 // different process. | 112 // different process. |
116 while (test_observer->icon_updates() < 1) { | 113 while (test_observer->icon_updates() < 1) { |
117 base::RunLoop run_loop; | 114 base::RunLoop run_loop; |
118 run_loop.RunUntilIdle(); | 115 run_loop.RunUntilIdle(); |
119 } | 116 } |
120 ShellWindow* shell_window = GetFirstShellWindow(); | 117 AppWindow* app_window = GetFirstAppWindow(); |
121 ASSERT_TRUE(shell_window); | 118 ASSERT_TRUE(app_window); |
122 EXPECT_NE(std::string::npos, | 119 EXPECT_NE(std::string::npos, |
123 shell_window->app_icon_url().spec().find("icon.png")); | 120 app_window->app_icon_url().spec().find("icon.png")); |
124 EXPECT_EQ(1, test_observer->icon_updates()); | 121 EXPECT_EQ(1, test_observer->icon_updates()); |
125 } | 122 } |
126 | 123 |
127 // TODO(asargent) - Figure out what to do about the fact that minimize events | 124 // TODO(asargent) - Figure out what to do about the fact that minimize events |
128 // don't work under ubuntu unity. | 125 // don't work under ubuntu unity. |
129 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073). | 126 // (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073). |
130 // TODO(linux_aura) http://crbug.com/163931 | 127 // TODO(linux_aura) http://crbug.com/163931 |
131 // Flaky on Mac, http://crbug.com/232330 | 128 // Flaky on Mac, http://crbug.com/232330 |
132 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && de
fined(USE_AURA)) | 129 #if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && de
fined(USE_AURA)) |
133 | 130 |
(...skipping 15 matching lines...) Expand all Loading... |
149 EXPECT_TRUE(RunPlatformAppTest( | 146 EXPECT_TRUE(RunPlatformAppTest( |
150 "platform_apps/windows_api_always_on_top/no_permissions")) << message_; | 147 "platform_apps/windows_api_always_on_top/no_permissions")) << message_; |
151 } | 148 } |
152 | 149 |
153 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) { | 150 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) { |
154 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get")) | 151 EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get")) |
155 << message_; | 152 << message_; |
156 } | 153 } |
157 | 154 |
158 } // namespace extensions | 155 } // namespace extensions |
OLD | NEW |