OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
10 #include "chrome/browser/extensions/browser_action_test_util.h" | 10 #include "chrome/browser/extensions/browser_action_test_util.h" |
11 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/extensions/extension_action.h" |
12 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 12 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
13 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
| 14 #include "chrome/browser/extensions/extension_action_runner.h" |
14 #include "chrome/browser/extensions/extension_apitest.h" | 15 #include "chrome/browser/extensions/extension_apitest.h" |
15 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
16 #include "chrome/browser/extensions/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_navigator_params.h" | 22 #include "chrome/browser/ui/browser_navigator_params.h" |
22 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 21 matching lines...) Expand all Loading... |
45 #include "ui/gfx/image/image_skia.h" | 46 #include "ui/gfx/image/image_skia.h" |
46 #include "ui/gfx/image/image_skia_operations.h" | 47 #include "ui/gfx/image/image_skia_operations.h" |
47 #include "ui/gfx/image/image_unittest_util.h" | 48 #include "ui/gfx/image/image_unittest_util.h" |
48 #include "ui/gfx/skia_util.h" | 49 #include "ui/gfx/skia_util.h" |
49 | 50 |
50 using content::WebContents; | 51 using content::WebContents; |
51 | 52 |
52 namespace extensions { | 53 namespace extensions { |
53 namespace { | 54 namespace { |
54 | 55 |
| 56 void ExecuteExtensionAction(Browser* browser, const Extension* extension) { |
| 57 ExtensionActionRunner::GetForWebContents( |
| 58 browser->tab_strip_model()->GetActiveWebContents()) |
| 59 ->RunAction(extension, true); |
| 60 } |
| 61 |
55 // An ImageSkia source that will do nothing (i.e., have a blank skia). We need | 62 // An ImageSkia source that will do nothing (i.e., have a blank skia). We need |
56 // this because we need a blank canvas at a certain size, and that can't be done | 63 // this because we need a blank canvas at a certain size, and that can't be done |
57 // by just using a null ImageSkia. | 64 // by just using a null ImageSkia. |
58 class BlankImageSource : public gfx::CanvasImageSource { | 65 class BlankImageSource : public gfx::CanvasImageSource { |
59 public: | 66 public: |
60 explicit BlankImageSource(const gfx::Size& size) | 67 explicit BlankImageSource(const gfx::Size& size) |
61 : gfx::CanvasImageSource(size, false) {} | 68 : gfx::CanvasImageSource(size, false) {} |
62 ~BlankImageSource() override {} | 69 ~BlankImageSource() override {} |
63 | 70 |
64 void Draw(gfx::Canvas* canvas) override {} | 71 void Draw(gfx::Canvas* canvas) override {} |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 ExtensionAction* action = GetBrowserAction(*extension); | 147 ExtensionAction* action = GetBrowserAction(*extension); |
141 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); | 148 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); |
142 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 149 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
143 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), | 150 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), |
144 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); | 151 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); |
145 | 152 |
146 // Simulate the browser action being clicked. | 153 // Simulate the browser action being clicked. |
147 ui_test_utils::NavigateToURL( | 154 ui_test_utils::NavigateToURL( |
148 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); | 155 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
149 | 156 |
150 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( | 157 ExecuteExtensionAction(browser(), extension); |
151 extension, browser(), true); | |
152 | 158 |
153 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 159 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
154 } | 160 } |
155 | 161 |
156 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { | 162 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
157 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; | 163 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; |
158 const Extension* extension = GetSingleLoadedExtension(); | 164 const Extension* extension = GetSingleLoadedExtension(); |
159 ASSERT_TRUE(extension) << message_; | 165 ASSERT_TRUE(extension) << message_; |
160 | 166 |
161 #if defined (OS_MACOSX) | 167 #if defined (OS_MACOSX) |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 549 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
544 Browser* incognito_browser = | 550 Browser* incognito_browser = |
545 new Browser(Browser::CreateParams(incognito_profile)); | 551 new Browser(Browser::CreateParams(incognito_profile)); |
546 base::RunLoop().RunUntilIdle(); // Wait for profile initialization. | 552 base::RunLoop().RunUntilIdle(); // Wait for profile initialization. |
547 // Navigate just to have a tab in this window, otherwise wonky things happen. | 553 // Navigate just to have a tab in this window, otherwise wonky things happen. |
548 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 554 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
549 ASSERT_EQ(1, | 555 ASSERT_EQ(1, |
550 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); | 556 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); |
551 | 557 |
552 // A click in the regular profile should open a tab in the regular profile. | 558 // A click in the regular profile should open a tab in the regular profile. |
553 ExtensionActionAPI* extension_action_api = | 559 ExecuteExtensionAction(browser(), extension); |
554 ExtensionActionAPI::Get(browser()->profile()); | |
555 extension_action_api->ExecuteExtensionAction( | |
556 extension, browser(), true); | |
557 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 560 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
558 | 561 |
559 // A click in the incognito profile should open a tab in the | 562 // A click in the incognito profile should open a tab in the |
560 // incognito profile. | 563 // incognito profile. |
561 extension_action_api->ExecuteExtensionAction( | 564 ExecuteExtensionAction(incognito_browser, extension); |
562 extension, incognito_browser, true); | |
563 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 565 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
564 } | 566 } |
565 | 567 |
566 // Disabled because of failures (crashes) on ASAN bot. | 568 // Disabled because of failures (crashes) on ASAN bot. |
567 // See http://crbug.com/98861. | 569 // See http://crbug.com/98861. |
568 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { | 570 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { |
569 ASSERT_TRUE(LoadExtension( | 571 ASSERT_TRUE(LoadExtension( |
570 test_data_dir_.AppendASCII("browser_action/close_background"))); | 572 test_data_dir_.AppendASCII("browser_action/close_background"))); |
571 const Extension* extension = GetSingleLoadedExtension(); | 573 const Extension* extension = GetSingleLoadedExtension(); |
572 | 574 |
573 // There is a background page and a browser action with no badge text. | 575 // There is a background page and a browser action with no badge text. |
574 extensions::ProcessManager* manager = | 576 extensions::ProcessManager* manager = |
575 extensions::ProcessManager::Get(browser()->profile()); | 577 extensions::ProcessManager::Get(browser()->profile()); |
576 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id())); | 578 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id())); |
577 ExtensionAction* action = GetBrowserAction(*extension); | 579 ExtensionAction* action = GetBrowserAction(*extension); |
578 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 580 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
579 | 581 |
580 content::WindowedNotificationObserver host_destroyed_observer( | 582 content::WindowedNotificationObserver host_destroyed_observer( |
581 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 583 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
582 content::NotificationService::AllSources()); | 584 content::NotificationService::AllSources()); |
583 | 585 |
584 // Click the browser action. | 586 // Click the browser action. |
585 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( | 587 ExecuteExtensionAction(browser(), extension); |
586 extension, browser(), true); | |
587 | 588 |
588 // It can take a moment for the background page to actually get destroyed | 589 // It can take a moment for the background page to actually get destroyed |
589 // so we wait for the notification before checking that it's really gone | 590 // so we wait for the notification before checking that it's really gone |
590 // and the badge text has been set. | 591 // and the badge text has been set. |
591 host_destroyed_observer.Wait(); | 592 host_destroyed_observer.Wait(); |
592 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); | 593 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); |
593 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 594 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
594 } | 595 } |
595 | 596 |
596 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { | 597 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 test_data_dir_.AppendASCII("browser_action/open_popup_on_reply"))); | 790 test_data_dir_.AppendASCII("browser_action/open_popup_on_reply"))); |
790 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 791 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
791 | 792 |
792 ResultCatcher catcher; | 793 ResultCatcher catcher; |
793 listener.Reply(std::string()); | 794 listener.Reply(std::string()); |
794 EXPECT_TRUE(catcher.GetNextResult()) << message_; | 795 EXPECT_TRUE(catcher.GetNextResult()) << message_; |
795 } | 796 } |
796 | 797 |
797 } // namespace | 798 } // namespace |
798 } // namespace extensions | 799 } // namespace extensions |
OLD | NEW |