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

ash / public / cpp / test / test_saved_desk_delegate.h [blame]

// 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 ASH_PUBLIC_CPP_TEST_TEST_SAVED_DESK_DELEGATE_H_
#define ASH_PUBLIC_CPP_TEST_TEST_SAVED_DESK_DELEGATE_H_

#include <vector>

#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/saved_desk_delegate.h"
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "ui/gfx/image/image_skia.h"

namespace aura {
class Window;
}

namespace desks_storage {
class AdminTemplateService;
class DeskModel;
}

namespace ui {
class ColorProvider;
}

namespace ash {

class DeskTemplate;

class ASH_PUBLIC_EXPORT TestSavedDeskDelegate : public SavedDeskDelegate {
 public:
  TestSavedDeskDelegate();
  TestSavedDeskDelegate(TestSavedDeskDelegate&) = delete;
  TestSavedDeskDelegate& operator=(TestSavedDeskDelegate&) = delete;
  ~TestSavedDeskDelegate() override;

  void set_desk_model(desks_storage::DeskModel* desk_model) {
    desk_model_ = desk_model;
  }

  void set_admin_template_service(
      desks_storage::AdminTemplateService* admin_template_service) {
    admin_template_service_ = admin_template_service;
  }

  void set_unavailable_apps(
      const std::vector<std::string>& unavailable_app_ids) {
    unavailable_app_ids_ = unavailable_app_ids;
  }

  void set_default_app_icon(const gfx::ImageSkia& default_app_icon) {
    default_app_icon_ = default_app_icon;
  }

  void set_app_ids_with_app_launch_info(
      const base::flat_set<std::string>& val) {
    app_ids_with_app_launch_info_ = val;
  }

  // SavedDeskDelegate:
  void GetAppLaunchDataForSavedDesk(
      aura::Window* window,
      GetAppLaunchDataCallback callback) const override;
  desks_storage::DeskModel* GetDeskModel() override;
  desks_storage::AdminTemplateService* GetAdminTemplateService() override;
  bool IsWindowPersistable(aura::Window* window) const override;
  std::optional<gfx::ImageSkia> MaybeRetrieveIconForSpecialIdentifier(
      const std::string& identifier,
      const ui::ColorProvider* color_provider) const override;
  void GetFaviconForUrl(
      const std::string& page_url,
      base::OnceCallback<void(const gfx::ImageSkia&)> callback,
      base::CancelableTaskTracker* tracker) const override;
  void GetIconForAppId(
      const std::string& app_id,
      int desired_icon_size,
      base::OnceCallback<void(const gfx::ImageSkia&)> callback) const override;
  void LaunchAppsFromSavedDesk(
      std::unique_ptr<DeskTemplate> saved_desk) override;
  bool IsWindowSupportedForSavedDesk(aura::Window* window) const override;
  std::string GetAppShortName(const std::string& app_id) override;
  bool IsAppAvailable(const std::string& app_id) const override;

 private:
  raw_ptr<desks_storage::DeskModel> desk_model_ = nullptr;
  raw_ptr<desks_storage::AdminTemplateService, DanglingUntriaged>
      admin_template_service_ = nullptr;
  std::vector<std::string> unavailable_app_ids_;
  gfx::ImageSkia default_app_icon_;

  // A test set of app ids so that tests can determine which apps have
  // `app_restore::AppLaunchInfo`.
  base::flat_set<std::string> app_ids_with_app_launch_info_;
};

}  // namespace ash

#endif  // ASH_PUBLIC_CPP_TEST_TEST_SAVED_DESK_DELEGATE_H_