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 "ash/wm/frame_painter.h" | 5 #include "ash/wm/frame_painter.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_properties.h" |
11 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
17 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
19 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 scoped_ptr<FramePainter> painter(new FramePainter); | 117 scoped_ptr<FramePainter> painter(new FramePainter); |
117 ASSERT_TRUE(FramePainter::instances_); | 118 ASSERT_TRUE(FramePainter::instances_); |
118 EXPECT_EQ(1u, FramePainter::instances_->size()); | 119 EXPECT_EQ(1u, FramePainter::instances_->size()); |
119 | 120 |
120 // Destroying that painter leaves a valid pointer but no instances. | 121 // Destroying that painter leaves a valid pointer but no instances. |
121 painter.reset(); | 122 painter.reset(); |
122 ASSERT_TRUE(FramePainter::instances_); | 123 ASSERT_TRUE(FramePainter::instances_); |
123 EXPECT_EQ(0u, FramePainter::instances_->size()); | 124 EXPECT_EQ(0u, FramePainter::instances_->size()); |
124 } | 125 } |
125 | 126 |
| 127 TEST_F(FramePainterTest, CreateAndDeleteSingleWindow) { |
| 128 // Ensure that creating/deleting a window works well and doesn't cause |
| 129 // crashes. See crbug.com/155634 |
| 130 aura::RootWindow* root = Shell::GetActiveRootWindow(); |
| 131 |
| 132 scoped_ptr<Widget> widget(CreateTestWidget()); |
| 133 scoped_ptr<FramePainter> painter(new FramePainter); |
| 134 ImageButton size(NULL); |
| 135 ImageButton close(NULL); |
| 136 painter->Init( |
| 137 widget.get(), NULL, &size, &close, FramePainter::SIZE_BUTTON_MAXIMIZES); |
| 138 widget->Show(); |
| 139 |
| 140 // We only have one window, so it should use a solo header. |
| 141 EXPECT_TRUE(painter->UseSoloWindowHeader()); |
| 142 EXPECT_EQ(painter.get(), |
| 143 root->GetProperty(internal::kSoloWindowFramePainterKey)); |
| 144 |
| 145 // Close the window. |
| 146 widget.reset(); |
| 147 EXPECT_EQ(NULL, root->GetProperty(internal::kSoloWindowFramePainterKey)); |
| 148 |
| 149 // Recreate another window again. |
| 150 painter.reset(new FramePainter); |
| 151 widget.reset(CreateTestWidget()); |
| 152 |
| 153 painter->Init( |
| 154 widget.get(), NULL, &size, &close, FramePainter::SIZE_BUTTON_MAXIMIZES); |
| 155 widget->Show(); |
| 156 EXPECT_TRUE(painter->UseSoloWindowHeader()); |
| 157 EXPECT_EQ(painter.get(), |
| 158 root->GetProperty(internal::kSoloWindowFramePainterKey)); |
| 159 } |
| 160 |
126 TEST_F(FramePainterTest, UseSoloWindowHeader) { | 161 TEST_F(FramePainterTest, UseSoloWindowHeader) { |
127 // Create a widget and a painter for it. | 162 // Create a widget and a painter for it. |
128 scoped_ptr<Widget> w1(CreateTestWidget()); | 163 scoped_ptr<Widget> w1(CreateTestWidget()); |
129 FramePainter p1; | 164 FramePainter p1; |
130 ImageButton size1(NULL); | 165 ImageButton size1(NULL); |
131 ImageButton close1(NULL); | 166 ImageButton close1(NULL); |
132 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); | 167 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); |
133 w1->Show(); | 168 w1->Show(); |
134 | 169 |
135 // We only have one window, so it should use a solo header. | 170 // We only have one window, so it should use a solo header. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 EXPECT_EQ(HTRIGHT, | 389 EXPECT_EQ(HTRIGHT, |
355 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, | 390 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, |
356 screen.height() / 2))); | 391 screen.height() / 2))); |
357 // A hit into the middle lower area should generate right - not bottom&right. | 392 // A hit into the middle lower area should generate right - not bottom&right. |
358 EXPECT_EQ(HTRIGHT, | 393 EXPECT_EQ(HTRIGHT, |
359 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, | 394 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, |
360 screen.height() - 1))); | 395 screen.height() - 1))); |
361 } | 396 } |
362 | 397 |
363 } // namespace ash | 398 } // namespace ash |
OLD | NEW |