Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ui/base/gtk/gtk_expanded_container.h" | 5 #include "ui/base/gtk/gtk_expanded_container.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 #define EXPECT_ALLOCATION_EQ(widget, x_, y_, width_, height_) \ | |
|
Elliot Glaysher
2011/11/28 18:47:08
Please use "do { ..code.. } while(0)" form inside
| |
| 10 { \ | |
| 11 GtkAllocation allocation; \ | |
| 12 gtk_widget_get_allocation(widget, &allocation); \ | |
| 13 EXPECT_EQ(x_, allocation.x); \ | |
| 14 EXPECT_EQ(y_, allocation.y); \ | |
| 15 EXPECT_EQ(width_, allocation.width); \ | |
| 16 EXPECT_EQ(height_, allocation.height); \ | |
| 17 } | |
| 18 | |
| 19 #define EXPECT_ALLOCATION_PARAM_EQ(widget, param, value) \ | |
| 20 { \ | |
| 21 GtkAllocation allocation; \ | |
| 22 gtk_widget_get_allocation(widget, &allocation); \ | |
| 23 EXPECT_EQ(value,allocation.param); \ | |
| 24 } | |
| 25 | |
| 9 class GtkExpandedContainerTest : public testing::Test { | 26 class GtkExpandedContainerTest : public testing::Test { |
| 10 protected: | 27 protected: |
| 11 GtkExpandedContainerTest() | 28 GtkExpandedContainerTest() |
| 12 : window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)), | 29 : window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)), |
| 13 expanded_(gtk_expanded_container_new()) { | 30 expanded_(gtk_expanded_container_new()) { |
| 14 gtk_window_set_default_size(GTK_WINDOW(window_), 200, 200); | 31 gtk_window_set_default_size(GTK_WINDOW(window_), 200, 200); |
| 15 gtk_container_add(GTK_CONTAINER(window_), expanded_); | 32 gtk_container_add(GTK_CONTAINER(window_), expanded_); |
| 16 } | 33 } |
| 17 ~GtkExpandedContainerTest() { | 34 ~GtkExpandedContainerTest() { |
| 18 gtk_widget_destroy(window_); | 35 gtk_widget_destroy(window_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 GtkWidget* child1 = gtk_fixed_new(); | 88 GtkWidget* child1 = gtk_fixed_new(); |
| 72 GtkWidget* child2 = gtk_fixed_new(); | 89 GtkWidget* child2 = gtk_fixed_new(); |
| 73 gtk_container_add(GTK_CONTAINER(expanded_), child1); | 90 gtk_container_add(GTK_CONTAINER(expanded_), child1); |
| 74 gtk_expanded_container_put(GTK_EXPANDED_CONTAINER(expanded_), | 91 gtk_expanded_container_put(GTK_EXPANDED_CONTAINER(expanded_), |
| 75 child2, 10, 20); | 92 child2, 10, 20); |
| 76 gtk_widget_show_all(window_); | 93 gtk_widget_show_all(window_); |
| 77 | 94 |
| 78 GtkAllocation allocation = { 0, 0, 50, 100 }; | 95 GtkAllocation allocation = { 0, 0, 50, 100 }; |
| 79 gtk_widget_size_allocate(expanded_, &allocation); | 96 gtk_widget_size_allocate(expanded_, &allocation); |
| 80 | 97 |
| 81 EXPECT_EQ(0, child1->allocation.x); | 98 EXPECT_ALLOCATION_EQ(child1, 0, 0, 50, 100); |
| 82 EXPECT_EQ(0, child1->allocation.y); | |
| 83 EXPECT_EQ(50, child1->allocation.width); | |
| 84 EXPECT_EQ(100, child1->allocation.height); | |
| 85 | 99 |
| 86 EXPECT_EQ(10, child2->allocation.x); | 100 EXPECT_ALLOCATION_EQ(child2, 10, 20, 50, 100); |
| 87 EXPECT_EQ(20, child2->allocation.y); | |
| 88 EXPECT_EQ(50, child2->allocation.width); | |
| 89 EXPECT_EQ(100, child2->allocation.height); | |
| 90 | 101 |
| 91 allocation.x = 10; | 102 allocation.x = 10; |
| 92 allocation.y = 20; | 103 allocation.y = 20; |
| 93 gtk_widget_size_allocate(expanded_, &allocation); | 104 gtk_widget_size_allocate(expanded_, &allocation); |
| 94 | 105 |
| 95 EXPECT_EQ(10, child1->allocation.x); | 106 EXPECT_ALLOCATION_PARAM_EQ(child1, x, 10); |
| 96 EXPECT_EQ(20, child1->allocation.y); | 107 EXPECT_ALLOCATION_PARAM_EQ(child1, y, 20); |
| 97 EXPECT_EQ(20, child2->allocation.x); | 108 EXPECT_ALLOCATION_PARAM_EQ(child2, x, 20); |
| 98 EXPECT_EQ(40, child2->allocation.y); | 109 EXPECT_ALLOCATION_PARAM_EQ(child2, y, 40); |
| 99 } | 110 } |
| 100 | 111 |
| 101 // Test if the size allocation for children still works when using own | 112 // Test if the size allocation for children still works when using own |
| 102 // GdkWindow. In this case, the children's origin starts from (0, 0) rather | 113 // GdkWindow. In this case, the children's origin starts from (0, 0) rather |
| 103 // than the container's origin. | 114 // than the container's origin. |
| 104 TEST_F(GtkExpandedContainerTest, HasWindow) { | 115 TEST_F(GtkExpandedContainerTest, HasWindow) { |
| 105 GtkWidget* child = gtk_fixed_new(); | 116 GtkWidget* child = gtk_fixed_new(); |
| 106 gtk_container_add(GTK_CONTAINER(expanded_), child); | 117 gtk_container_add(GTK_CONTAINER(expanded_), child); |
| 107 gtk_expanded_container_set_has_window(GTK_EXPANDED_CONTAINER(expanded_), | 118 gtk_expanded_container_set_has_window(GTK_EXPANDED_CONTAINER(expanded_), |
| 108 TRUE); | 119 TRUE); |
| 109 gtk_widget_show_all(window_); | 120 gtk_widget_show_all(window_); |
| 110 | 121 |
| 111 GtkAllocation allocation = { 10, 10, 50, 100 }; | 122 GtkAllocation allocation = { 10, 10, 50, 100 }; |
| 112 gtk_widget_size_allocate(expanded_, &allocation); | 123 gtk_widget_size_allocate(expanded_, &allocation); |
| 113 | 124 |
| 114 EXPECT_EQ(0, child->allocation.x); | 125 EXPECT_ALLOCATION_EQ(child, 0, 0, 50, 100); |
| 115 EXPECT_EQ(0, child->allocation.y); | |
| 116 EXPECT_EQ(50, child->allocation.width); | |
| 117 EXPECT_EQ(100, child->allocation.height); | |
| 118 } | 126 } |
| 119 | 127 |
| 120 static void OnChildSizeRequest(GtkExpandedContainer* container, | 128 static void OnChildSizeRequest(GtkExpandedContainer* container, |
| 121 GtkWidget* child, | 129 GtkWidget* child, |
| 122 GtkRequisition* requisition, | 130 GtkRequisition* requisition, |
| 123 gpointer userdata) { | 131 gpointer userdata) { |
| 124 ASSERT_EQ(child, GTK_WIDGET(userdata)); | 132 ASSERT_EQ(child, GTK_WIDGET(userdata)); |
| 125 requisition->width = 250; | 133 requisition->width = 250; |
| 126 requisition->height = -1; | 134 requisition->height = -1; |
| 127 } | 135 } |
| 128 | 136 |
| 129 TEST_F(GtkExpandedContainerTest, ChildSizeRequest) { | 137 TEST_F(GtkExpandedContainerTest, ChildSizeRequest) { |
| 130 GtkWidget* child = gtk_fixed_new(); | 138 GtkWidget* child = gtk_fixed_new(); |
| 131 gtk_widget_set_size_request(child, 10, 25); | 139 gtk_widget_set_size_request(child, 10, 25); |
| 132 g_signal_connect(expanded_, "child-size-request", | 140 g_signal_connect(expanded_, "child-size-request", |
| 133 G_CALLBACK(OnChildSizeRequest), child); | 141 G_CALLBACK(OnChildSizeRequest), child); |
| 134 gtk_container_add(GTK_CONTAINER(expanded_), child); | 142 gtk_container_add(GTK_CONTAINER(expanded_), child); |
| 135 gtk_widget_show_all(window_); | 143 gtk_widget_show_all(window_); |
| 136 | 144 |
| 137 GtkAllocation allocation = { 0, 0, 300, 100 }; | 145 GtkAllocation allocation = { 0, 0, 300, 100 }; |
| 138 gtk_widget_size_allocate(expanded_, &allocation); | 146 gtk_widget_size_allocate(expanded_, &allocation); |
| 139 | 147 |
| 140 EXPECT_EQ(0, child->allocation.x); | 148 EXPECT_ALLOCATION_EQ(child, 0, 0, 250, 25); |
| 141 EXPECT_EQ(0, child->allocation.y); | |
| 142 EXPECT_EQ(250, child->allocation.width); | |
| 143 EXPECT_EQ(25, child->allocation.height); | |
| 144 } | 149 } |
| 145 | 150 |
| 146 TEST_F(GtkExpandedContainerTest, ChildPosition) { | 151 TEST_F(GtkExpandedContainerTest, ChildPosition) { |
| 147 GtkWidget* child = gtk_fixed_new(); | 152 GtkWidget* child = gtk_fixed_new(); |
| 148 gtk_expanded_container_put(GTK_EXPANDED_CONTAINER(expanded_), | 153 gtk_expanded_container_put(GTK_EXPANDED_CONTAINER(expanded_), |
| 149 child, 10, 20); | 154 child, 10, 20); |
| 150 gtk_widget_show_all(window_); | 155 gtk_widget_show_all(window_); |
| 151 | 156 |
| 152 EXPECT_EQ(10, GetChildX(child)); | 157 EXPECT_EQ(10, GetChildX(child)); |
| 153 EXPECT_EQ(20, GetChildY(child)); | 158 EXPECT_EQ(20, GetChildY(child)); |
| 154 | 159 |
| 155 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(expanded_), | 160 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(expanded_), |
| 156 child, 40, 50); | 161 child, 40, 50); |
| 157 EXPECT_EQ(40, GetChildX(child)); | 162 EXPECT_EQ(40, GetChildX(child)); |
| 158 EXPECT_EQ(50, GetChildY(child)); | 163 EXPECT_EQ(50, GetChildY(child)); |
| 159 } | 164 } |
| OLD | NEW |