resource_loader_unittest.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/webui/file_manager/resource_loader.h"
  5. #include "content/public/test/browser_task_environment.h"
  6. #include "content/public/test/test_web_ui_data_source.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "ui/base/webui/resource_path.h"
  9. #include "url/url_util.h"
  10. namespace ash {
  11. namespace file_manager {
  12. GURL GetURL(const std::string& path) {
  13. return GURL("chrome://test-file-manager-host/" + path);
  14. }
  15. class ResourceLoaderTest : public testing::Test {
  16. public:
  17. ResourceLoaderTest() = default;
  18. content::TestWebUIDataSource* source() { return source_.get(); }
  19. private:
  20. void SetUp() override {
  21. source_ = content::TestWebUIDataSource::Create("test-file-manager-host");
  22. }
  23. content::BrowserTaskEnvironment task_environment_;
  24. std::unique_ptr<content::TestWebUIDataSource> source_;
  25. };
  26. TEST_F(ResourceLoaderTest, AddFilesAppResources) {
  27. url::ScopedSchemeRegistryForTests scoped_registry;
  28. url::AddStandardScheme("chrome", url::SchemeType::SCHEME_WITH_HOST);
  29. const webui::ResourcePath kTestResources[] = {
  30. {"file_manager/images/icon192.png", 8},
  31. {"file_manager/untrusted_resources_files_img_content.css", 10},
  32. {"file_manager/untrusted_resources/files_img_content.css", 11},
  33. };
  34. const size_t kTestResourcesSize = std::size(kTestResources);
  35. AddFilesAppResources(source()->GetWebUIDataSource(), kTestResources,
  36. kTestResourcesSize);
  37. EXPECT_EQ(8, source()->URLToIdrOrDefault(GetURL("images/icon192.png")));
  38. EXPECT_EQ(10, source()->URLToIdrOrDefault(
  39. GetURL("untrusted_resources_files_img_content.css")));
  40. EXPECT_EQ(-1, source()->URLToIdrOrDefault(
  41. GetURL("untrusted_resources/files_img_content.css")));
  42. }
  43. } // namespace file_manager
  44. } // namespace ash