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

media / base / android / mock_android_overlay.cc [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/android/mock_android_overlay.h"

#include <memory>

#include "base/functional/bind.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {

MockAndroidOverlay::Callbacks::Callbacks() = default;
MockAndroidOverlay::Callbacks::Callbacks(const Callbacks&) = default;
MockAndroidOverlay::Callbacks::~Callbacks() = default;

MockAndroidOverlay::MockAndroidOverlay() {}

MockAndroidOverlay::~MockAndroidOverlay() {}

void MockAndroidOverlay::SetConfig(AndroidOverlayConfig config) {
  config_ = std::make_unique<AndroidOverlayConfig>(std::move(config));
}

MockAndroidOverlay::Callbacks MockAndroidOverlay::GetCallbacks() {
  Callbacks c;
  c.OverlayReady = base::BindRepeating(&MockAndroidOverlay::OnOverlayReady,
                                       weak_factory_.GetWeakPtr());
  c.OverlayFailed = base::BindRepeating(&MockAndroidOverlay::OnOverlayFailed,
                                        weak_factory_.GetWeakPtr());
  c.SurfaceDestroyed = base::BindRepeating(
      &MockAndroidOverlay::OnSurfaceDestroyed, weak_factory_.GetWeakPtr());
  c.PowerEfficientState = base::BindRepeating(
      &MockAndroidOverlay::OnPowerEfficientState, weak_factory_.GetWeakPtr());

  return c;
}

void MockAndroidOverlay::OnOverlayReady() {
  config_->is_ready(this);
}

void MockAndroidOverlay::OnOverlayFailed() {
  config_->is_failed(this);
}

void MockAndroidOverlay::OnSurfaceDestroyed() {
  RunSurfaceDestroyedCallbacks();
}

void MockAndroidOverlay::OnPowerEfficientState(bool state) {
  config_->power_cb.Run(this, state);
}

void MockAndroidOverlay::AddSurfaceDestroyedCallback(
    AndroidOverlayConfig::DestroyedCB cb) {
  MockAddSurfaceDestroyedCallback();
  this->AndroidOverlay::AddSurfaceDestroyedCallback(std::move(cb));
}

}  // namespace media