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

Side by Side Diff: chrome/browser/extensions/extension_icon_manager_unittest.cc

Issue 925783002: Split ValueSerializer into separate Serializer and Deserializer classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cpplint warnings. Created 5 years, 9 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
OLDNEW
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 "base/json/json_file_value_serializer.h" 5 #include "base/json/json_file_value_serializer.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_icon_manager.h" 9 #include "chrome/browser/extensions/extension_icon_manager.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Tests loading an icon for an extension, removing it, then re-loading it. 101 // Tests loading an icon for an extension, removing it, then re-loading it.
102 TEST_F(ExtensionIconManagerTest, LoadRemoveLoad) { 102 TEST_F(ExtensionIconManagerTest, LoadRemoveLoad) {
103 scoped_ptr<Profile> profile(new TestingProfile()); 103 scoped_ptr<Profile> profile(new TestingProfile());
104 SkBitmap default_icon = GetDefaultIcon(); 104 SkBitmap default_icon = GetDefaultIcon();
105 105
106 base::FilePath test_dir; 106 base::FilePath test_dir;
107 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 107 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
108 base::FilePath manifest_path = test_dir.AppendASCII( 108 base::FilePath manifest_path = test_dir.AppendASCII(
109 "extensions/image_loading_tracker/app.json"); 109 "extensions/image_loading_tracker/app.json");
110 110
111 JSONFileValueSerializer serializer(manifest_path); 111 JSONFileValueDeserializer deserializer(manifest_path);
112 scoped_ptr<base::DictionaryValue> manifest( 112 scoped_ptr<base::DictionaryValue> manifest(
113 static_cast<base::DictionaryValue*>(serializer.Deserialize(NULL, NULL))); 113 static_cast<base::DictionaryValue*>(deserializer.Deserialize(NULL,
114 NULL)));
114 ASSERT_TRUE(manifest.get() != NULL); 115 ASSERT_TRUE(manifest.get() != NULL);
115 116
116 std::string error; 117 std::string error;
117 scoped_refptr<Extension> extension(Extension::Create( 118 scoped_refptr<Extension> extension(Extension::Create(
118 manifest_path.DirName(), Manifest::INVALID_LOCATION, *manifest.get(), 119 manifest_path.DirName(), Manifest::INVALID_LOCATION, *manifest.get(),
119 Extension::NO_FLAGS, &error)); 120 Extension::NO_FLAGS, &error));
120 ASSERT_TRUE(extension.get()); 121 ASSERT_TRUE(extension.get());
121 TestIconManager icon_manager(this); 122 TestIconManager icon_manager(this);
122 123
123 // Load the icon and grab the bitmap. 124 // Load the icon and grab the bitmap.
(...skipping 19 matching lines...) Expand all
143 // Tests loading an icon for a component extension. 144 // Tests loading an icon for a component extension.
144 TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) { 145 TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) {
145 scoped_ptr<Profile> profile(new TestingProfile()); 146 scoped_ptr<Profile> profile(new TestingProfile());
146 SkBitmap default_icon = GetDefaultIcon(); 147 SkBitmap default_icon = GetDefaultIcon();
147 148
148 base::FilePath test_dir; 149 base::FilePath test_dir;
149 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 150 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
150 base::FilePath manifest_path = test_dir.AppendASCII( 151 base::FilePath manifest_path = test_dir.AppendASCII(
151 "extensions/file_manager/app.json"); 152 "extensions/file_manager/app.json");
152 153
153 JSONFileValueSerializer serializer(manifest_path); 154 JSONFileValueDeserializer deserializer(manifest_path);
154 scoped_ptr<base::DictionaryValue> manifest( 155 scoped_ptr<base::DictionaryValue> manifest(
155 static_cast<base::DictionaryValue*>(serializer.Deserialize(NULL, NULL))); 156 static_cast<base::DictionaryValue*>(deserializer.Deserialize(NULL,
157 NULL)));
156 ASSERT_TRUE(manifest.get() != NULL); 158 ASSERT_TRUE(manifest.get() != NULL);
157 159
158 std::string error; 160 std::string error;
159 scoped_refptr<Extension> extension(Extension::Create( 161 scoped_refptr<Extension> extension(Extension::Create(
160 manifest_path.DirName(), Manifest::COMPONENT, *manifest.get(), 162 manifest_path.DirName(), Manifest::COMPONENT, *manifest.get(),
161 Extension::NO_FLAGS, &error)); 163 Extension::NO_FLAGS, &error));
162 ASSERT_TRUE(extension.get()); 164 ASSERT_TRUE(extension.get());
163 165
164 TestIconManager icon_manager(this); 166 TestIconManager icon_manager(this);
165 // Load the icon and grab the bitmap. 167 // Load the icon and grab the bitmap.
166 icon_manager.LoadIcon(profile.get(), extension.get()); 168 icon_manager.LoadIcon(profile.get(), extension.get());
167 WaitForImageLoad(); 169 WaitForImageLoad();
168 SkBitmap first_icon = icon_manager.GetIcon(extension->id()); 170 SkBitmap first_icon = icon_manager.GetIcon(extension->id());
169 EXPECT_FALSE(gfx::BitmapsAreEqual(first_icon, default_icon)); 171 EXPECT_FALSE(gfx::BitmapsAreEqual(first_icon, default_icon));
170 172
171 // Remove the icon from the manager. 173 // Remove the icon from the manager.
172 icon_manager.RemoveIcon(extension->id()); 174 icon_manager.RemoveIcon(extension->id());
173 175
174 // Now re-load the icon - we should get the same result bitmap (and not the 176 // Now re-load the icon - we should get the same result bitmap (and not the
175 // default icon). 177 // default icon).
176 icon_manager.LoadIcon(profile.get(), extension.get()); 178 icon_manager.LoadIcon(profile.get(), extension.get());
177 WaitForImageLoad(); 179 WaitForImageLoad();
178 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); 180 SkBitmap second_icon = icon_manager.GetIcon(extension->id());
179 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); 181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon));
180 182
181 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); 183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon));
182 } 184 }
183 #endif 185 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698