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 <gtk/gtk.h> 8 9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" 12 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" 13 #include "chrome/browser/ui/gtk/view_id_util.h" 14 15 namespace { 16 17 GtkWidget* GetButton(Browser* browser, int index) { 18 GtkWidget* toolbar = 19 ViewIDUtil::GetWidget(GTK_WIDGET(browser->window()->GetNativeHandle()), 20 VIEW_ID_BROWSER_ACTION_TOOLBAR); 21 GtkWidget* button = NULL; 22 if (toolbar) { 23 GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar)); 24 GtkWidget* alignment = 25 static_cast<GtkWidget*>(g_list_nth(children, index)->data); 26 button = gtk_bin_get_child(GTK_BIN(alignment)); 27 g_list_free(children); 28 } 29 return button; 30 } 31 32 } // namespace 33 34 int BrowserActionTestUtil::NumberOfBrowserActions() { 35 int count = -1; 36 GtkWidget* toolbar = 37 ViewIDUtil::GetWidget(GTK_WIDGET(browser_->window()->GetNativeHandle()), 38 VIEW_ID_BROWSER_ACTION_TOOLBAR); 39 if (toolbar) { 40 GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar)); 41 count = g_list_length(children); 42 g_list_free(children); 43 } 44 return count; 45 } 46 47 bool BrowserActionTestUtil::HasIcon(int index) { 48 GtkWidget* button = GetButton(browser_, index); 49 return gtk_button_get_image(GTK_BUTTON(button)) != NULL; 50 } 51 52 void BrowserActionTestUtil::Press(int index) { 53 GtkWidget* button = GetButton(browser_, index); 54 gtk_button_clicked(GTK_BUTTON(button)); 55 } 56 57 std::string BrowserActionTestUtil::GetTooltip(int index) { 58 GtkWidget* button = GetButton(browser_, index); 59 gchar* text = gtk_widget_get_tooltip_text(button); 60 std::string tooltip(text); 61 g_free(text); 62 return tooltip; 63 } 64 65 bool BrowserActionTestUtil::HasPopup() { 66 return ExtensionPopupGtk::get_current_extension_popup() != NULL; 67 } 68 69 gfx::Rect BrowserActionTestUtil::GetPopupBounds() { 70 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); 71 if (popup) 72 return popup->GetViewBounds(); 73 return gfx::Rect(); 74 } 75 76 bool BrowserActionTestUtil::HidePopup() { 77 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); 78 if (popup) 79 return popup->DestroyPopup(); 80 return false; 81 } 82 83 // static 84 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { 85 // On Linux we actually just limit the size of the extension view. 86 return gfx::Size(ExtensionPopupGtk::kMinWidth, ExtensionPopupGtk::kMinHeight); 87 } 88 89 // static 90 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { 91 return gfx::Size(ExtensionPopupGtk::kMaxWidth, ExtensionPopupGtk::kMaxHeight); 92 } 93