1 // Copyright (c) 2012 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"
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 #include "ui/gfx/image/image.h"
18 GtkWidget
* GetButton(Browser
* browser
, int index
) {
20 ViewIDUtil::GetWidget(GTK_WIDGET(browser
->window()->GetNativeWindow()),
21 VIEW_ID_BROWSER_ACTION_TOOLBAR
);
22 GtkWidget
* button
= NULL
;
24 GList
* children
= gtk_container_get_children(GTK_CONTAINER(toolbar
));
25 GtkWidget
* alignment
=
26 static_cast<GtkWidget
*>(g_list_nth(children
, index
)->data
);
27 button
= gtk_bin_get_child(GTK_BIN(alignment
));
28 g_list_free(children
);
35 int BrowserActionTestUtil::NumberOfBrowserActions() {
38 ViewIDUtil::GetWidget(GTK_WIDGET(browser_
->window()->GetNativeWindow()),
39 VIEW_ID_BROWSER_ACTION_TOOLBAR
);
41 GList
* children
= gtk_container_get_children(GTK_CONTAINER(toolbar
));
42 count
= g_list_length(children
);
43 g_list_free(children
);
48 bool BrowserActionTestUtil::HasIcon(int index
) {
49 GtkWidget
* button
= GetButton(browser_
, index
);
50 return gtk_button_get_image(GTK_BUTTON(button
)) != NULL
;
53 gfx::Image
BrowserActionTestUtil::GetIcon(int index
) {
54 GtkWidget
* button
= GetButton(browser_
, index
);
55 GtkWidget
* image
= gtk_button_get_image(GTK_BUTTON(button
));
56 GdkPixbuf
* pixbuf
= gtk_image_get_pixbuf(GTK_IMAGE(image
));
57 // gfx::Image takes ownership of the |pixbuf| reference. We have to increase
58 // the ref count so |pixbuf| stays around when the image object is destroyed.
60 return gfx::Image(pixbuf
);
63 void BrowserActionTestUtil::Press(int index
) {
64 GtkWidget
* button
= GetButton(browser_
, index
);
65 gtk_button_clicked(GTK_BUTTON(button
));
68 std::string
BrowserActionTestUtil::GetTooltip(int index
) {
69 GtkWidget
* button
= GetButton(browser_
, index
);
70 gchar
* text
= gtk_widget_get_tooltip_text(button
);
71 std::string
tooltip(text
);
76 bool BrowserActionTestUtil::HasPopup() {
77 return ExtensionPopupGtk::get_current_extension_popup() != NULL
;
80 gfx::Rect
BrowserActionTestUtil::GetPopupBounds() {
81 ExtensionPopupGtk
* popup
= ExtensionPopupGtk::get_current_extension_popup();
83 return popup
->GetViewBounds();
87 bool BrowserActionTestUtil::HidePopup() {
88 ExtensionPopupGtk
* popup
= ExtensionPopupGtk::get_current_extension_popup();
90 return popup
->DestroyPopup();
95 gfx::Size
BrowserActionTestUtil::GetMinPopupSize() {
96 // On Linux we actually just limit the size of the extension view.
97 return gfx::Size(ExtensionPopupGtk::kMinWidth
, ExtensionPopupGtk::kMinHeight
);
101 gfx::Size
BrowserActionTestUtil::GetMaxPopupSize() {
102 return gfx::Size(ExtensionPopupGtk::kMaxWidth
, ExtensionPopupGtk::kMaxHeight
);