Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / extensions / browser_action_test_util_gtk.cc
blob3aed0a8084a2882d630e589856df180c549c467b
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"
7 #include <gtk/gtk.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"
16 namespace {
18 GtkWidget* GetButton(Browser* browser, int index) {
19 GtkWidget* toolbar =
20 ViewIDUtil::GetWidget(GTK_WIDGET(browser->window()->GetNativeWindow()),
21 VIEW_ID_BROWSER_ACTION_TOOLBAR);
22 GtkWidget* button = NULL;
23 if (toolbar) {
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);
30 return button;
33 } // namespace
35 int BrowserActionTestUtil::NumberOfBrowserActions() {
36 int count = -1;
37 GtkWidget* toolbar =
38 ViewIDUtil::GetWidget(GTK_WIDGET(browser_->window()->GetNativeWindow()),
39 VIEW_ID_BROWSER_ACTION_TOOLBAR);
40 if (toolbar) {
41 GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar));
42 count = g_list_length(children);
43 g_list_free(children);
45 return count;
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.
59 g_object_ref(pixbuf);
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);
72 g_free(text);
73 return tooltip;
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();
82 if (popup)
83 return popup->GetViewBounds();
84 return gfx::Rect();
87 bool BrowserActionTestUtil::HidePopup() {
88 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup();
89 if (popup)
90 return popup->DestroyPopup();
91 return false;
94 // static
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);
100 // static
101 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
102 return gfx::Size(ExtensionPopupGtk::kMaxWidth, ExtensionPopupGtk::kMaxHeight);