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

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

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: icon_factory: NULL check on the observer Created 8 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
11 #include "chrome/browser/extensions/browser_action_test_util.h" 11 #include "chrome/browser/extensions/browser_action_test_util.h"
12 #include "chrome/browser/extensions/extension_action_icon_factory.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 13 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h" 18 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_tabstrip.h" 19 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/extensions/extension_action.h" 22 #include "chrome/common/extensions/extension_action.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 134 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
134 const Extension* extension = GetSingleLoadedExtension(); 135 const Extension* extension = GetSingleLoadedExtension();
135 ASSERT_TRUE(extension) << message_; 136 ASSERT_TRUE(extension) << message_;
136 137
137 #if defined (OS_MACOSX) 138 #if defined (OS_MACOSX)
138 // We need this on mac so we don't loose 2x representations from browser icon 139 // We need this on mac so we don't loose 2x representations from browser icon
139 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia. 140 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia.
140 gfx::test::SetSupportedScaleFactorsTo1xAnd2x(); 141 gfx::test::SetSupportedScaleFactorsTo1xAnd2x();
141 #endif 142 #endif
142 143
144 // We should not be creating icons asynchronoulsy, so we don't need an
145 // observer.
146 ExtensionActionIconFactory icon_factory(extension, NULL);
147
143 // Test that there is a browser action in the toolbar. 148 // Test that there is a browser action in the toolbar.
144 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 149 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
145 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); 150 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
146 151
147 gfx::Image action_icon = extension->browser_action()->GetIcon(0); 152 gfx::Image action_icon =
153 icon_factory.GetIcon(extension->browser_action(), 0);
148 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); 154 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID();
149 155
150 // Let's check that |GetIcon| doesn't always return bitmap with new id. 156 // Let's check that |GetIcon| doesn't always return bitmap with new id.
151 ASSERT_EQ(action_icon_last_id, 157 ASSERT_EQ(action_icon_last_id,
152 extension->browser_action()->GetIcon(0).ToSkBitmap()-> 158 icon_factory.GetIcon(extension->browser_action(), 0).ToSkBitmap()->
153 getGenerationID()); 159 getGenerationID());
154 160
155 uint32_t action_icon_current_id = 0; 161 uint32_t action_icon_current_id = 0;
156 162
157 ResultCatcher catcher; 163 ResultCatcher catcher;
158 164
159 // Tell the extension to update the icon using ImageData object. 165 // Tell the extension to update the icon using ImageData object.
160 GetBrowserActionsBar().Press(0); 166 GetBrowserActionsBar().Press(0);
161 ASSERT_TRUE(catcher.GetNextResult()); 167 ASSERT_TRUE(catcher.GetNextResult());
162 168
163 action_icon = extension->browser_action()->GetIcon(0); 169 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
164 170
165 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 171 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
166 EXPECT_GT(action_icon_current_id, action_icon_last_id); 172 EXPECT_GT(action_icon_current_id, action_icon_last_id);
167 action_icon_last_id = action_icon_current_id; 173 action_icon_last_id = action_icon_current_id;
168 174
169 EXPECT_FALSE( 175 EXPECT_FALSE(
170 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 176 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
171 177
172 EXPECT_TRUE(ImagesAreEqualAtScale( 178 EXPECT_TRUE(ImagesAreEqualAtScale(
173 AddBackgroundForViews(*action_icon.ToImageSkia()), 179 AddBackgroundForViews(*action_icon.ToImageSkia()),
174 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 180 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
175 ui::SCALE_FACTOR_100P)); 181 ui::SCALE_FACTOR_100P));
176 182
177 // Tell the extension to update the icon using path. 183 // Tell the extension to update the icon using path.
178 GetBrowserActionsBar().Press(0); 184 GetBrowserActionsBar().Press(0);
179 ASSERT_TRUE(catcher.GetNextResult()); 185 ASSERT_TRUE(catcher.GetNextResult());
180 186
181 action_icon = extension->browser_action()->GetIcon(0); 187 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
182 188
183 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 189 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
184 EXPECT_GT(action_icon_current_id, action_icon_last_id); 190 EXPECT_GT(action_icon_current_id, action_icon_last_id);
185 action_icon_last_id = action_icon_current_id; 191 action_icon_last_id = action_icon_current_id;
186 192
187 EXPECT_FALSE( 193 EXPECT_FALSE(
188 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 194 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
189 195
190 EXPECT_TRUE(ImagesAreEqualAtScale( 196 EXPECT_TRUE(ImagesAreEqualAtScale(
191 AddBackgroundForViews(*action_icon.ToImageSkia()), 197 AddBackgroundForViews(*action_icon.ToImageSkia()),
192 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 198 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
193 ui::SCALE_FACTOR_100P)); 199 ui::SCALE_FACTOR_100P));
194 200
195 // Tell the extension to update the icon using dictionary of ImageData 201 // Tell the extension to update the icon using dictionary of ImageData
196 // objects. 202 // objects.
197 GetBrowserActionsBar().Press(0); 203 GetBrowserActionsBar().Press(0);
198 ASSERT_TRUE(catcher.GetNextResult()); 204 ASSERT_TRUE(catcher.GetNextResult());
199 205
200 action_icon = extension->browser_action()->GetIcon(0); 206 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
201 207
202 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 208 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
203 EXPECT_GT(action_icon_current_id, action_icon_last_id); 209 EXPECT_GT(action_icon_current_id, action_icon_last_id);
204 action_icon_last_id = action_icon_current_id; 210 action_icon_last_id = action_icon_current_id;
205 211
206 EXPECT_TRUE( 212 EXPECT_TRUE(
207 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 213 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
208 214
209 EXPECT_TRUE(ImagesAreEqualAtScale( 215 EXPECT_TRUE(ImagesAreEqualAtScale(
210 AddBackgroundForViews(*action_icon.ToImageSkia()), 216 AddBackgroundForViews(*action_icon.ToImageSkia()),
211 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 217 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
212 ui::SCALE_FACTOR_100P)); 218 ui::SCALE_FACTOR_100P));
213 219
214 // Tell the extension to update the icon using dictionary of paths. 220 // Tell the extension to update the icon using dictionary of paths.
215 GetBrowserActionsBar().Press(0); 221 GetBrowserActionsBar().Press(0);
216 ASSERT_TRUE(catcher.GetNextResult()); 222 ASSERT_TRUE(catcher.GetNextResult());
217 223
218 action_icon = extension->browser_action()->GetIcon(0); 224 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
219 225
220 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 226 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
221 EXPECT_GT(action_icon_current_id, action_icon_last_id); 227 EXPECT_GT(action_icon_current_id, action_icon_last_id);
222 action_icon_last_id = action_icon_current_id; 228 action_icon_last_id = action_icon_current_id;
223 229
224 EXPECT_TRUE( 230 EXPECT_TRUE(
225 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 231 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
226 232
227 EXPECT_TRUE(ImagesAreEqualAtScale( 233 EXPECT_TRUE(ImagesAreEqualAtScale(
228 AddBackgroundForViews(*action_icon.ToImageSkia()), 234 AddBackgroundForViews(*action_icon.ToImageSkia()),
229 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 235 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
230 ui::SCALE_FACTOR_100P)); 236 ui::SCALE_FACTOR_100P));
231 237
232 // Tell the extension to update the icon using dictionary of ImageData 238 // Tell the extension to update the icon using dictionary of ImageData
233 // objects, but setting only size 19. 239 // objects, but setting only size 19.
234 GetBrowserActionsBar().Press(0); 240 GetBrowserActionsBar().Press(0);
235 ASSERT_TRUE(catcher.GetNextResult()); 241 ASSERT_TRUE(catcher.GetNextResult());
236 242
237 action_icon = extension->browser_action()->GetIcon(0); 243 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
238 244
239 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 245 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
240 EXPECT_GT(action_icon_current_id, action_icon_last_id); 246 EXPECT_GT(action_icon_current_id, action_icon_last_id);
241 action_icon_last_id = action_icon_current_id; 247 action_icon_last_id = action_icon_current_id;
242 248
243 EXPECT_FALSE( 249 EXPECT_FALSE(
244 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 250 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
245 251
246 EXPECT_TRUE(ImagesAreEqualAtScale( 252 EXPECT_TRUE(ImagesAreEqualAtScale(
247 AddBackgroundForViews(*action_icon.ToImageSkia()), 253 AddBackgroundForViews(*action_icon.ToImageSkia()),
248 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 254 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
249 ui::SCALE_FACTOR_100P)); 255 ui::SCALE_FACTOR_100P));
250 256
251 // Tell the extension to update the icon using dictionary of paths, but 257 // Tell the extension to update the icon using dictionary of paths, but
252 // setting only size 19. 258 // setting only size 19.
253 GetBrowserActionsBar().Press(0); 259 GetBrowserActionsBar().Press(0);
254 ASSERT_TRUE(catcher.GetNextResult()); 260 ASSERT_TRUE(catcher.GetNextResult());
255 261
256 action_icon = extension->browser_action()->GetIcon(0); 262 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
257 263
258 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 264 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
259 EXPECT_GT(action_icon_current_id, action_icon_last_id); 265 EXPECT_GT(action_icon_current_id, action_icon_last_id);
260 action_icon_last_id = action_icon_current_id; 266 action_icon_last_id = action_icon_current_id;
261 267
262 EXPECT_FALSE( 268 EXPECT_FALSE(
263 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 269 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
264 270
265 EXPECT_TRUE(ImagesAreEqualAtScale( 271 EXPECT_TRUE(ImagesAreEqualAtScale(
266 AddBackgroundForViews(*action_icon.ToImageSkia()), 272 AddBackgroundForViews(*action_icon.ToImageSkia()),
267 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 273 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
268 ui::SCALE_FACTOR_100P)); 274 ui::SCALE_FACTOR_100P));
269 275
270 // Tell the extension to update the icon using dictionary of ImageData 276 // Tell the extension to update the icon using dictionary of ImageData
271 // objects, but setting only size 38. 277 // objects, but setting only size 38.
272 GetBrowserActionsBar().Press(0); 278 GetBrowserActionsBar().Press(0);
273 ASSERT_TRUE(catcher.GetNextResult()); 279 ASSERT_TRUE(catcher.GetNextResult());
274 280
275 action_icon = extension->browser_action()->GetIcon(0); 281 action_icon = icon_factory.GetIcon(extension->browser_action(), 0);
276 282
277 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); 283 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
278 284
279 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P)); 285 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P));
280 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P)); 286 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P));
281 287
282 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 288 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
283 EXPECT_GT(action_icon_current_id, action_icon_last_id); 289 EXPECT_GT(action_icon_current_id, action_icon_last_id);
284 action_icon_last_id = action_icon_current_id; 290 action_icon_last_id = action_icon_current_id;
285 291
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 GURL(extension->GetResourceURL("update.html"))); 650 GURL(extension->GetResourceURL("update.html")));
645 ASSERT_TRUE(catcher.GetNextResult()); 651 ASSERT_TRUE(catcher.GetNextResult());
646 652
647 // Test the getters for a specific tab. 653 // Test the getters for a specific tab.
648 ui_test_utils::NavigateToURL(browser(), 654 ui_test_utils::NavigateToURL(browser(),
649 GURL(extension->GetResourceURL("update2.html"))); 655 GURL(extension->GetResourceURL("update2.html")));
650 ASSERT_TRUE(catcher.GetNextResult()); 656 ASSERT_TRUE(catcher.GetNextResult());
651 } 657 }
652 658
653 } // namespace 659 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698