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
|
// Copyright (c) 2010 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 "app/l10n_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/views/generic_info_view.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "views/controls/label.h"
#include "views/controls/textfield/textfield.h"
#include "views/widget/root_view.h"
#include "views/window/window.h"
#if defined(OS_WIN)
#include "views/widget/widget_win.h"
#endif
// This class is only used on windows for now.
#if defined(OS_WIN)
using namespace views;
class GenericInfoViewTest : public testing::Test {
public:
Widget* CreateWidget() {
return new WidgetWin();
}
private:
MessageLoopForUI message_loop_;
};
TEST_F(GenericInfoViewTest, GenericInfoView) {
const string16 kName = ASCIIToUTF16("Name");
const string16 kValue = ASCIIToUTF16("Value");
Widget* window = CreateWidget();
static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100));
RootView* root_view = window->GetRootView();
GenericInfoView* view1 = new GenericInfoView(1);
root_view->AddChildView(view1);
view1->SetName(0, kName);
view1->SetValue(0, kValue);
EXPECT_EQ(kName, view1->name_views_[0]->GetText());
EXPECT_EQ(kValue, view1->value_views_[0]->text());
view1->ClearValues();
EXPECT_TRUE(view1->value_views_[0]->text().empty());
// Test setting values by localized string id.
static int kNameIds[] = {
IDS_PRODUCT_NAME,
IDS_PRODUCT_DESCRIPTION
};
GenericInfoView* view2 = new GenericInfoView(ARRAYSIZE(kNameIds), kNameIds);
root_view->AddChildView(view2);
string16 product_name = l10n_util::GetString(IDS_PRODUCT_NAME);
string16 product_desc = l10n_util::GetString(IDS_PRODUCT_DESCRIPTION);
EXPECT_EQ(product_name, view2->name_views_[0]->GetText());
EXPECT_EQ(product_desc, view2->name_views_[1]->GetText());
window->CloseNow();
}
#endif // OS_WIN
|