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
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162

ash / components / arc / test / fake_intent_helper_instance.h [blame]

// Copyright 2016 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_COMPONENTS_ARC_TEST_FAKE_INTENT_HELPER_INSTANCE_H_
#define ASH_COMPONENTS_ARC_TEST_FAKE_INTENT_HELPER_INSTANCE_H_

#include <map>
#include <string>
#include <vector>

#include "ash/components/arc/mojom/intent_helper.mojom.h"
#include "base/functional/callback.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace arc {

class FakeIntentHelperInstance : public mojom::IntentHelperInstance {
 public:
  FakeIntentHelperInstance();

  class Broadcast {
   public:
    Broadcast(const std::string& action,
              const std::string& package_name,
              const std::string& cls,
              const std::string& extras);

    ~Broadcast();

    Broadcast(const Broadcast& broadcast);

    std::string action;
    std::string package_name;
    std::string cls;
    std::string extras;
  };

  // Parameters passed to HandleIntent().
  struct HandledIntent {
    HandledIntent(mojom::IntentInfoPtr intent, mojom::ActivityNamePtr activity);
    HandledIntent(HandledIntent&& other);
    HandledIntent& operator=(HandledIntent&& other);
    ~HandledIntent();

    mojom::IntentInfoPtr intent;
    mojom::ActivityNamePtr activity;
  };

  void clear_broadcasts() { broadcasts_.clear(); }
  void clear_handled_intents() { handled_intents_.clear(); }

  const std::vector<Broadcast>& broadcasts() const { return broadcasts_; }
  const std::vector<HandledIntent>& handled_intents() const {
    return handled_intents_;
  }
  const std::map<std::string, bool>& verified_links() const {
    return verified_links_;
  }

  std::vector<Broadcast> GetBroadcastsForAction(
      const std::string& action) const;

  arc::mojom::CaptionStylePtr GetCaptionStyle() const {
    return caption_style_->Clone();
  }
  arc::mojom::AccessibilityFeaturesPtr GetAccessibilityFeatures() const {
    return accessibility_features_->Clone();
  }

  // Sets a list of intent handlers to be returned in response to
  // RequestIntentHandlerList() calls with intents containing |action|.
  void SetIntentHandlers(const std::string& action,
                         std::vector<mojom::IntentHandlerInfoPtr> handlers);

  FakeIntentHelperInstance(const FakeIntentHelperInstance&) = delete;
  FakeIntentHelperInstance& operator=(const FakeIntentHelperInstance&) = delete;

  // mojom::IntentHelperInstance:
  ~FakeIntentHelperInstance() override;

  void AddPreferredPackage(const std::string& package_name) override;

  void SetVerifiedLinks(const std::vector<std::string>& package_names,
                        bool always_open) override;

  void HandleIntent(mojom::IntentInfoPtr intent,
                    mojom::ActivityNamePtr activity) override;

  void HandleIntentWithWindowInfo(mojom::IntentInfoPtr intent,
                                  mojom::ActivityNamePtr activity,
                                  mojom::WindowInfoPtr window_info) override;

  void HandleUrl(const std::string& url,
                 const std::string& package_name) override;

  void Init(mojo::PendingRemote<mojom::IntentHelperHost> host_remote,
            InitCallback callback) override;

  void RequestActivityIcons(std::vector<mojom::ActivityNamePtr> activities,
                            ::arc::mojom::ScaleFactor scale_factor,
                            RequestActivityIconsCallback callback) override;

  void RequestIntentHandlerList(
      mojom::IntentInfoPtr intent,
      RequestIntentHandlerListCallback callback) override;

  void RequestUrlHandlerList(const std::string& url,
                             RequestUrlHandlerListCallback callback) override;

  void RequestUrlListHandlerList(
      std::vector<mojom::UrlWithMimeTypePtr> urls,
      RequestUrlListHandlerListCallback callback) override;

  void SendBroadcast(const std::string& action,
                     const std::string& package_name,
                     const std::string& cls,
                     const std::string& extras) override;

  void RequestTextSelectionActions(
      const std::string& text,
      ::arc::mojom::ScaleFactor scale_factor,
      RequestTextSelectionActionsCallback callback) override;

  void HandleCameraResult(uint32_t intent_id,
                          arc::mojom::CameraIntentAction action,
                          const std::vector<uint8_t>& data,
                          HandleCameraResultCallback callback) override;

  void RequestDomainVerificationStatusUpdate() override;

  void SetCaptionStyle(arc::mojom::CaptionStylePtr caption_style) override;

  void EnableAccessibilityFeatures(
      arc::mojom::AccessibilityFeaturesPtr accessibility_features) override;

 private:
  std::vector<Broadcast> broadcasts_;

  // Information about calls to HandleIntent().
  std::vector<HandledIntent> handled_intents_;

  // Map from action names to intent handlers to be returned by
  // RequestIntentHandlerList().
  std::map<std::string, std::vector<mojom::IntentHandlerInfoPtr>>
      intent_handlers_;

  std::map<std::string, bool> verified_links_;

  // Keeps the binding alive so that calls to this class can be correctly
  // routed.
  mojo::Remote<mojom::IntentHelperHost> host_remote_;

  arc::mojom::CaptionStylePtr caption_style_;

  arc::mojom::AccessibilityFeaturesPtr accessibility_features_;
};

}  // namespace arc

#endif  // ASH_COMPONENTS_ARC_TEST_FAKE_INTENT_HELPER_INSTANCE_H_