Commit 1adaaeb9 authored by Ben Reich's avatar Ben Reich Committed by Commit Bot

[js-code-coverage] Helper to setup coverage directory structure

The structure of the coverage directory is internal details of the
DevToolsListener class, extract the structure into a static function
|SetupCoverageStore| to avoid duplication of setup code.

R=noel@chromium.org

	--devtools-code-coverage

Bug: 1113941
Test: browser_tests --gtest_filter=*FilesApp* --devtools-code-coverage
Test: browser_tests --gtest_filter=*DevToolsListener*
Change-Id: Ia5d2a0553eeb791af707734bb5e28d8b3ef1c304
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2528607
Auto-Submit: Ben Reich <benreich@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825750}
parent 45a53a43
......@@ -85,6 +85,19 @@ std::string DevToolsListener::HostString(content::DevToolsAgentHost* host,
return result;
}
void DevToolsListener::SetupCoverageStore(const base::FilePath& store_path) {
if (!base::PathExists(store_path))
CHECK(base::CreateDirectory(store_path));
base::FilePath tests = store_path.AppendASCII("tests");
if (!base::PathExists(tests))
CHECK(base::CreateDirectory(tests));
base::FilePath scripts = store_path.AppendASCII("scripts");
if (!base::PathExists(scripts))
CHECK(base::CreateDirectory(scripts));
}
void DevToolsListener::Start(content::DevToolsAgentHost* host) {
std::string enable_runtime = "{\"id\":10,\"method\":\"Runtime.enable\"}";
SendCommandMessage(host, enable_runtime);
......
......@@ -42,6 +42,9 @@ class DevToolsListener : public content::DevToolsAgentHostClient {
static std::string HostString(content::DevToolsAgentHost* host,
const std::string& prefix = {});
// Creates coverage output directory and subdirectories.
static void SetupCoverageStore(const base::FilePath& store_path);
private:
// Starts CDP session on host.
void Start(content::DevToolsAgentHost* host);
......
......@@ -78,15 +78,7 @@ class DevToolsListenerBrowserTest : public content::DevToolsAgentHostObserver,
CHECK(tmp_dir_.CreateUniqueTempDir());
base::FilePath coverage_store =
tmp_dir_.GetPath().AppendASCII("devtools_listener_browser_test");
CHECK(base::CreateDirectory(coverage_store));
base::FilePath tests = coverage_store.AppendASCII("tests");
if (!base::PathExists(tests))
CHECK(base::CreateDirectory(tests));
base::FilePath scripts = coverage_store.AppendASCII("scripts");
if (!base::PathExists(scripts))
CHECK(base::CreateDirectory(scripts));
DevToolsListener::SetupCoverageStore(coverage_store);
for (auto& agent : devtools_agent_) {
auto* host = agent.first;
......
......@@ -1917,15 +1917,7 @@ void FileManagerBrowserTestBase::StartTest() {
base::FilePath store;
CHECK(base::PathService::Get(base::DIR_EXE, &store));
store = store.AppendASCII("devtools_code_coverage");
CHECK(base::CreateDirectory(store));
base::FilePath tests = store.AppendASCII("tests");
if (!base::PathExists(tests))
CHECK(base::CreateDirectory(tests));
base::FilePath scripts = store.AppendASCII("scripts");
if (!base::PathExists(scripts))
CHECK(base::CreateDirectory(scripts));
DevToolsListener::SetupCoverageStore(store);
for (auto& agent : devtools_agent_) {
auto* host = agent.first;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment