diff options
author | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 01:22:56 +0000 |
---|---|---|
committer | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 01:22:56 +0000 |
commit | 49b261df4977d5c0f349fbc6513520ea62edf114 (patch) | |
tree | 7732e9c11bf49290b4af64de34eb97783530706c /content/browser/webui | |
parent | 6b2e271f2babfee4e7c3e3814872cf2308efb4b9 (diff) | |
download | chromium_src-49b261df4977d5c0f349fbc6513520ea62edf114.zip chromium_src-49b261df4977d5c0f349fbc6513520ea62edf114.tar.gz chromium_src-49b261df4977d5c0f349fbc6513520ea62edf114.tar.bz2 |
Fix WebUIMessageHandler unit tests.
BUG=110784
TEST=content_unittests --gtest_filter="WebUIMessageHandlerTest.*"
Review URL: http://codereview.chromium.org/9732027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/webui')
-rw-r--r-- | content/browser/webui/web_ui_message_handler.cc | 6 | ||||
-rw-r--r-- | content/browser/webui/web_ui_message_handler_unittest.cc | 46 |
2 files changed, 45 insertions, 7 deletions
diff --git a/content/browser/webui/web_ui_message_handler.cc b/content/browser/webui/web_ui_message_handler.cc index 8090e93..bf2d391 100644 --- a/content/browser/webui/web_ui_message_handler.cc +++ b/content/browser/webui/web_ui_message_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -54,10 +54,12 @@ bool WebUIMessageHandler::ExtractIntegerValue(const ListValue* value, } bool WebUIMessageHandler::ExtractDoubleValue(const ListValue* value, - double* out_value) { + double* out_value) { std::string string_value; if (value->GetString(0, &string_value)) return base::StringToDouble(string_value, out_value); + if (value->GetDouble(0, out_value)) + return true; NOTREACHED(); return false; } diff --git a/content/browser/webui/web_ui_message_handler_unittest.cc b/content/browser/webui/web_ui_message_handler_unittest.cc index 23ff85c..9b98211 100644 --- a/content/browser/webui/web_ui_message_handler_unittest.cc +++ b/content/browser/webui/web_ui_message_handler_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -14,6 +14,9 @@ namespace content { TEST(WebUIMessageHandlerTest, ExtractIntegerValue) { ListValue list; int value, zero_value = 0, neg_value = -1234, pos_value = 1234; + string16 zero_string(UTF8ToUTF16("0")); + string16 neg_string(UTF8ToUTF16("-1234")); + string16 pos_string(UTF8ToUTF16("1234")); list.Append(Value::CreateIntegerValue(zero_value)); EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value)); @@ -28,25 +31,58 @@ TEST(WebUIMessageHandlerTest, ExtractIntegerValue) { list.Append(Value::CreateIntegerValue(pos_value)); EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value)); EXPECT_EQ(value, pos_value); + list.Clear(); + + list.Append(Value::CreateStringValue(zero_string)); + EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value)); + EXPECT_EQ(value, zero_value); + list.Clear(); + + list.Append(Value::CreateStringValue(neg_string)); + EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value)); + EXPECT_EQ(value, neg_value); + list.Clear(); + + list.Append(Value::CreateStringValue(pos_string)); + EXPECT_TRUE(WebUIMessageHandler::ExtractIntegerValue(&list, &value)); + EXPECT_EQ(value, pos_value); } TEST(WebUIMessageHandlerTest, ExtractDoubleValue) { ListValue list; double value, zero_value = 0.0, neg_value = -1234.5, pos_value = 1234.5; + string16 zero_string(UTF8ToUTF16("0")); + string16 neg_string(UTF8ToUTF16("-1234.5")); + string16 pos_string(UTF8ToUTF16("1234.5")); list.Append(Value::CreateDoubleValue(zero_value)); EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value)); - EXPECT_EQ(value, zero_value); + EXPECT_DOUBLE_EQ(value, zero_value); list.Clear(); list.Append(Value::CreateDoubleValue(neg_value)); EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value)); - EXPECT_EQ(value, neg_value); + EXPECT_DOUBLE_EQ(value, neg_value); list.Clear(); list.Append(Value::CreateDoubleValue(pos_value)); EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value)); - EXPECT_EQ(value, pos_value); + EXPECT_DOUBLE_EQ(value, pos_value); + list.Clear(); + + list.Append(Value::CreateStringValue(zero_string)); + EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value)); + EXPECT_DOUBLE_EQ(value, zero_value); + list.Clear(); + + list.Append(Value::CreateStringValue(neg_string)); + EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value)); + EXPECT_DOUBLE_EQ(value, neg_value); + list.Clear(); + + list.Append(Value::CreateStringValue(pos_string)); + EXPECT_TRUE(WebUIMessageHandler::ExtractDoubleValue(&list, &value)); + EXPECT_DOUBLE_EQ(value, pos_value); } TEST(WebUIMessageHandlerTest, ExtractStringValue) { @@ -55,7 +91,7 @@ TEST(WebUIMessageHandlerTest, ExtractStringValue) { "The facts, though interesting, are irrelevant.")); list.Append(Value::CreateStringValue(in_string)); string16 out_string = WebUIMessageHandler::ExtractStringValue(&list); - EXPECT_STREQ(in_string.c_str(), out_string.c_str()); + EXPECT_EQ(in_string, out_string); } } // namespace content |