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 "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
6 #include "base/prefs/mock_pref_change_callback.h" | 7 #include "base/prefs/mock_pref_change_callback.h" |
7 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/shell_window_geometry_cache.h" | |
10 #include "chrome/browser/extensions/test_extension_prefs.h" | 10 #include "chrome/browser/extensions/test_extension_prefs.h" |
11 #include "chrome/browser/prefs/pref_service_syncable.h" | |
12 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
13 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
14 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace { | 16 namespace { |
18 static const char kWindowId[] = "windowid"; | 17 static const char kWindowId[] = "windowid"; |
19 static const char kWindowId2[] = "windowid2"; | 18 static const char kWindowId2[] = "windowid2"; |
20 | 19 |
21 const char kWindowGeometryKey[] = "window_geometry"; | 20 const char kWindowGeometryKey[] = "window_geometry"; |
22 } // namespace | 21 } // namespace |
23 | 22 |
24 using content::BrowserThread; | 23 using content::BrowserThread; |
25 | 24 |
26 namespace extensions { | 25 namespace apps { |
27 | 26 |
28 // Base class for tests. | 27 // Base class for tests. |
29 class ShellWindowGeometryCacheTest : public testing::Test { | 28 class ShellWindowGeometryCacheTest : public testing::Test { |
30 public: | 29 public: |
31 ShellWindowGeometryCacheTest() : | 30 ShellWindowGeometryCacheTest() : |
32 ui_thread_(BrowserThread::UI, &ui_message_loop_) { | 31 ui_thread_(BrowserThread::UI, &ui_message_loop_) { |
33 prefs_.reset(new TestExtensionPrefs(ui_message_loop_.message_loop_proxy())); | 32 prefs_.reset(new extensions::TestExtensionPrefs( |
| 33 ui_message_loop_.message_loop_proxy())); |
34 cache_.reset( | 34 cache_.reset( |
35 new ShellWindowGeometryCache(&profile_, prefs_->prefs())); | 35 new ShellWindowGeometryCache(&profile_, prefs_->prefs())); |
36 cache_->SetSyncDelayForTests(0); | 36 cache_->SetSyncDelayForTests(0); |
37 } | 37 } |
38 | 38 |
39 void AddGeometryAndLoadExtension( | 39 void AddGeometryAndLoadExtension( |
40 const std::string& extension_id, | 40 const std::string& extension_id, |
41 const std::string& window_id, | 41 const std::string& window_id, |
42 const gfx::Rect& bounds, | 42 const gfx::Rect& bounds, |
43 ui::WindowShowState state); | 43 ui::WindowShowState state); |
44 | 44 |
45 // Spins the UI threads' message loops to make sure any task | 45 // Spins the UI threads' message loops to make sure any task |
46 // posted to sync the geometry to the value store gets a chance to run. | 46 // posted to sync the geometry to the value store gets a chance to run. |
47 void WaitForSync(); | 47 void WaitForSync(); |
48 | 48 |
49 void LoadExtension(const std::string& extension_id); | 49 void LoadExtension(const std::string& extension_id); |
50 void UnloadExtension(const std::string& extension_id); | 50 void UnloadExtension(const std::string& extension_id); |
51 | 51 |
52 protected: | 52 protected: |
53 TestingProfile profile_; | 53 TestingProfile profile_; |
54 MessageLoopForUI ui_message_loop_; | 54 MessageLoopForUI ui_message_loop_; |
55 content::TestBrowserThread ui_thread_; | 55 content::TestBrowserThread ui_thread_; |
56 scoped_ptr<TestExtensionPrefs> prefs_; | 56 scoped_ptr<extensions::TestExtensionPrefs> prefs_; |
57 scoped_ptr<ShellWindowGeometryCache> cache_; | 57 scoped_ptr<ShellWindowGeometryCache> cache_; |
58 }; | 58 }; |
59 | 59 |
60 void ShellWindowGeometryCacheTest::AddGeometryAndLoadExtension( | 60 void ShellWindowGeometryCacheTest::AddGeometryAndLoadExtension( |
61 const std::string& extension_id, | 61 const std::string& extension_id, |
62 const std::string& window_id, | 62 const std::string& window_id, |
63 const gfx::Rect& bounds, | 63 const gfx::Rect& bounds, |
64 ui::WindowShowState state) { | 64 ui::WindowShowState state) { |
65 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 65 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
66 base::DictionaryValue* value = new base::DictionaryValue; | 66 base::DictionaryValue* value = new base::DictionaryValue; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // The first added window should no longer have cached geometry. | 247 // The first added window should no longer have cached geometry. |
248 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL)); | 248 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL)); |
249 // All other windows should still exist. | 249 // All other windows should still exist. |
250 for (size_t i = 1; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) { | 250 for (size_t i = 1; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) { |
251 std::string window_id = "window_" + base::IntToString(i); | 251 std::string window_id = "window_" + base::IntToString(i); |
252 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL)); | 252 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL)); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 } // namespace extensions | 256 } // namespace extensions |
OLD | NEW |