@@ -139,7 +139,8 @@ class TestAssetResolver : public AssetResolver {
139139 }
140140
141141 std::vector<std::unique_ptr<fml::Mapping>> GetAsMappings (
142- const std::string& asset_pattern) const override {
142+ const std::string& asset_pattern,
143+ const std::optional<std::string>& subdir) const override {
143144 return {};
144145 };
145146
@@ -2436,16 +2437,78 @@ TEST_F(ShellTest, AssetManagerMulti) {
24362437 asset_manager.PushBack (
24372438 std::make_unique<DirectoryAssetBundle>(std::move (asset_dir_fd), false ));
24382439
2439- auto mappings = asset_manager.GetAsMappings (" (.*)" );
2440- ASSERT_TRUE (mappings.size () == 4 );
2440+ auto mappings = asset_manager.GetAsMappings (" (.*)" , std:: nullopt );
2441+ EXPECT_EQ (mappings.size (), 4u );
24412442
24422443 std::vector<std::string> expected_results = {
24432444 " good0" ,
24442445 " good1" ,
24452446 };
24462447
2447- mappings = asset_manager.GetAsMappings (" (.*)good(.*)" );
2448- ASSERT_TRUE (mappings.size () == expected_results.size ());
2448+ mappings = asset_manager.GetAsMappings (" (.*)good(.*)" , std::nullopt );
2449+ ASSERT_EQ (mappings.size (), expected_results.size ());
2450+
2451+ for (auto & mapping : mappings) {
2452+ std::string result (reinterpret_cast <const char *>(mapping->GetMapping ()),
2453+ mapping->GetSize ());
2454+ EXPECT_NE (
2455+ std::find (expected_results.begin (), expected_results.end (), result),
2456+ expected_results.end ());
2457+ }
2458+ }
2459+
2460+ #if defined(OS_FUCHSIA)
2461+ TEST_F (ShellTest, AssetManagerMultiSubdir) {
2462+ std::string subdir_path = " subdir" ;
2463+
2464+ fml::ScopedTemporaryDirectory asset_dir;
2465+ fml::UniqueFD asset_dir_fd = fml::OpenDirectory (
2466+ asset_dir.path ().c_str (), false , fml::FilePermission::kRead );
2467+ fml::UniqueFD subdir_fd =
2468+ fml::OpenDirectory ((asset_dir.path () + " /" + subdir_path).c_str (), true ,
2469+ fml::FilePermission::kReadWrite );
2470+
2471+ std::vector<std::string> filenames = {
2472+ " bad0" ,
2473+ " notgood" , // this is to make sure the pattern (.*)good(.*) only matches
2474+ // things in the subdirectory
2475+ };
2476+
2477+ std::vector<std::string> subdir_filenames = {
2478+ " good0" ,
2479+ " good1" ,
2480+ " bad1" ,
2481+ };
2482+
2483+ for (auto filename : filenames) {
2484+ bool success = fml::WriteAtomically (asset_dir_fd, filename.c_str (),
2485+ fml::DataMapping (filename));
2486+ ASSERT_TRUE (success);
2487+ }
2488+
2489+ for (auto filename : subdir_filenames) {
2490+ bool success = fml::WriteAtomically (subdir_fd, filename.c_str (),
2491+ fml::DataMapping (filename));
2492+ ASSERT_TRUE (success);
2493+ }
2494+
2495+ AssetManager asset_manager;
2496+ asset_manager.PushBack (
2497+ std::make_unique<DirectoryAssetBundle>(std::move (asset_dir_fd), false ));
2498+
2499+ auto mappings = asset_manager.GetAsMappings (" (.*)" , std::nullopt );
2500+ EXPECT_EQ (mappings.size (), 5u );
2501+
2502+ mappings = asset_manager.GetAsMappings (" (.*)" , subdir_path);
2503+ EXPECT_EQ (mappings.size (), 3u );
2504+
2505+ std::vector<std::string> expected_results = {
2506+ " good0" ,
2507+ " good1" ,
2508+ };
2509+
2510+ mappings = asset_manager.GetAsMappings (" (.*)good(.*)" , subdir_path);
2511+ ASSERT_EQ (mappings.size (), expected_results.size ());
24492512
24502513 for (auto & mapping : mappings) {
24512514 std::string result (reinterpret_cast <const char *>(mapping->GetMapping ()),
@@ -2455,6 +2518,7 @@ TEST_F(ShellTest, AssetManagerMulti) {
24552518 expected_results.end ());
24562519 }
24572520}
2521+ #endif // OS_FUCHSIA
24582522
24592523TEST_F (ShellTest, Spawn) {
24602524 auto settings = CreateSettingsForFixture ();
0 commit comments