Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase code coverage #25

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .assets/sample.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Use the <code>chrome.webrtcLoggingPrivate</code> API to control diagnostic
// WebRTC logging.
namespace webrtcLoggingPrivate {
dictionary MetaDataEntry {
// The meta data entry key.
DOMString key;

// The meta data entry value.
DOMString value;
};

dictionary UploadResult {
// The report ID for the uploaded log. Will be empty if not successful.
DOMString reportId;
};

dictionary RequestInfo {
// The tab identifier from the chrome.tabs API, if the request is from a
// tab.
long? tabId;

// The guest process id for the requester, if the request is from a
// webview.
long? guestProcessId;
};

callback GenericDoneCallback = void ();
callback UploadDoneCallback = void (UploadResult result);

interface Functions {
// For all functions, |request| determines which render process to apply
// the operation on. |request| identifies the requesting process.
// |securityOrigin| is the security origin for the tab identified by |tabId|
// and is used for verifying that the tab is the correct one and has not
// been navigated away from.

// Sets additional custom meta data that will be uploaded along with the
// log. |metaData| is a dictionary of the metadata (key, value).
static void setMetaData(RequestInfo request,
DOMString securityOrigin,
MetaDataEntry[] metaData,
GenericDoneCallback callback);

// Starts logging. If logging has already been started for this render
// process, the call will be ignored. |appSessionId| is the unique session
// ID which will be added to the log.
static void start(RequestInfo request,
DOMString securityOrigin,
GenericDoneCallback callback);

// Sets whether the log should be uploaded automatically for the case when
// the render process goes away (tab is closed or crashes) and stop has not
// been called before that. If |shouldUpload| is true it will be uploaded,
// otherwise it will be discarded. The default setting is to discard it.
static void setUploadOnRenderClose(RequestInfo request,
DOMString securityOrigin,
boolean shouldUpload);

// Stops logging. After stop has finished, either upload() or discard()
// should be called, otherwise the log will be kept in memory until the
// render process is closed or logging restarted.
static void stop(RequestInfo request,
DOMString securityOrigin,
GenericDoneCallback callback);

// Stores the current log without uploading. The log may stay around for
// as much as 5 days. The application has the option of supplying an id
// for uniquely identifying the log for later upload via a call to
// uploadStored().
static void store(RequestInfo request,
DOMString securityOrigin,
DOMString logId,
GenericDoneCallback callback);

// Uploads a previously kept log that was stored via a call to store().
// The caller needs to know the logId as was originally provided in the
// call to store().
static void uploadStored(RequestInfo request,
DOMString securityOrigin,
DOMString logId,
UploadDoneCallback callback);

// Uploads the log and the RTP dumps, if they exist. Logging and RTP dumping
// must be stopped before this function is called.
static void upload(RequestInfo request,
DOMString securityOrigin,
UploadDoneCallback callback);

// Discards the log. Logging must be stopped before this function is called.
static void discard(RequestInfo request,
DOMString securityOrigin,
GenericDoneCallback callback);

// Starts RTP dumping. If it has already been started for this render
// process, the call will be ignored.
static void startRtpDump(RequestInfo request,
DOMString securityOrigin,
boolean incoming,
boolean outgoing,
GenericDoneCallback callback);

// Stops RTP dumping. After stop has finished, the dumps will be
// uploaded with the log if upload is called. Otherwise, the dumps will be
// discarded.
static void stopRtpDump(RequestInfo request,
DOMString securityOrigin,
boolean incoming,
boolean outgoing,
GenericDoneCallback callback);
};
};
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"scripts": {
"build": "node tools/run-release.js",
"test": "c8 --reporter=lcov --reporter=json --all --src=tools ava"
},
"private": true,
"type": "module",
"engines": {
"node": "16"
},
"devDependencies": {
"@types/fancy-log": "^1.3.1",
"@types/mri": "^1.1.1",
Expand All @@ -26,10 +34,5 @@
"tmp": "^0.2.1",
"turndown": "^7.1.1",
"typescript": "^4.4.3"
},
"scripts": {
"build": "node tools/run-release.js",
"test": "c8 --reporter=lcov --reporter=json --all --src=tools ava"
},
"private": true
}
}
2 changes: 1 addition & 1 deletion tests/buffer.js → tests/lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import test from 'ava';
import { RenderBuffer } from '../tools/lib/buffer.js';
import { RenderBuffer } from '../../tools/lib/buffer.js';


test('comment', t => {
Expand Down
57 changes: 57 additions & 0 deletions tests/lib/cache-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import test from 'ava';
import { readFromCache, writeToCache } from '../../tools/lib/cache-helper.js';

const filename = 'file.txt';
const message = 'abc';

test('readFromCache', (t) => {
let rfc;

// Returns message if file is found
writeToCache(filename, message);
rfc = readFromCache(filename);
t.deepEqual(rfc, Buffer.from(message));

// Returns null if file has expired
writeToCache(filename, message);
rfc = readFromCache(filename, -100);
t.is(rfc, null);

// Returns null if file is not found
rfc = readFromCache(String(Math.random()));
t.is(rfc, null);

// Returns null if no file name is provided
rfc = readFromCache('');
t.is(rfc, null);
});

test('writeToCache', (t) => {
// `writeToCache` doesn't throw an error with valid arguments
t.notThrows(() => {
writeToCache(filename, message);
writeToCache(filename, Buffer.from(message));
});

// `writeToCache` throws an error with invalid arguments
t.throws(() => {
//@ts-ignore
writeToCache(filename, new Promise());
});
});
53 changes: 53 additions & 0 deletions tests/lib/chrome-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import test from 'ava';
import {tmpdir} from 'os';
import { urlFor, fetchAllTo } from '../../tools/lib/chrome-source.js';

const revision = '23a41c068e35f33df1c3579a3b0b469d4458e6c1';
const chromePath = 'chrome/common/apps/platform_apps/api';
const chromePaths = [
'tools/json_schema_compiler',
'tools/json_schema_compiler/test',
'tools/json_comment_eater',
'ppapi/generators',
'third_party/ply',
];

test('urlFor', (t) => {
// Returns valid url
const uf = urlFor(revision, chromePath);
t.is(uf.startsWith('https://'), true);
t.is(uf.includes(revision), true);
t.is(uf.endsWith(`${chromePath}.tar.gz`), true);
});

test('fetchAllTo', async (t) => {
let fta;
// Returns chrome source tree files for each path
fta = await fetchAllTo(tmpdir(), chromePaths, revision);
t.is(Array.isArray(fta), true);
t.is(fta.length, chromePaths.length);

// Throws error with invalid arguments
// @ts-ignore
await t.throwsAsync(() => fetchAllTo(null, chromePaths, revision));
// @ts-ignore
t.throws(() => fetchAllTo(tmpdir(), null, revision));
// @ts-ignore
await t.throwsAsync(() => fetchAllTo(tmpdir(), chromePaths, null));
});
64 changes: 64 additions & 0 deletions tests/lib/chrome-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import test from 'ava';
import {
splitChromeRelease,
chromeVersions,
chromePublishedStable,
} from '../../tools/lib/chrome-versions.js';

test('splitChromeRelease', async (t) => {
/** @type {any} */
let scr;

// Returns undefined if too few parts
scr = await splitChromeRelease('88.0.4324');
t.is(scr, undefined);

// Returns undefined if too many parts
scr = await splitChromeRelease('88.0.4324.1.1');
t.is(scr, undefined);

// Returns major version is invalid
scr = await splitChromeRelease('a.b.c.d');
t.is(scr, undefined);

// Returns undefined if semantic version is invalid
scr = await splitChromeRelease('88.0.a.1');
t.is(scr, undefined);

// Returns release and rest of release tag if valid
scr = await splitChromeRelease('88.0.4324.47');
t.deepEqual(Object.keys(scr), ['release', 'rest']);
t.is(typeof scr.release, 'number');
t.is(typeof scr.rest, 'string');
});

test('chromeVersions', async (t) => {
// Returns head and map of chrome version releases
const cv = await chromeVersions();
t.is(typeof cv.head, 'string');
t.is(cv.releases instanceof Map, true);
t.is(cv.releases.size > 0, true);
t.deepEqual(Object.keys(cv), ['head', 'releases']);
})

test('chromePublishedStable', async (t) => {
// Returns number representing current stable version of Chrome
const cps = await chromePublishedStable();
t.is(typeof cps, 'number');
});
Loading