| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ | 5 #ifndef COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ |
| 6 #define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ | 6 #define COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 13 #include "components/arc/arc_bridge_service.h" | 12 #include "components/arc/common/app.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 | 14 |
| 15 namespace arc { | 15 namespace arc { |
| 16 | 16 |
| 17 class FakeArcBridgeService : public ArcBridgeService { | 17 class FakeAppInstance : public AppInstance { |
| 18 public: | 18 public: |
| 19 class Request { | 19 class Request { |
| 20 public: | 20 public: |
| 21 Request(const std::string& package, const std::string& activity) | 21 Request(const std::string& package, const std::string& activity) |
| 22 : package_(package), | 22 : package_(package), activity_(activity) {} |
| 23 activity_(activity) { | 23 ~Request() {} |
| 24 } | |
| 25 | |
| 26 ~Request() { | |
| 27 } | |
| 28 | 24 |
| 29 const std::string& package() const { return package_; } | 25 const std::string& package() const { return package_; } |
| 30 | 26 |
| 31 const std::string& activity() const { return activity_; } | 27 const std::string& activity() const { return activity_; } |
| 32 | 28 |
| 33 bool IsForApp(const AppInfo& app_info) const { | 29 bool IsForApp(const AppInfo& app_info) const { |
| 34 return package_ == app_info.package && activity_ == app_info.activity; | 30 return package_ == app_info.package && activity_ == app_info.activity; |
| 35 } | 31 } |
| 36 | 32 |
| 37 private: | 33 private: |
| 38 std::string package_; | 34 std::string package_; |
| 39 std::string activity_; | 35 std::string activity_; |
| 40 | 36 |
| 41 DISALLOW_COPY_AND_ASSIGN(Request); | 37 DISALLOW_COPY_AND_ASSIGN(Request); |
| 42 }; | 38 }; |
| 43 | 39 |
| 44 class IconRequest : public Request { | 40 class IconRequest : public Request { |
| 45 public: | 41 public: |
| 46 IconRequest(const std::string& package, | 42 IconRequest(const std::string& package, |
| 47 const std::string& activity, | 43 const std::string& activity, |
| 48 ScaleFactor scale_factor) | 44 ScaleFactor scale_factor) |
| 49 : Request(package, activity), | 45 : Request(package, activity), scale_factor_(scale_factor) {} |
| 50 scale_factor_(scale_factor) { | 46 ~IconRequest() {} |
| 51 } | |
| 52 | |
| 53 ~IconRequest() { | |
| 54 } | |
| 55 | 47 |
| 56 int scale_factor() const { return scale_factor_; } | 48 int scale_factor() const { return scale_factor_; } |
| 57 | 49 |
| 58 private: | 50 private: |
| 59 int scale_factor_; | 51 int scale_factor_; |
| 60 | 52 |
| 61 DISALLOW_COPY_AND_ASSIGN(IconRequest); | 53 DISALLOW_COPY_AND_ASSIGN(IconRequest); |
| 62 }; | 54 }; |
| 63 | 55 |
| 64 FakeArcBridgeService(); | 56 explicit FakeAppInstance(AppHost* app_host); |
| 65 ~FakeArcBridgeService() override; | 57 ~FakeAppInstance() override; |
| 66 | 58 |
| 67 // arc::ArcBridgeService | 59 void Bind(mojo::InterfaceRequest<AppInstance> interface_request) { |
| 68 void DetectAvailability() override; | 60 binding_.Bind(std::move(interface_request)); |
| 69 void HandleStartup() override; | 61 } |
| 70 void Shutdown() override; | 62 |
| 71 bool RegisterInputDevice(const std::string& name, | 63 // AppInstance overrides: |
| 72 const std::string& device_type, | 64 void Init(AppHostPtr host_ptr) override {} |
| 73 base::ScopedFD fd) override; | 65 void RefreshAppList() override; |
| 74 bool SendBroadcast(const std::string& action, | 66 void LaunchApp(const mojo::String& package, |
| 75 const std::string& package, | 67 const mojo::String& activity) override; |
| 76 const std::string& clazz, | 68 void RequestAppIcon(const mojo::String& package, |
| 77 const base::DictionaryValue& extras) override; | 69 const mojo::String& activity, |
| 78 bool RefreshAppList() override; | |
| 79 bool LaunchApp(const std::string& package, | |
| 80 const std::string& activity) override; | |
| 81 bool RequestAppIcon(const std::string& package, | |
| 82 const std::string& activity, | |
| 83 ScaleFactor scale_factor) override; | 70 ScaleFactor scale_factor) override; |
| 84 bool SendNotificationEventToAndroid(const std::string& key, | 71 |
| 85 ArcNotificationEvent event) override; | 72 // Methods to reply messages. |
| 86 bool RequestProcessList() override; | 73 void SendRefreshAppList(const std::vector<AppInfo>& apps); |
| 74 bool GenerateAndSendIcon(const AppInfo& app, |
| 75 ScaleFactor scale_factor, |
| 76 std::string* png_data_as_string); |
| 87 | 77 |
| 88 int refresh_app_list_count() const { return refresh_app_list_count_; } | 78 int refresh_app_list_count() const { return refresh_app_list_count_; } |
| 89 | 79 |
| 90 const ScopedVector<Request>& launch_requests() const { | 80 const ScopedVector<Request>& launch_requests() const { |
| 91 return launch_requests_; | 81 return launch_requests_; |
| 92 } | 82 } |
| 93 | 83 |
| 94 const ScopedVector<IconRequest>& icon_requests() const { | 84 const ScopedVector<IconRequest>& icon_requests() const { |
| 95 return icon_requests_; | 85 return icon_requests_; |
| 96 } | 86 } |
| 97 | 87 |
| 98 void SetReady(); | 88 // This method can be called on tests when a method is intended to |
| 89 // be called across a Mojo proxy. |
| 90 void WaitForIncomingMethodCall(); |
| 99 | 91 |
| 100 void SetStopped(); | 92 // As part of the initialization process, the instance side calls |
| 101 | 93 // AppHost::OnAppInstanceReady(), which in turn calls AppInstance::Init() and |
| 102 bool HasObserver(const Observer* observer); | 94 // AppInstance::RefreshAppList(). This method should be called after a call |
| 103 bool HasAppObserver(const AppObserver* observer); | 95 // to ArcBridgeHost::OnAppInstanceReady() to make sure all method calls have |
| 104 | 96 // been dispatched. |
| 105 void SendRefreshAppList(const std::vector<AppInfo>& apps); | 97 void WaitForOnAppInstanceReady(); |
| 106 | |
| 107 bool GenerateAndSendIcon(const AppInfo& app, | |
| 108 ScaleFactor scale_factor, | |
| 109 std::string* png_data); | |
| 110 | 98 |
| 111 private: | 99 private: |
| 100 // Mojo endpoints. |
| 101 mojo::Binding<AppInstance> binding_; |
| 102 AppHost* app_host_; |
| 112 // Number of RefreshAppList calls. | 103 // Number of RefreshAppList calls. |
| 113 int refresh_app_list_count_ = 0; | 104 int refresh_app_list_count_ = 0; |
| 114 // Keeps information about launch requests. | 105 // Keeps information about launch requests. |
| 115 ScopedVector<Request> launch_requests_; | 106 ScopedVector<Request> launch_requests_; |
| 116 // Keeps information about icon load requests. | 107 // Keeps information about icon load requests. |
| 117 ScopedVector<IconRequest> icon_requests_; | 108 ScopedVector<IconRequest> icon_requests_; |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeService); | |
| 120 }; | 109 }; |
| 121 | 110 |
| 122 } // namespace arc | 111 } // namespace arc |
| 123 | 112 |
| 124 #endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ | 113 #endif // COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ |
| OLD | NEW |