| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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/views/browser_action_view.h" | |
| 12 #include "chrome/browser/ui/views/browser_actions_container.h" | |
| 13 #include "chrome/browser/ui/views/extensions/extension_popup.h" | |
| 14 #include "chrome/browser/ui/views/toolbar_view.h" | |
| 15 #include "ui/gfx/image/image.h" | |
| 16 #include "ui/gfx/rect.h" | |
| 17 #include "ui/gfx/size.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 BrowserActionsContainer* GetContainer(Browser* browser) { | |
| 22 BrowserActionsContainer* container = | |
| 23 browser->window()->GetBrowserWindowTesting()->GetToolbarView()-> | |
| 24 browser_actions(); | |
| 25 return container; | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 int BrowserActionTestUtil::NumberOfBrowserActions() { | |
| 31 return GetContainer(browser_)->num_browser_actions(); | |
| 32 } | |
| 33 | |
| 34 int BrowserActionTestUtil::VisibleBrowserActions() { | |
| 35 return GetContainer(browser_)->VisibleBrowserActions(); | |
| 36 } | |
| 37 | |
| 38 ExtensionAction* BrowserActionTestUtil::GetExtensionAction(int index) { | |
| 39 return extensions::ExtensionActionManager::Get(browser_->profile())-> | |
| 40 GetBrowserAction(*GetContainer(browser_)->GetBrowserActionViewAt(index)-> | |
| 41 button()->extension()); | |
| 42 } | |
| 43 | |
| 44 bool BrowserActionTestUtil::HasIcon(int index) { | |
| 45 return GetContainer(browser_)->GetBrowserActionViewAt(index)->button()-> | |
| 46 HasIcon(); | |
| 47 } | |
| 48 | |
| 49 gfx::Image BrowserActionTestUtil::GetIcon(int index) { | |
| 50 gfx::ImageSkia icon = GetContainer(browser_)->GetBrowserActionViewAt(index)-> | |
| 51 button()->GetIconForTest(); | |
| 52 return gfx::Image(icon); | |
| 53 } | |
| 54 | |
| 55 void BrowserActionTestUtil::Press(int index) { | |
| 56 GetContainer(browser_)->TestExecuteBrowserAction(index); | |
| 57 } | |
| 58 | |
| 59 std::string BrowserActionTestUtil::GetExtensionId(int index) { | |
| 60 BrowserActionButton* button = | |
| 61 GetContainer(browser_)->GetBrowserActionViewAt(index)->button(); | |
| 62 return button->extension()->id(); | |
| 63 } | |
| 64 | |
| 65 std::string BrowserActionTestUtil::GetTooltip(int index) { | |
| 66 string16 text; | |
| 67 GetContainer(browser_)->GetBrowserActionViewAt(index)->button()-> | |
| 68 GetTooltipText(gfx::Point(), &text); | |
| 69 return UTF16ToUTF8(text); | |
| 70 } | |
| 71 | |
| 72 bool BrowserActionTestUtil::HasPopup() { | |
| 73 return GetContainer(browser_)->TestGetPopup() != NULL; | |
| 74 } | |
| 75 | |
| 76 gfx::Rect BrowserActionTestUtil::GetPopupBounds() { | |
| 77 return GetContainer(browser_)->TestGetPopup()->bounds(); | |
| 78 } | |
| 79 | |
| 80 bool BrowserActionTestUtil::HidePopup() { | |
| 81 BrowserActionsContainer* container = GetContainer(browser_); | |
| 82 container->HidePopup(); | |
| 83 return !HasPopup(); | |
| 84 } | |
| 85 | |
| 86 void BrowserActionTestUtil::SetIconVisibilityCount(size_t icons) { | |
| 87 GetContainer(browser_)->TestSetIconVisibilityCount(icons); | |
| 88 } | |
| 89 | |
| 90 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { | |
| 91 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); | |
| 92 } | |
| 93 | |
| 94 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { | |
| 95 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); | |
| 96 } | |
| OLD | NEW |