| 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/app_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/test_extension_prefs.h" | 9 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 const char kWindowId[] = "windowid"; | 16 const char kWindowId[] = "windowid"; |
| 17 const char kWindowId2[] = "windowid2"; | 17 const char kWindowId2[] = "windowid2"; |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 namespace apps { | 21 namespace apps { |
| 22 | 22 |
| 23 // Base class for tests. | 23 // Base class for tests. |
| 24 class ShellWindowGeometryCacheTest : public testing::Test { | 24 class AppWindowGeometryCacheTest : public testing::Test { |
| 25 public: | 25 public: |
| 26 ShellWindowGeometryCacheTest() : | 26 AppWindowGeometryCacheTest() |
| 27 ui_thread_(BrowserThread::UI, &ui_message_loop_) { | 27 : ui_thread_(BrowserThread::UI, &ui_message_loop_) { |
| 28 prefs_.reset(new extensions::TestExtensionPrefs( | 28 prefs_.reset(new extensions::TestExtensionPrefs( |
| 29 ui_message_loop_.message_loop_proxy().get())); | 29 ui_message_loop_.message_loop_proxy().get())); |
| 30 cache_.reset(new ShellWindowGeometryCache(&profile_, prefs_->prefs())); | 30 cache_.reset(new AppWindowGeometryCache(&profile_, prefs_->prefs())); |
| 31 cache_->SetSyncDelayForTests(0); | 31 cache_->SetSyncDelayForTests(0); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void AddGeometryAndLoadExtension( | 34 void AddGeometryAndLoadExtension(const std::string& extension_id, |
| 35 const std::string& extension_id, | 35 const std::string& window_id, |
| 36 const std::string& window_id, | 36 const gfx::Rect& bounds, |
| 37 const gfx::Rect& bounds, | 37 const gfx::Rect& screen_bounds, |
| 38 const gfx::Rect& screen_bounds, | 38 ui::WindowShowState state); |
| 39 ui::WindowShowState state); | |
| 40 | 39 |
| 41 // Spins the UI threads' message loops to make sure any task | 40 // Spins the UI threads' message loops to make sure any task |
| 42 // posted to sync the geometry to the value store gets a chance to run. | 41 // posted to sync the geometry to the value store gets a chance to run. |
| 43 void WaitForSync(); | 42 void WaitForSync(); |
| 44 | 43 |
| 45 void LoadExtension(const std::string& extension_id); | 44 void LoadExtension(const std::string& extension_id); |
| 46 void UnloadExtension(const std::string& extension_id); | 45 void UnloadExtension(const std::string& extension_id); |
| 47 | 46 |
| 48 protected: | 47 protected: |
| 49 TestingProfile profile_; | 48 TestingProfile profile_; |
| 50 base::MessageLoopForUI ui_message_loop_; | 49 base::MessageLoopForUI ui_message_loop_; |
| 51 content::TestBrowserThread ui_thread_; | 50 content::TestBrowserThread ui_thread_; |
| 52 scoped_ptr<extensions::TestExtensionPrefs> prefs_; | 51 scoped_ptr<extensions::TestExtensionPrefs> prefs_; |
| 53 scoped_ptr<ShellWindowGeometryCache> cache_; | 52 scoped_ptr<AppWindowGeometryCache> cache_; |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 void ShellWindowGeometryCacheTest::AddGeometryAndLoadExtension( | 55 void AppWindowGeometryCacheTest::AddGeometryAndLoadExtension( |
| 57 const std::string& extension_id, | 56 const std::string& extension_id, |
| 58 const std::string& window_id, | 57 const std::string& window_id, |
| 59 const gfx::Rect& bounds, | 58 const gfx::Rect& bounds, |
| 60 const gfx::Rect& screen_bounds, | 59 const gfx::Rect& screen_bounds, |
| 61 ui::WindowShowState state) { | 60 ui::WindowShowState state) { |
| 62 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 61 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 63 base::DictionaryValue* value = new base::DictionaryValue; | 62 base::DictionaryValue* value = new base::DictionaryValue; |
| 64 value->SetInteger("x", bounds.x()); | 63 value->SetInteger("x", bounds.x()); |
| 65 value->SetInteger("y", bounds.y()); | 64 value->SetInteger("y", bounds.y()); |
| 66 value->SetInteger("w", bounds.width()); | 65 value->SetInteger("w", bounds.width()); |
| 67 value->SetInteger("h", bounds.height()); | 66 value->SetInteger("h", bounds.height()); |
| 68 value->SetInteger("screen_bounds_x", screen_bounds.x()); | 67 value->SetInteger("screen_bounds_x", screen_bounds.x()); |
| 69 value->SetInteger("screen_bounds_y", screen_bounds.y()); | 68 value->SetInteger("screen_bounds_y", screen_bounds.y()); |
| 70 value->SetInteger("screen_bounds_w", screen_bounds.width()); | 69 value->SetInteger("screen_bounds_w", screen_bounds.width()); |
| 71 value->SetInteger("screen_bounds_h", screen_bounds.height()); | 70 value->SetInteger("screen_bounds_h", screen_bounds.height()); |
| 72 value->SetInteger("state", state); | 71 value->SetInteger("state", state); |
| 73 dict->SetWithoutPathExpansion(window_id, value); | 72 dict->SetWithoutPathExpansion(window_id, value); |
| 74 prefs_->prefs()->SetGeometryCache(extension_id, dict.Pass()); | 73 prefs_->prefs()->SetGeometryCache(extension_id, dict.Pass()); |
| 75 LoadExtension(extension_id); | 74 LoadExtension(extension_id); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void ShellWindowGeometryCacheTest::WaitForSync() { | 77 void AppWindowGeometryCacheTest::WaitForSync() { |
| 79 content::RunAllPendingInMessageLoop(); | 78 content::RunAllPendingInMessageLoop(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 void ShellWindowGeometryCacheTest::LoadExtension( | 81 void AppWindowGeometryCacheTest::LoadExtension( |
| 83 const std::string& extension_id) { | 82 const std::string& extension_id) { |
| 84 cache_->LoadGeometryFromStorage(extension_id); | 83 cache_->LoadGeometryFromStorage(extension_id); |
| 85 WaitForSync(); | 84 WaitForSync(); |
| 86 } | 85 } |
| 87 | 86 |
| 88 void ShellWindowGeometryCacheTest::UnloadExtension( | 87 void AppWindowGeometryCacheTest::UnloadExtension( |
| 89 const std::string& extension_id) { | 88 const std::string& extension_id) { |
| 90 cache_->OnExtensionUnloaded(extension_id); | 89 cache_->OnExtensionUnloaded(extension_id); |
| 91 WaitForSync(); | 90 WaitForSync(); |
| 92 } | 91 } |
| 93 | 92 |
| 94 // Test getting geometry from an empty store. | 93 // Test getting geometry from an empty store. |
| 95 TEST_F(ShellWindowGeometryCacheTest, GetGeometryEmptyStore) { | 94 TEST_F(AppWindowGeometryCacheTest, GetGeometryEmptyStore) { |
| 96 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 95 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 97 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL)); | 96 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL)); |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Test getting geometry for an unknown extension. | 99 // Test getting geometry for an unknown extension. |
| 101 TEST_F(ShellWindowGeometryCacheTest, GetGeometryUnkownExtension) { | 100 TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownExtension) { |
| 102 const std::string extension_id1 = prefs_->AddExtensionAndReturnId("ext1"); | 101 const std::string extension_id1 = prefs_->AddExtensionAndReturnId("ext1"); |
| 103 const std::string extension_id2 = prefs_->AddExtensionAndReturnId("ext2"); | 102 const std::string extension_id2 = prefs_->AddExtensionAndReturnId("ext2"); |
| 104 AddGeometryAndLoadExtension(extension_id1, kWindowId, | 103 AddGeometryAndLoadExtension(extension_id1, |
| 104 kWindowId, |
| 105 gfx::Rect(4, 5, 31, 43), | 105 gfx::Rect(4, 5, 31, 43), |
| 106 gfx::Rect(0, 0, 1600, 900), | 106 gfx::Rect(0, 0, 1600, 900), |
| 107 ui::SHOW_STATE_NORMAL); | 107 ui::SHOW_STATE_NORMAL); |
| 108 ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, NULL, NULL, NULL)); | 108 ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, NULL, NULL, NULL)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Test getting geometry for an unknown window in a known extension. | 111 // Test getting geometry for an unknown window in a known extension. |
| 112 TEST_F(ShellWindowGeometryCacheTest, GetGeometryUnkownWindow) { | 112 TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownWindow) { |
| 113 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 113 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 114 AddGeometryAndLoadExtension(extension_id, kWindowId, | 114 AddGeometryAndLoadExtension(extension_id, |
| 115 kWindowId, |
| 115 gfx::Rect(4, 5, 31, 43), | 116 gfx::Rect(4, 5, 31, 43), |
| 116 gfx::Rect(0, 0, 1600, 900), | 117 gfx::Rect(0, 0, 1600, 900), |
| 117 ui::SHOW_STATE_NORMAL); | 118 ui::SHOW_STATE_NORMAL); |
| 118 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, NULL, NULL, NULL)); | 119 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, NULL, NULL, NULL)); |
| 119 } | 120 } |
| 120 | 121 |
| 121 // Test that loading geometry, screen_bounds and state from the store works | 122 // Test that loading geometry, screen_bounds and state from the store works |
| 122 // correctly. | 123 // correctly. |
| 123 TEST_F(ShellWindowGeometryCacheTest, GetGeometryAndStateFromStore) { | 124 TEST_F(AppWindowGeometryCacheTest, GetGeometryAndStateFromStore) { |
| 124 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 125 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 125 gfx::Rect bounds(4, 5, 31, 43); | 126 gfx::Rect bounds(4, 5, 31, 43); |
| 126 gfx::Rect screen_bounds(0, 0, 1600, 900); | 127 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 127 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; | 128 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
| 128 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, | 129 AddGeometryAndLoadExtension( |
| 129 screen_bounds, state); | 130 extension_id, kWindowId, bounds, screen_bounds, state); |
| 130 gfx::Rect new_bounds; | 131 gfx::Rect new_bounds; |
| 131 gfx::Rect new_screen_bounds; | 132 gfx::Rect new_screen_bounds; |
| 132 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; | 133 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 133 ASSERT_TRUE(cache_->GetGeometry( | 134 ASSERT_TRUE(cache_->GetGeometry( |
| 134 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); | 135 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 135 ASSERT_EQ(bounds, new_bounds); | 136 ASSERT_EQ(bounds, new_bounds); |
| 136 ASSERT_EQ(screen_bounds, new_screen_bounds); | 137 ASSERT_EQ(screen_bounds, new_screen_bounds); |
| 137 ASSERT_EQ(state, new_state); | 138 ASSERT_EQ(state, new_state); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Test corrupt bounds will not be loaded. | 141 // Test corrupt bounds will not be loaded. |
| 141 TEST_F(ShellWindowGeometryCacheTest, CorruptBounds) { | 142 TEST_F(AppWindowGeometryCacheTest, CorruptBounds) { |
| 142 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 143 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 143 gfx::Rect bounds; | 144 gfx::Rect bounds; |
| 144 gfx::Rect screen_bounds(0, 0, 1600, 900); | 145 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 145 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; | 146 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
| 146 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, | 147 AddGeometryAndLoadExtension( |
| 147 screen_bounds, state); | 148 extension_id, kWindowId, bounds, screen_bounds, state); |
| 148 gfx::Rect new_bounds; | 149 gfx::Rect new_bounds; |
| 149 gfx::Rect new_screen_bounds; | 150 gfx::Rect new_screen_bounds; |
| 150 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; | 151 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 151 ASSERT_FALSE(cache_->GetGeometry( | 152 ASSERT_FALSE(cache_->GetGeometry( |
| 152 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); | 153 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 153 ASSERT_TRUE(new_bounds.IsEmpty()); | 154 ASSERT_TRUE(new_bounds.IsEmpty()); |
| 154 ASSERT_TRUE(new_screen_bounds.IsEmpty()); | 155 ASSERT_TRUE(new_screen_bounds.IsEmpty()); |
| 155 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); | 156 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); |
| 156 } | 157 } |
| 157 | 158 |
| 158 // Test corrupt screen bounds will not be loaded. | 159 // Test corrupt screen bounds will not be loaded. |
| 159 TEST_F(ShellWindowGeometryCacheTest, CorruptScreenBounds) { | 160 TEST_F(AppWindowGeometryCacheTest, CorruptScreenBounds) { |
| 160 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 161 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 161 gfx::Rect bounds(4, 5, 31, 43); | 162 gfx::Rect bounds(4, 5, 31, 43); |
| 162 gfx::Rect screen_bounds; | 163 gfx::Rect screen_bounds; |
| 163 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; | 164 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
| 164 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, | 165 AddGeometryAndLoadExtension( |
| 165 screen_bounds, state); | 166 extension_id, kWindowId, bounds, screen_bounds, state); |
| 166 gfx::Rect new_bounds; | 167 gfx::Rect new_bounds; |
| 167 gfx::Rect new_screen_bounds; | 168 gfx::Rect new_screen_bounds; |
| 168 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; | 169 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 169 ASSERT_FALSE(cache_->GetGeometry( | 170 ASSERT_FALSE(cache_->GetGeometry( |
| 170 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); | 171 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 171 ASSERT_TRUE(new_bounds.IsEmpty()); | 172 ASSERT_TRUE(new_bounds.IsEmpty()); |
| 172 ASSERT_TRUE(new_screen_bounds.IsEmpty()); | 173 ASSERT_TRUE(new_screen_bounds.IsEmpty()); |
| 173 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); | 174 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); |
| 174 } | 175 } |
| 175 | 176 |
| 176 // Test corrupt state will not be loaded. | 177 // Test corrupt state will not be loaded. |
| 177 TEST_F(ShellWindowGeometryCacheTest, CorruptState) { | 178 TEST_F(AppWindowGeometryCacheTest, CorruptState) { |
| 178 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 179 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 179 gfx::Rect bounds(4, 5, 31, 43); | 180 gfx::Rect bounds(4, 5, 31, 43); |
| 180 gfx::Rect screen_bounds(0, 0, 1600, 900); | 181 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 181 ui::WindowShowState state = ui::SHOW_STATE_DEFAULT; | 182 ui::WindowShowState state = ui::SHOW_STATE_DEFAULT; |
| 182 AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, | 183 AddGeometryAndLoadExtension( |
| 183 screen_bounds, state); | 184 extension_id, kWindowId, bounds, screen_bounds, state); |
| 184 gfx::Rect new_bounds; | 185 gfx::Rect new_bounds; |
| 185 gfx::Rect new_screen_bounds; | 186 gfx::Rect new_screen_bounds; |
| 186 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; | 187 ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT; |
| 187 ASSERT_FALSE(cache_->GetGeometry( | 188 ASSERT_FALSE(cache_->GetGeometry( |
| 188 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); | 189 extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state)); |
| 189 ASSERT_TRUE(new_bounds.IsEmpty()); | 190 ASSERT_TRUE(new_bounds.IsEmpty()); |
| 190 ASSERT_TRUE(new_screen_bounds.IsEmpty()); | 191 ASSERT_TRUE(new_screen_bounds.IsEmpty()); |
| 191 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); | 192 ASSERT_EQ(new_state, ui::SHOW_STATE_DEFAULT); |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Test saving geometry, screen_bounds and state to the cache and state store, | 195 // Test saving geometry, screen_bounds and state to the cache and state store, |
| 195 // and reading it back. | 196 // and reading it back. |
| 196 TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) { | 197 TEST_F(AppWindowGeometryCacheTest, SaveGeometryAndStateToStore) { |
| 197 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 198 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 198 const std::string window_id(kWindowId); | 199 const std::string window_id(kWindowId); |
| 199 | 200 |
| 200 // inform cache of extension | 201 // inform cache of extension |
| 201 LoadExtension(extension_id); | 202 LoadExtension(extension_id); |
| 202 | 203 |
| 203 // update geometry stored in cache | 204 // update geometry stored in cache |
| 204 gfx::Rect bounds(4, 5, 31, 43); | 205 gfx::Rect bounds(4, 5, 31, 43); |
| 205 gfx::Rect screen_bounds(0, 0, 1600, 900); | 206 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 206 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; | 207 ui::WindowShowState state = ui::SHOW_STATE_NORMAL; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // and make sure the geometry got reloaded properly too | 251 // and make sure the geometry got reloaded properly too |
| 251 ASSERT_TRUE(cache_->GetGeometry( | 252 ASSERT_TRUE(cache_->GetGeometry( |
| 252 extension_id, window_id, &new_bounds, &new_screen_bounds, &new_state)); | 253 extension_id, window_id, &new_bounds, &new_screen_bounds, &new_state)); |
| 253 ASSERT_EQ(bounds, new_bounds); | 254 ASSERT_EQ(bounds, new_bounds); |
| 254 ASSERT_EQ(screen_bounds, new_screen_bounds); | 255 ASSERT_EQ(screen_bounds, new_screen_bounds); |
| 255 ASSERT_EQ(state, new_state); | 256 ASSERT_EQ(state, new_state); |
| 256 } | 257 } |
| 257 | 258 |
| 258 // Tests that we won't do writes to the state store for SaveGeometry calls | 259 // Tests that we won't do writes to the state store for SaveGeometry calls |
| 259 // which don't change the state we already have. | 260 // which don't change the state we already have. |
| 260 TEST_F(ShellWindowGeometryCacheTest, NoDuplicateWrites) { | 261 TEST_F(AppWindowGeometryCacheTest, NoDuplicateWrites) { |
| 261 using testing::_; | 262 using testing::_; |
| 262 using testing::Mock; | 263 using testing::Mock; |
| 263 | 264 |
| 264 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 265 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 265 gfx::Rect bounds1(100, 200, 300, 400); | 266 gfx::Rect bounds1(100, 200, 300, 400); |
| 266 gfx::Rect bounds2(200, 400, 600, 800); | 267 gfx::Rect bounds2(200, 400, 600, 800); |
| 267 gfx::Rect bounds2_duplicate(200, 400, 600, 800); | 268 gfx::Rect bounds2_duplicate(200, 400, 600, 800); |
| 268 | 269 |
| 269 gfx::Rect screen_bounds1(0, 0, 1600, 900); | 270 gfx::Rect screen_bounds1(0, 0, 1600, 900); |
| 270 gfx::Rect screen_bounds2(0, 0, 1366, 768); | 271 gfx::Rect screen_bounds2(0, 0, 1366, 768); |
| 271 gfx::Rect screen_bounds2_duplicate(0, 0, 1366, 768); | 272 gfx::Rect screen_bounds2_duplicate(0, 0, 1366, 768); |
| 272 | 273 |
| 273 MockPrefChangeCallback observer(prefs_->pref_service()); | 274 MockPrefChangeCallback observer(prefs_->pref_service()); |
| 274 PrefChangeRegistrar registrar; | 275 PrefChangeRegistrar registrar; |
| 275 registrar.Init(prefs_->pref_service()); | 276 registrar.Init(prefs_->pref_service()); |
| 276 registrar.Add("extensions.settings", observer.GetCallback()); | 277 registrar.Add("extensions.settings", observer.GetCallback()); |
| 277 | 278 |
| 278 // Write the first bounds - it should do > 0 writes. | 279 // Write the first bounds - it should do > 0 writes. |
| 279 EXPECT_CALL(observer, OnPreferenceChanged(_)); | 280 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
| 280 cache_->SaveGeometry(extension_id, kWindowId, bounds1, | 281 cache_->SaveGeometry( |
| 281 screen_bounds1, ui::SHOW_STATE_NORMAL); | 282 extension_id, kWindowId, bounds1, screen_bounds1, ui::SHOW_STATE_NORMAL); |
| 282 WaitForSync(); | 283 WaitForSync(); |
| 283 Mock::VerifyAndClearExpectations(&observer); | 284 Mock::VerifyAndClearExpectations(&observer); |
| 284 | 285 |
| 285 // Write a different bounds - it should also do > 0 writes. | 286 // Write a different bounds - it should also do > 0 writes. |
| 286 EXPECT_CALL(observer, OnPreferenceChanged(_)); | 287 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
| 287 cache_->SaveGeometry(extension_id, kWindowId, bounds2, | 288 cache_->SaveGeometry( |
| 288 screen_bounds1, ui::SHOW_STATE_NORMAL); | 289 extension_id, kWindowId, bounds2, screen_bounds1, ui::SHOW_STATE_NORMAL); |
| 289 WaitForSync(); | 290 WaitForSync(); |
| 290 Mock::VerifyAndClearExpectations(&observer); | 291 Mock::VerifyAndClearExpectations(&observer); |
| 291 | 292 |
| 292 // Write a different screen bounds - it should also do > 0 writes. | 293 // Write a different screen bounds - it should also do > 0 writes. |
| 293 EXPECT_CALL(observer, OnPreferenceChanged(_)); | 294 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
| 294 cache_->SaveGeometry(extension_id, kWindowId, bounds2, | 295 cache_->SaveGeometry( |
| 295 screen_bounds2, ui::SHOW_STATE_NORMAL); | 296 extension_id, kWindowId, bounds2, screen_bounds2, ui::SHOW_STATE_NORMAL); |
| 296 WaitForSync(); | 297 WaitForSync(); |
| 297 Mock::VerifyAndClearExpectations(&observer); | 298 Mock::VerifyAndClearExpectations(&observer); |
| 298 | 299 |
| 299 // Write a different state - it should also do > 0 writes. | 300 // Write a different state - it should also do > 0 writes. |
| 300 EXPECT_CALL(observer, OnPreferenceChanged(_)); | 301 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
| 301 cache_->SaveGeometry(extension_id, kWindowId, bounds2, | 302 cache_->SaveGeometry(extension_id, |
| 302 screen_bounds2, ui::SHOW_STATE_MAXIMIZED); | 303 kWindowId, |
| 304 bounds2, |
| 305 screen_bounds2, |
| 306 ui::SHOW_STATE_MAXIMIZED); |
| 303 WaitForSync(); | 307 WaitForSync(); |
| 304 Mock::VerifyAndClearExpectations(&observer); | 308 Mock::VerifyAndClearExpectations(&observer); |
| 305 | 309 |
| 306 // Write a bounds, screen bounds and state that's a duplicate of what we | 310 // Write a bounds, screen bounds and state that's a duplicate of what we |
| 307 // already have. This should not do any writes. | 311 // already have. This should not do any writes. |
| 308 EXPECT_CALL(observer, OnPreferenceChanged(_)).Times(0); | 312 EXPECT_CALL(observer, OnPreferenceChanged(_)).Times(0); |
| 309 cache_->SaveGeometry(extension_id, kWindowId, bounds2_duplicate, | 313 cache_->SaveGeometry(extension_id, |
| 310 screen_bounds2_duplicate, ui::SHOW_STATE_MAXIMIZED); | 314 kWindowId, |
| 315 bounds2_duplicate, |
| 316 screen_bounds2_duplicate, |
| 317 ui::SHOW_STATE_MAXIMIZED); |
| 311 WaitForSync(); | 318 WaitForSync(); |
| 312 Mock::VerifyAndClearExpectations(&observer); | 319 Mock::VerifyAndClearExpectations(&observer); |
| 313 } | 320 } |
| 314 | 321 |
| 315 // Tests that no more than kMaxCachedWindows windows will be cached. | 322 // Tests that no more than kMaxCachedWindows windows will be cached. |
| 316 TEST_F(ShellWindowGeometryCacheTest, MaxWindows) { | 323 TEST_F(AppWindowGeometryCacheTest, MaxWindows) { |
| 317 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); | 324 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); |
| 318 // inform cache of extension | 325 // inform cache of extension |
| 319 LoadExtension(extension_id); | 326 LoadExtension(extension_id); |
| 320 | 327 |
| 321 gfx::Rect bounds(4, 5, 31, 43); | 328 gfx::Rect bounds(4, 5, 31, 43); |
| 322 gfx::Rect screen_bounds(0, 0, 1600, 900); | 329 gfx::Rect screen_bounds(0, 0, 1600, 900); |
| 323 for (size_t i = 0; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) { | 330 for (size_t i = 0; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { |
| 324 std::string window_id = "window_" + base::IntToString(i); | 331 std::string window_id = "window_" + base::IntToString(i); |
| 325 cache_->SaveGeometry(extension_id, window_id, bounds, | 332 cache_->SaveGeometry( |
| 326 screen_bounds, ui::SHOW_STATE_NORMAL); | 333 extension_id, window_id, bounds, screen_bounds, ui::SHOW_STATE_NORMAL); |
| 327 } | 334 } |
| 328 | 335 |
| 329 // The first added window should no longer have cached geometry. | 336 // The first added window should no longer have cached geometry. |
| 330 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL)); | 337 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL)); |
| 331 // All other windows should still exist. | 338 // All other windows should still exist. |
| 332 for (size_t i = 1; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) { | 339 for (size_t i = 1; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { |
| 333 std::string window_id = "window_" + base::IntToString(i); | 340 std::string window_id = "window_" + base::IntToString(i); |
| 334 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL)); | 341 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL)); |
| 335 } | 342 } |
| 336 } | 343 } |
| 337 | 344 |
| 338 } // namespace extensions | 345 } // namespace extensions |
| OLD | NEW |