Home | History | Annotate | Download | only in extensions
      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/utf_string_conversions.h"
      8 #include "chrome/browser/ui/browser.h"
      9 #include "chrome/browser/ui/browser_window.h"
     10 #include "chrome/browser/ui/views/browser_actions_container.h"
     11 #include "chrome/browser/ui/views/extensions/extension_popup.h"
     12 #include "chrome/browser/ui/views/toolbar_view.h"
     13 #include "chrome/test/in_process_browser_test.h"
     14 #include "chrome/test/ui_test_utils.h"
     15 #include "ui/gfx/rect.h"
     16 #include "ui/gfx/size.h"
     17 
     18 namespace {
     19 
     20 BrowserActionsContainer* GetContainer(Browser* browser) {
     21   BrowserActionsContainer* container =
     22       browser->window()->GetBrowserWindowTesting()->GetToolbarView()->
     23           browser_actions();
     24   return container;
     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 void BrowserActionTestUtil::WaitForBrowserActionUpdated(int index) {
     38   ui_test_utils::WaitForBrowserActionUpdated(
     39       GetContainer(browser_)->GetBrowserActionViewAt(index)->
     40           button()->extension()->browser_action());
     41 }
     42 
     43 bool BrowserActionTestUtil::HasIcon(int index) {
     44   return GetContainer(browser_)->GetBrowserActionViewAt(index)->button()->
     45       HasIcon();
     46 }
     47 
     48 void BrowserActionTestUtil::Press(int index) {
     49   GetContainer(browser_)->TestExecuteBrowserAction(index);
     50 }
     51 
     52 std::string BrowserActionTestUtil::GetExtensionId(int index) {
     53   BrowserActionButton* button =
     54       GetContainer(browser_)->GetBrowserActionViewAt(index)->button();
     55   return button->extension()->id();
     56 }
     57 
     58 std::string BrowserActionTestUtil::GetTooltip(int index) {
     59   std::wstring text;
     60   GetContainer(browser_)->GetBrowserActionViewAt(index)->button()->
     61     GetTooltipText(gfx::Point(), &text);
     62   return WideToUTF8(text);
     63 }
     64 
     65 bool BrowserActionTestUtil::HasPopup() {
     66   return GetContainer(browser_)->TestGetPopup() != NULL;
     67 }
     68 
     69 gfx::Rect BrowserActionTestUtil::GetPopupBounds() {
     70   return GetContainer(browser_)->TestGetPopup()->view()->bounds();
     71 }
     72 
     73 bool BrowserActionTestUtil::HidePopup() {
     74   BrowserActionsContainer* container = GetContainer(browser_);
     75   container->HidePopup();
     76   return !HasPopup();
     77 }
     78 
     79 void BrowserActionTestUtil::SetIconVisibilityCount(size_t icons) {
     80   GetContainer(browser_)->TestSetIconVisibilityCount(icons);
     81 }
     82 
     83 gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
     84   return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight);
     85 }
     86 
     87 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
     88   return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight);
     89 }
     90