Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: test/unittests/value-serializer-unittest.cc

Issue 2696133007: ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "include/v8.h" 10 #include "include/v8.h"
(...skipping 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 })); 2530 }));
2531 RoundTripTest( 2531 RoundTripTest(
2532 "({ a: new ExampleHostObject(), get b() { return this.a; }})", 2532 "({ a: new ExampleHostObject(), get b() { return this.a; }})",
2533 [this](Local<Value> value) { 2533 [this](Local<Value> value) {
2534 EXPECT_TRUE(EvaluateScriptForResultBool( 2534 EXPECT_TRUE(EvaluateScriptForResultBool(
2535 "result.a instanceof ExampleHostObject")); 2535 "result.a instanceof ExampleHostObject"));
2536 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 2536 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
2537 }); 2537 });
2538 } 2538 }
2539 2539
2540 class ValueSerializerTestWithHostArrayBufferView
2541 : public ValueSerializerTestWithHostObject {
2542 protected:
2543 void BeforeEncode(ValueSerializer* serializer) override {
2544 serializer_ = serializer;
jbroman 2017/02/16 23:10:03 nit: prefer to call the superclass method rather t
Anna Henningsen 2017/02/17 12:22:55 Done.
2545 serializer_->SetTreatArrayBufferViewsAsHostObjects(true);
2546 }
2547 };
2548
2549 TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) {
2550 EXPECT_CALL(serializer_delegate_, WriteHostObject(isolate(), _))
2551 .WillOnce(Invoke([this](Isolate*, Local<Object> object) {
jbroman 2017/02/16 23:10:03 nit: EXPECT_TRUE(object->IsUint8Array()); Maybe a
Anna Henningsen 2017/02/17 12:22:55 Done, except for the second part... I can do that
2552 WriteExampleHostObjectTag();
2553 return Just(true);
2554 }));
2555 EXPECT_CALL(deserializer_delegate_, ReadHostObject(isolate()))
2556 .WillOnce(Invoke([this](Isolate*) {
2557 EXPECT_TRUE(ReadExampleHostObjectTag());
2558 return NewHostObject(deserialization_context(), 0, nullptr);
jbroman 2017/02/16 23:10:03 nit: it's a little weird to produce an entirely di
Anna Henningsen 2017/02/17 12:22:55 Done.
2559 }));
2560 RoundTripTest(
2561 "({ a: new Uint8Array([1, 2, 3]), get b() { return this.a; }})",
2562 [this](Local<Value> value) {
2563 EXPECT_TRUE(EvaluateScriptForResultBool(
2564 "result.a instanceof ExampleHostObject"));
2565 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
2566 });
2567 }
2568
2540 // It's expected that WebAssembly has more exhaustive tests elsewhere; this 2569 // It's expected that WebAssembly has more exhaustive tests elsewhere; this
2541 // mostly checks that the logic to embed it in structured clone serialization 2570 // mostly checks that the logic to embed it in structured clone serialization
2542 // works correctly. 2571 // works correctly.
2543 2572
2544 class ValueSerializerTestWithWasm : public ValueSerializerTest { 2573 class ValueSerializerTestWithWasm : public ValueSerializerTest {
2545 protected: 2574 protected:
2546 static void SetUpTestCase() { 2575 static void SetUpTestCase() {
2547 g_saved_flag = i::FLAG_expose_wasm; 2576 g_saved_flag = i::FLAG_expose_wasm;
2548 i::FLAG_expose_wasm = true; 2577 i::FLAG_expose_wasm = true;
2549 ValueSerializerTest::SetUpTestCase(); 2578 ValueSerializerTest::SetUpTestCase();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 InvalidDecodeTest(raw); 2720 InvalidDecodeTest(raw);
2692 } 2721 }
2693 2722
2694 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { 2723 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) {
2695 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); 2724 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00});
2696 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); 2725 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f});
2697 } 2726 }
2698 2727
2699 } // namespace 2728 } // namespace
2700 } // namespace v8 2729 } // namespace v8
OLDNEW
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698