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

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"
23 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
27 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
29 #include "content/public/test/browser_test_utils.h" 31 #include "content/public/test/browser_test_utils.h"
30 #include "extensions/browser/extension_system.h" 32 #include "extensions/browser/extension_system.h"
31 #include "grit/theme_resources.h" 33 #include "grit/theme_resources.h"
32 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/image/image_skia.h" 35 #include "ui/gfx/image/image_skia.h"
34 #include "ui/gfx/image/image_skia_operations.h" 36 #include "ui/gfx/image/image_skia_operations.h"
35 #include "ui/gfx/rect.h" 37 #include "ui/gfx/rect.h"
36 #include "ui/gfx/size.h" 38 #include "ui/gfx/size.h"
37 #include "ui/gfx/skia_util.h" 39 #include "ui/gfx/skia_util.h"
38 40
39 using content::WebContents; 41 using content::WebContents;
40 42
41 namespace extensions { 43 namespace extensions {
42 namespace { 44 namespace {
43 45
44 const char kEmptyImageDataError[] = 46 const char kEmptyImageDataError[] =
45 "The imageData property must contain an ImageData object or dictionary " 47 "The imageData property must contain an ImageData object or dictionary "
46 "of ImageData objects."; 48 "of ImageData objects.";
47 const char kEmptyPathError[] = "The path property must not be empty."; 49 const char kEmptyPathError[] = "The path property must not be empty.";
48 50
49 // Views implementation of browser action button will return icon whose
50 // background will be set.
51 gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) {
52 #if defined(TOOLKIT_VIEWS)
53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
54 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION);
55 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
56 #endif
57
58 return icon;
59 }
60
61 bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1, 51 bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
62 const gfx::ImageSkia& i2, 52 const gfx::ImageSkia& i2,
63 float scale) { 53 float scale) {
64 SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap(); 54 SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
65 SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap(); 55 SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap();
66 return gfx::BitmapsAreEqual(bitmap1, bitmap2); 56 return gfx::BitmapsAreEqual(bitmap1, bitmap2);
67 } 57 }
68 58
69 class BrowserActionApiTest : public ExtensionApiTest { 59 class BrowserActionApiTest : public ExtensionApiTest {
70 public: 60 public:
(...skipping 13 matching lines...) Expand all
84 GetBrowserActionsBar().Press(index); 74 GetBrowserActionsBar().Press(index);
85 popup_observer.Wait(); 75 popup_observer.Wait();
86 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 76 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
87 return GetBrowserActionsBar().HasPopup(); 77 return GetBrowserActionsBar().HasPopup();
88 } 78 }
89 79
90 ExtensionAction* GetBrowserAction(const Extension& extension) { 80 ExtensionAction* GetBrowserAction(const Extension& extension) {
91 return ExtensionActionManager::Get(browser()->profile())-> 81 return ExtensionActionManager::Get(browser()->profile())->
92 GetBrowserAction(extension); 82 GetBrowserAction(extension);
93 } 83 }
84
85 // Views implementation of browser action button will return icon whose
86 // background will be set.
87 gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) {
88 #if defined(TOOLKIT_VIEWS)
89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
90 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION);
91 // We may have a different background than the default - see
92 // BrowserActionButton::UpdateState.
93 if (extensions::DevModeBubbleController::IsDevModeExtension(extension_))
Jeffrey Yasskin 2014/02/19 01:13:34 Can we pass this extension as a function argument
94 bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION_HIGHLIGHT);
95 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
96 #endif
97
98 return icon;
99 }
100
101 const Extension* extension_;
94 }; 102 };
95 103
96 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { 104 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
97 ASSERT_TRUE(test_server()->Start()); 105 ASSERT_TRUE(test_server()->Start());
98 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 106 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
99 const Extension* extension = GetSingleLoadedExtension(); 107 extension_ = GetSingleLoadedExtension();
100 ASSERT_TRUE(extension) << message_; 108 ASSERT_TRUE(extension_) << message_;
101 109
102 // Test that there is a browser action in the toolbar. 110 // Test that there is a browser action in the toolbar.
103 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 111 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
104 112
105 // Tell the extension to update the browser action state. 113 // Tell the extension to update the browser action state.
106 ResultCatcher catcher; 114 ResultCatcher catcher;
107 ui_test_utils::NavigateToURL(browser(), 115 ui_test_utils::NavigateToURL(browser(),
108 GURL(extension->GetResourceURL("update.html"))); 116 GURL(extension_->GetResourceURL("update.html")));
109 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 117 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
110 118
111 // Test that we received the changes. 119 // Test that we received the changes.
112 ExtensionAction* action = GetBrowserAction(*extension); 120 ExtensionAction* action = GetBrowserAction(*extension_);
113 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); 121 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId));
114 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 122 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId));
115 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), 123 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
116 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 124 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
117 125
118 // Simulate the browser action being clicked. 126 // Simulate the browser action being clicked.
119 ui_test_utils::NavigateToURL(browser(), 127 ui_test_utils::NavigateToURL(browser(),
120 test_server()->GetURL("files/extensions/test_file.txt")); 128 test_server()->GetURL("files/extensions/test_file.txt"));
121 129
122 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( 130 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
123 browser()->profile()); 131 browser()->profile());
124 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); 132 toolbar_model->ExecuteBrowserAction(extension_, browser(), NULL, true);
125 133
126 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 134 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
127 } 135 }
128 136
129 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { 137 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
130 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 138 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
131 const Extension* extension = GetSingleLoadedExtension(); 139 extension_ = GetSingleLoadedExtension();
132 ASSERT_TRUE(extension) << message_; 140 ASSERT_TRUE(extension_) << message_;
133 141
134 #if defined (OS_MACOSX) 142 #if defined (OS_MACOSX)
135 // We need this on mac so we don't loose 2x representations from browser icon 143 // We need this on mac so we don't loose 2x representations from browser icon
136 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia. 144 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia.
137 std::vector<ui::ScaleFactor> supported_scale_factors; 145 std::vector<ui::ScaleFactor> supported_scale_factors;
138 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); 146 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
139 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); 147 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
140 ui::SetSupportedScaleFactors(supported_scale_factors); 148 ui::SetSupportedScaleFactors(supported_scale_factors);
141 #endif 149 #endif
142 150
143 // We should not be creating icons asynchronously, so we don't need an 151 // We should not be creating icons asynchronously, so we don't need an
144 // observer. 152 // observer.
145 ExtensionActionIconFactory icon_factory( 153 ExtensionActionIconFactory icon_factory(
146 profile(), 154 profile(), extension_, GetBrowserAction(*extension_), NULL);
147 extension,
148 GetBrowserAction(*extension),
149 NULL);
150 // Test that there is a browser action in the toolbar. 155 // Test that there is a browser action in the toolbar.
151 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 156 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
152 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); 157 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
153 158
154 gfx::Image action_icon = icon_factory.GetIcon(0); 159 gfx::Image action_icon = icon_factory.GetIcon(0);
155 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); 160 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID();
156 161
157 // Let's check that |GetIcon| doesn't always return bitmap with new id. 162 // Let's check that |GetIcon| doesn't always return bitmap with new id.
158 ASSERT_EQ(action_icon_last_id, 163 ASSERT_EQ(action_icon_last_id,
159 icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID()); 164 icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 GetBrowserActionsBar().Press(0); 307 GetBrowserActionsBar().Press(0);
303 ASSERT_FALSE(catcher.GetNextResult()); 308 ASSERT_FALSE(catcher.GetNextResult());
304 EXPECT_EQ(kEmptyPathError, catcher.message()); 309 EXPECT_EQ(kEmptyPathError, catcher.message());
305 } 310 }
306 311
307 // This test is flaky as per http://crbug.com/74557. 312 // This test is flaky as per http://crbug.com/74557.
308 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, 313 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest,
309 DISABLED_TabSpecificBrowserActionState) { 314 DISABLED_TabSpecificBrowserActionState) {
310 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << 315 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) <<
311 message_; 316 message_;
312 const Extension* extension = GetSingleLoadedExtension(); 317 extension_ = GetSingleLoadedExtension();
Jeffrey Yasskin 2014/02/19 01:13:34 I don't think you have to make this change, since
313 ASSERT_TRUE(extension) << message_; 318 ASSERT_TRUE(extension_) << message_;
314 319
315 // Test that there is a browser action in the toolbar and that it has an icon. 320 // Test that there is a browser action in the toolbar and that it has an icon.
316 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 321 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
317 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); 322 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
318 323
319 // Execute the action, its title should change. 324 // Execute the action, its title should change.
320 ResultCatcher catcher; 325 ResultCatcher catcher;
321 GetBrowserActionsBar().Press(0); 326 GetBrowserActionsBar().Press(0);
322 ASSERT_TRUE(catcher.GetNextResult()); 327 ASSERT_TRUE(catcher.GetNextResult());
323 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); 328 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
324 329
325 // Open a new tab, the title should go back. 330 // Open a new tab, the title should go back.
326 chrome::NewTab(browser()); 331 chrome::NewTab(browser());
327 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); 332 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
328 333
329 // Go back to first tab, changed title should reappear. 334 // Go back to first tab, changed title should reappear.
330 browser()->tab_strip_model()->ActivateTabAt(0, true); 335 browser()->tab_strip_model()->ActivateTabAt(0, true);
331 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); 336 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
332 337
333 // Reload that tab, default title should come back. 338 // Reload that tab, default title should come back.
334 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 339 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
335 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); 340 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
336 } 341 }
337 342
338 // http://code.google.com/p/chromium/issues/detail?id=70829 343 // http://code.google.com/p/chromium/issues/detail?id=70829
339 // Mac used to be ok, but then mac 10.5 started failing too. =( 344 // Mac used to be ok, but then mac 10.5 started failing too. =(
340 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) { 345 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) {
341 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 346 extension_ =
342 "browser_action/popup"))); 347 LoadExtension(test_data_dir_.AppendASCII("browser_action/popup"));
348 ASSERT_TRUE(extension_) << message_;
343 BrowserActionTestUtil actions_bar = GetBrowserActionsBar(); 349 BrowserActionTestUtil actions_bar = GetBrowserActionsBar();
344 const Extension* extension = GetSingleLoadedExtension();
345 ASSERT_TRUE(extension) << message_;
346 350
347 // The extension's popup's size grows by |growFactor| each click. 351 // The extension's popup's size grows by |growFactor| each click.
348 const int growFactor = 500; 352 const int growFactor = 500;
349 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); 353 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize();
350 gfx::Size middleSize = gfx::Size(growFactor, growFactor); 354 gfx::Size middleSize = gfx::Size(growFactor, growFactor);
351 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize(); 355 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize();
352 356
353 // Ensure that two clicks will exceed the maximum allowed size. 357 // Ensure that two clicks will exceed the maximum allowed size.
354 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height()); 358 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height());
355 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width()); 359 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width());
(...skipping 11 matching lines...) Expand all
367 // One more time, but this time it should be constrained by the max values. 371 // One more time, but this time it should be constrained by the max values.
368 ASSERT_TRUE(OpenPopup(0)); 372 ASSERT_TRUE(OpenPopup(0));
369 EXPECT_EQ(maxSize, actions_bar.GetPopupBounds().size()); 373 EXPECT_EQ(maxSize, actions_bar.GetPopupBounds().size());
370 EXPECT_TRUE(actions_bar.HidePopup()); 374 EXPECT_TRUE(actions_bar.HidePopup());
371 } 375 }
372 376
373 // Test that calling chrome.browserAction.setPopup() can enable and change 377 // Test that calling chrome.browserAction.setPopup() can enable and change
374 // a popup. 378 // a popup.
375 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) { 379 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) {
376 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_; 380 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_;
377 const Extension* extension = GetSingleLoadedExtension(); 381 extension_ = GetSingleLoadedExtension();
378 ASSERT_TRUE(extension) << message_; 382 ASSERT_TRUE(extension_) << message_;
379 383
380 int tab_id = ExtensionTabUtil::GetTabId( 384 int tab_id = ExtensionTabUtil::GetTabId(
381 browser()->tab_strip_model()->GetActiveWebContents()); 385 browser()->tab_strip_model()->GetActiveWebContents());
382 386
383 ExtensionAction* browser_action = GetBrowserAction(*extension); 387 ExtensionAction* browser_action = GetBrowserAction(*extension_);
384 ASSERT_TRUE(browser_action) 388 ASSERT_TRUE(browser_action)
385 << "Browser action test extension should have a browser action."; 389 << "Browser action test extension should have a browser action.";
386 390
387 ASSERT_FALSE(browser_action->HasPopup(tab_id)); 391 ASSERT_FALSE(browser_action->HasPopup(tab_id));
388 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); 392 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId));
389 393
390 // Simulate a click on the browser action icon. The onClicked handler 394 // Simulate a click on the browser action icon. The onClicked handler
391 // will add a popup. 395 // will add a popup.
392 { 396 {
393 ResultCatcher catcher; 397 ResultCatcher catcher;
(...skipping 12 matching lines...) Expand all
406 << "popup."; 410 << "popup.";
407 411
408 ASSERT_STREQ("/a_popup.html", 412 ASSERT_STREQ("/a_popup.html",
409 browser_action->GetPopupUrl(tab_id).path().c_str()); 413 browser_action->GetPopupUrl(tab_id).path().c_str());
410 414
411 // Now change the popup from a_popup.html to another_popup.html by loading 415 // Now change the popup from a_popup.html to another_popup.html by loading
412 // a page which removes the popup using chrome.browserAction.setPopup(). 416 // a page which removes the popup using chrome.browserAction.setPopup().
413 { 417 {
414 ResultCatcher catcher; 418 ResultCatcher catcher;
415 ui_test_utils::NavigateToURL( 419 ui_test_utils::NavigateToURL(
416 browser(), 420 browser(), GURL(extension_->GetResourceURL("change_popup.html")));
417 GURL(extension->GetResourceURL("change_popup.html")));
418 ASSERT_TRUE(catcher.GetNextResult()); 421 ASSERT_TRUE(catcher.GetNextResult());
419 } 422 }
420 423
421 // The call to setPopup in change_popup.html did not use a tab id, 424 // The call to setPopup in change_popup.html did not use a tab id,
422 // so the default setting should have changed as well as the current tab. 425 // so the default setting should have changed as well as the current tab.
423 ASSERT_TRUE(browser_action->HasPopup(tab_id)); 426 ASSERT_TRUE(browser_action->HasPopup(tab_id));
424 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); 427 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId));
425 ASSERT_STREQ("/another_popup.html", 428 ASSERT_STREQ("/another_popup.html",
426 browser_action->GetPopupUrl(tab_id).path().c_str()); 429 browser_action->GetPopupUrl(tab_id).path().c_str());
427 } 430 }
428 431
429 // Test that calling chrome.browserAction.setPopup() can remove a popup. 432 // Test that calling chrome.browserAction.setPopup() can remove a popup.
430 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) { 433 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) {
431 // Load the extension, which has a browser action with a default popup. 434 // Load the extension, which has a browser action with a default popup.
432 ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_; 435 ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_;
433 const Extension* extension = GetSingleLoadedExtension(); 436 extension_ = GetSingleLoadedExtension();
434 ASSERT_TRUE(extension) << message_; 437 ASSERT_TRUE(extension_) << message_;
435 438
436 int tab_id = ExtensionTabUtil::GetTabId( 439 int tab_id = ExtensionTabUtil::GetTabId(
437 browser()->tab_strip_model()->GetActiveWebContents()); 440 browser()->tab_strip_model()->GetActiveWebContents());
438 441
439 ExtensionAction* browser_action = GetBrowserAction(*extension); 442 ExtensionAction* browser_action = GetBrowserAction(*extension_);
440 ASSERT_TRUE(browser_action) 443 ASSERT_TRUE(browser_action)
441 << "Browser action test extension should have a browser action."; 444 << "Browser action test extension should have a browser action.";
442 445
443 ASSERT_TRUE(browser_action->HasPopup(tab_id)) 446 ASSERT_TRUE(browser_action->HasPopup(tab_id))
444 << "Expect a browser action popup before the test removes it."; 447 << "Expect a browser action popup before the test removes it.";
445 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) 448 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
446 << "Expect a browser action popup is the default for all tabs."; 449 << "Expect a browser action popup is the default for all tabs.";
447 450
448 // Load a page which removes the popup using chrome.browserAction.setPopup(). 451 // Load a page which removes the popup using chrome.browserAction.setPopup().
449 { 452 {
450 ResultCatcher catcher; 453 ResultCatcher catcher;
451 ui_test_utils::NavigateToURL( 454 ui_test_utils::NavigateToURL(
452 browser(), 455 browser(), GURL(extension_->GetResourceURL("remove_popup.html")));
453 GURL(extension->GetResourceURL("remove_popup.html")));
454 ASSERT_TRUE(catcher.GetNextResult()); 456 ASSERT_TRUE(catcher.GetNextResult());
455 } 457 }
456 458
457 ASSERT_FALSE(browser_action->HasPopup(tab_id)) 459 ASSERT_FALSE(browser_action->HasPopup(tab_id))
458 << "Browser action popup should have been removed."; 460 << "Browser action popup should have been removed.";
459 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) 461 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
460 << "Browser action popup default should not be changed by setting " 462 << "Browser action popup default should not be changed by setting "
461 << "a specific tab id."; 463 << "a specific tab id.";
462 } 464 }
463 465
464 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { 466 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) {
465 ASSERT_TRUE(test_server()->Start()); 467 ASSERT_TRUE(test_server()->Start());
466 468
467 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 469 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
468 const Extension* extension = GetSingleLoadedExtension(); 470 extension_ = GetSingleLoadedExtension();
469 ASSERT_TRUE(extension) << message_; 471 ASSERT_TRUE(extension_) << message_;
470 472
471 // Test that there is a browser action in the toolbar. 473 // Test that there is a browser action in the toolbar.
472 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 474 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
473 475
474 // Open an incognito window and test that the browser action isn't there by 476 // Open an incognito window and test that the browser action isn't there by
475 // default. 477 // default.
476 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 478 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
477 Browser* incognito_browser = 479 Browser* incognito_browser =
478 new Browser(Browser::CreateParams(incognito_profile, 480 new Browser(Browser::CreateParams(incognito_profile,
479 browser()->host_desktop_type())); 481 browser()->host_desktop_type()));
480 482
481 ASSERT_EQ(0, 483 ASSERT_EQ(0,
482 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); 484 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
483 485
484 // Now enable the extension in incognito mode, and test that the browser 486 // Now enable the extension in incognito mode, and test that the browser
485 // action shows up. Note that we don't update the existing window at the 487 // action shows up. Note that we don't update the existing window at the
486 // moment, so we just create a new one. 488 // moment, so we just create a new one.
487 extensions::ExtensionSystem::Get(browser()->profile())->extension_service()-> 489 extensions::ExtensionSystem::Get(browser()->profile())
488 extension_prefs()->SetIsIncognitoEnabled(extension->id(), true); 490 ->extension_service()
491 ->extension_prefs()
492 ->SetIsIncognitoEnabled(extension_->id(), true);
489 493
490 chrome::CloseWindow(incognito_browser); 494 chrome::CloseWindow(incognito_browser);
491 incognito_browser = 495 incognito_browser =
492 new Browser(Browser::CreateParams(incognito_profile, 496 new Browser(Browser::CreateParams(incognito_profile,
493 browser()->host_desktop_type())); 497 browser()->host_desktop_type()));
494 ASSERT_EQ(1, 498 ASSERT_EQ(1,
495 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); 499 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
496 500
497 // TODO(mpcomplete): simulate a click and have it do the right thing in 501 // TODO(mpcomplete): simulate a click and have it do the right thing in
498 // incognito. 502 // incognito.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(2)); 574 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(2));
571 575
572 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); 576 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0));
573 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); 577 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1));
574 } 578 }
575 579
576 // Tests that events are dispatched to the correct profile for split mode 580 // Tests that events are dispatched to the correct profile for split mode
577 // extensions. 581 // extensions.
578 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) { 582 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) {
579 ResultCatcher catcher; 583 ResultCatcher catcher;
580 const Extension* extension = LoadExtensionWithFlags( 584 extension_ = LoadExtensionWithFlags(
581 test_data_dir_.AppendASCII("browser_action/split_mode"), 585 test_data_dir_.AppendASCII("browser_action/split_mode"),
582 kFlagEnableIncognito); 586 kFlagEnableIncognito);
583 ASSERT_TRUE(extension) << message_; 587 ASSERT_TRUE(extension_) << message_;
584 588
585 // Open an incognito window. 589 // Open an incognito window.
586 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 590 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
587 Browser* incognito_browser = 591 Browser* incognito_browser =
588 new Browser(Browser::CreateParams(incognito_profile, 592 new Browser(Browser::CreateParams(incognito_profile,
589 browser()->host_desktop_type())); 593 browser()->host_desktop_type()));
590 // Navigate just to have a tab in this window, otherwise wonky things happen. 594 // Navigate just to have a tab in this window, otherwise wonky things happen.
591 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); 595 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
592 ASSERT_EQ(1, 596 ASSERT_EQ(1,
593 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); 597 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
594 598
595 // A click in the regular profile should open a tab in the regular profile. 599 // A click in the regular profile should open a tab in the regular profile.
596 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( 600 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
597 browser()->profile()); 601 browser()->profile());
598 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); 602 toolbar_model->ExecuteBrowserAction(extension_, browser(), NULL, true);
599 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 603 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
600 604
601 // A click in the incognito profile should open a tab in the 605 // A click in the incognito profile should open a tab in the
602 // incognito profile. 606 // incognito profile.
603 toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true); 607 toolbar_model->ExecuteBrowserAction(
608 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 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,
623 content::NotificationService::AllSources()); 628 content::NotificationService::AllSources());
624 629
625 // Click the browser action. 630 // Click the browser action.
626 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( 631 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
627 browser()->profile()); 632 browser()->profile());
628 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); 633 toolbar_model->ExecuteBrowserAction(extension_, browser(), NULL, true);
629 634
630 // It can take a moment for the background page to actually get destroyed 635 // It can take a moment for the background page to actually get destroyed
631 // so we wait for the notification before checking that it's really gone 636 // so we wait for the notification before checking that it's really gone
632 // and the badge text has been set. 637 // and the badge text has been set.
633 host_destroyed_observer.Wait(); 638 host_destroyed_observer.Wait();
634 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); 639 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension_->id()));
635 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 640 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId));
636 } 641 }
637 642
638 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { 643 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) {
639 ASSERT_TRUE(test_server()->Start()); 644 ASSERT_TRUE(test_server()->Start());
640 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_; 645 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_;
641 const Extension* extension = GetSingleLoadedExtension(); 646 extension_ = GetSingleLoadedExtension();
642 ASSERT_TRUE(extension) << message_; 647 ASSERT_TRUE(extension_) << message_;
643 648
644 // Test that there is a browser action in the toolbar. 649 // Test that there is a browser action in the toolbar.
645 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 650 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
646 651
647 // Test that CSS values (#FF0000) set color correctly. 652 // Test that CSS values (#FF0000) set color correctly.
648 ExtensionAction* action = GetBrowserAction(*extension); 653 ExtensionAction* action = GetBrowserAction(*extension_);
649 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0), 654 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0),
650 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 655 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
651 656
652 // Tell the extension to update the browser action state. 657 // Tell the extension to update the browser action state.
653 ResultCatcher catcher; 658 ResultCatcher catcher;
654 ui_test_utils::NavigateToURL(browser(), 659 ui_test_utils::NavigateToURL(browser(),
655 GURL(extension->GetResourceURL("update.html"))); 660 GURL(extension_->GetResourceURL("update.html")));
656 ASSERT_TRUE(catcher.GetNextResult()); 661 ASSERT_TRUE(catcher.GetNextResult());
657 662
658 // Test that CSS values (#0F0) set color correctly. 663 // Test that CSS values (#0F0) set color correctly.
659 ASSERT_EQ(SkColorSetARGB(255, 0, 255, 0), 664 ASSERT_EQ(SkColorSetARGB(255, 0, 255, 0),
660 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 665 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
661 666
662 ui_test_utils::NavigateToURL(browser(), 667 ui_test_utils::NavigateToURL(
663 GURL(extension->GetResourceURL("update2.html"))); 668 browser(), GURL(extension_->GetResourceURL("update2.html")));
664 ASSERT_TRUE(catcher.GetNextResult()); 669 ASSERT_TRUE(catcher.GetNextResult());
665 670
666 // Test that array values set color correctly. 671 // Test that array values set color correctly.
667 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), 672 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
668 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 673 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
669 } 674 }
670 675
671 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) { 676 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) {
672 ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_; 677 ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_;
673 const Extension* extension = GetSingleLoadedExtension(); 678 extension_ = GetSingleLoadedExtension();
674 ASSERT_TRUE(extension) << message_; 679 ASSERT_TRUE(extension_) << message_;
675 680
676 // Test that there is a browser action in the toolbar. 681 // Test that there is a browser action in the toolbar.
677 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 682 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
678 683
679 // Test the getters for defaults. 684 // Test the getters for defaults.
680 ResultCatcher catcher; 685 ResultCatcher catcher;
681 ui_test_utils::NavigateToURL(browser(), 686 ui_test_utils::NavigateToURL(browser(),
682 GURL(extension->GetResourceURL("update.html"))); 687 GURL(extension_->GetResourceURL("update.html")));
683 ASSERT_TRUE(catcher.GetNextResult()); 688 ASSERT_TRUE(catcher.GetNextResult());
684 689
685 // Test the getters for a specific tab. 690 // Test the getters for a specific tab.
686 ui_test_utils::NavigateToURL(browser(), 691 ui_test_utils::NavigateToURL(
687 GURL(extension->GetResourceURL("update2.html"))); 692 browser(), GURL(extension_->GetResourceURL("update2.html")));
688 ASSERT_TRUE(catcher.GetNextResult()); 693 ASSERT_TRUE(catcher.GetNextResult());
689 } 694 }
690 695
691 // Verify triggering browser action. 696 // Verify triggering browser action.
692 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) { 697 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) {
693 ASSERT_TRUE(test_server()->Start()); 698 ASSERT_TRUE(test_server()->Start());
694 699
695 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_; 700 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_;
696 const Extension* extension = GetSingleLoadedExtension(); 701 extension_ = GetSingleLoadedExtension();
697 ASSERT_TRUE(extension) << message_; 702 ASSERT_TRUE(extension_) << message_;
698 703
699 // Test that there is a browser action in the toolbar. 704 // Test that there is a browser action in the toolbar.
700 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 705 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
701 706
702 ui_test_utils::NavigateToURL( 707 ui_test_utils::NavigateToURL(
703 browser(), 708 browser(),
704 test_server()->GetURL("files/simple.html")); 709 test_server()->GetURL("files/simple.html"));
705 710
706 ExtensionAction* browser_action = GetBrowserAction(*extension); 711 ExtensionAction* browser_action = GetBrowserAction(*extension_);
707 EXPECT_TRUE(browser_action != NULL); 712 EXPECT_TRUE(browser_action != NULL);
708 713
709 // Simulate a click on the browser action icon. 714 // Simulate a click on the browser action icon.
710 { 715 {
711 ResultCatcher catcher; 716 ResultCatcher catcher;
712 GetBrowserActionsBar().Press(0); 717 GetBrowserActionsBar().Press(0);
713 EXPECT_TRUE(catcher.GetNextResult()); 718 EXPECT_TRUE(catcher.GetNextResult());
714 } 719 }
715 720
716 WebContents* tab = 721 WebContents* tab =
717 browser()->tab_strip_model()->GetActiveWebContents(); 722 browser()->tab_strip_model()->GetActiveWebContents();
718 EXPECT_TRUE(tab != NULL); 723 EXPECT_TRUE(tab != NULL);
719 724
720 // Verify that the browser action turned the background color red. 725 // Verify that the browser action turned the background color red.
721 const std::string script = 726 const std::string script =
722 "window.domAutomationController.send(document.body.style." 727 "window.domAutomationController.send(document.body.style."
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