fake_intent_helper_instance.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright 2016 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. #ifndef COMPONENTS_ARC_TEST_FAKE_INTENT_HELPER_INSTANCE_H_
  5. #define COMPONENTS_ARC_TEST_FAKE_INTENT_HELPER_INSTANCE_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/components/arc/mojom/intent_helper.mojom.h"
  10. #include "base/callback.h"
  11. #include "mojo/public/cpp/bindings/pending_remote.h"
  12. #include "mojo/public/cpp/bindings/remote.h"
  13. namespace arc {
  14. class FakeIntentHelperInstance : public mojom::IntentHelperInstance {
  15. public:
  16. FakeIntentHelperInstance();
  17. class Broadcast {
  18. public:
  19. Broadcast(const std::string& action,
  20. const std::string& package_name,
  21. const std::string& cls,
  22. const std::string& extras);
  23. ~Broadcast();
  24. Broadcast(const Broadcast& broadcast);
  25. std::string action;
  26. std::string package_name;
  27. std::string cls;
  28. std::string extras;
  29. };
  30. // Parameters passed to HandleIntent().
  31. struct HandledIntent {
  32. HandledIntent(mojom::IntentInfoPtr intent, mojom::ActivityNamePtr activity);
  33. HandledIntent(HandledIntent&& other);
  34. HandledIntent& operator=(HandledIntent&& other);
  35. ~HandledIntent();
  36. mojom::IntentInfoPtr intent;
  37. mojom::ActivityNamePtr activity;
  38. };
  39. void clear_broadcasts() { broadcasts_.clear(); }
  40. void clear_handled_intents() { handled_intents_.clear(); }
  41. const std::vector<Broadcast>& broadcasts() const { return broadcasts_; }
  42. const std::vector<HandledIntent>& handled_intents() const {
  43. return handled_intents_;
  44. }
  45. const std::map<std::string, bool>& verified_links() const {
  46. return verified_links_;
  47. }
  48. std::vector<Broadcast> GetBroadcastsForAction(
  49. const std::string& action) const;
  50. // Sets a list of intent handlers to be returned in response to
  51. // RequestIntentHandlerList() calls with intents containing |action|.
  52. void SetIntentHandlers(const std::string& action,
  53. std::vector<mojom::IntentHandlerInfoPtr> handlers);
  54. FakeIntentHelperInstance(const FakeIntentHelperInstance&) = delete;
  55. FakeIntentHelperInstance& operator=(const FakeIntentHelperInstance&) = delete;
  56. // mojom::IntentHelperInstance:
  57. ~FakeIntentHelperInstance() override;
  58. void AddPreferredPackage(const std::string& package_name) override;
  59. void AddPreferredApp(const std::string& package_name,
  60. IntentFilter intent_filter,
  61. mojom::IntentInfoPtr intent) override;
  62. void SetVerifiedLinks(const std::vector<std::string>& package_names,
  63. bool always_open) override;
  64. void HandleIntent(mojom::IntentInfoPtr intent,
  65. mojom::ActivityNamePtr activity) override;
  66. void HandleIntentWithWindowInfo(mojom::IntentInfoPtr intent,
  67. mojom::ActivityNamePtr activity,
  68. mojom::WindowInfoPtr window_info) override;
  69. void HandleUrl(const std::string& url,
  70. const std::string& package_name) override;
  71. void Init(mojo::PendingRemote<mojom::IntentHelperHost> host_remote,
  72. InitCallback callback) override;
  73. void RequestActivityIcons(std::vector<mojom::ActivityNamePtr> activities,
  74. ::arc::mojom::ScaleFactor scale_factor,
  75. RequestActivityIconsCallback callback) override;
  76. void RequestIntentHandlerList(
  77. mojom::IntentInfoPtr intent,
  78. RequestIntentHandlerListCallback callback) override;
  79. void RequestUrlHandlerList(const std::string& url,
  80. RequestUrlHandlerListCallback callback) override;
  81. void RequestUrlListHandlerList(
  82. std::vector<mojom::UrlWithMimeTypePtr> urls,
  83. RequestUrlListHandlerListCallback callback) override;
  84. void SendBroadcast(const std::string& action,
  85. const std::string& package_name,
  86. const std::string& cls,
  87. const std::string& extras) override;
  88. void RequestTextSelectionActions(
  89. const std::string& text,
  90. ::arc::mojom::ScaleFactor scale_factor,
  91. RequestTextSelectionActionsCallback callback) override;
  92. void HandleCameraResult(uint32_t intent_id,
  93. arc::mojom::CameraIntentAction action,
  94. const std::vector<uint8_t>& data,
  95. HandleCameraResultCallback callback) override;
  96. void RequestDomainVerificationStatusUpdate() override;
  97. private:
  98. std::vector<Broadcast> broadcasts_;
  99. // Information about calls to HandleIntent().
  100. std::vector<HandledIntent> handled_intents_;
  101. // Map from action names to intent handlers to be returned by
  102. // RequestIntentHandlerList().
  103. std::map<std::string, std::vector<mojom::IntentHandlerInfoPtr>>
  104. intent_handlers_;
  105. std::map<std::string, bool> verified_links_;
  106. // Keeps the binding alive so that calls to this class can be correctly
  107. // routed.
  108. mojo::Remote<mojom::IntentHelperHost> host_remote_;
  109. };
  110. } // namespace arc
  111. #endif // COMPONENTS_ARC_TEST_FAKE_INTENT_HELPER_INSTANCE_H_