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

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: disable unittest on android 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 125 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
125 const Extension* extension = GetSingleLoadedExtension(); 126 const Extension* extension = GetSingleLoadedExtension();
126 ASSERT_TRUE(extension) << message_; 127 ASSERT_TRUE(extension) << message_;
127 128
128 #if defined (OS_MACOSX) 129 #if defined (OS_MACOSX)
129 // We need this on mac so we don't loose 2x representations from browser icon 130 // We need this on mac so we don't loose 2x representations from browser icon
130 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia. 131 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia.
131 gfx::test::SetSupportedScaleFactorsTo1xAnd2x(); 132 gfx::test::SetSupportedScaleFactorsTo1xAnd2x();
132 #endif 133 #endif
133 134
135 // We should not be creating icons asynchronously, so we don't need an
136 // observer.
137 ExtensionActionIconFactory icon_factory(extension,
138 extension->browser_action(),
139 NULL);
134 // Test that there is a browser action in the toolbar. 140 // Test that there is a browser action in the toolbar.
135 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 141 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
136 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); 142 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
137 143
138 gfx::Image action_icon = extension->browser_action()->GetIcon(0); 144 gfx::Image action_icon = icon_factory.GetIcon(0);
139 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); 145 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID();
140 146
141 // Let's check that |GetIcon| doesn't always return bitmap with new id. 147 // Let's check that |GetIcon| doesn't always return bitmap with new id.
142 ASSERT_EQ(action_icon_last_id, 148 ASSERT_EQ(action_icon_last_id,
143 extension->browser_action()->GetIcon(0).ToSkBitmap()-> 149 icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID());
144 getGenerationID());
145 150
146 uint32_t action_icon_current_id = 0; 151 uint32_t action_icon_current_id = 0;
147 152
148 ResultCatcher catcher; 153 ResultCatcher catcher;
149 154
150 // Tell the extension to update the icon using ImageData object. 155 // Tell the extension to update the icon using ImageData object.
151 GetBrowserActionsBar().Press(0); 156 GetBrowserActionsBar().Press(0);
152 ASSERT_TRUE(catcher.GetNextResult()); 157 ASSERT_TRUE(catcher.GetNextResult());
153 158
154 action_icon = extension->browser_action()->GetIcon(0); 159 action_icon = icon_factory.GetIcon(0);
155 160
156 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 161 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
157 EXPECT_GT(action_icon_current_id, action_icon_last_id); 162 EXPECT_GT(action_icon_current_id, action_icon_last_id);
158 action_icon_last_id = action_icon_current_id; 163 action_icon_last_id = action_icon_current_id;
159 164
160 EXPECT_FALSE( 165 EXPECT_FALSE(
161 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 166 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
162 167
163 EXPECT_TRUE(ImagesAreEqualAtScale( 168 EXPECT_TRUE(ImagesAreEqualAtScale(
164 AddBackgroundForViews(*action_icon.ToImageSkia()), 169 AddBackgroundForViews(*action_icon.ToImageSkia()),
165 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 170 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
166 ui::SCALE_FACTOR_100P)); 171 ui::SCALE_FACTOR_100P));
167 172
168 // Tell the extension to update the icon using path. 173 // Tell the extension to update the icon using path.
169 GetBrowserActionsBar().Press(0); 174 GetBrowserActionsBar().Press(0);
170 ASSERT_TRUE(catcher.GetNextResult()); 175 ASSERT_TRUE(catcher.GetNextResult());
171 176
172 action_icon = extension->browser_action()->GetIcon(0); 177 action_icon = icon_factory.GetIcon(0);
173 178
174 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 179 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
175 EXPECT_GT(action_icon_current_id, action_icon_last_id); 180 EXPECT_GT(action_icon_current_id, action_icon_last_id);
176 action_icon_last_id = action_icon_current_id; 181 action_icon_last_id = action_icon_current_id;
177 182
178 EXPECT_FALSE( 183 EXPECT_FALSE(
179 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 184 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
180 185
181 EXPECT_TRUE(ImagesAreEqualAtScale( 186 EXPECT_TRUE(ImagesAreEqualAtScale(
182 AddBackgroundForViews(*action_icon.ToImageSkia()), 187 AddBackgroundForViews(*action_icon.ToImageSkia()),
183 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 188 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
184 ui::SCALE_FACTOR_100P)); 189 ui::SCALE_FACTOR_100P));
185 190
186 // Tell the extension to update the icon using dictionary of ImageData 191 // Tell the extension to update the icon using dictionary of ImageData
187 // objects. 192 // objects.
188 GetBrowserActionsBar().Press(0); 193 GetBrowserActionsBar().Press(0);
189 ASSERT_TRUE(catcher.GetNextResult()); 194 ASSERT_TRUE(catcher.GetNextResult());
190 195
191 action_icon = extension->browser_action()->GetIcon(0); 196 action_icon = icon_factory.GetIcon(0);
192 197
193 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 198 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
194 EXPECT_GT(action_icon_current_id, action_icon_last_id); 199 EXPECT_GT(action_icon_current_id, action_icon_last_id);
195 action_icon_last_id = action_icon_current_id; 200 action_icon_last_id = action_icon_current_id;
196 201
197 EXPECT_TRUE( 202 EXPECT_TRUE(
198 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 203 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
199 204
200 EXPECT_TRUE(ImagesAreEqualAtScale( 205 EXPECT_TRUE(ImagesAreEqualAtScale(
201 AddBackgroundForViews(*action_icon.ToImageSkia()), 206 AddBackgroundForViews(*action_icon.ToImageSkia()),
202 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 207 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
203 ui::SCALE_FACTOR_100P)); 208 ui::SCALE_FACTOR_100P));
204 209
205 // Tell the extension to update the icon using dictionary of paths. 210 // Tell the extension to update the icon using dictionary of paths.
206 GetBrowserActionsBar().Press(0); 211 GetBrowserActionsBar().Press(0);
207 ASSERT_TRUE(catcher.GetNextResult()); 212 ASSERT_TRUE(catcher.GetNextResult());
208 213
209 action_icon = extension->browser_action()->GetIcon(0); 214 action_icon = icon_factory.GetIcon(0);
210 215
211 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 216 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
212 EXPECT_GT(action_icon_current_id, action_icon_last_id); 217 EXPECT_GT(action_icon_current_id, action_icon_last_id);
213 action_icon_last_id = action_icon_current_id; 218 action_icon_last_id = action_icon_current_id;
214 219
215 EXPECT_TRUE( 220 EXPECT_TRUE(
216 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 221 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
217 222
218 EXPECT_TRUE(ImagesAreEqualAtScale( 223 EXPECT_TRUE(ImagesAreEqualAtScale(
219 AddBackgroundForViews(*action_icon.ToImageSkia()), 224 AddBackgroundForViews(*action_icon.ToImageSkia()),
220 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 225 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
221 ui::SCALE_FACTOR_100P)); 226 ui::SCALE_FACTOR_100P));
222 227
223 // Tell the extension to update the icon using dictionary of ImageData 228 // Tell the extension to update the icon using dictionary of ImageData
224 // objects, but setting only size 19. 229 // objects, but setting only size 19.
225 GetBrowserActionsBar().Press(0); 230 GetBrowserActionsBar().Press(0);
226 ASSERT_TRUE(catcher.GetNextResult()); 231 ASSERT_TRUE(catcher.GetNextResult());
227 232
228 action_icon = extension->browser_action()->GetIcon(0); 233 action_icon = icon_factory.GetIcon(0);
229 234
230 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 235 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
231 EXPECT_GT(action_icon_current_id, action_icon_last_id); 236 EXPECT_GT(action_icon_current_id, action_icon_last_id);
232 action_icon_last_id = action_icon_current_id; 237 action_icon_last_id = action_icon_current_id;
233 238
234 EXPECT_FALSE( 239 EXPECT_FALSE(
235 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 240 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
236 241
237 EXPECT_TRUE(ImagesAreEqualAtScale( 242 EXPECT_TRUE(ImagesAreEqualAtScale(
238 AddBackgroundForViews(*action_icon.ToImageSkia()), 243 AddBackgroundForViews(*action_icon.ToImageSkia()),
239 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 244 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
240 ui::SCALE_FACTOR_100P)); 245 ui::SCALE_FACTOR_100P));
241 246
242 // Tell the extension to update the icon using dictionary of paths, but 247 // Tell the extension to update the icon using dictionary of paths, but
243 // setting only size 19. 248 // setting only size 19.
244 GetBrowserActionsBar().Press(0); 249 GetBrowserActionsBar().Press(0);
245 ASSERT_TRUE(catcher.GetNextResult()); 250 ASSERT_TRUE(catcher.GetNextResult());
246 251
247 action_icon = extension->browser_action()->GetIcon(0); 252 action_icon = icon_factory.GetIcon(0);
248 253
249 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 254 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
250 EXPECT_GT(action_icon_current_id, action_icon_last_id); 255 EXPECT_GT(action_icon_current_id, action_icon_last_id);
251 action_icon_last_id = action_icon_current_id; 256 action_icon_last_id = action_icon_current_id;
252 257
253 EXPECT_FALSE( 258 EXPECT_FALSE(
254 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); 259 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
255 260
256 EXPECT_TRUE(ImagesAreEqualAtScale( 261 EXPECT_TRUE(ImagesAreEqualAtScale(
257 AddBackgroundForViews(*action_icon.ToImageSkia()), 262 AddBackgroundForViews(*action_icon.ToImageSkia()),
258 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 263 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
259 ui::SCALE_FACTOR_100P)); 264 ui::SCALE_FACTOR_100P));
260 265
261 // Tell the extension to update the icon using dictionary of ImageData 266 // Tell the extension to update the icon using dictionary of ImageData
262 // objects, but setting only size 38. 267 // objects, but setting only size 38.
263 GetBrowserActionsBar().Press(0); 268 GetBrowserActionsBar().Press(0);
264 ASSERT_TRUE(catcher.GetNextResult()); 269 ASSERT_TRUE(catcher.GetNextResult());
265 270
266 action_icon = extension->browser_action()->GetIcon(0); 271 action_icon = icon_factory.GetIcon(0);
267 272
268 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); 273 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
269 274
270 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P)); 275 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P));
271 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P)); 276 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P));
272 277
273 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 278 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
274 EXPECT_GT(action_icon_current_id, action_icon_last_id); 279 EXPECT_GT(action_icon_current_id, action_icon_last_id);
275 action_icon_last_id = action_icon_current_id; 280 action_icon_last_id = action_icon_current_id;
276 281
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 GURL(extension->GetResourceURL("update.html"))); 640 GURL(extension->GetResourceURL("update.html")));
636 ASSERT_TRUE(catcher.GetNextResult()); 641 ASSERT_TRUE(catcher.GetNextResult());
637 642
638 // Test the getters for a specific tab. 643 // Test the getters for a specific tab.
639 ui_test_utils::NavigateToURL(browser(), 644 ui_test_utils::NavigateToURL(browser(),
640 GURL(extension->GetResourceURL("update2.html"))); 645 GURL(extension->GetResourceURL("update2.html")));
641 ASSERT_TRUE(catcher.GetNextResult()); 646 ASSERT_TRUE(catcher.GetNextResult());
642 } 647 }
643 648
644 } // namespace 649 } // namespace
OLDNEW
« no previous file with comments | « build/android/gtest_filter/unit_tests_disabled ('k') | chrome/browser/extensions/api/extension_action/page_action_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698