OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/app_window/app_window_geometry_cache.h" | 5 #include "extensions/browser/app_window/app_window_geometry_cache.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/mock_pref_change_callback.h" | 9 #include "base/prefs/mock_pref_change_callback.h" |
10 #include "base/prefs/pref_service_factory.h" | 10 #include "base/prefs/pref_service_factory.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 extension.get(), | 171 extension.get(), |
172 Extension::ENABLED, | 172 Extension::ENABLED, |
173 syncer::StringOrdinal::CreateInitialOrdinal(), | 173 syncer::StringOrdinal::CreateInitialOrdinal(), |
174 std::string()); | 174 std::string()); |
175 return extension->id(); | 175 return extension->id(); |
176 } | 176 } |
177 | 177 |
178 // Test getting geometry from an empty store. | 178 // Test getting geometry from an empty store. |
179 TEST_F(AppWindowGeometryCacheTest, GetGeometryEmptyStore) { | 179 TEST_F(AppWindowGeometryCacheTest, GetGeometryEmptyStore) { |
180 const std::string extension_id = AddExtensionWithPrefs("ext1"); | 180 const std::string extension_id = AddExtensionWithPrefs("ext1"); |
181 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL)); | 181 ASSERT_FALSE( |
| 182 cache_->GetGeometry(extension_id, kWindowId, nullptr, NULL, NULL)); |
182 } | 183 } |
183 | 184 |
184 // Test getting geometry for an unknown extension. | 185 // Test getting geometry for an unknown extension. |
185 TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownExtension) { | 186 TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownExtension) { |
186 const std::string extension_id1 = AddExtensionWithPrefs("ext1"); | 187 const std::string extension_id1 = AddExtensionWithPrefs("ext1"); |
187 const std::string extension_id2 = AddExtensionWithPrefs("ext2"); | 188 const std::string extension_id2 = AddExtensionWithPrefs("ext2"); |
188 AddGeometryAndLoadExtension(extension_id1, | 189 AddGeometryAndLoadExtension(extension_id1, |
189 kWindowId, | 190 kWindowId, |
190 gfx::Rect(4, 5, 31, 43), | 191 gfx::Rect(4, 5, 31, 43), |
191 gfx::Rect(0, 0, 1600, 900), | 192 gfx::Rect(0, 0, 1600, 900), |
192 ui::SHOW_STATE_NORMAL); | 193 ui::SHOW_STATE_NORMAL); |
193 ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, NULL, NULL, NULL)); | 194 ASSERT_FALSE( |
| 195 cache_->GetGeometry(extension_id2, kWindowId, nullptr, NULL, NULL)); |
194 } | 196 } |
195 | 197 |
196 // Test getting geometry for an unknown window in a known extension. | 198 // Test getting geometry for an unknown window in a known extension. |
197 TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownWindow) { | 199 TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownWindow) { |
198 const std::string extension_id = AddExtensionWithPrefs("ext1"); | 200 const std::string extension_id = AddExtensionWithPrefs("ext1"); |
199 AddGeometryAndLoadExtension(extension_id, | 201 AddGeometryAndLoadExtension(extension_id, |
200 kWindowId, | 202 kWindowId, |
201 gfx::Rect(4, 5, 31, 43), | 203 gfx::Rect(4, 5, 31, 43), |
202 gfx::Rect(0, 0, 1600, 900), | 204 gfx::Rect(0, 0, 1600, 900), |
203 ui::SHOW_STATE_NORMAL); | 205 ui::SHOW_STATE_NORMAL); |
204 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, NULL, NULL, NULL)); | 206 ASSERT_FALSE( |
| 207 cache_->GetGeometry(extension_id, kWindowId2, nullptr, NULL, NULL)); |
205 } | 208 } |
206 | 209 |
207 // Test that loading geometry, screen_bounds and state from the store works | 210 // Test that loading geometry, screen_bounds and state from the store works |
208 // correctly. | 211 // correctly. |
209 TEST_F(AppWindowGeometryCacheTest, GetGeometryAndStateFromStore) { | 212 TEST_F(AppWindowGeometryCacheTest, GetGeometryAndStateFromStore) { |
210 const std::string extension_id = AddExtensionWithPrefs("ext1"); | 213 const std::string extension_id = AddExtensionWithPrefs("ext1"); |
211 gfx::Rect bounds(4, 5, 31, 43); | 214 gfx::Rect bounds(4, 5, 31, 43); |
212 gfx::Rect screen_bounds(0, 0, 1600, 900); | 215 gfx::Rect screen_bounds(0, 0, 1600, 900); |
213 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; | 216 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
214 AddGeometryAndLoadExtension( | 217 AddGeometryAndLoadExtension( |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 415 |
413 gfx::Rect bounds(4, 5, 31, 43); | 416 gfx::Rect bounds(4, 5, 31, 43); |
414 gfx::Rect screen_bounds(0, 0, 1600, 900); | 417 gfx::Rect screen_bounds(0, 0, 1600, 900); |
415 for (size_t i = 0; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { | 418 for (size_t i = 0; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { |
416 std::string window_id = "window_" + base::IntToString(i); | 419 std::string window_id = "window_" + base::IntToString(i); |
417 cache_->SaveGeometry( | 420 cache_->SaveGeometry( |
418 extension_id, window_id, bounds, screen_bounds, ui::SHOW_STATE_NORMAL); | 421 extension_id, window_id, bounds, screen_bounds, ui::SHOW_STATE_NORMAL); |
419 } | 422 } |
420 | 423 |
421 // The first added window should no longer have cached geometry. | 424 // The first added window should no longer have cached geometry. |
422 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL)); | 425 EXPECT_FALSE( |
| 426 cache_->GetGeometry(extension_id, "window_0", nullptr, NULL, NULL)); |
423 // All other windows should still exist. | 427 // All other windows should still exist. |
424 for (size_t i = 1; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { | 428 for (size_t i = 1; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { |
425 std::string window_id = "window_" + base::IntToString(i); | 429 std::string window_id = "window_" + base::IntToString(i); |
426 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL)); | 430 EXPECT_TRUE( |
| 431 cache_->GetGeometry(extension_id, window_id, nullptr, NULL, NULL)); |
427 } | 432 } |
428 } | 433 } |
429 | 434 |
430 } // namespace extensions | 435 } // namespace extensions |
OLD | NEW |