File: media_router_ui_for_test_base.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (116 lines) | stat: -rw-r--r-- 4,422 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_MEDIA_ROUTER_MEDIA_ROUTER_UI_FOR_TEST_BASE_H_
#define CHROME_TEST_MEDIA_ROUTER_MEDIA_ROUTER_UI_FOR_TEST_BASE_H_

#include <optional>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_view.h"
#include "chrome/browser/ui/views/media_router/media_router_dialog_controller_views.h"
#include "components/media_router/common/media_sink.h"
#include "components/media_router/common/media_source.h"
#include "content/public/browser/web_contents_user_data.h"

namespace content {
class WebContents;
}  // namespace content

namespace media_router {

class MediaRouterUiForTestBase {
 public:
  virtual void SetUp() = 0;

  // Destruction of the test helper happens in two phases: the user of this
  // helper must first call `TearDown()` before destroying it. `TearDown()`
  // itself needs to call virtual functions, so that logic cannot live in the
  // destructor itself: by the time the destructor of this base class runs, the
  // virtual methods will not work as expected, because the derived class's
  // destructor will have already completed.
  void TearDown();

  // NOTE: the dialog being showable depends on the button used to open it
  // being visible. Callers should ensure that the button is visible before
  // calling ShowDialog(), e.g. by playing video to make the GMC button appear.
  virtual void ShowDialog() = 0;
  virtual bool IsDialogShown() const = 0;
  virtual void HideDialog() = 0;

  // Chooses the source type in the dialog. Requires that the dialog is shown.
  virtual void ChooseSourceType(CastDialogView::SourceType source_type) = 0;
  virtual CastDialogView::SourceType GetChosenSourceType() const = 0;

  // These methods require that the dialog is shown and the specified sink is
  // shown in the dialog.
  virtual void StartCasting(const std::string& sink_name) = 0;
  virtual void StopCasting(const std::string& sink_name) = 0;

  // Waits until a condition is met. Requires that the dialog is shown.
  virtual void WaitForSink(const std::string& sink_name) = 0;
  virtual void WaitForSinkAvailable(const std::string& sink_name) = 0;
  virtual void WaitForAnyIssue() = 0;
  virtual void WaitForAnyRoute() = 0;
  virtual void WaitForDialogShown() = 0;
  virtual void WaitForDialogHidden() = 0;

  // These methods require that the dialog is shown, and the sink specified by
  // |sink_name| is in the dialog.
  virtual MediaRoute::Id GetRouteIdForSink(
      const std::string& sink_name) const = 0;
  virtual std::string GetStatusTextForSink(
      const std::string& sink_name) const = 0;
  virtual std::string GetIssueTextForSink(
      const std::string& sink_name) const = 0;

  // Called by MediaRouterDialogControllerViews.
  virtual void OnDialogCreated();

  content::WebContents* web_contents() const { return web_contents_; }

  virtual ~MediaRouterUiForTestBase();

 protected:
  enum class WatchType {
    kNone,
    kSink,           // Sink is found in any state.
    kSinkAvailable,  // Sink is found in the "Available" state.
    kAnyIssue,
    kAnyRoute,
    kDialogShown,
    kDialogHidden
  };

  explicit MediaRouterUiForTestBase(content::WebContents* web_contents);
  void WaitForAnyDialogShown();

  static void ClickOnButton(views::Button* button);

  virtual views::Button* GetSinkButton(const std::string& sink_name) const = 0;

  // Registers itself as an observer to the dialog, and waits until an event
  // of |watch_type| is observed. |sink_name| should be set only if observing
  // for a sink.
  virtual void ObserveDialog(
      WatchType watch_type,
      std::optional<std::string> sink_name = std::nullopt) = 0;

  const raw_ptr<content::WebContents> web_contents_;
  const raw_ptr<MediaRouterDialogControllerViews> dialog_controller_;
  std::optional<std::string> watch_sink_name_;
  WatchType watch_type_ = WatchType::kNone;
  std::optional<base::OnceClosure> watch_callback_;
  base::test::ScopedFeatureList feature_list_;
  bool torn_down_ = false;

  base::WeakPtrFactory<MediaRouterUiForTestBase> weak_factory_{this};
};

}  // namespace media_router

#endif  // CHROME_TEST_MEDIA_ROUTER_MEDIA_ROUTER_UI_FOR_TEST_BASE_H_