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
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/ui/views/generic_info_view.h"
7 #include "grit/chromium_strings.h"
8 #include "grit/generated_resources.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "views/controls/label.h"
12 #include "views/controls/textfield/textfield.h"
13 #include "views/widget/root_view.h"
14 #include "views/window/window.h"
15
16 #if defined(OS_WIN)
17 #include "views/widget/widget_win.h"
18 #endif
19
20 // This class is only used on windows for now.
21 #if defined(OS_WIN)
22
23 using namespace views;
24
25 class GenericInfoViewTest : public testing::Test {
26 public:
CreateWidget()27 Widget* CreateWidget() {
28 return views::Widget::CreateWidget(
29 Widget::CreateParams(Widget::CreateParams::TYPE_POPUP));
30 }
31 private:
32 MessageLoopForUI message_loop_;
33 };
34
TEST_F(GenericInfoViewTest,GenericInfoView)35 TEST_F(GenericInfoViewTest, GenericInfoView) {
36 const string16 kName = ASCIIToUTF16("Name");
37 const string16 kValue = ASCIIToUTF16("Value");
38
39 Widget* widget = CreateWidget();
40 widget->Init(NULL, gfx::Rect(0, 0, 100, 100));
41 RootView* root_view = widget->GetRootView();
42
43 GenericInfoView* view1 = new GenericInfoView(1);
44 root_view->AddChildView(view1);
45 view1->SetName(0, kName);
46 view1->SetValue(0, kValue);
47 EXPECT_EQ(kName, view1->name_views_[0]->GetText());
48 EXPECT_EQ(kValue, view1->value_views_[0]->text());
49 view1->ClearValues();
50 EXPECT_TRUE(view1->value_views_[0]->text().empty());
51
52 // Test setting values by localized string id.
53 static int kNameIds[] = {
54 IDS_PRODUCT_NAME,
55 IDS_PRODUCT_DESCRIPTION
56 };
57 GenericInfoView* view2 = new GenericInfoView(ARRAYSIZE(kNameIds), kNameIds);
58 root_view->AddChildView(view2);
59
60 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
61 string16 product_desc = l10n_util::GetStringUTF16(IDS_PRODUCT_DESCRIPTION);
62 EXPECT_EQ(product_name, view2->name_views_[0]->GetText());
63 EXPECT_EQ(product_desc, view2->name_views_[1]->GetText());
64 widget->CloseNow();
65 }
66 #endif // OS_WIN
67