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

fix: reject contentTracing.stopRecording on failure #26655

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions shell/browser/api/electron_api_content_tracing.cc
Expand Up @@ -66,15 +66,26 @@ base::Optional<base::FilePath> CreateTemporaryFileOnIO() {

void StopTracing(gin_helper::Promise<base::FilePath> promise,
base::Optional<base::FilePath> file_path) {
auto resolve_or_reject = base::AdaptCallbackForRepeating(base::BindOnce(
[](gin_helper::Promise<base::FilePath> promise,
const base::FilePath& path, base::Optional<std::string> error) {
if (error) {
promise.RejectWithErrorMessage(error.value());
} else {
promise.Resolve(path);
}
},
std::move(promise), *file_path));
if (file_path) {
auto endpoint = TracingController::CreateFileEndpoint(
*file_path, base::AdaptCallbackForRepeating(base::BindOnce(
&gin_helper::Promise<base::FilePath>::ResolvePromise,
std::move(promise), *file_path)));
TracingController::GetInstance()->StopTracing(endpoint);
*file_path, base::BindRepeating(resolve_or_reject, base::nullopt));
if (!TracingController::GetInstance()->StopTracing(endpoint)) {
resolve_or_reject.Run(base::make_optional(
"Failed to stop tracing (was a trace in progress?)"));
}
} else {
promise.RejectWithErrorMessage(
"Failed to create temporary file for trace data");
resolve_or_reject.Run(
base::make_optional("Failed to create temporary file for trace data"));
}
}

Expand Down
4 changes: 4 additions & 0 deletions spec-main/api-content-tracing-spec.ts
Expand Up @@ -119,6 +119,10 @@ ifdescribe(!(process.platform !== 'win32' && ['arm', 'arm64'].includes(process.a
const resultFilePath = await record(/* options */ {}, /* outputFilePath */ undefined);
expect(resultFilePath).to.be.a('string').that.is.not.empty('result path');
});

it('rejects if no trace is happening', async () => {
await expect(contentTracing.stopRecording()).to.be.rejected();
});
});

describe('captured events', () => {
Expand Down