Skip to content

Commit e5f893f

Browse files
committed
test(idl-convert): add test for idl-convert.js
1 parent dfe80f3 commit e5f893f

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

.assets/sample.idl

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright 2013 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+
// Use the <code>chrome.webrtcLoggingPrivate</code> API to control diagnostic
6+
// WebRTC logging.
7+
namespace webrtcLoggingPrivate {
8+
dictionary MetaDataEntry {
9+
// The meta data entry key.
10+
DOMString key;
11+
12+
// The meta data entry value.
13+
DOMString value;
14+
};
15+
16+
dictionary UploadResult {
17+
// The report ID for the uploaded log. Will be empty if not successful.
18+
DOMString reportId;
19+
};
20+
21+
dictionary RequestInfo {
22+
// The tab identifier from the chrome.tabs API, if the request is from a
23+
// tab.
24+
long? tabId;
25+
26+
// The guest process id for the requester, if the request is from a
27+
// webview.
28+
long? guestProcessId;
29+
};
30+
31+
callback GenericDoneCallback = void ();
32+
callback UploadDoneCallback = void (UploadResult result);
33+
34+
interface Functions {
35+
// For all functions, |request| determines which render process to apply
36+
// the operation on. |request| identifies the requesting process.
37+
// |securityOrigin| is the security origin for the tab identified by |tabId|
38+
// and is used for verifying that the tab is the correct one and has not
39+
// been navigated away from.
40+
41+
// Sets additional custom meta data that will be uploaded along with the
42+
// log. |metaData| is a dictionary of the metadata (key, value).
43+
static void setMetaData(RequestInfo request,
44+
DOMString securityOrigin,
45+
MetaDataEntry[] metaData,
46+
GenericDoneCallback callback);
47+
48+
// Starts logging. If logging has already been started for this render
49+
// process, the call will be ignored. |appSessionId| is the unique session
50+
// ID which will be added to the log.
51+
static void start(RequestInfo request,
52+
DOMString securityOrigin,
53+
GenericDoneCallback callback);
54+
55+
// Sets whether the log should be uploaded automatically for the case when
56+
// the render process goes away (tab is closed or crashes) and stop has not
57+
// been called before that. If |shouldUpload| is true it will be uploaded,
58+
// otherwise it will be discarded. The default setting is to discard it.
59+
static void setUploadOnRenderClose(RequestInfo request,
60+
DOMString securityOrigin,
61+
boolean shouldUpload);
62+
63+
// Stops logging. After stop has finished, either upload() or discard()
64+
// should be called, otherwise the log will be kept in memory until the
65+
// render process is closed or logging restarted.
66+
static void stop(RequestInfo request,
67+
DOMString securityOrigin,
68+
GenericDoneCallback callback);
69+
70+
// Stores the current log without uploading. The log may stay around for
71+
// as much as 5 days. The application has the option of supplying an id
72+
// for uniquely identifying the log for later upload via a call to
73+
// uploadStored().
74+
static void store(RequestInfo request,
75+
DOMString securityOrigin,
76+
DOMString logId,
77+
GenericDoneCallback callback);
78+
79+
// Uploads a previously kept log that was stored via a call to store().
80+
// The caller needs to know the logId as was originally provided in the
81+
// call to store().
82+
static void uploadStored(RequestInfo request,
83+
DOMString securityOrigin,
84+
DOMString logId,
85+
UploadDoneCallback callback);
86+
87+
// Uploads the log and the RTP dumps, if they exist. Logging and RTP dumping
88+
// must be stopped before this function is called.
89+
static void upload(RequestInfo request,
90+
DOMString securityOrigin,
91+
UploadDoneCallback callback);
92+
93+
// Discards the log. Logging must be stopped before this function is called.
94+
static void discard(RequestInfo request,
95+
DOMString securityOrigin,
96+
GenericDoneCallback callback);
97+
98+
// Starts RTP dumping. If it has already been started for this render
99+
// process, the call will be ignored.
100+
static void startRtpDump(RequestInfo request,
101+
DOMString securityOrigin,
102+
boolean incoming,
103+
boolean outgoing,
104+
GenericDoneCallback callback);
105+
106+
// Stops RTP dumping. After stop has finished, the dumps will be
107+
// uploaded with the log if upload is called. Otherwise, the dumps will be
108+
// discarded.
109+
static void stopRtpDump(RequestInfo request,
110+
DOMString securityOrigin,
111+
boolean incoming,
112+
boolean outgoing,
113+
GenericDoneCallback callback);
114+
};
115+
};

tests/lib/idl-convert.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import test from 'ava';
18+
import { convertFromIdl } from '../../tools/lib/idl-convert.js';
19+
import { fetchAllTo } from '../../tools/lib/chrome-source.js';
20+
import { toolsPaths } from '../../tools/prepare.js';
21+
import { chromeVersions } from '../../tools/lib/chrome-versions.js';
22+
23+
test('convertFromIdl', async (t) => {
24+
// Make sure IDL still generated
25+
const filename = '.assets/sample.idl';
26+
let root = process.cwd();
27+
28+
if (process.env.CI) {
29+
const {head} = await chromeVersions()
30+
await fetchAllTo(root, toolsPaths, head);
31+
}
32+
33+
await t.notThrowsAsync(() =>
34+
convertFromIdl(root, filename)
35+
);
36+
});

tools/prepare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const definitionPaths = [
5151
/**
5252
* Fetch these folders to run the IDL => JSON converter.
5353
*/
54-
const toolsPaths = [
54+
export const toolsPaths = [
5555
'tools/json_schema_compiler',
5656
'tools/json_comment_eater',
5757
'ppapi/generators',

0 commit comments

Comments
 (0)