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

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

Issue 170843005: Fix BrowserActionApiTest.DynamicBrowserAction interaction with dev-mode highlighting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: , Created 6 years, 10 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
« no previous file with comments | « no previous file | 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 (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/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/browser_action_test_util.h" 12 #include "chrome/browser/extensions/browser_action_test_util.h"
13 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
13 #include "chrome/browser/extensions/extension_action.h" 14 #include "chrome/browser/extensions/extension_action.h"
14 #include "chrome/browser/extensions/extension_action_icon_factory.h" 15 #include "chrome/browser/extensions/extension_action_icon_factory.h"
15 #include "chrome/browser/extensions/extension_action_manager.h" 16 #include "chrome/browser/extensions/extension_action_manager.h"
16 #include "chrome/browser/extensions/extension_apitest.h" 17 #include "chrome/browser/extensions/extension_apitest.h"
17 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_tab_util.h" 19 #include "chrome/browser/extensions/extension_tab_util.h"
19 #include "chrome/browser/extensions/extension_toolbar_model.h" 20 #include "chrome/browser/extensions/extension_toolbar_model.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_commands.h" 23 #include "chrome/browser/ui/browser_commands.h"
(...skipping 18 matching lines...) Expand all
41 namespace extensions { 42 namespace extensions {
42 namespace { 43 namespace {
43 44
44 const char kEmptyImageDataError[] = 45 const char kEmptyImageDataError[] =
45 "The imageData property must contain an ImageData object or dictionary " 46 "The imageData property must contain an ImageData object or dictionary "
46 "of ImageData objects."; 47 "of ImageData objects.";
47 const char kEmptyPathError[] = "The path property must not be empty."; 48 const char kEmptyPathError[] = "The path property must not be empty.";
48 49
49 // Views implementation of browser action button will return icon whose 50 // Views implementation of browser action button will return icon whose
50 // background will be set. 51 // background will be set.
51 gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) { 52 gfx::ImageSkia AddBackgroundForViews(const Extension* extension,
53 const gfx::ImageSkia& icon) {
52 #if defined(TOOLKIT_VIEWS) 54 #if defined(TOOLKIT_VIEWS)
53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 55 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
54 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION); 56 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION);
57 // We may have a different background than the default - see
58 // BrowserActionButton::UpdateState.
59 if (extensions::DevModeBubbleController::IsDevModeExtension(extension))
60 bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION_HIGHLIGHT);
55 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon); 61 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
56 #endif 62 #endif
57 63
58 return icon; 64 return icon;
59 } 65 }
60 66
61 bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1, 67 bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
62 const gfx::ImageSkia& i2, 68 const gfx::ImageSkia& i2,
63 float scale) { 69 float scale) {
64 SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap(); 70 SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 174
169 action_icon = icon_factory.GetIcon(0); 175 action_icon = icon_factory.GetIcon(0);
170 176
171 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 177 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
172 EXPECT_GT(action_icon_current_id, action_icon_last_id); 178 EXPECT_GT(action_icon_current_id, action_icon_last_id);
173 action_icon_last_id = action_icon_current_id; 179 action_icon_last_id = action_icon_current_id;
174 180
175 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); 181 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
176 182
177 EXPECT_TRUE(ImagesAreEqualAtScale( 183 EXPECT_TRUE(ImagesAreEqualAtScale(
178 AddBackgroundForViews(*action_icon.ToImageSkia()), 184 AddBackgroundForViews(extension, *action_icon.ToImageSkia()),
179 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 185 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
180 1.0f)); 186 1.0f));
181 187
182 // Tell the extension to update the icon using path. 188 // Tell the extension to update the icon using path.
183 GetBrowserActionsBar().Press(0); 189 GetBrowserActionsBar().Press(0);
184 ASSERT_TRUE(catcher.GetNextResult()); 190 ASSERT_TRUE(catcher.GetNextResult());
185 191
186 action_icon = icon_factory.GetIcon(0); 192 action_icon = icon_factory.GetIcon(0);
187 193
188 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 194 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
189 EXPECT_GT(action_icon_current_id, action_icon_last_id); 195 EXPECT_GT(action_icon_current_id, action_icon_last_id);
190 action_icon_last_id = action_icon_current_id; 196 action_icon_last_id = action_icon_current_id;
191 197
192 EXPECT_FALSE( 198 EXPECT_FALSE(
193 action_icon.ToImageSkia()->HasRepresentation(2.0f)); 199 action_icon.ToImageSkia()->HasRepresentation(2.0f));
194 200
195 EXPECT_TRUE(ImagesAreEqualAtScale( 201 EXPECT_TRUE(ImagesAreEqualAtScale(
196 AddBackgroundForViews(*action_icon.ToImageSkia()), 202 AddBackgroundForViews(extension, *action_icon.ToImageSkia()),
197 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 203 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
198 1.0f)); 204 1.0f));
199 205
200 // Tell the extension to update the icon using dictionary of ImageData 206 // Tell the extension to update the icon using dictionary of ImageData
201 // objects. 207 // objects.
202 GetBrowserActionsBar().Press(0); 208 GetBrowserActionsBar().Press(0);
203 ASSERT_TRUE(catcher.GetNextResult()); 209 ASSERT_TRUE(catcher.GetNextResult());
204 210
205 action_icon = icon_factory.GetIcon(0); 211 action_icon = icon_factory.GetIcon(0);
206 212
207 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 213 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
208 EXPECT_GT(action_icon_current_id, action_icon_last_id); 214 EXPECT_GT(action_icon_current_id, action_icon_last_id);
209 action_icon_last_id = action_icon_current_id; 215 action_icon_last_id = action_icon_current_id;
210 216
211 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); 217 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
212 218
213 EXPECT_TRUE(ImagesAreEqualAtScale( 219 EXPECT_TRUE(ImagesAreEqualAtScale(
214 AddBackgroundForViews(*action_icon.ToImageSkia()), 220 AddBackgroundForViews(extension, *action_icon.ToImageSkia()),
215 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 221 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
216 1.0f)); 222 1.0f));
217 223
218 // Tell the extension to update the icon using dictionary of paths. 224 // Tell the extension to update the icon using dictionary of paths.
219 GetBrowserActionsBar().Press(0); 225 GetBrowserActionsBar().Press(0);
220 ASSERT_TRUE(catcher.GetNextResult()); 226 ASSERT_TRUE(catcher.GetNextResult());
221 227
222 action_icon = icon_factory.GetIcon(0); 228 action_icon = icon_factory.GetIcon(0);
223 229
224 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 230 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
225 EXPECT_GT(action_icon_current_id, action_icon_last_id); 231 EXPECT_GT(action_icon_current_id, action_icon_last_id);
226 action_icon_last_id = action_icon_current_id; 232 action_icon_last_id = action_icon_current_id;
227 233
228 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); 234 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
229 235
230 EXPECT_TRUE(ImagesAreEqualAtScale( 236 EXPECT_TRUE(ImagesAreEqualAtScale(
231 AddBackgroundForViews(*action_icon.ToImageSkia()), 237 AddBackgroundForViews(extension, *action_icon.ToImageSkia()),
232 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 238 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
233 1.0f)); 239 1.0f));
234 240
235 // Tell the extension to update the icon using dictionary of ImageData 241 // Tell the extension to update the icon using dictionary of ImageData
236 // objects, but setting only size 19. 242 // objects, but setting only size 19.
237 GetBrowserActionsBar().Press(0); 243 GetBrowserActionsBar().Press(0);
238 ASSERT_TRUE(catcher.GetNextResult()); 244 ASSERT_TRUE(catcher.GetNextResult());
239 245
240 action_icon = icon_factory.GetIcon(0); 246 action_icon = icon_factory.GetIcon(0);
241 247
242 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 248 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
243 EXPECT_GT(action_icon_current_id, action_icon_last_id); 249 EXPECT_GT(action_icon_current_id, action_icon_last_id);
244 action_icon_last_id = action_icon_current_id; 250 action_icon_last_id = action_icon_current_id;
245 251
246 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); 252 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
247 253
248 EXPECT_TRUE(ImagesAreEqualAtScale( 254 EXPECT_TRUE(ImagesAreEqualAtScale(
249 AddBackgroundForViews(*action_icon.ToImageSkia()), 255 AddBackgroundForViews(extension, *action_icon.ToImageSkia()),
250 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 256 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
251 1.0f)); 257 1.0f));
252 258
253 // Tell the extension to update the icon using dictionary of paths, but 259 // Tell the extension to update the icon using dictionary of paths, but
254 // setting only size 19. 260 // setting only size 19.
255 GetBrowserActionsBar().Press(0); 261 GetBrowserActionsBar().Press(0);
256 ASSERT_TRUE(catcher.GetNextResult()); 262 ASSERT_TRUE(catcher.GetNextResult());
257 263
258 action_icon = icon_factory.GetIcon(0); 264 action_icon = icon_factory.GetIcon(0);
259 265
260 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 266 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
261 EXPECT_GT(action_icon_current_id, action_icon_last_id); 267 EXPECT_GT(action_icon_current_id, action_icon_last_id);
262 action_icon_last_id = action_icon_current_id; 268 action_icon_last_id = action_icon_current_id;
263 269
264 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); 270 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
265 271
266 EXPECT_TRUE(ImagesAreEqualAtScale( 272 EXPECT_TRUE(ImagesAreEqualAtScale(
267 AddBackgroundForViews(*action_icon.ToImageSkia()), 273 AddBackgroundForViews(extension, *action_icon.ToImageSkia()),
268 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 274 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
269 1.0f)); 275 1.0f));
270 276
271 // Tell the extension to update the icon using dictionary of ImageData 277 // Tell the extension to update the icon using dictionary of ImageData
272 // objects, but setting only size 38. 278 // objects, but setting only size 38.
273 GetBrowserActionsBar().Press(0); 279 GetBrowserActionsBar().Press(0);
274 ASSERT_TRUE(catcher.GetNextResult()); 280 ASSERT_TRUE(catcher.GetNextResult());
275 281
276 action_icon = icon_factory.GetIcon(0); 282 action_icon = icon_factory.GetIcon(0);
277 283
278 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); 284 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
279 285
280 EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f)); 286 EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f));
281 EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f)); 287 EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f));
282 288
283 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 289 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
284 EXPECT_GT(action_icon_current_id, action_icon_last_id); 290 EXPECT_GT(action_icon_current_id, action_icon_last_id);
285 action_icon_last_id = action_icon_current_id; 291 action_icon_last_id = action_icon_current_id;
286 292
287 EXPECT_TRUE(gfx::BitmapsAreEqual( 293 EXPECT_TRUE(gfx::BitmapsAreEqual(
288 *action_icon.ToSkBitmap(), 294 *action_icon.ToSkBitmap(),
289 action_icon_skia->GetRepresentation(2.0f).sk_bitmap())); 295 action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
290 296
291 EXPECT_TRUE(ImagesAreEqualAtScale( 297 EXPECT_TRUE(
292 AddBackgroundForViews(*action_icon_skia), 298 ImagesAreEqualAtScale(AddBackgroundForViews(extension, *action_icon_skia),
293 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 299 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
294 2.0f)); 300 2.0f));
295 301
296 // Try setting icon with empty dictionary of ImageData objects. 302 // Try setting icon with empty dictionary of ImageData objects.
297 GetBrowserActionsBar().Press(0); 303 GetBrowserActionsBar().Press(0);
298 ASSERT_FALSE(catcher.GetNextResult()); 304 ASSERT_FALSE(catcher.GetNextResult());
299 EXPECT_EQ(kEmptyImageDataError, catcher.message()); 305 EXPECT_EQ(kEmptyImageDataError, catcher.message());
300 306
301 // Try setting icon with empty dictionary of path objects. 307 // Try setting icon with empty dictionary of path objects.
302 GetBrowserActionsBar().Press(0); 308 GetBrowserActionsBar().Press(0);
303 ASSERT_FALSE(catcher.GetNextResult()); 309 ASSERT_FALSE(catcher.GetNextResult());
304 EXPECT_EQ(kEmptyPathError, catcher.message()); 310 EXPECT_EQ(kEmptyPathError, catcher.message());
(...skipping 26 matching lines...) Expand all
331 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); 337 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
332 338
333 // Reload that tab, default title should come back. 339 // Reload that tab, default title should come back.
334 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 340 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
335 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); 341 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
336 } 342 }
337 343
338 // http://code.google.com/p/chromium/issues/detail?id=70829 344 // http://code.google.com/p/chromium/issues/detail?id=70829
339 // Mac used to be ok, but then mac 10.5 started failing too. =( 345 // Mac used to be ok, but then mac 10.5 started failing too. =(
340 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) { 346 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) {
341 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 347 const Extension* extension =
342 "browser_action/popup"))); 348 LoadExtension(test_data_dir_.AppendASCII("browser_action/popup"));
349 ASSERT_TRUE(extension) << message_;
343 BrowserActionTestUtil actions_bar = GetBrowserActionsBar(); 350 BrowserActionTestUtil actions_bar = GetBrowserActionsBar();
344 const Extension* extension = GetSingleLoadedExtension();
345 ASSERT_TRUE(extension) << message_;
346 351
347 // The extension's popup's size grows by |growFactor| each click. 352 // The extension's popup's size grows by |growFactor| each click.
348 const int growFactor = 500; 353 const int growFactor = 500;
349 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); 354 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize();
350 gfx::Size middleSize = gfx::Size(growFactor, growFactor); 355 gfx::Size middleSize = gfx::Size(growFactor, growFactor);
351 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize(); 356 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize();
352 357
353 // Ensure that two clicks will exceed the maximum allowed size. 358 // Ensure that two clicks will exceed the maximum allowed size.
354 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height()); 359 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height());
355 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width()); 360 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width());
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 605
601 // A click in the incognito profile should open a tab in the 606 // A click in the incognito profile should open a tab in the
602 // incognito profile. 607 // incognito profile.
603 toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true); 608 toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true);
604 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 609 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
605 } 610 }
606 611
607 // Disabled because of failures (crashes) on ASAN bot. 612 // Disabled because of failures (crashes) on ASAN bot.
608 // See http://crbug.com/98861. 613 // See http://crbug.com/98861.
609 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { 614 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) {
610 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 615 const Extension* extension = LoadExtension(
611 "browser_action/close_background"))); 616 test_data_dir_.AppendASCII("browser_action/close_background"));
612 const Extension* extension = GetSingleLoadedExtension(); 617 ASSERT_TRUE(extension) << message_;
613 618
614 // There is a background page and a browser action with no badge text. 619 // There is a background page and a browser action with no badge text.
615 extensions::ProcessManager* manager = 620 extensions::ProcessManager* manager =
616 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 621 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
617 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id())); 622 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id()));
618 ExtensionAction* action = GetBrowserAction(*extension); 623 ExtensionAction* action = GetBrowserAction(*extension);
619 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 624 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId));
620 625
621 content::WindowedNotificationObserver host_destroyed_observer( 626 content::WindowedNotificationObserver host_destroyed_observer(
622 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 627 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 "backgroundColor);"; 728 "backgroundColor);";
724 std::string result; 729 std::string result;
725 const std::string frame_xpath; 730 const std::string frame_xpath;
726 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString( 731 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString(
727 tab, frame_xpath, script, &result)); 732 tab, frame_xpath, script, &result));
728 EXPECT_EQ(result, "red"); 733 EXPECT_EQ(result, "red");
729 } 734 }
730 735
731 } // namespace 736 } // namespace
732 } // namespace extensions 737 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698