OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 mojo::Binding<TestTime> binding_; | 115 mojo::Binding<TestTime> binding_; |
116 }; | 116 }; |
117 | 117 |
118 class TestValueImpl : public TestValue { | 118 class TestValueImpl : public TestValue { |
119 public: | 119 public: |
120 explicit TestValueImpl(TestValueRequest request) | 120 explicit TestValueImpl(TestValueRequest request) |
121 : binding_(this, std::move(request)) {} | 121 : binding_(this, std::move(request)) {} |
122 | 122 |
123 // TestValue implementation: | 123 // TestValue implementation: |
124 void BounceDictionaryValue( | 124 void BounceDictionaryValue( |
125 std::unique_ptr<base::DictionaryValue> in, | 125 const base::DictionaryValue& in, |
126 const BounceDictionaryValueCallback& callback) override { | 126 const BounceDictionaryValueCallback& callback) override { |
127 callback.Run(std::move(in)); | 127 callback.Run(in); |
128 } | 128 } |
129 | 129 |
130 void BounceListValue(std::unique_ptr<base::ListValue> in, | 130 void BounceListValue(const base::ListValue& in, |
131 const BounceListValueCallback& callback) override { | 131 const BounceListValueCallback& callback) override { |
132 callback.Run(std::move(in)); | 132 callback.Run(in); |
133 } | 133 } |
134 | 134 |
135 void BounceValue(std::unique_ptr<base::Value> in, | 135 void BounceValue(const base::Optional<base::Value>& in, |
136 const BounceValueCallback& callback) override { | 136 const BounceValueCallback& callback) override { |
137 callback.Run(std::move(in)); | 137 callback.Run(in); |
138 } | 138 } |
139 | 139 |
140 private: | 140 private: |
141 mojo::Binding<TestValue> binding_; | 141 mojo::Binding<TestValue> binding_; |
142 }; | 142 }; |
143 | 143 |
144 class TestString16Impl : public TestString16 { | 144 class TestString16Impl : public TestString16 { |
145 public: | 145 public: |
146 explicit TestString16Impl(TestString16Request request) | 146 explicit TestString16Impl(TestString16Request request) |
147 : binding_(this, std::move(request)) {} | 147 : binding_(this, std::move(request)) {} |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 262 |
263 ptr->BounceTimeTicks(t, ExpectResponse(&t, run_loop.QuitClosure())); | 263 ptr->BounceTimeTicks(t, ExpectResponse(&t, run_loop.QuitClosure())); |
264 | 264 |
265 run_loop.Run(); | 265 run_loop.Run(); |
266 } | 266 } |
267 | 267 |
268 TEST_F(CommonCustomTypesTest, Value) { | 268 TEST_F(CommonCustomTypesTest, Value) { |
269 TestValuePtr ptr; | 269 TestValuePtr ptr; |
270 TestValueImpl impl(MakeRequest(&ptr)); | 270 TestValueImpl impl(MakeRequest(&ptr)); |
271 | 271 |
272 std::unique_ptr<base::Value> output; | 272 base::Optional<base::Value> output; |
273 | 273 |
274 ASSERT_TRUE(ptr->BounceValue(nullptr, &output)); | 274 ASSERT_TRUE(ptr->BounceValue(base::nullopt, &output)); |
275 EXPECT_FALSE(output); | 275 EXPECT_FALSE(output); |
276 | 276 |
277 std::unique_ptr<base::Value> input = base::Value::CreateNullValue(); | 277 base::Optional<base::Value> input = *base::Value::CreateNullValue(); |
278 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 278 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
279 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 279 EXPECT_EQ(input, output); |
280 | 280 |
281 input = base::MakeUnique<base::Value>(123); | 281 input = base::Value(123); |
282 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 282 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
283 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 283 EXPECT_EQ(input, output); |
284 | 284 |
285 input = base::MakeUnique<base::Value>(1.23); | 285 input = base::Value(1.23); |
286 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 286 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
287 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 287 EXPECT_EQ(input, output); |
288 | 288 |
289 input = base::MakeUnique<base::Value>(false); | 289 input = base::Value(false); |
290 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 290 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
291 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 291 EXPECT_EQ(input, output); |
292 | 292 |
293 input = base::MakeUnique<base::Value>("test string"); | 293 input = base::Value("test string"); |
294 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 294 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
295 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 295 EXPECT_EQ(input, output); |
296 | 296 |
297 input = base::BinaryValue::CreateWithCopiedBuffer("mojo", 4); | 297 input = base::Value(std::vector<char>{'m', 'o', 'j', 'o'}); |
298 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 298 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
299 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 299 EXPECT_EQ(input, output); |
300 | 300 |
301 auto dict = base::MakeUnique<base::DictionaryValue>(); | 301 base::DictionaryValue dict; |
302 dict->SetBoolean("bool", false); | 302 dict.SetBoolean("bool", false); |
303 dict->SetInteger("int", 2); | 303 dict.SetInteger("int", 2); |
304 dict->SetString("string", "some string"); | 304 dict.SetString("string", "some string"); |
305 dict->SetBoolean("nested.bool", true); | 305 dict.SetBoolean("nested.bool", true); |
306 dict->SetInteger("nested.int", 9); | 306 dict.SetInteger("nested.int", 9); |
307 dict->Set("some_binary", | 307 dict.Set("some_binary", base::BinaryValue::CreateWithCopiedBuffer("mojo", 4)); |
308 base::BinaryValue::CreateWithCopiedBuffer("mojo", 4)); | 308 dict.Set("null_value", base::Value::CreateNullValue()); |
309 dict->Set("null_value", base::Value::CreateNullValue()); | 309 dict.SetIntegerWithoutPathExpansion("non_nested.int", 10); |
310 dict->SetIntegerWithoutPathExpansion("non_nested.int", 10); | |
311 { | 310 { |
312 std::unique_ptr<base::ListValue> dict_list(new base::ListValue()); | 311 std::unique_ptr<base::ListValue> dict_list(new base::ListValue()); |
313 dict_list->AppendString("string"); | 312 dict_list->AppendString("string"); |
314 dict_list->AppendBoolean(true); | 313 dict_list->AppendBoolean(true); |
315 dict->Set("list", std::move(dict_list)); | 314 dict.Set("list", std::move(dict_list)); |
316 } | 315 } |
317 | 316 |
318 std::unique_ptr<base::DictionaryValue> dict_output; | 317 base::DictionaryValue dict_output; |
319 ASSERT_TRUE(ptr->BounceDictionaryValue(dict->CreateDeepCopy(), &dict_output)); | 318 ASSERT_TRUE(ptr->BounceDictionaryValue(dict, &dict_output)); |
320 EXPECT_TRUE(base::Value::Equals(dict.get(), dict_output.get())); | 319 EXPECT_EQ(dict, dict_output); |
321 | 320 |
322 input = std::move(dict); | 321 input = std::move(dict); |
323 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 322 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
324 EXPECT_TRUE(base::Value::Equals(input.get(), output.get())); | 323 EXPECT_EQ(input, output); |
325 | 324 |
326 auto list = base::MakeUnique<base::ListValue>(); | 325 base::ListValue list; |
327 list->AppendString("string"); | 326 list.AppendString("string"); |
328 list->AppendDouble(42.1); | 327 list.AppendDouble(42.1); |
329 list->AppendBoolean(true); | 328 list.AppendBoolean(true); |
330 list->Append(base::BinaryValue::CreateWithCopiedBuffer("mojo", 4)); | 329 list.Append(base::BinaryValue::CreateWithCopiedBuffer("mojo", 4)); |
331 list->Append(base::Value::CreateNullValue()); | 330 list.Append(base::Value::CreateNullValue()); |
332 { | 331 { |
333 std::unique_ptr<base::DictionaryValue> list_dict( | 332 std::unique_ptr<base::DictionaryValue> list_dict( |
334 new base::DictionaryValue()); | 333 new base::DictionaryValue()); |
335 list_dict->SetString("string", "str"); | 334 list_dict->SetString("string", "str"); |
336 list->Append(std::move(list_dict)); | 335 list.Append(std::move(list_dict)); |
337 } | 336 } |
338 std::unique_ptr<base::ListValue> list_output; | 337 base::ListValue list_output; |
339 ASSERT_TRUE(ptr->BounceListValue(list->CreateDeepCopy(), &list_output)); | 338 ASSERT_TRUE(ptr->BounceListValue(list, &list_output)); |
340 EXPECT_TRUE(base::Value::Equals(list.get(), list_output.get())); | 339 EXPECT_EQ(list, list_output); |
341 | 340 |
342 input = std::move(list); | 341 input = std::move(list); |
343 ASSERT_TRUE(ptr->BounceValue(input->CreateDeepCopy(), &output)); | 342 ASSERT_TRUE(ptr->BounceValue(input, &output)); |
344 ASSERT_TRUE(base::Value::Equals(input.get(), output.get())); | 343 EXPECT_EQ(input, output); |
345 } | 344 } |
346 | 345 |
347 TEST_F(CommonCustomTypesTest, String16) { | 346 TEST_F(CommonCustomTypesTest, String16) { |
348 base::RunLoop run_loop; | 347 base::RunLoop run_loop; |
349 | 348 |
350 TestString16Ptr ptr; | 349 TestString16Ptr ptr; |
351 TestString16Impl impl(MakeRequest(&ptr)); | 350 TestString16Impl impl(MakeRequest(&ptr)); |
352 | 351 |
353 base::string16 str16 = base::ASCIIToUTF16("hello world"); | 352 base::string16 str16 = base::ASCIIToUTF16("hello world"); |
354 | 353 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 for (size_t i = 0; i < arraysize(kTestDirections); i++) { | 423 for (size_t i = 0; i < arraysize(kTestDirections); i++) { |
425 base::i18n::TextDirection direction_out; | 424 base::i18n::TextDirection direction_out; |
426 ASSERT_TRUE(ptr->BounceTextDirection(kTestDirections[i], &direction_out)); | 425 ASSERT_TRUE(ptr->BounceTextDirection(kTestDirections[i], &direction_out)); |
427 EXPECT_EQ(kTestDirections[i], direction_out); | 426 EXPECT_EQ(kTestDirections[i], direction_out); |
428 } | 427 } |
429 } | 428 } |
430 | 429 |
431 } // namespace test | 430 } // namespace test |
432 } // namespace common | 431 } // namespace common |
433 } // namespace mojo | 432 } // namespace mojo |
OLD | NEW |