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_geometry_cache.h" | 5 #include "apps/shell_window_geometry_cache.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/prefs/mock_pref_change_callback.h" | 7 #include "base/prefs/mock_pref_change_callback.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
10 #include "chrome/browser/extensions/test_extension_prefs.h" | 10 #include "chrome/browser/extensions/test_extension_prefs.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 gfx::Rect new_bounds; | 134 gfx::Rect new_bounds; |
135 gfx::Rect new_screen_bounds; | 135 gfx::Rect new_screen_bounds; |
136 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; | 136 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
137 ASSERT_TRUE(cache_->GetGeometry( | 137 ASSERT_TRUE(cache_->GetGeometry( |
138 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); | 138 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
139 ASSERT_EQ(bounds, new_bounds); | 139 ASSERT_EQ(bounds, new_bounds); |
140 ASSERT_EQ(screen_bounds, new_screen_bounds); | 140 ASSERT_EQ(screen_bounds, new_screen_bounds); |
141 ASSERT_EQ(state, new_state); | 141 ASSERT_EQ(state, new_state); |
142 } | 142 } |
143 | 143 |
| 144 // Test corrupt bounds will not be loaded. |
| 145 TEST_F(ShellWindowGeometryCacheTest, CorruptBounds) { |
| 146 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 147 gfx::Rect bounds; |
| 148 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 149 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
| 150 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, |
| 151 screen_bounds, state); |
| 152 gfx::Rect new_bounds; |
| 153 gfx::Rect new_screen_bounds; |
| 154 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 155 ASSERT_FALSE(cache_->GetGeometry( |
| 156 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 157 ASSERT_TRUE(new_bounds.IsEmpty()); |
| 158 ASSERT_TRUE(new_screen_bounds.IsEmpty()); |
| 159 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); |
| 160 } |
| 161 |
| 162 // Test corrupt screen bounds will not be loaded. |
| 163 TEST_F(ShellWindowGeometryCacheTest, CorruptScreenBounds) { |
| 164 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 165 gfx::Rect bounds(4, 5, 31, 43); |
| 166 gfx::Rect screen_bounds; |
| 167 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
| 168 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, |
| 169 screen_bounds, state); |
| 170 gfx::Rect new_bounds; |
| 171 gfx::Rect new_screen_bounds; |
| 172 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 173 ASSERT_FALSE(cache_->GetGeometry( |
| 174 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 175 ASSERT_TRUE(new_bounds.IsEmpty()); |
| 176 ASSERT_TRUE(new_screen_bounds.IsEmpty()); |
| 177 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); |
| 178 } |
| 179 |
| 180 // Test corrupt state will not be loaded. |
| 181 TEST_F(ShellWindowGeometryCacheTest, CorruptState) { |
| 182 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 183 gfx::Rect bounds(4, 5, 31, 43); |
| 184 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 185 ui::WindowShowState state = ui::SHOW_STATE_DEFAULT; |
| 186 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, |
| 187 screen_bounds, state); |
| 188 gfx::Rect new_bounds; |
| 189 gfx::Rect new_screen_bounds; |
| 190 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 191 ASSERT_FALSE(cache_->GetGeometry( |
| 192 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 193 ASSERT_TRUE(new_bounds.IsEmpty()); |
| 194 ASSERT_TRUE(new_screen_bounds.IsEmpty()); |
| 195 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); |
| 196 } |
| 197 |
144 // Test saving geometry, screen_bounds and state to the cache and state store, | 198 // Test saving geometry, screen_bounds and state to the cache and state store, |
145 // and reading it back. | 199 // and reading it back. |
146 TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) { | 200 TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) { |
147 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 201 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
148 const std::string window_id(kWindowId); | 202 const std::string window_id(kWindowId); |
149 | 203 |
150 // inform cache of extension | 204 // inform cache of extension |
151 LoadExtension(extension_id); | 205 LoadExtension(extension_id); |
152 | 206 |
153 // update geometry stored in cache | 207 // update geometry stored in cache |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // The first added window should no longer have cached geometry. | 333 // The first added window should no longer have cached geometry. |
280 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL)); | 334 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL)); |
281 // All other windows should still exist. | 335 // All other windows should still exist. |
282 for (size_t i = 1; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) { | 336 for (size_t i = 1; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) { |
283 std::string window_id = "window_" + base::IntToString(i); | 337 std::string window_id = "window_" + base::IntToString(i); |
284 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL)); | 338 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL)); |
285 } | 339 } |
286 } | 340 } |
287 | 341 |
288 } // namespace extensions | 342 } // namespace extensions |
OLD | NEW |