summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authortsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-24 23:27:30 +0000
committertsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-24 23:27:30 +0000
commitc1e6534c6315aa4271dab1b0b630a1f916f3cb29 (patch)
tree19fa83841ad7d586daeac7ceb6ebed1828418b21 /content
parent7985c12b9f4ccfaa7fc18ba9d1ea19891aa09dde (diff)
downloadchromium_src-c1e6534c6315aa4271dab1b0b630a1f916f3cb29.zip
chromium_src-c1e6534c6315aa4271dab1b0b630a1f916f3cb29.tar.gz
chromium_src-c1e6534c6315aa4271dab1b0b630a1f916f3cb29.tar.bz2
Add support for Float/Double types for JS Mojo bindings.
This is now straightforward using the underlying DataView representation used by the Mojo JS bindings, given its support for these types. Review URL: https://codereview.chromium.org/247013008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/webui/web_ui_mojo_browsertest.cc25
-rw-r--r--content/test/data/web_ui_test_mojo_bindings.mojom8
2 files changed, 33 insertions, 0 deletions
diff --git a/content/browser/webui/web_ui_mojo_browsertest.cc b/content/browser/webui/web_ui_mojo_browsertest.cc
index 43f4ade..9bacd66 100644
--- a/content/browser/webui/web_ui_mojo_browsertest.cc
+++ b/content/browser/webui/web_ui_mojo_browsertest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <limits>
+
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
@@ -47,6 +49,17 @@ const uint16 kExpectedUInt16Value = 16961;
const uint32 kExpectedUInt32Value = 1145258561;
const uint64 kExpectedUInt64Value = 77263311946305LL;
+// Double/float values, including special case constants.
+const double kExpectedDoubleVal = 3.14159265358979323846;
+const double kExpectedDoubleInf = std::numeric_limits<double>::infinity();
+const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN();
+const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal);
+const float kExpectedFloatInf = std::numeric_limits<float>::infinity();
+const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN();
+
+// NaN has the property that it is not equal to itself.
+#define EXPECT_NAN(x) EXPECT_NE(x, x)
+
// Returns the path to the mojom js bindings file.
base::FilePath GetFilePathForJSResource(const std::string& path) {
std::string binding_path = "gen/" + path + ".js";
@@ -144,6 +157,12 @@ class EchoBrowserTargetImpl : public BrowserTargetImpl {
builder.set_ui32(kExpectedUInt32Value);
builder.set_ui16(kExpectedUInt16Value);
builder.set_ui8(kExpectedUInt8Value);
+ builder.set_float_val(kExpectedFloatVal);
+ builder.set_float_inf(kExpectedFloatInf);
+ builder.set_float_nan(kExpectedFloatNan);
+ builder.set_double_val(kExpectedDoubleVal);
+ builder.set_double_inf(kExpectedDoubleInf);
+ builder.set_double_nan(kExpectedDoubleNan);
builder.set_name("coming");
client_->Echo(builder.Finish());
}
@@ -162,6 +181,12 @@ class EchoBrowserTargetImpl : public BrowserTargetImpl {
EXPECT_EQ(kExpectedUInt32Value, arg1.ui32());
EXPECT_EQ(kExpectedUInt16Value, arg1.ui16());
EXPECT_EQ(kExpectedUInt8Value, arg1.ui8());
+ EXPECT_EQ(kExpectedFloatVal, arg1.float_val());
+ EXPECT_EQ(kExpectedFloatInf, arg1.float_inf());
+ EXPECT_NAN(arg1.float_nan());
+ EXPECT_EQ(kExpectedDoubleVal, arg1.double_val());
+ EXPECT_EQ(kExpectedDoubleInf, arg1.double_inf());
+ EXPECT_NAN(arg1.double_nan());
EXPECT_EQ(std::string("coming"), arg1.name().To<std::string>());
EXPECT_EQ(-1, arg2.si64());
diff --git a/content/test/data/web_ui_test_mojo_bindings.mojom b/content/test/data/web_ui_test_mojo_bindings.mojom
index 08dbc02..7fde1b3 100644
--- a/content/test/data/web_ui_test_mojo_bindings.mojom
+++ b/content/test/data/web_ui_test_mojo_bindings.mojom
@@ -1,5 +1,7 @@
module mojo {
+// This struct encompasses all of the basic types, so that they
+// may be sent from C++ to JS and back for validation.
struct EchoArgs {
int64 si64;
int32 si32;
@@ -9,6 +11,12 @@ struct EchoArgs {
uint32 ui32;
uint16 ui16;
uint8 ui8;
+ float float_val;
+ float float_inf;
+ float float_nan;
+ double double_val;
+ double double_inf;
+ double double_nan;
string name;
};