Commit 2a12f742 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[filesapp] Add DevToolsBrowserTest NavigateToTestFile helper

Add NavigateToTestFile helper: used to navigate chrome/test/data files
in-test with usage NavigateToTestFile("test.html").

CanCollectCodeCoverage uses content::ExecJs() to inject/run test JS on
the test page. This causes the script to be eval()-ed by ExecJS helper
JS code, which adds it to the JS coverage results.

Ideally, that would not be case. Denote the test script by kEvalScript
as a reminder that it's included in JS coverage results. Some upcoming
tests will give examples of controlling a page in-test, that leaves no
trace in the coverage results.

Tbr: benreich
Bug: 1113941
Change-Id: I8df81ded20bc2d67b12f8ee83d9674b48db47065
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484040
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818800}
parent 62c45457
...@@ -59,7 +59,20 @@ class DevToolsListenerBrowserTest : public content::DevToolsAgentHostObserver, ...@@ -59,7 +59,20 @@ class DevToolsListenerBrowserTest : public content::DevToolsAgentHostObserver,
LOG(FATAL) << "Host crashed: " << DevToolsListener::HostString(host); LOG(FATAL) << "Host crashed: " << DevToolsListener::HostString(host);
} }
void CollectCodeCoverage(const std::string test_name) { protected:
content::WebContents* NavigateToTestFile(const std::string& name) {
base::FilePath test_data_dir;
base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
CHECK(embedded_test_server()->Start());
GURL test_file_name_url = embedded_test_server()->GetURL('/' + name);
CHECK(ui_test_utils::NavigateToURL(browser(), test_file_name_url));
return browser()->tab_strip_model()->GetActiveWebContents();
}
void CollectCodeCoverage(const std::string& test_name) {
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
CHECK(tmp_dir_.CreateUniqueTempDir()); CHECK(tmp_dir_.CreateUniqueTempDir());
...@@ -90,18 +103,10 @@ class DevToolsListenerBrowserTest : public content::DevToolsAgentHostObserver, ...@@ -90,18 +103,10 @@ class DevToolsListenerBrowserTest : public content::DevToolsAgentHostObserver,
}; };
IN_PROC_BROWSER_TEST_F(DevToolsListenerBrowserTest, CanCollectCodeCoverage) { IN_PROC_BROWSER_TEST_F(DevToolsListenerBrowserTest, CanCollectCodeCoverage) {
base::FilePath test_data_dir; content::WebContents* web_contents = NavigateToTestFile("title2.html");
base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
embedded_test_server()->ServeFilesFromDirectory(test_data_dir); constexpr char kEvalScript[] = "(function() { console.log('test') })()";
ASSERT_TRUE(content::ExecJs(web_contents, kEvalScript));
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), embedded_test_server()->GetURL("/title2.html"), 1);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(
content::ExecJs(web_contents, "(function() { console.log('test'); })()"));
content::DevToolsAgentHost::RemoveObserver(this); content::DevToolsAgentHost::RemoveObserver(this);
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
......
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