Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / webui / web_ui_message_handler_unittest.cc
blobcd12a3e8d61004129cfc0a6375c81dc590e4b9f2
1 // Copyright (c) 2012 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.
5 #include "content/public/browser/web_ui_message_handler.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace content {
14 TEST(WebUIMessageHandlerTest, ExtractIntegerValue) {
15 base::ListValue list;
16 int value, zero_value = 0, neg_value = -1234, pos_value = 1234;
17 base::string16 zero_string(base::UTF8ToUTF16("0"));
18 base::string16 neg_string(base::UTF8ToUTF16("-1234"));
19 base::string16 pos_string(base::UTF8ToUTF16("1234"));
21 list.Append(new base::FundamentalValue(zero_value));
22 EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
23 EXPECT_EQ(value, zero_value);
24 list.Clear();
26 list.Append(new base::FundamentalValue(neg_value));
27 EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
28 EXPECT_EQ(value, neg_value);
29 list.Clear();
31 list.Append(new base::FundamentalValue(pos_value));
32 EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
33 EXPECT_EQ(value, pos_value);
34 list.Clear();
36 list.Append(new base::StringValue(zero_string));
37 EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
38 EXPECT_EQ(value, zero_value);
39 list.Clear();
41 list.Append(new base::StringValue(neg_string));
42 EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
43 EXPECT_EQ(value, neg_value);
44 list.Clear();
46 list.Append(new base::StringValue(pos_string));
47 EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value));
48 EXPECT_EQ(value, pos_value);
51 TEST(WebUIMessageHandlerTest, ExtractDoubleValue) {
52 base::ListValue list;
53 double value, zero_value = 0.0, neg_value = -1234.5, pos_value = 1234.5;
54 base::string16 zero_string(base::UTF8ToUTF16("0"));
55 base::string16 neg_string(base::UTF8ToUTF16("-1234.5"));
56 base::string16 pos_string(base::UTF8ToUTF16("1234.5"));
58 list.Append(new base::FundamentalValue(zero_value));
59 EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
60 EXPECT_DOUBLE_EQ(value, zero_value);
61 list.Clear();
63 list.Append(new base::FundamentalValue(neg_value));
64 EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
65 EXPECT_DOUBLE_EQ(value, neg_value);
66 list.Clear();
68 list.Append(new base::FundamentalValue(pos_value));
69 EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
70 EXPECT_DOUBLE_EQ(value, pos_value);
71 list.Clear();
73 list.Append(new base::StringValue(zero_string));
74 EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
75 EXPECT_DOUBLE_EQ(value, zero_value);
76 list.Clear();
78 list.Append(new base::StringValue(neg_string));
79 EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
80 EXPECT_DOUBLE_EQ(value, neg_value);
81 list.Clear();
83 list.Append(new base::StringValue(pos_string));
84 EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value));
85 EXPECT_DOUBLE_EQ(value, pos_value);
88 TEST(WebUIMessageHandlerTest, ExtractStringValue) {
89 base::ListValue list;
90 base::string16 in_string(base::UTF8ToUTF16(
91 "The facts, though interesting, are irrelevant."));
92 list.Append(new base::StringValue(in_string));
93 base::string16 out_string = WebUIMessageHandler::ExtractStringValue(&list);
94 EXPECT_EQ(in_string, out_string);
97 } // namespace content