OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_geometry_cache.h" | 5 #include "apps/app_window_geometry_cache.h" |
6 #include "chrome/browser/apps/app_browsertest_util.h" | 6 #include "chrome/browser/apps/app_browsertest_util.h" |
7 #include "chrome/browser/extensions/extension_test_message_listener.h" | 7 #include "chrome/browser/extensions/extension_test_message_listener.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/extensions/application_launch.h" | 10 #include "chrome/browser/ui/extensions/application_launch.h" |
11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
13 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
15 | 15 |
16 using apps::ShellWindowGeometryCache; | 16 using apps::AppWindowGeometryCache; |
17 | 17 |
18 // This helper class can be used to wait for changes in the shell window | 18 // This helper class can be used to wait for changes in the app window |
19 // geometry cache registry for a specific window in a specific extension. | 19 // geometry cache registry for a specific window in a specific extension. |
20 class GeometryCacheChangeHelper : ShellWindowGeometryCache::Observer { | 20 class GeometryCacheChangeHelper : AppWindowGeometryCache::Observer { |
21 public: | 21 public: |
22 GeometryCacheChangeHelper(ShellWindowGeometryCache* cache, | 22 GeometryCacheChangeHelper(AppWindowGeometryCache* cache, |
23 const std::string& extension_id, | 23 const std::string& extension_id, |
24 const std::string& window_id, | 24 const std::string& window_id, |
25 const gfx::Rect& bounds) | 25 const gfx::Rect& bounds) |
26 : cache_(cache), | 26 : cache_(cache), |
27 extension_id_(extension_id), | 27 extension_id_(extension_id), |
28 window_id_(window_id), | 28 window_id_(window_id), |
29 bounds_(bounds), | 29 bounds_(bounds), |
30 satisfied_(false), | 30 satisfied_(false), |
31 waiting_(false) { | 31 waiting_(false) { |
32 cache_->AddObserver(this); | 32 cache_->AddObserver(this); |
33 } | 33 } |
34 | 34 |
35 // This method will block until the shell window geometry cache registry will | 35 // This method will block until the app window geometry cache registry will |
36 // provide a bound for |window_id_| that is entirely different (as in x/y/w/h) | 36 // provide a bound for |window_id_| that is entirely different (as in x/y/w/h) |
37 // from the initial |bounds_|. | 37 // from the initial |bounds_|. |
38 void WaitForEntirelyChanged() { | 38 void WaitForEntirelyChanged() { |
39 if (satisfied_) | 39 if (satisfied_) |
40 return; | 40 return; |
41 | 41 |
42 waiting_ = true; | 42 waiting_ = true; |
43 content::RunMessageLoop(); | 43 content::RunMessageLoop(); |
44 } | 44 } |
45 | 45 |
(...skipping 11 matching lines...) Expand all Loading... |
57 bounds_.height() != bounds.height()) { | 57 bounds_.height() != bounds.height()) { |
58 satisfied_ = true; | 58 satisfied_ = true; |
59 cache_->RemoveObserver(this); | 59 cache_->RemoveObserver(this); |
60 | 60 |
61 if (waiting_) | 61 if (waiting_) |
62 base::MessageLoopForUI::current()->Quit(); | 62 base::MessageLoopForUI::current()->Quit(); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 ShellWindowGeometryCache* cache_; | 67 AppWindowGeometryCache* cache_; |
68 std::string extension_id_; | 68 std::string extension_id_; |
69 std::string window_id_; | 69 std::string window_id_; |
70 gfx::Rect bounds_; | 70 gfx::Rect bounds_; |
71 bool satisfied_; | 71 bool satisfied_; |
72 bool waiting_; | 72 bool waiting_; |
73 }; | 73 }; |
74 | 74 |
75 // Helper class for tests related to the Apps Window API (chrome.app.window). | 75 // Helper class for tests related to the Apps Window API (chrome.app.window). |
76 class AppWindowAPITest : public extensions::PlatformAppBrowserTest { | 76 class AppWindowAPITest : public extensions::PlatformAppBrowserTest { |
77 protected: | 77 protected: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 NEW_WINDOW)); | 182 NEW_WINDOW)); |
183 | 183 |
184 ExtensionTestMessageListener geometry_listener("ListenGeometryChange", true); | 184 ExtensionTestMessageListener geometry_listener("ListenGeometryChange", true); |
185 | 185 |
186 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 186 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
187 launched_listener.Reply("testRestoreAfterGeometryCacheChange"); | 187 launched_listener.Reply("testRestoreAfterGeometryCacheChange"); |
188 | 188 |
189 ASSERT_TRUE(geometry_listener.WaitUntilSatisfied()); | 189 ASSERT_TRUE(geometry_listener.WaitUntilSatisfied()); |
190 | 190 |
191 GeometryCacheChangeHelper geo_change_helper_1( | 191 GeometryCacheChangeHelper geo_change_helper_1( |
192 ShellWindowGeometryCache::Get(browser()->profile()), extension->id(), | 192 AppWindowGeometryCache::Get(browser()->profile()), |
| 193 extension->id(), |
193 // The next line has information that has to stay in sync with the app. | 194 // The next line has information that has to stay in sync with the app. |
194 "test-ra", gfx::Rect(200, 200, 200, 200)); | 195 "test-ra", |
| 196 gfx::Rect(200, 200, 200, 200)); |
195 | 197 |
196 GeometryCacheChangeHelper geo_change_helper_2( | 198 GeometryCacheChangeHelper geo_change_helper_2( |
197 ShellWindowGeometryCache::Get(browser()->profile()), extension->id(), | 199 AppWindowGeometryCache::Get(browser()->profile()), |
| 200 extension->id(), |
198 // The next line has information that has to stay in sync with the app. | 201 // The next line has information that has to stay in sync with the app. |
199 "test-rb", gfx::Rect(200, 200, 200, 200)); | 202 "test-rb", |
| 203 gfx::Rect(200, 200, 200, 200)); |
200 | 204 |
201 // These calls will block until the shell window geometry cache will change. | 205 // These calls will block until the app window geometry cache will change. |
202 geo_change_helper_1.WaitForEntirelyChanged(); | 206 geo_change_helper_1.WaitForEntirelyChanged(); |
203 geo_change_helper_2.WaitForEntirelyChanged(); | 207 geo_change_helper_2.WaitForEntirelyChanged(); |
204 | 208 |
205 ResultCatcher catcher; | 209 ResultCatcher catcher; |
206 geometry_listener.Reply(""); | 210 geometry_listener.Reply(""); |
207 ASSERT_TRUE(catcher.GetNextResult()); | 211 ASSERT_TRUE(catcher.GetNextResult()); |
208 } | 212 } |
209 | 213 |
210 IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestBadging) { | 214 IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestBadging) { |
211 ASSERT_TRUE( | 215 ASSERT_TRUE( |
212 RunAppWindowAPITestAndWaitForRoundTrip("testBadging")) << message_; | 216 RunAppWindowAPITestAndWaitForRoundTrip("testBadging")) << message_; |
213 } | 217 } |
OLD | NEW |