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
91
92
93
94
95
96
97
|
// Copyright (c) 2012 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 "content/public/browser/web_ui_message_handler.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
TEST(WebUIMessageHandlerTest, ExtractIntegerValue) {
base::ListValue list;
int value, zero_value = 0, neg_value = -1234, pos_value = 1234;
base::string16 zero_string(base::UTF8ToUTF16("0"));
base::string16 neg_string(base::UTF8ToUTF16("-1234"));
base::string16 pos_string(base::UTF8ToUTF16("1234"));
list.Append(new base::FundamentalValue(zero_value));
EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, zero_value);
list.Clear();
list.Append(new base::FundamentalValue(neg_value));
EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, neg_value);
list.Clear();
list.Append(new base::FundamentalValue(pos_value));
EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, pos_value);
list.Clear();
list.Append(new base::StringValue(zero_string));
EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, zero_value);
list.Clear();
list.Append(new base::StringValue(neg_string));
EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, neg_value);
list.Clear();
list.Append(new base::StringValue(pos_string));
EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, pos_value);
}
TEST(WebUIMessageHandlerTest, ExtractDoubleValue) {
base::ListValue list;
double value, zero_value = 0.0, neg_value = -1234.5, pos_value = 1234.5;
base::string16 zero_string(base::UTF8ToUTF16("0"));
base::string16 neg_string(base::UTF8ToUTF16("-1234.5"));
base::string16 pos_string(base::UTF8ToUTF16("1234.5"));
list.Append(new base::FundamentalValue(zero_value));
EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
EXPECT_DOUBLE_EQ(value, zero_value);
list.Clear();
list.Append(new base::FundamentalValue(neg_value));
EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
EXPECT_DOUBLE_EQ(value, neg_value);
list.Clear();
list.Append(new base::FundamentalValue(pos_value));
EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
EXPECT_DOUBLE_EQ(value, pos_value);
list.Clear();
list.Append(new base::StringValue(zero_string));
EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
EXPECT_DOUBLE_EQ(value, zero_value);
list.Clear();
list.Append(new base::StringValue(neg_string));
EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
EXPECT_DOUBLE_EQ(value, neg_value);
list.Clear();
list.Append(new base::StringValue(pos_string));
EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
EXPECT_DOUBLE_EQ(value, pos_value);
}
TEST(WebUIMessageHandlerTest, ExtractStringValue) {
base::ListValue list;
base::string16 in_string(base::UTF8ToUTF16(
"The facts, though interesting, are irrelevant."));
list.Append(new base::StringValue(in_string));
base::string16 out_string = WebUIMessageHandler::ExtractStringValue(&list);
EXPECT_EQ(in_string, out_string);
}
} // namespace content
|