OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ui/views/confirm_bubble_views.h" | 5 #include "chrome/browser/ui/views/confirm_bubble_views.h" |
6 | 6 |
7 #include "chrome/browser/ui/confirm_bubble.h" | 7 #include "chrome/browser/ui/confirm_bubble.h" |
8 #include "chrome/browser/ui/test/test_confirm_bubble_model.h" | 8 #include "chrome/browser/ui/test/test_confirm_bubble_model.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
12 | 12 |
13 using views::Widget; | 13 using views::Widget; |
14 | 14 |
15 typedef views::ViewsTestBase ConfirmBubbleViewsTest; | 15 typedef views::ViewsTestBase ConfirmBubbleViewsTest; |
16 | 16 |
17 TEST_F(ConfirmBubbleViewsTest, CreateAndClose) { | 17 TEST_F(ConfirmBubbleViewsTest, CreateAndClose) { |
18 // Create parent widget, as confirm bubble must have an owner. | 18 // Create parent widget, as confirm bubble must have an owner. |
19 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 19 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
20 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 20 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
21 scoped_ptr<views::Widget> parent_widget(new Widget); | 21 scoped_ptr<views::Widget> parent_widget(new Widget); |
22 parent_widget->Init(params); | 22 parent_widget->Init(params); |
23 parent_widget->Show(); | 23 parent_widget->Show(); |
24 | 24 |
25 // Bubble owns the model. | 25 // Bubble owns the model. |
26 bool model_deleted = false; | 26 bool model_deleted = false; |
27 TestConfirmBubbleModel* model = | 27 TestConfirmBubbleModel* model = |
28 new TestConfirmBubbleModel(&model_deleted, NULL, NULL, NULL); | 28 new TestConfirmBubbleModel(&model_deleted, NULL, NULL, NULL); |
29 ConfirmBubbleViews* bubble = | 29 ConfirmBubbleViews* bubble = new ConfirmBubbleViews(model); |
30 new ConfirmBubbleViews(parent_widget->GetNativeView(), | 30 gfx::NativeView parent = parent_widget->GetNativeView(); |
31 gfx::Point(12, 34), | 31 views::DialogDelegateView::CreateDialogWidget(bubble, NULL, parent)->Show(); |
32 model); | |
33 views::BubbleDelegateView::CreateBubble(bubble); | |
34 bubble->Show(); | |
35 | |
36 // We're anchored to a point, not a specific view or widget. | |
37 EXPECT_EQ("12,34", bubble->anchor_point().ToString()); | |
38 EXPECT_FALSE(bubble->anchor_view()); | |
39 EXPECT_FALSE(bubble->anchor_widget()); | |
40 | 32 |
41 // Clean up. | 33 // Clean up. |
42 bubble->GetWidget()->CloseNow(); | 34 bubble->GetWidget()->CloseNow(); |
43 parent_widget->CloseNow(); | 35 parent_widget->CloseNow(); |
44 EXPECT_TRUE(model_deleted); | 36 EXPECT_TRUE(model_deleted); |
45 } | 37 } |
OLD | NEW |