Commit 93ebd765 authored by Yiming Zhou's avatar Yiming Zhou Committed by Commit Bot

Support subdirectories inside password manager tests.

There are 15 different test scenario for password manager on each site. We therefore need to have subdirectories for different scenarios. This change adds support for 1 level of subdirectories in the password manager captured sites tests.

Bug: 847905
Change-Id: If3b52088bf857f8fcb0b42a5abcbf33ba9382055
Reviewed-on: https://chromium-review.googlesource.com/c/1325309
Commit-Queue: Yiming Zhou <uwyiming@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606574}
parent c0558c5b
...@@ -19,13 +19,20 @@ ...@@ -19,13 +19,20 @@
namespace { namespace {
// Return path to the Password Manager captured sites test directory. The struct TestParams {
// directory contains site capture files and test recipe replay files. std::string scenarioDir;
base::FilePath GetReplayFilesDirectory() { std::string siteName;
};
// Return path to the Password Manager captured sites test root directory. The
// directory contains subdirectories for different password manager test
// scenarios. The test scenario subdirectories contain site capture files
// and test recipe replay files.
base::FilePath GetReplayFilesRootDirectory() {
base::FilePath src_dir; base::FilePath src_dir;
if (base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) { if (base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) {
return src_dir.Append( return src_dir.Append(
FILE_PATH_LITERAL("chrome/test/data/password/captured_sites/sign_in")); FILE_PATH_LITERAL("chrome/test/data/password/captured_sites"));
} }
ADD_FAILURE() << "Unable to obtain the Chromium src directory!"; ADD_FAILURE() << "Unable to obtain the Chromium src directory!";
...@@ -36,10 +43,13 @@ base::FilePath GetReplayFilesDirectory() { ...@@ -36,10 +43,13 @@ base::FilePath GetReplayFilesDirectory() {
// Iterate through Password Manager's Web Page Replay capture file directory to // Iterate through Password Manager's Web Page Replay capture file directory to
// look for captures sites and automation recipe files. Return a list of sites // look for captures sites and automation recipe files. Return a list of sites
// for which recipe-based testing is available. // for which recipe-based testing is available.
std::vector<std::string> GetCapturedSites() { std::vector<TestParams> GetCapturedSites() {
std::vector<std::string> sites; std::vector<TestParams> sites;
base::FileEnumerator capture_files(GetReplayFilesDirectory(), false, base::FileEnumerator sub_dirs(GetReplayFilesRootDirectory(), false,
base::FileEnumerator::FILES); base::FileEnumerator::DIRECTORIES);
for (base::FilePath dir = sub_dirs.Next(); !dir.empty();
dir = sub_dirs.Next()) {
base::FileEnumerator capture_files(dir, false, base::FileEnumerator::FILES);
for (base::FilePath file = capture_files.Next(); !file.empty(); for (base::FilePath file = capture_files.Next(); !file.empty();
file = capture_files.Next()) { file = capture_files.Next()) {
// If a site capture file is found, also look to see if the directory has // If a site capture file is found, also look to see if the directory has
...@@ -48,18 +58,23 @@ std::vector<std::string> GetCapturedSites() { ...@@ -48,18 +58,23 @@ std::vector<std::string> GetCapturedSites() {
// has the '.test' extension. // has the '.test' extension.
if (file.Extension().empty() && if (file.Extension().empty() &&
base::PathExists(file.AddExtension(FILE_PATH_LITERAL(".test")))) { base::PathExists(file.AddExtension(FILE_PATH_LITERAL(".test")))) {
sites.push_back( TestParams params;
captured_sites_test_utils::FilePathToUTF8(file.BaseName().value())); params.scenarioDir =
captured_sites_test_utils::FilePathToUTF8(dir.BaseName().value());
params.siteName =
captured_sites_test_utils::FilePathToUTF8(file.BaseName().value());
sites.push_back(params);
}
} }
} }
std::sort(sites.begin(), sites.end());
return sites; return sites;
} }
struct GetParamAsString { struct GetParamAsString {
template <class ParamType> template <class ParamType>
std::string operator()(const testing::TestParamInfo<ParamType>& info) const { std::string operator()(const testing::TestParamInfo<ParamType>& info) const {
return info.param; return base::StringPrintf("%s_%s", info.param.scenarioDir.c_str(),
info.param.siteName.c_str());
} }
}; };
...@@ -74,7 +89,7 @@ class CapturedSitesPasswordManagerBrowserTest ...@@ -74,7 +89,7 @@ class CapturedSitesPasswordManagerBrowserTest
: public InProcessBrowserTest, : public InProcessBrowserTest,
public captured_sites_test_utils:: public captured_sites_test_utils::
TestRecipeReplayChromeFeatureActionExecutor, TestRecipeReplayChromeFeatureActionExecutor,
public ::testing::WithParamInterface<std::string> { public ::testing::WithParamInterface<TestParams> {
public: public:
// TestRecipeReplayChromeFeatureActionExecutor: // TestRecipeReplayChromeFeatureActionExecutor:
bool AddCredential(const std::string& origin, bool AddCredential(const std::string& origin,
...@@ -200,11 +215,16 @@ IN_PROC_BROWSER_TEST_P(CapturedSitesPasswordManagerBrowserTest, Recipe) { ...@@ -200,11 +215,16 @@ IN_PROC_BROWSER_TEST_P(CapturedSitesPasswordManagerBrowserTest, Recipe) {
base::FilePath src_dir; base::FilePath src_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
base::FilePath capture_file_path = base::FilePath capture_file_path =
GetReplayFilesDirectory().AppendASCII(GetParam().c_str()); GetReplayFilesRootDirectory()
.AppendASCII(GetParam().scenarioDir.c_str())
.AppendASCII(GetParam().siteName.c_str());
// Craft the recipe file path. // Craft the recipe file path.
base::FilePath recipe_file_path = GetReplayFilesDirectory().AppendASCII( base::FilePath recipe_file_path =
base::StringPrintf("%s.test", GetParam().c_str())); GetReplayFilesRootDirectory()
.AppendASCII(GetParam().scenarioDir.c_str())
.AppendASCII(
base::StringPrintf("%s.test", GetParam().siteName.c_str()));
ASSERT_TRUE( ASSERT_TRUE(
recipe_replayer()->ReplayTest(capture_file_path, recipe_file_path)); recipe_replayer()->ReplayTest(capture_file_path, recipe_file_path));
......
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