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
|
// Copyright (c) 2011 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/browser/webui/web_ui.h"
#include "base/string16.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
class TestWebUIMessageHandler : public WebUIMessageHandler {
public:
TestWebUIMessageHandler() {}
virtual ~TestWebUIMessageHandler() {}
protected:
virtual void RegisterMessages() {}
private:
DISALLOW_COPY_AND_ASSIGN(TestWebUIMessageHandler);
};
TEST(WebUIMessageHandlerTest, ExtractIntegerValue) {
TestWebUIMessageHandler handler;
ListValue list;
int value, zero_value = 0, neg_value = -1234, pos_value = 1234;
list.Append(Value::CreateIntegerValue(zero_value));
EXPECT_TRUE(handler.ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, zero_value);
list.Clear();
list.Append(Value::CreateIntegerValue(neg_value));
EXPECT_TRUE(handler.ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, neg_value);
list.Clear();
list.Append(Value::CreateIntegerValue(pos_value));
EXPECT_TRUE(handler.ExtractIntegerValue(&list, &value));
EXPECT_EQ(value, pos_value);
}
TEST(WebUIMessageHandlerTest, ExtractDoubleValue) {
TestWebUIMessageHandler handler;
ListValue list;
double value, zero_value = 0.0, neg_value = -1234.5, pos_value = 1234.5;
list.Append(Value::CreateDoubleValue(zero_value));
EXPECT_TRUE(handler.ExtractDoubleValue(&list, &value));
EXPECT_EQ(value, zero_value);
list.Clear();
list.Append(Value::CreateDoubleValue(neg_value));
EXPECT_TRUE(handler.ExtractDoubleValue(&list, &value));
EXPECT_EQ(value, neg_value);
list.Clear();
list.Append(Value::CreateDoubleValue(pos_value));
EXPECT_TRUE(handler.ExtractDoubleValue(&list, &value));
EXPECT_EQ(value, pos_value);
}
TEST(WebUIMessageHandlerTest, ExtractStringValue) {
TestWebUIMessageHandler handler;
ListValue list;
string16 in_string = "The facts, though interesting, are irrelevant."
list.Append(Value::CreateStringValue(string));
string16 out_string = handler.ExtractStringValue(&list);
EXPECT_STREQ(in_string.c_str(), out_string.c_str());
}
|