Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / toolbar / browser_action_test_util_views.cc
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.
4
5 #include "chrome/browser/extensions/browser_action_test_util.h"
6
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"
19
20 namespace {
21
22 BrowserActionsContainer* GetContainer(Browser* browser) {
23   return browser->window()->GetBrowserWindowTesting()->GetToolbarView()->
24       browser_actions();
25 }
26
27 }  // namespace
28
29 int BrowserActionTestUtil::NumberOfBrowserActions() {
30   return GetContainer(browser_)->num_browser_actions();
31 }
32
33 int BrowserActionTestUtil::VisibleBrowserActions() {
34   return GetContainer(browser_)->VisibleBrowserActions();
35 }
36
37 ExtensionAction* BrowserActionTestUtil::GetExtensionAction(int index) {
38   return extensions::ExtensionActionManager::Get(browser_->profile())->
39       GetBrowserAction(*GetContainer(browser_)->GetBrowserActionViewAt(index)->
40                        extension());
41 }
42
43 void BrowserActionTestUtil::InspectPopup(int index) {
44   GetContainer(browser_)->GetBrowserActionViewAt(index)->
45       view_controller()->InspectPopup();
46 }
47
48 bool BrowserActionTestUtil::HasIcon(int index) {
49   return !GetContainer(browser_)->GetBrowserActionViewAt(index)->
50       GetImage(views::Button::STATE_NORMAL).isNull();
51 }
52
53 gfx::Image BrowserActionTestUtil::GetIcon(int index) {
54   gfx::ImageSkia icon = GetContainer(browser_)->GetBrowserActionViewAt(index)->
55       GetIconForTest();
56   return gfx::Image(icon);
57 }
58
59 void BrowserActionTestUtil::Press(int index) {
60   GetContainer(browser_)->GetBrowserActionViewAt(index)->
61       view_controller()->ExecuteActionByUser();
62 }
63
64 std::string BrowserActionTestUtil::GetExtensionId(int index) {
65   return GetContainer(browser_)->GetBrowserActionViewAt(index)->
66       extension()->id();
67 }
68
69 std::string BrowserActionTestUtil::GetTooltip(int index) {
70   base::string16 text;
71   GetContainer(browser_)->GetBrowserActionViewAt(index)->
72       GetTooltipText(gfx::Point(), &text);
73   return base::UTF16ToUTF8(text);
74 }
75
76 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() {
77   return GetContainer(browser_)->TestGetPopup()->GetWidget()->GetNativeView();
78 }
79
80 bool BrowserActionTestUtil::HasPopup() {
81   return GetContainer(browser_)->TestGetPopup() != NULL;
82 }
83
84 gfx::Rect BrowserActionTestUtil::GetPopupBounds() {
85   return GetContainer(browser_)->TestGetPopup()->bounds();
86 }
87
88 bool BrowserActionTestUtil::HidePopup() {
89   GetContainer(browser_)->HideActivePopup();
90   return !HasPopup();
91 }
92
93 void BrowserActionTestUtil::SetIconVisibilityCount(size_t icons) {
94   GetContainer(browser_)->TestSetIconVisibilityCount(icons);
95 }
96
97 gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
98   return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight);
99 }
100
101 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
102   return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight);
103 }