test_image_loader.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2015 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. #ifndef EXTENSIONS_BROWSER_TEST_IMAGE_LOADER_H_
  5. #define EXTENSIONS_BROWSER_TEST_IMAGE_LOADER_H_
  6. #include "base/run_loop.h"
  7. #include "ui/gfx/image/image.h"
  8. namespace extensions {
  9. class Extension;
  10. // Helper class for synchronously loading an extension image resource.
  11. class TestImageLoader {
  12. public:
  13. TestImageLoader();
  14. TestImageLoader(const TestImageLoader&) = delete;
  15. TestImageLoader& operator=(const TestImageLoader&) = delete;
  16. ~TestImageLoader();
  17. // Loads an image to be used in test from |extension|.
  18. // The image will be loaded from the relative path |image_path|.
  19. static SkBitmap LoadAndGetExtensionBitmap(const Extension* extension,
  20. const std::string& image_path,
  21. int size);
  22. private:
  23. void OnImageLoaded(const gfx::Image& image);
  24. SkBitmap LoadAndGetBitmap(const Extension* extension,
  25. const std::string& path,
  26. int size);
  27. gfx::Image image_;
  28. base::OnceClosure loader_message_loop_quit_;
  29. bool waiting_ = false;
  30. bool image_loaded_ = false;
  31. };
  32. } // namespace extensions
  33. #endif // EXTENSIONS_BROWSER_TEST_IMAGE_LOADER_H_