Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/browser_action_test_util.h" | 5 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" | 11 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| 12 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" | 12 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" |
| 13 #include "chrome/browser/ui/gtk/view_id_util.h" | 13 #include "chrome/browser/ui/gtk/view_id_util.h" |
| 14 #include "ui/gfx/image/image.h" | |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 GtkWidget* GetButton(Browser* browser, int index) { | 18 GtkWidget* GetButton(Browser* browser, int index) { |
| 18 GtkWidget* toolbar = | 19 GtkWidget* toolbar = |
| 19 ViewIDUtil::GetWidget(GTK_WIDGET(browser->window()->GetNativeWindow()), | 20 ViewIDUtil::GetWidget(GTK_WIDGET(browser->window()->GetNativeWindow()), |
| 20 VIEW_ID_BROWSER_ACTION_TOOLBAR); | 21 VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 21 GtkWidget* button = NULL; | 22 GtkWidget* button = NULL; |
| 22 if (toolbar) { | 23 if (toolbar) { |
| 23 GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar)); | 24 GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 42 g_list_free(children); | 43 g_list_free(children); |
| 43 } | 44 } |
| 44 return count; | 45 return count; |
| 45 } | 46 } |
| 46 | 47 |
| 47 bool BrowserActionTestUtil::HasIcon(int index) { | 48 bool BrowserActionTestUtil::HasIcon(int index) { |
| 48 GtkWidget* button = GetButton(browser_, index); | 49 GtkWidget* button = GetButton(browser_, index); |
| 49 return gtk_button_get_image(GTK_BUTTON(button)) != NULL; | 50 return gtk_button_get_image(GTK_BUTTON(button)) != NULL; |
| 50 } | 51 } |
| 51 | 52 |
| 53 uint32 BrowserActionTestUtil::GetIconID(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 will unref |pixbuf| when it goes away. Pair that unref here so | |
|
Jeffrey Yasskin
2012/08/17 23:20:28
"will unref" is a bit lower-level than I'd expect.
tbarzic
2012/08/21 00:22:07
Done.
| |
| 58 // |pixbuf| stays around. | |
| 59 g_object_ref(pixbuf); | |
| 60 return gfx::Image(pixbuf).AsBitmap().getGenerationID(); | |
|
Jeffrey Yasskin
2012/08/17 23:20:28
Isn't this going to return a new ID each time it's
tbarzic
2012/08/21 00:22:07
Yeah, you're probably right, but doesn't matter af
| |
| 61 } | |
| 62 | |
| 52 void BrowserActionTestUtil::Press(int index) { | 63 void BrowserActionTestUtil::Press(int index) { |
| 53 GtkWidget* button = GetButton(browser_, index); | 64 GtkWidget* button = GetButton(browser_, index); |
| 54 gtk_button_clicked(GTK_BUTTON(button)); | 65 gtk_button_clicked(GTK_BUTTON(button)); |
| 55 } | 66 } |
| 56 | 67 |
| 57 std::string BrowserActionTestUtil::GetTooltip(int index) { | 68 std::string BrowserActionTestUtil::GetTooltip(int index) { |
| 58 GtkWidget* button = GetButton(browser_, index); | 69 GtkWidget* button = GetButton(browser_, index); |
| 59 gchar* text = gtk_widget_get_tooltip_text(button); | 70 gchar* text = gtk_widget_get_tooltip_text(button); |
| 60 std::string tooltip(text); | 71 std::string tooltip(text); |
| 61 g_free(text); | 72 g_free(text); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 83 // static | 94 // static |
| 84 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { | 95 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { |
| 85 // On Linux we actually just limit the size of the extension view. | 96 // On Linux we actually just limit the size of the extension view. |
| 86 return gfx::Size(ExtensionPopupGtk::kMinWidth, ExtensionPopupGtk::kMinHeight); | 97 return gfx::Size(ExtensionPopupGtk::kMinWidth, ExtensionPopupGtk::kMinHeight); |
| 87 } | 98 } |
| 88 | 99 |
| 89 // static | 100 // static |
| 90 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { | 101 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { |
| 91 return gfx::Size(ExtensionPopupGtk::kMaxWidth, ExtensionPopupGtk::kMaxHeight); | 102 return gfx::Size(ExtensionPopupGtk::kMaxWidth, ExtensionPopupGtk::kMaxHeight); |
| 92 } | 103 } |
| OLD | NEW |