load_completion_observer.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 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 WEBLAYER_TEST_LOAD_COMPLETION_OBSERVER_H_
  5. #define WEBLAYER_TEST_LOAD_COMPLETION_OBSERVER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/run_loop.h"
  8. #include "weblayer/public/navigation_observer.h"
  9. namespace weblayer {
  10. class Shell;
  11. class Tab;
  12. // A helper that waits for the next load to complete.
  13. class LoadCompletionObserver : public NavigationObserver {
  14. public:
  15. // Creates an instance that begins waiting for a load within |shell| to
  16. // complete.
  17. explicit LoadCompletionObserver(Shell* shell);
  18. LoadCompletionObserver(const LoadCompletionObserver&) = delete;
  19. LoadCompletionObserver& operator=(const LoadCompletionObserver&) = delete;
  20. ~LoadCompletionObserver() override;
  21. // Spins a RunLoop until the next load completes.
  22. void Wait();
  23. private:
  24. // NavigationObserver implementation:
  25. void LoadStateChanged(bool is_loading, bool should_show_loading_ui) override;
  26. raw_ptr<Tab> tab_;
  27. base::RunLoop run_loop_;
  28. };
  29. } // namespace weblayer
  30. #endif // WEBLAYER_TEST_LOAD_COMPLETION_OBSERVER_H_