| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits> |
| 6 |
| 5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 8 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 11 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 13 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 12 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 40 const int32 kExpectedInt32Value = -1145258561; | 42 const int32 kExpectedInt32Value = -1145258561; |
| 41 const int64 kExpectedInt64Value = -77263311946305LL; | 43 const int64 kExpectedInt64Value = -77263311946305LL; |
| 42 | 44 |
| 43 // Positive numbers with different values in each byte, the last of | 45 // Positive numbers with different values in each byte, the last of |
| 44 // which can survive promotion to double and back. | 46 // which can survive promotion to double and back. |
| 45 const uint8 kExpectedUInt8Value = 65; | 47 const uint8 kExpectedUInt8Value = 65; |
| 46 const uint16 kExpectedUInt16Value = 16961; | 48 const uint16 kExpectedUInt16Value = 16961; |
| 47 const uint32 kExpectedUInt32Value = 1145258561; | 49 const uint32 kExpectedUInt32Value = 1145258561; |
| 48 const uint64 kExpectedUInt64Value = 77263311946305LL; | 50 const uint64 kExpectedUInt64Value = 77263311946305LL; |
| 49 | 51 |
| 52 // Double/float values, including special case constants. |
| 53 const double kExpectedDoubleVal = 3.14159265358979323846; |
| 54 const double kExpectedDoubleInf = std::numeric_limits<double>::infinity(); |
| 55 const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN(); |
| 56 const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal); |
| 57 const float kExpectedFloatInf = std::numeric_limits<float>::infinity(); |
| 58 const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN(); |
| 59 |
| 60 // NaN has the property that it is not equal to itself. |
| 61 #define EXPECT_NAN(x) EXPECT_NE(x, x) |
| 62 |
| 50 // Returns the path to the mojom js bindings file. | 63 // Returns the path to the mojom js bindings file. |
| 51 base::FilePath GetFilePathForJSResource(const std::string& path) { | 64 base::FilePath GetFilePathForJSResource(const std::string& path) { |
| 52 std::string binding_path = "gen/" + path + ".js"; | 65 std::string binding_path = "gen/" + path + ".js"; |
| 53 #if defined(OS_WIN) | 66 #if defined(OS_WIN) |
| 54 std::string tmp; | 67 std::string tmp; |
| 55 base::ReplaceChars(binding_path, "//", "\\", &tmp); | 68 base::ReplaceChars(binding_path, "//", "\\", &tmp); |
| 56 binding_path.swap(tmp); | 69 binding_path.swap(tmp); |
| 57 #endif | 70 #endif |
| 58 base::FilePath file_path; | 71 base::FilePath file_path; |
| 59 PathService::Get(CHILD_PROCESS_EXE, &file_path); | 72 PathService::Get(CHILD_PROCESS_EXE, &file_path); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 mojo::AllocationScope scope; | 150 mojo::AllocationScope scope; |
| 138 mojo::EchoArgs::Builder builder; | 151 mojo::EchoArgs::Builder builder; |
| 139 builder.set_si64(kExpectedInt64Value); | 152 builder.set_si64(kExpectedInt64Value); |
| 140 builder.set_si32(kExpectedInt32Value); | 153 builder.set_si32(kExpectedInt32Value); |
| 141 builder.set_si16(kExpectedInt16Value); | 154 builder.set_si16(kExpectedInt16Value); |
| 142 builder.set_si8(kExpectedInt8Value); | 155 builder.set_si8(kExpectedInt8Value); |
| 143 builder.set_ui64(kExpectedUInt64Value); | 156 builder.set_ui64(kExpectedUInt64Value); |
| 144 builder.set_ui32(kExpectedUInt32Value); | 157 builder.set_ui32(kExpectedUInt32Value); |
| 145 builder.set_ui16(kExpectedUInt16Value); | 158 builder.set_ui16(kExpectedUInt16Value); |
| 146 builder.set_ui8(kExpectedUInt8Value); | 159 builder.set_ui8(kExpectedUInt8Value); |
| 160 builder.set_float_val(kExpectedFloatVal); |
| 161 builder.set_float_inf(kExpectedFloatInf); |
| 162 builder.set_float_nan(kExpectedFloatNan); |
| 163 builder.set_double_val(kExpectedDoubleVal); |
| 164 builder.set_double_inf(kExpectedDoubleInf); |
| 165 builder.set_double_nan(kExpectedDoubleNan); |
| 147 builder.set_name("coming"); | 166 builder.set_name("coming"); |
| 148 client_->Echo(builder.Finish()); | 167 client_->Echo(builder.Finish()); |
| 149 } | 168 } |
| 150 | 169 |
| 151 virtual ~EchoBrowserTargetImpl() {} | 170 virtual ~EchoBrowserTargetImpl() {} |
| 152 | 171 |
| 153 // mojo::BrowserTarget overrides: | 172 // mojo::BrowserTarget overrides: |
| 154 // Check the response, and quit the RunLoop after N calls. | 173 // Check the response, and quit the RunLoop after N calls. |
| 155 virtual void EchoResponse(const mojo::EchoArgs& arg1, | 174 virtual void EchoResponse(const mojo::EchoArgs& arg1, |
| 156 const mojo::EchoArgs& arg2) OVERRIDE { | 175 const mojo::EchoArgs& arg2) OVERRIDE { |
| 157 EXPECT_EQ(kExpectedInt64Value, arg1.si64()); | 176 EXPECT_EQ(kExpectedInt64Value, arg1.si64()); |
| 158 EXPECT_EQ(kExpectedInt32Value, arg1.si32()); | 177 EXPECT_EQ(kExpectedInt32Value, arg1.si32()); |
| 159 EXPECT_EQ(kExpectedInt16Value, arg1.si16()); | 178 EXPECT_EQ(kExpectedInt16Value, arg1.si16()); |
| 160 EXPECT_EQ(kExpectedInt8Value, arg1.si8()); | 179 EXPECT_EQ(kExpectedInt8Value, arg1.si8()); |
| 161 EXPECT_EQ(kExpectedUInt64Value, arg1.ui64()); | 180 EXPECT_EQ(kExpectedUInt64Value, arg1.ui64()); |
| 162 EXPECT_EQ(kExpectedUInt32Value, arg1.ui32()); | 181 EXPECT_EQ(kExpectedUInt32Value, arg1.ui32()); |
| 163 EXPECT_EQ(kExpectedUInt16Value, arg1.ui16()); | 182 EXPECT_EQ(kExpectedUInt16Value, arg1.ui16()); |
| 164 EXPECT_EQ(kExpectedUInt8Value, arg1.ui8()); | 183 EXPECT_EQ(kExpectedUInt8Value, arg1.ui8()); |
| 184 EXPECT_EQ(kExpectedFloatVal, arg1.float_val()); |
| 185 EXPECT_EQ(kExpectedFloatInf, arg1.float_inf()); |
| 186 EXPECT_NAN(arg1.float_nan()); |
| 187 EXPECT_EQ(kExpectedDoubleVal, arg1.double_val()); |
| 188 EXPECT_EQ(kExpectedDoubleInf, arg1.double_inf()); |
| 189 EXPECT_NAN(arg1.double_nan()); |
| 165 EXPECT_EQ(std::string("coming"), arg1.name().To<std::string>()); | 190 EXPECT_EQ(std::string("coming"), arg1.name().To<std::string>()); |
| 166 | 191 |
| 167 EXPECT_EQ(-1, arg2.si64()); | 192 EXPECT_EQ(-1, arg2.si64()); |
| 168 EXPECT_EQ(-1, arg2.si32()); | 193 EXPECT_EQ(-1, arg2.si32()); |
| 169 EXPECT_EQ(-1, arg2.si16()); | 194 EXPECT_EQ(-1, arg2.si16()); |
| 170 EXPECT_EQ(-1, arg2.si8()); | 195 EXPECT_EQ(-1, arg2.si8()); |
| 171 EXPECT_EQ(std::string("going"), arg2.name().To<std::string>()); | 196 EXPECT_EQ(std::string("going"), arg2.name().To<std::string>()); |
| 172 | 197 |
| 173 message_count += 1; | 198 message_count += 1; |
| 174 if (message_count == kExpectedMessageCount) | 199 if (message_count == kExpectedMessageCount) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 factory()->set_run_loop(&run_loop); | 374 factory()->set_run_loop(&run_loop); |
| 350 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?echo")); | 375 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?echo")); |
| 351 NavigateToURL(shell(), test_url); | 376 NavigateToURL(shell(), test_url); |
| 352 // RunLoop is quit when response received from page. | 377 // RunLoop is quit when response received from page. |
| 353 run_loop.Run(); | 378 run_loop.Run(); |
| 354 EXPECT_EQ(kExpectedMessageCount, message_count); | 379 EXPECT_EQ(kExpectedMessageCount, message_count); |
| 355 } | 380 } |
| 356 | 381 |
| 357 } // namespace | 382 } // namespace |
| 358 } // namespace content | 383 } // namespace content |
| OLD | NEW |