test_ash_web_view.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2020 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/test/test_ash_web_view.h"
  5. #include "base/bind.h"
  6. #include "base/threading/sequenced_task_runner_handle.h"
  7. #include "ui/views/view.h"
  8. namespace ash {
  9. TestAshWebView::TestAshWebView(const AshWebView::InitParams& init_params)
  10. : init_params_(init_params) {}
  11. TestAshWebView::~TestAshWebView() = default;
  12. void TestAshWebView::AddObserver(Observer* observer) {
  13. observers_.AddObserver(observer);
  14. }
  15. void TestAshWebView::RemoveObserver(Observer* observer) {
  16. observers_.RemoveObserver(observer);
  17. }
  18. gfx::NativeView TestAshWebView::GetNativeView() {
  19. // Not yet implemented for unittests.
  20. return nullptr;
  21. }
  22. bool TestAshWebView::GoBack() {
  23. // Not yet implemented for unittests.
  24. return false;
  25. }
  26. void TestAshWebView::Navigate(const GURL& url) {
  27. // Simulate navigation by notifying |observers_| of the expected event that
  28. // would normally signal navigation completion. We do this asynchronously to
  29. // more accurately simulate real-world conditions.
  30. base::SequencedTaskRunnerHandle::Get()->PostTask(
  31. FROM_HERE, base::BindOnce(
  32. [](const base::WeakPtr<TestAshWebView>& self) {
  33. if (self) {
  34. for (auto& observer : self->observers_)
  35. observer.DidStopLoading();
  36. }
  37. },
  38. weak_factory_.GetWeakPtr()));
  39. }
  40. views::View* TestAshWebView::GetInitiallyFocusedView() {
  41. return this;
  42. }
  43. void TestAshWebView::RequestFocus() {
  44. focused_ = true;
  45. }
  46. bool TestAshWebView::HasFocus() const {
  47. return focused_;
  48. }
  49. } // namespace ash