Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: apps/app_window_geometry_cache_unittest.cc

Issue 270703003: Use ExtensionRegistryObserver instead of DEPRECATED extension notify from app_window_geometry_cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit_tests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/app_window_geometry_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "apps/app_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 "extensions/common/extension_builder.h"
15 #include "extensions/common/value_builder.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 const char kWindowId[] = "windowid";
17 const char kWindowId2[] = "windowid2";
18
19 using content::BrowserThread; 18 using content::BrowserThread;
20 19
21 namespace apps { 20 namespace apps {
22 21
22 namespace {
23 const char kWindowId[] = "windowid";
24 const char kWindowId2[] = "windowid2";
25
26 // Create a very simple extension with id.
27 scoped_refptr<extensions::Extension> CreateExtension(const std::string& id) {
28 return extensions::ExtensionBuilder()
29 .SetManifest(extensions::DictionaryBuilder().Set("name", "test").Set(
30 "version", "0.1"))
31 .SetID(id)
32 .Build();
33 }
34
35 } // namespace
36
23 // Base class for tests. 37 // Base class for tests.
24 class AppWindowGeometryCacheTest : public testing::Test { 38 class AppWindowGeometryCacheTest : public testing::Test {
25 public: 39 public:
26 AppWindowGeometryCacheTest() 40 AppWindowGeometryCacheTest()
27 : ui_thread_(BrowserThread::UI, &ui_message_loop_) { 41 : profile_(new TestingProfile),
42 ui_thread_(BrowserThread::UI, &ui_message_loop_) {
28 prefs_.reset(new extensions::TestExtensionPrefs( 43 prefs_.reset(new extensions::TestExtensionPrefs(
29 ui_message_loop_.message_loop_proxy().get())); 44 ui_message_loop_.message_loop_proxy().get()));
30 cache_.reset(new AppWindowGeometryCache(&profile_, prefs_->prefs())); 45 cache_.reset(new AppWindowGeometryCache(profile_.get(), prefs_->prefs()));
31 cache_->SetSyncDelayForTests(0); 46 cache_->SetSyncDelayForTests(0);
32 } 47 }
33 48
34 void AddGeometryAndLoadExtension(const std::string& extension_id, 49 void AddGeometryAndLoadExtension(const std::string& extension_id,
35 const std::string& window_id, 50 const std::string& window_id,
36 const gfx::Rect& bounds, 51 const gfx::Rect& bounds,
37 const gfx::Rect& screen_bounds, 52 const gfx::Rect& screen_bounds,
38 ui::WindowShowState state); 53 ui::WindowShowState state);
39 54
40 // Spins the UI threads' message loops to make sure any task 55 // Spins the UI threads' message loops to make sure any task
41 // posted to sync the geometry to the value store gets a chance to run. 56 // posted to sync the geometry to the value store gets a chance to run.
42 void WaitForSync(); 57 void WaitForSync();
43 58
44 void LoadExtension(const std::string& extension_id); 59 void LoadExtension(const std::string& extension_id);
45 void UnloadExtension(const std::string& extension_id); 60 void UnloadExtension(const std::string& extension_id);
46 61
47 protected: 62 protected:
48 TestingProfile profile_; 63 scoped_ptr<TestingProfile> profile_;
49 base::MessageLoopForUI ui_message_loop_; 64 base::MessageLoopForUI ui_message_loop_;
50 content::TestBrowserThread ui_thread_; 65 content::TestBrowserThread ui_thread_;
51 scoped_ptr<extensions::TestExtensionPrefs> prefs_; 66 scoped_ptr<extensions::TestExtensionPrefs> prefs_;
52 scoped_ptr<AppWindowGeometryCache> cache_; 67 scoped_ptr<AppWindowGeometryCache> cache_;
53 }; 68 };
54 69
55 void AppWindowGeometryCacheTest::AddGeometryAndLoadExtension( 70 void AppWindowGeometryCacheTest::AddGeometryAndLoadExtension(
56 const std::string& extension_id, 71 const std::string& extension_id,
57 const std::string& window_id, 72 const std::string& window_id,
58 const gfx::Rect& bounds, 73 const gfx::Rect& bounds,
(...skipping 20 matching lines...) Expand all
79 } 94 }
80 95
81 void AppWindowGeometryCacheTest::LoadExtension( 96 void AppWindowGeometryCacheTest::LoadExtension(
82 const std::string& extension_id) { 97 const std::string& extension_id) {
83 cache_->LoadGeometryFromStorage(extension_id); 98 cache_->LoadGeometryFromStorage(extension_id);
84 WaitForSync(); 99 WaitForSync();
85 } 100 }
86 101
87 void AppWindowGeometryCacheTest::UnloadExtension( 102 void AppWindowGeometryCacheTest::UnloadExtension(
88 const std::string& extension_id) { 103 const std::string& extension_id) {
89 cache_->OnExtensionUnloaded(extension_id); 104 scoped_refptr<extensions::Extension> extension =
105 CreateExtension(extension_id);
106 cache_->OnExtensionUnloaded(
107 profile_.get(),
108 extension.get(),
109 extensions::UnloadedExtensionInfo::REASON_DISABLE);
90 WaitForSync(); 110 WaitForSync();
91 } 111 }
92 112
93 // Test getting geometry from an empty store. 113 // Test getting geometry from an empty store.
94 TEST_F(AppWindowGeometryCacheTest, GetGeometryEmptyStore) { 114 TEST_F(AppWindowGeometryCacheTest, GetGeometryEmptyStore) {
95 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1"); 115 const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
96 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL)); 116 ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL));
97 } 117 }
98 118
99 // Test getting geometry for an unknown extension. 119 // Test getting geometry for an unknown extension.
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // The first added window should no longer have cached geometry. 356 // The first added window should no longer have cached geometry.
337 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL)); 357 EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL, NULL));
338 // All other windows should still exist. 358 // All other windows should still exist.
339 for (size_t i = 1; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) { 359 for (size_t i = 1; i < AppWindowGeometryCache::kMaxCachedWindows + 1; ++i) {
340 std::string window_id = "window_" + base::IntToString(i); 360 std::string window_id = "window_" + base::IntToString(i);
341 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL)); 361 EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL));
342 } 362 }
343 } 363 }
344 364
345 } // namespace apps 365 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_window_geometry_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698