blob: 90d78088e50f76739961d60b1f3978e80ce13951 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/confirm_bubble_views.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/confirm_bubble.h"
#include "chrome/browser/ui/confirm_bubble_model.h"
#include "grit/theme_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
using views::Widget;
class TestConfirmBubbleModel : public ConfirmBubbleModel {
public:
TestConfirmBubbleModel() {}
virtual ~TestConfirmBubbleModel() {}
virtual string16 GetTitle() const OVERRIDE;
virtual string16 GetMessageText() const OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual int GetButtons() const OVERRIDE;
virtual string16 GetButtonLabel(BubbleButton button) const OVERRIDE;
virtual void Accept() OVERRIDE {}
virtual void Cancel() OVERRIDE {}
virtual string16 GetLinkText() const OVERRIDE;
virtual void LinkClicked() OVERRIDE {}
private:
DISALLOW_COPY_AND_ASSIGN(TestConfirmBubbleModel);
};
string16 TestConfirmBubbleModel::GetTitle() const {
return ASCIIToUTF16("Title");
}
string16 TestConfirmBubbleModel::GetMessageText() const {
return ASCIIToUTF16("Message");
}
gfx::Image* TestConfirmBubbleModel::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_PRODUCT_LOGO_16);
}
int TestConfirmBubbleModel::GetButtons() const {
return BUTTON_OK | BUTTON_CANCEL;
}
string16 TestConfirmBubbleModel::GetButtonLabel(BubbleButton button) const {
return button == BUTTON_OK ? ASCIIToUTF16("OK") : ASCIIToUTF16("Cancel");
}
string16 TestConfirmBubbleModel::GetLinkText() const {
return ASCIIToUTF16("Link");
}
///////////////////////////////////////////////////////////////////////////////
typedef views::ViewsTestBase ConfirmBubbleViewsTest;
TEST_F(ConfirmBubbleViewsTest, CreateAndClose) {
// Create parent widget, as confirm bubble must have an owner.
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
scoped_ptr<views::Widget> parent_widget(new Widget);
parent_widget->Init(params);
parent_widget->Show();
// Bubble owns the model.
ConfirmBubbleViews* bubble =
new ConfirmBubbleViews(parent_widget->GetNativeView(),
gfx::Point(12, 34),
new TestConfirmBubbleModel);
views::BubbleDelegateView::CreateBubble(bubble);
bubble->Show();
// We're anchored to a point, not a specific view or widget.
EXPECT_EQ("12,34", bubble->anchor_point().ToString());
EXPECT_FALSE(bubble->anchor_view());
EXPECT_FALSE(bubble->anchor_widget());
// Clean up.
bubble->GetWidget()->CloseNow();
parent_widget->CloseNow();
}
|