| 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 "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/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 14 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
| 16 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.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" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 30 #include "content/public/test/browser_test_utils.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 ExtensionAction* action = GetBrowserAction(*extension); | 112 ExtensionAction* action = GetBrowserAction(*extension); |
| 112 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); | 113 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); |
| 113 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 114 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
| 114 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), | 115 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), |
| 115 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); | 116 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); |
| 116 | 117 |
| 117 // Simulate the browser action being clicked. | 118 // Simulate the browser action being clicked. |
| 118 ui_test_utils::NavigateToURL(browser(), | 119 ui_test_utils::NavigateToURL(browser(), |
| 119 test_server()->GetURL("files/extensions/test_file.txt")); | 120 test_server()->GetURL("files/extensions/test_file.txt")); |
| 120 | 121 |
| 121 ExtensionService* service = extensions::ExtensionSystem::Get( | 122 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( |
| 122 browser()->profile())->extension_service(); | 123 browser()->profile()); |
| 123 service->toolbar_model()->ExecuteBrowserAction( | 124 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); |
| 124 extension, browser(), NULL, true); | |
| 125 | 125 |
| 126 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 126 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { | 129 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
| 130 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; | 130 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; |
| 131 const Extension* extension = GetSingleLoadedExtension(); | 131 const Extension* extension = GetSingleLoadedExtension(); |
| 132 ASSERT_TRUE(extension) << message_; | 132 ASSERT_TRUE(extension) << message_; |
| 133 | 133 |
| 134 #if defined (OS_MACOSX) | 134 #if defined (OS_MACOSX) |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1)); | 544 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1)); |
| 545 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(2)); | 545 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(2)); |
| 546 | 546 |
| 547 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(0)); | 547 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(0)); |
| 548 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(1)); | 548 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(1)); |
| 549 | 549 |
| 550 // Now rearrange them and ensure that they are rearranged correctly in both | 550 // Now rearrange them and ensure that they are rearranged correctly in both |
| 551 // regular and incognito mode. | 551 // regular and incognito mode. |
| 552 | 552 |
| 553 // ABC -> CAB | 553 // ABC -> CAB |
| 554 service->toolbar_model()->MoveBrowserAction(extension_c, 0); | 554 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( |
| 555 browser()->profile()); |
| 556 toolbar_model->MoveBrowserAction(extension_c, 0); |
| 555 | 557 |
| 556 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0)); | 558 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0)); |
| 557 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(1)); | 559 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(1)); |
| 558 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(2)); | 560 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(2)); |
| 559 | 561 |
| 560 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); | 562 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); |
| 561 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); | 563 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); |
| 562 | 564 |
| 563 // CAB -> CBA | 565 // CAB -> CBA |
| 564 service->toolbar_model()->MoveBrowserAction(extension_b, 1); | 566 toolbar_model->MoveBrowserAction(extension_b, 1); |
| 565 | 567 |
| 566 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0)); | 568 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0)); |
| 567 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1)); | 569 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1)); |
| 568 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(2)); | 570 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(2)); |
| 569 | 571 |
| 570 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); | 572 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); |
| 571 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); | 573 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); |
| 572 } | 574 } |
| 573 | 575 |
| 574 // Tests that events are dispatched to the correct profile for split mode | 576 // Tests that events are dispatched to the correct profile for split mode |
| 575 // extensions. | 577 // extensions. |
| 576 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) { | 578 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) { |
| 577 ResultCatcher catcher; | 579 ResultCatcher catcher; |
| 578 const Extension* extension = LoadExtensionWithFlags( | 580 const Extension* extension = LoadExtensionWithFlags( |
| 579 test_data_dir_.AppendASCII("browser_action/split_mode"), | 581 test_data_dir_.AppendASCII("browser_action/split_mode"), |
| 580 kFlagEnableIncognito); | 582 kFlagEnableIncognito); |
| 581 ASSERT_TRUE(extension) << message_; | 583 ASSERT_TRUE(extension) << message_; |
| 582 | 584 |
| 583 // Open an incognito window. | 585 // Open an incognito window. |
| 584 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 586 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
| 585 Browser* incognito_browser = | 587 Browser* incognito_browser = |
| 586 new Browser(Browser::CreateParams(incognito_profile, | 588 new Browser(Browser::CreateParams(incognito_profile, |
| 587 browser()->host_desktop_type())); | 589 browser()->host_desktop_type())); |
| 588 // Navigate just to have a tab in this window, otherwise wonky things happen. | 590 // Navigate just to have a tab in this window, otherwise wonky things happen. |
| 589 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 591 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
| 590 ASSERT_EQ(1, | 592 ASSERT_EQ(1, |
| 591 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); | 593 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); |
| 592 | 594 |
| 593 // A click in the regular profile should open a tab in the regular profile. | 595 // A click in the regular profile should open a tab in the regular profile. |
| 594 ExtensionService* service = extensions::ExtensionSystem::Get( | 596 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( |
| 595 browser()->profile())->extension_service(); | 597 browser()->profile()); |
| 596 service->toolbar_model()->ExecuteBrowserAction( | 598 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); |
| 597 extension, browser(), NULL, true); | |
| 598 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 599 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 599 | 600 |
| 600 // A click in the incognito profile should open a tab in the | 601 // A click in the incognito profile should open a tab in the |
| 601 // incognito profile. | 602 // incognito profile. |
| 602 service->toolbar_model()->ExecuteBrowserAction( | 603 toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true); |
| 603 extension, incognito_browser, NULL, true); | |
| 604 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 604 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 605 } | 605 } |
| 606 | 606 |
| 607 // Disabled because of failures (crashes) on ASAN bot. | 607 // Disabled because of failures (crashes) on ASAN bot. |
| 608 // See http://crbug.com/98861. | 608 // See http://crbug.com/98861. |
| 609 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { | 609 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { |
| 610 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 610 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 611 "browser_action/close_background"))); | 611 "browser_action/close_background"))); |
| 612 const Extension* extension = GetSingleLoadedExtension(); | 612 const Extension* extension = GetSingleLoadedExtension(); |
| 613 | 613 |
| 614 // There is a background page and a browser action with no badge text. | 614 // There is a background page and a browser action with no badge text. |
| 615 ExtensionProcessManager* manager = | 615 ExtensionProcessManager* manager = |
| 616 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); | 616 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 617 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id())); | 617 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id())); |
| 618 ExtensionAction* action = GetBrowserAction(*extension); | 618 ExtensionAction* action = GetBrowserAction(*extension); |
| 619 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 619 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
| 620 | 620 |
| 621 content::WindowedNotificationObserver host_destroyed_observer( | 621 content::WindowedNotificationObserver host_destroyed_observer( |
| 622 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 622 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 623 content::NotificationService::AllSources()); | 623 content::NotificationService::AllSources()); |
| 624 | 624 |
| 625 // Click the browser action. | 625 // Click the browser action. |
| 626 extensions::ExtensionSystem::Get(browser()->profile())->extension_service()-> | 626 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( |
| 627 toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL, true); | 627 browser()->profile()); |
| 628 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); |
| 628 | 629 |
| 629 // It can take a moment for the background page to actually get destroyed | 630 // It can take a moment for the background page to actually get destroyed |
| 630 // so we wait for the notification before checking that it's really gone | 631 // so we wait for the notification before checking that it's really gone |
| 631 // and the badge text has been set. | 632 // and the badge text has been set. |
| 632 host_destroyed_observer.Wait(); | 633 host_destroyed_observer.Wait(); |
| 633 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); | 634 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); |
| 634 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 635 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
| 635 } | 636 } |
| 636 | 637 |
| 637 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { | 638 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 "backgroundColor);"; | 723 "backgroundColor);"; |
| 723 std::string result; | 724 std::string result; |
| 724 const std::string frame_xpath; | 725 const std::string frame_xpath; |
| 725 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString( | 726 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString( |
| 726 tab, frame_xpath, script, &result)); | 727 tab, frame_xpath, script, &result)); |
| 727 EXPECT_EQ(result, "red"); | 728 EXPECT_EQ(result, "red"); |
| 728 } | 729 } |
| 729 | 730 |
| 730 } // namespace | 731 } // namespace |
| 731 } // namespace extensions | 732 } // namespace extensions |
| OLD | NEW |