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

Side by Side Diff: extensions/test/data/stash_client_unittest.js

Issue 2410743002: Remove the mojo serial interfaces and related infrastructure. (Closed)
Patch Set: Created 4 years, 2 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 | « extensions/test/data/serial_unittest.js ('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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Unit tests for the JS stash client.
7 *
8 * They are launched by extensions/renderer/mojo/stash_client_unittest.cc
9 */
10
11 var test = require('test').binding;
12 var unittestBindings = require('test_environment_specific_bindings');
13 var utils = require('utils');
14
15 var modulesPromise = Promise.all([
16 requireAsync('stash_client'),
17 requireAsync('extensions/common/mojo/stash.mojom'),
18 requireAsync('mojo/public/js/core'),
19 ]);
20
21 function writeAndClose(core, handle) {
22 var data = new Int8Array(1);
23 data[0] = 'a'.charCodeAt(0);
24 var result = core.writeData(handle, data, core.WRITE_DATA_FLAG_NONE);
25 test.assertEq(core.RESULT_OK, result.result);
26 test.assertEq(1, result.numBytes);
27 core.close(handle);
28 }
29
30 function readAndClose(core, handle) {
31 var result = core.readData(handle, core.READ_DATA_FLAG_NONE);
32 test.assertEq(core.RESULT_OK, result.result);
33 core.close(handle);
34 test.assertEq(1, result.buffer.byteLength);
35 test.assertEq('a'.charCodeAt(0), new Int8Array(result.buffer)[0]);
36 }
37
38 unittestBindings.exportTests([
39 function testStash() {
40 modulesPromise.then(function(modules) {
41 var stashClient = modules[0];
42 var stashMojom = modules[1];
43 var core = modules[2];
44 stashClient.registerClient('test', stashMojom.StashedObject, function() {
45 var stashedObject = new stashMojom.StashedObject();
46 stashedObject.id = 'test id';
47 stashedObject.data = [1, 2, 3, 4];
48 var dataPipe = core.createDataPipe({
49 flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
50 elementNumBytes: 1,
51 capacityNumBytes: 10,
52 });
53 writeAndClose(core, dataPipe.producerHandle);
54 stashedObject.stashed_handles = [dataPipe.consumerHandle];
55 return [{serialization: stashedObject, monitorHandles: true}];
56 });
57 stashClient.saveStashForTesting();
58 }).then(test.succeed, test.fail);
59 },
60
61 function testRetrieve() {
62 modulesPromise.then(function(modules) {
63 var stashClient = modules[0];
64 var stashMojom = modules[1];
65 var core = modules[2];
66 return stashClient.retrieve('test', stashMojom.StashedObject)
67 .then(function(stashedObjects) {
68 test.assertEq(1, stashedObjects.length);
69 test.assertEq('test id', stashedObjects[0].id);
70 test.assertEq([1, 2, 3, 4], stashedObjects[0].data);
71 test.assertEq(1, stashedObjects[0].stashed_handles.length);
72 readAndClose(core, stashedObjects[0].stashed_handles[0]);
73 });
74 }).then(test.succeed, test.fail);
75 },
76
77 ], test.runTests, exports);
OLDNEW
« no previous file with comments | « extensions/test/data/serial_unittest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698