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

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new usage of scale in FastShowPickler Created 7 years, 3 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 | Annotate | Revision Log
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 52 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
53 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION); 53 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION);
54 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon); 54 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
55 #endif 55 #endif
56 56
57 return icon; 57 return icon;
58 } 58 }
59 59
60 bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1, 60 bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
61 const gfx::ImageSkia& i2, 61 const gfx::ImageSkia& i2,
62 ui::ScaleFactor scale_factor) { 62 float scale) {
63 SkBitmap bitmap1 = i1.GetRepresentation(scale_factor).sk_bitmap(); 63 SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
64 SkBitmap bitmap2 = i2.GetRepresentation(scale_factor).sk_bitmap(); 64 SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap();
65 return gfx::BitmapsAreEqual(bitmap1, bitmap2); 65 return gfx::BitmapsAreEqual(bitmap1, bitmap2);
66 } 66 }
67 67
68 class BrowserActionApiTest : public ExtensionApiTest { 68 class BrowserActionApiTest : public ExtensionApiTest {
69 public: 69 public:
70 BrowserActionApiTest() {} 70 BrowserActionApiTest() {}
71 virtual ~BrowserActionApiTest() {} 71 virtual ~BrowserActionApiTest() {}
72 72
73 protected: 73 protected:
74 BrowserActionTestUtil GetBrowserActionsBar() { 74 BrowserActionTestUtil GetBrowserActionsBar() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 129 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
130 const Extension* extension = GetSingleLoadedExtension(); 130 const Extension* extension = GetSingleLoadedExtension();
131 ASSERT_TRUE(extension) << message_; 131 ASSERT_TRUE(extension) << message_;
132 132
133 #if defined (OS_MACOSX) 133 #if defined (OS_MACOSX)
134 // We need this on mac so we don't loose 2x representations from browser icon 134 // We need this on mac so we don't loose 2x representations from browser icon
135 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia. 135 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia.
136 std::vector<ui::ScaleFactor> supported_scale_factors; 136 std::vector<ui::ScaleFactor> supported_scale_factors;
137 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); 137 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
138 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); 138 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
139 ui::test::SetSupportedScaleFactors(supported_scale_factors); 139 ui::SetSupportedScaleFactors(supported_scale_factors);
140 #endif 140 #endif
141 141
142 // We should not be creating icons asynchronously, so we don't need an 142 // We should not be creating icons asynchronously, so we don't need an
143 // observer. 143 // observer.
144 ExtensionActionIconFactory icon_factory( 144 ExtensionActionIconFactory icon_factory(
145 profile(), 145 profile(),
146 extension, 146 extension,
147 GetBrowserAction(*extension), 147 GetBrowserAction(*extension),
148 NULL); 148 NULL);
149 // Test that there is a browser action in the toolbar. 149 // Test that there is a browser action in the toolbar.
(...skipping 14 matching lines...) Expand all
164 // Tell the extension to update the icon using ImageData object. 164 // Tell the extension to update the icon using ImageData object.
165 GetBrowserActionsBar().Press(0); 165 GetBrowserActionsBar().Press(0);
166 ASSERT_TRUE(catcher.GetNextResult()); 166 ASSERT_TRUE(catcher.GetNextResult());
167 167
168 action_icon = icon_factory.GetIcon(0); 168 action_icon = icon_factory.GetIcon(0);
169 169
170 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 170 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
171 EXPECT_GT(action_icon_current_id, action_icon_last_id); 171 EXPECT_GT(action_icon_current_id, action_icon_last_id);
172 action_icon_last_id = action_icon_current_id; 172 action_icon_last_id = action_icon_current_id;
173 173
174 EXPECT_FALSE( 174 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
175 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
176 175
177 EXPECT_TRUE(ImagesAreEqualAtScale( 176 EXPECT_TRUE(ImagesAreEqualAtScale(
178 AddBackgroundForViews(*action_icon.ToImageSkia()), 177 AddBackgroundForViews(*action_icon.ToImageSkia()),
179 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 178 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
180 ui::SCALE_FACTOR_100P)); 179 1.0f));
181 180
182 // Tell the extension to update the icon using path. 181 // Tell the extension to update the icon using path.
183 GetBrowserActionsBar().Press(0); 182 GetBrowserActionsBar().Press(0);
184 ASSERT_TRUE(catcher.GetNextResult()); 183 ASSERT_TRUE(catcher.GetNextResult());
185 184
186 action_icon = icon_factory.GetIcon(0); 185 action_icon = icon_factory.GetIcon(0);
187 186
188 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 187 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
189 EXPECT_GT(action_icon_current_id, action_icon_last_id); 188 EXPECT_GT(action_icon_current_id, action_icon_last_id);
190 action_icon_last_id = action_icon_current_id; 189 action_icon_last_id = action_icon_current_id;
191 190
192 EXPECT_FALSE( 191 EXPECT_FALSE(
193 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 192 action_icon.ToImageSkia()->HasRepresentation(2.0f));
194 193
195 EXPECT_TRUE(ImagesAreEqualAtScale( 194 EXPECT_TRUE(ImagesAreEqualAtScale(
196 AddBackgroundForViews(*action_icon.ToImageSkia()), 195 AddBackgroundForViews(*action_icon.ToImageSkia()),
197 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 196 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
198 ui::SCALE_FACTOR_100P)); 197 1.0f));
199 198
200 // Tell the extension to update the icon using dictionary of ImageData 199 // Tell the extension to update the icon using dictionary of ImageData
201 // objects. 200 // objects.
202 GetBrowserActionsBar().Press(0); 201 GetBrowserActionsBar().Press(0);
203 ASSERT_TRUE(catcher.GetNextResult()); 202 ASSERT_TRUE(catcher.GetNextResult());
204 203
205 action_icon = icon_factory.GetIcon(0); 204 action_icon = icon_factory.GetIcon(0);
206 205
207 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 206 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
208 EXPECT_GT(action_icon_current_id, action_icon_last_id); 207 EXPECT_GT(action_icon_current_id, action_icon_last_id);
209 action_icon_last_id = action_icon_current_id; 208 action_icon_last_id = action_icon_current_id;
210 209
211 EXPECT_TRUE( 210 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
212 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
213 211
214 EXPECT_TRUE(ImagesAreEqualAtScale( 212 EXPECT_TRUE(ImagesAreEqualAtScale(
215 AddBackgroundForViews(*action_icon.ToImageSkia()), 213 AddBackgroundForViews(*action_icon.ToImageSkia()),
216 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 214 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
217 ui::SCALE_FACTOR_100P)); 215 1.0f));
218 216
219 // Tell the extension to update the icon using dictionary of paths. 217 // Tell the extension to update the icon using dictionary of paths.
220 GetBrowserActionsBar().Press(0); 218 GetBrowserActionsBar().Press(0);
221 ASSERT_TRUE(catcher.GetNextResult()); 219 ASSERT_TRUE(catcher.GetNextResult());
222 220
223 action_icon = icon_factory.GetIcon(0); 221 action_icon = icon_factory.GetIcon(0);
224 222
225 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 223 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
226 EXPECT_GT(action_icon_current_id, action_icon_last_id); 224 EXPECT_GT(action_icon_current_id, action_icon_last_id);
227 action_icon_last_id = action_icon_current_id; 225 action_icon_last_id = action_icon_current_id;
228 226
229 EXPECT_TRUE( 227 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
230 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
231 228
232 EXPECT_TRUE(ImagesAreEqualAtScale( 229 EXPECT_TRUE(ImagesAreEqualAtScale(
233 AddBackgroundForViews(*action_icon.ToImageSkia()), 230 AddBackgroundForViews(*action_icon.ToImageSkia()),
234 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 231 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
235 ui::SCALE_FACTOR_100P)); 232 1.0f));
236 233
237 // Tell the extension to update the icon using dictionary of ImageData 234 // Tell the extension to update the icon using dictionary of ImageData
238 // objects, but setting only size 19. 235 // objects, but setting only size 19.
239 GetBrowserActionsBar().Press(0); 236 GetBrowserActionsBar().Press(0);
240 ASSERT_TRUE(catcher.GetNextResult()); 237 ASSERT_TRUE(catcher.GetNextResult());
241 238
242 action_icon = icon_factory.GetIcon(0); 239 action_icon = icon_factory.GetIcon(0);
243 240
244 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 241 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
245 EXPECT_GT(action_icon_current_id, action_icon_last_id); 242 EXPECT_GT(action_icon_current_id, action_icon_last_id);
246 action_icon_last_id = action_icon_current_id; 243 action_icon_last_id = action_icon_current_id;
247 244
248 EXPECT_FALSE( 245 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
249 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
250 246
251 EXPECT_TRUE(ImagesAreEqualAtScale( 247 EXPECT_TRUE(ImagesAreEqualAtScale(
252 AddBackgroundForViews(*action_icon.ToImageSkia()), 248 AddBackgroundForViews(*action_icon.ToImageSkia()),
253 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 249 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
254 ui::SCALE_FACTOR_100P)); 250 1.0f));
255 251
256 // Tell the extension to update the icon using dictionary of paths, but 252 // Tell the extension to update the icon using dictionary of paths, but
257 // setting only size 19. 253 // setting only size 19.
258 GetBrowserActionsBar().Press(0); 254 GetBrowserActionsBar().Press(0);
259 ASSERT_TRUE(catcher.GetNextResult()); 255 ASSERT_TRUE(catcher.GetNextResult());
260 256
261 action_icon = icon_factory.GetIcon(0); 257 action_icon = icon_factory.GetIcon(0);
262 258
263 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 259 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
264 EXPECT_GT(action_icon_current_id, action_icon_last_id); 260 EXPECT_GT(action_icon_current_id, action_icon_last_id);
265 action_icon_last_id = action_icon_current_id; 261 action_icon_last_id = action_icon_current_id;
266 262
267 EXPECT_FALSE( 263 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
268 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
269 264
270 EXPECT_TRUE(ImagesAreEqualAtScale( 265 EXPECT_TRUE(ImagesAreEqualAtScale(
271 AddBackgroundForViews(*action_icon.ToImageSkia()), 266 AddBackgroundForViews(*action_icon.ToImageSkia()),
272 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 267 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
273 ui::SCALE_FACTOR_100P)); 268 1.0f));
274 269
275 // Tell the extension to update the icon using dictionary of ImageData 270 // Tell the extension to update the icon using dictionary of ImageData
276 // objects, but setting only size 38. 271 // objects, but setting only size 38.
277 GetBrowserActionsBar().Press(0); 272 GetBrowserActionsBar().Press(0);
278 ASSERT_TRUE(catcher.GetNextResult()); 273 ASSERT_TRUE(catcher.GetNextResult());
279 274
280 action_icon = icon_factory.GetIcon(0); 275 action_icon = icon_factory.GetIcon(0);
281 276
282 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); 277 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
283 278
284 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P)); 279 EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f));
285 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P)); 280 EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f));
286 281
287 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 282 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
288 EXPECT_GT(action_icon_current_id, action_icon_last_id); 283 EXPECT_GT(action_icon_current_id, action_icon_last_id);
289 action_icon_last_id = action_icon_current_id; 284 action_icon_last_id = action_icon_current_id;
290 285
291 EXPECT_TRUE(gfx::BitmapsAreEqual( 286 EXPECT_TRUE(gfx::BitmapsAreEqual(
292 *action_icon.ToSkBitmap(), 287 *action_icon.ToSkBitmap(),
293 action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap())); 288 action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
294 289
295 EXPECT_TRUE(ImagesAreEqualAtScale( 290 EXPECT_TRUE(ImagesAreEqualAtScale(
296 AddBackgroundForViews(*action_icon_skia), 291 AddBackgroundForViews(*action_icon_skia),
297 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 292 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
298 ui::SCALE_FACTOR_200P)); 293 2.0f));
299 294
300 // Try setting icon with empty dictionary of ImageData objects. 295 // Try setting icon with empty dictionary of ImageData objects.
301 GetBrowserActionsBar().Press(0); 296 GetBrowserActionsBar().Press(0);
302 ASSERT_FALSE(catcher.GetNextResult()); 297 ASSERT_FALSE(catcher.GetNextResult());
303 EXPECT_EQ(kEmptyImageDataError, catcher.message()); 298 EXPECT_EQ(kEmptyImageDataError, catcher.message());
304 299
305 // Try setting icon with empty dictionary of path objects. 300 // Try setting icon with empty dictionary of path objects.
306 GetBrowserActionsBar().Press(0); 301 GetBrowserActionsBar().Press(0);
307 ASSERT_FALSE(catcher.GetNextResult()); 302 ASSERT_FALSE(catcher.GetNextResult());
308 EXPECT_EQ(kEmptyPathError, catcher.message()); 303 EXPECT_EQ(kEmptyPathError, catcher.message());
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 "backgroundColor);"; 688 "backgroundColor);";
694 std::string result; 689 std::string result;
695 const std::string frame_xpath; 690 const std::string frame_xpath;
696 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString( 691 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString(
697 tab, frame_xpath, script, &result)); 692 tab, frame_xpath, script, &result));
698 EXPECT_EQ(result, "red"); 693 EXPECT_EQ(result, "red");
699 } 694 }
700 695
701 } // namespace 696 } // namespace
702 } // namespace extensions 697 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698