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

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

Issue 496863003: Consolidate ExtensionAction execution code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
6 #include "chrome/browser/extensions/browser_action_test_util.h" 7 #include "chrome/browser/extensions/browser_action_test_util.h"
7 #include "chrome/browser/extensions/extension_action.h" 8 #include "chrome/browser/extensions/extension_action.h"
8 #include "chrome/browser/extensions/extension_action_icon_factory.h" 9 #include "chrome/browser/extensions/extension_action_icon_factory.h"
9 #include "chrome/browser/extensions/extension_action_manager.h" 10 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 13 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/extensions/extension_toolbar_model.h" 14 #include "chrome/browser/extensions/extension_toolbar_model.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 ExtensionAction* action = GetBrowserAction(*extension); 109 ExtensionAction* action = GetBrowserAction(*extension);
109 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); 110 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId));
110 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 111 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId));
111 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), 112 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
112 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 113 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
113 114
114 // Simulate the browser action being clicked. 115 // Simulate the browser action being clicked.
115 ui_test_utils::NavigateToURL(browser(), 116 ui_test_utils::NavigateToURL(browser(),
116 test_server()->GetURL("files/extensions/test_file.txt")); 117 test_server()->GetURL("files/extensions/test_file.txt"));
117 118
118 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( 119 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
119 browser()->profile()); 120 extension, browser(), true);
120 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
121 121
122 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 122 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
123 } 123 }
124 124
125 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { 125 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
126 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 126 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
127 const Extension* extension = GetSingleLoadedExtension(); 127 const Extension* extension = GetSingleLoadedExtension();
128 ASSERT_TRUE(extension) << message_; 128 ASSERT_TRUE(extension) << message_;
129 129
130 #if defined (OS_MACOSX) 130 #if defined (OS_MACOSX)
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 585 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
586 Browser* incognito_browser = 586 Browser* incognito_browser =
587 new Browser(Browser::CreateParams(incognito_profile, 587 new Browser(Browser::CreateParams(incognito_profile,
588 browser()->host_desktop_type())); 588 browser()->host_desktop_type()));
589 // Navigate just to have a tab in this window, otherwise wonky things happen. 589 // Navigate just to have a tab in this window, otherwise wonky things happen.
590 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); 590 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
591 ASSERT_EQ(1, 591 ASSERT_EQ(1,
592 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); 592 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
593 593
594 // A click in the regular profile should open a tab in the regular profile. 594 // A click in the regular profile should open a tab in the regular profile.
595 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( 595 ExtensionActionAPI* extension_action_api =
596 browser()->profile()); 596 ExtensionActionAPI::Get(browser()->profile());
597 toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true); 597 extension_action_api->ExecuteExtensionAction(
598 extension, browser(), 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 toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true); 603 extension_action_api->ExecuteExtensionAction(
604 extension, incognito_browser, true);
603 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 605 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
604 } 606 }
605 607
606 // Disabled because of failures (crashes) on ASAN bot. 608 // Disabled because of failures (crashes) on ASAN bot.
607 // See http://crbug.com/98861. 609 // See http://crbug.com/98861.
608 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { 610 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) {
609 ASSERT_TRUE(LoadExtension( 611 ASSERT_TRUE(LoadExtension(
610 test_data_dir_.AppendASCII("browser_action/close_background"))); 612 test_data_dir_.AppendASCII("browser_action/close_background")));
611 const Extension* extension = GetSingleLoadedExtension(); 613 const Extension* extension = GetSingleLoadedExtension();
612 614
613 // There is a background page and a browser action with no badge text. 615 // There is a background page and a browser action with no badge text.
614 extensions::ProcessManager* manager = 616 extensions::ProcessManager* manager =
615 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 617 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
616 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id())); 618 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id()));
617 ExtensionAction* action = GetBrowserAction(*extension); 619 ExtensionAction* action = GetBrowserAction(*extension);
618 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); 620 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId));
619 621
620 content::WindowedNotificationObserver host_destroyed_observer( 622 content::WindowedNotificationObserver host_destroyed_observer(
621 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 623 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
622 content::NotificationService::AllSources()); 624 content::NotificationService::AllSources());
623 625
624 // Click the browser action. 626 // Click the browser action.
625 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get( 627 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
626 browser()->profile()); 628 extension, browser(), true);
627 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 const std::string script = 721 const std::string script =
721 "window.domAutomationController.send(document.body.style." 722 "window.domAutomationController.send(document.body.style."
722 "backgroundColor);"; 723 "backgroundColor);";
723 std::string result; 724 std::string result;
724 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); 725 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result));
725 EXPECT_EQ(result, "red"); 726 EXPECT_EQ(result, "red");
726 } 727 }
727 728
728 } // namespace 729 } // namespace
729 } // namespace extensions 730 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/active_tab_apitest.cc ('k') | chrome/browser/extensions/api/extension_action/extension_action_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698