1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/browser_action_test_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_action_manager.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/browser_window_testing_views.h"
12 #include "chrome/browser/ui/views/extensions/extension_popup.h"
13 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
14 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
16 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/size.h"
22 BrowserActionsContainer* GetContainer(Browser* browser) {
23 return browser->window()->GetBrowserWindowTesting()->GetToolbarView()->
29 int BrowserActionTestUtil::NumberOfBrowserActions() {
30 return GetContainer(browser_)->num_browser_actions();
33 int BrowserActionTestUtil::VisibleBrowserActions() {
34 return GetContainer(browser_)->VisibleBrowserActions();
37 ExtensionAction* BrowserActionTestUtil::GetExtensionAction(int index) {
38 return extensions::ExtensionActionManager::Get(browser_->profile())->
39 GetBrowserAction(*GetContainer(browser_)->GetBrowserActionViewAt(index)->
43 void BrowserActionTestUtil::InspectPopup(int index) {
44 GetContainer(browser_)->GetBrowserActionViewAt(index)->
45 view_controller()->InspectPopup();
48 bool BrowserActionTestUtil::HasIcon(int index) {
49 return !GetContainer(browser_)->GetBrowserActionViewAt(index)->
50 GetImage(views::Button::STATE_NORMAL).isNull();
53 gfx::Image BrowserActionTestUtil::GetIcon(int index) {
54 gfx::ImageSkia icon = GetContainer(browser_)->GetBrowserActionViewAt(index)->
56 return gfx::Image(icon);
59 void BrowserActionTestUtil::Press(int index) {
60 GetContainer(browser_)->GetBrowserActionViewAt(index)->
61 view_controller()->ExecuteActionByUser();
64 std::string BrowserActionTestUtil::GetExtensionId(int index) {
65 return GetContainer(browser_)->GetBrowserActionViewAt(index)->
69 std::string BrowserActionTestUtil::GetTooltip(int index) {
71 GetContainer(browser_)->GetBrowserActionViewAt(index)->
72 GetTooltipText(gfx::Point(), &text);
73 return base::UTF16ToUTF8(text);
76 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() {
77 return GetContainer(browser_)->TestGetPopup()->GetWidget()->GetNativeView();
80 bool BrowserActionTestUtil::HasPopup() {
81 return GetContainer(browser_)->TestGetPopup() != NULL;
84 gfx::Rect BrowserActionTestUtil::GetPopupBounds() {
85 return GetContainer(browser_)->TestGetPopup()->bounds();
88 bool BrowserActionTestUtil::HidePopup() {
89 GetContainer(browser_)->HideActivePopup();
93 void BrowserActionTestUtil::SetIconVisibilityCount(size_t icons) {
94 GetContainer(browser_)->TestSetIconVisibilityCount(icons);
97 gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
98 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight);
101 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
102 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight);