Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / browser_action_test_util_views.cc
blob28339f43640e898e696f7984d9e923e9febb0364
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/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
11 #include "chrome/browser/ui/views/extensions/extension_popup.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h"
13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
16 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
17 #include "ui/aura/window.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/size.h"
20 #include "ui/gfx/image/image.h"
21 #include "ui/views/widget/widget.h"
23 namespace {
25 BrowserActionsContainer* GetContainer(Browser* browser,
26 ToolbarActionsBarDelegate* bar_delegate) {
27 if (bar_delegate)
28 return static_cast<BrowserActionsContainer*>(bar_delegate);
29 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->
30 browser_actions();
33 } // namespace
35 int BrowserActionTestUtil::NumberOfBrowserActions() {
36 return GetContainer(browser_, bar_delegate_)->num_toolbar_actions();
39 int BrowserActionTestUtil::VisibleBrowserActions() {
40 return GetContainer(browser_, bar_delegate_)->VisibleBrowserActions();
43 bool BrowserActionTestUtil::IsChevronShowing() {
44 BrowserActionsContainer* container = GetContainer(browser_, bar_delegate_);
45 gfx::Size visible_size = container->GetVisibleBounds().size();
46 return container->chevron() &&
47 container->chevron()->visible() &&
48 visible_size.width() >=
49 container->chevron()->GetPreferredSize().width() &&
50 !visible_size.IsEmpty();
53 void BrowserActionTestUtil::InspectPopup(int index) {
54 ToolbarActionView* view =
55 GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index);
56 static_cast<ExtensionActionViewController*>(view->view_controller())->
57 InspectPopup();
60 bool BrowserActionTestUtil::HasIcon(int index) {
61 return !GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
62 GetImage(views::Button::STATE_NORMAL).isNull();
65 gfx::Image BrowserActionTestUtil::GetIcon(int index) {
66 gfx::ImageSkia icon =
67 GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
68 GetIconForTest();
69 return gfx::Image(icon);
72 void BrowserActionTestUtil::Press(int index) {
73 GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
74 view_controller()->ExecuteAction(true);
77 std::string BrowserActionTestUtil::GetExtensionId(int index) {
78 return GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
79 view_controller()->GetId();
82 std::string BrowserActionTestUtil::GetTooltip(int index) {
83 base::string16 text;
84 GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
85 GetTooltipText(gfx::Point(), &text);
86 return base::UTF16ToUTF8(text);
89 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() {
90 return GetContainer(browser_, bar_delegate_)->TestGetPopup();
93 bool BrowserActionTestUtil::HasPopup() {
94 return GetContainer(browser_, bar_delegate_)->TestGetPopup() != NULL;
97 gfx::Size BrowserActionTestUtil::GetPopupSize() {
98 gfx::NativeView popup = GetContainer(browser_, bar_delegate_)->TestGetPopup();
99 views::Widget* widget = views::Widget::GetWidgetForNativeView(popup);
100 return widget->GetWindowBoundsInScreen().size();
103 bool BrowserActionTestUtil::HidePopup() {
104 GetContainer(browser_, bar_delegate_)->HideActivePopup();
105 return !HasPopup();
108 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) {
109 return GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
110 wants_to_run_for_testing();
113 bool BrowserActionTestUtil::OverflowedActionButtonWantsToRun() {
114 return BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->
115 app_menu()->overflowed_toolbar_action_wants_to_run_for_testing();
118 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() {
119 return GetContainer(browser_, bar_delegate_)->toolbar_actions_bar();
122 // static
123 gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
124 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight);
127 // static
128 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
129 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight);