| 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_APP_INSTANCE_H_ | 5 #ifndef COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ |
| 6 #define COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ | 6 #define COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "components/arc/common/app.mojom.h" | 14 #include "components/arc/common/app.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 | 16 |
| 17 namespace arc { | 17 namespace arc { |
| 18 | 18 |
| 19 class FakeAppInstance : public AppInstance { | 19 class FakeAppInstance : public mojom::AppInstance { |
| 20 public: | 20 public: |
| 21 class Request { | 21 class Request { |
| 22 public: | 22 public: |
| 23 Request(const std::string& package_name, const std::string& activity) | 23 Request(const std::string& package_name, const std::string& activity) |
| 24 : package_name_(package_name), activity_(activity) {} | 24 : package_name_(package_name), activity_(activity) {} |
| 25 ~Request() {} | 25 ~Request() {} |
| 26 | 26 |
| 27 const std::string& package_name() const { return package_name_; } | 27 const std::string& package_name() const { return package_name_; } |
| 28 | 28 |
| 29 const std::string& activity() const { return activity_; } | 29 const std::string& activity() const { return activity_; } |
| 30 | 30 |
| 31 bool IsForApp(const AppInfo& app_info) const { | 31 bool IsForApp(const mojom::AppInfo& app_info) const { |
| 32 return package_name_ == app_info.package_name && | 32 return package_name_ == app_info.package_name && |
| 33 activity_ == app_info.activity; | 33 activity_ == app_info.activity; |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 std::string package_name_; | 37 std::string package_name_; |
| 38 std::string activity_; | 38 std::string activity_; |
| 39 | 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(Request); | 40 DISALLOW_COPY_AND_ASSIGN(Request); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 class IconRequest : public Request { | 43 class IconRequest : public Request { |
| 44 public: | 44 public: |
| 45 IconRequest(const std::string& package_name, | 45 IconRequest(const std::string& package_name, |
| 46 const std::string& activity, | 46 const std::string& activity, |
| 47 ScaleFactor scale_factor) | 47 mojom::ScaleFactor scale_factor) |
| 48 : Request(package_name, activity), | 48 : Request(package_name, activity), |
| 49 scale_factor_(static_cast<int>(scale_factor)) {} | 49 scale_factor_(static_cast<int>(scale_factor)) {} |
| 50 ~IconRequest() {} | 50 ~IconRequest() {} |
| 51 | 51 |
| 52 int scale_factor() const { return scale_factor_; } | 52 int scale_factor() const { return scale_factor_; } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 int scale_factor_; | 55 int scale_factor_; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(IconRequest); | 57 DISALLOW_COPY_AND_ASSIGN(IconRequest); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 explicit FakeAppInstance(AppHost* app_host); | 60 explicit FakeAppInstance(mojom::AppHost* app_host); |
| 61 ~FakeAppInstance() override; | 61 ~FakeAppInstance() override; |
| 62 | 62 |
| 63 void Bind(mojo::InterfaceRequest<AppInstance> interface_request) { | 63 void Bind(mojo::InterfaceRequest<mojom::AppInstance> interface_request) { |
| 64 binding_.Bind(std::move(interface_request)); | 64 binding_.Bind(std::move(interface_request)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // AppInstance overrides: | 67 // mojom::AppInstance overrides: |
| 68 void Init(AppHostPtr host_ptr) override {} | 68 void Init(mojom::AppHostPtr host_ptr) override {} |
| 69 void RefreshAppList() override; | 69 void RefreshAppList() override; |
| 70 void LaunchApp(const mojo::String& package_name, | 70 void LaunchApp(const mojo::String& package_name, |
| 71 const mojo::String& activity, | 71 const mojo::String& activity, |
| 72 ScreenRectPtr dimension) override; | 72 mojom::ScreenRectPtr dimension) override; |
| 73 void RequestAppIcon(const mojo::String& package_name, | 73 void RequestAppIcon(const mojo::String& package_name, |
| 74 const mojo::String& activity, | 74 const mojo::String& activity, |
| 75 ScaleFactor scale_factor) override; | 75 mojom::ScaleFactor scale_factor) override; |
| 76 void CanHandleResolution(const mojo::String& package_name, | 76 void CanHandleResolution( |
| 77 const mojo::String& package_name, |
| 77 const mojo::String& activity, | 78 const mojo::String& activity, |
| 78 ScreenRectPtr dimension, | 79 mojom::ScreenRectPtr dimension, |
| 79 const CanHandleResolutionCallback& callback) override; | 80 const CanHandleResolutionCallback& callback) override; |
| 80 void UninstallPackage(const mojo::String& package_name) override; | 81 void UninstallPackage(const mojo::String& package_name) override; |
| 81 void GetTaskInfo(int32_t task_id, | 82 void GetTaskInfo(int32_t task_id, |
| 82 const GetTaskInfoCallback& callback) override; | 83 const GetTaskInfoCallback& callback) override; |
| 83 | 84 |
| 84 // Methods to reply messages. | 85 // Methods to reply messages. |
| 85 void SendRefreshAppList(const std::vector<AppInfo>& apps); | 86 void SendRefreshAppList(const std::vector<mojom::AppInfo>& apps); |
| 86 bool GenerateAndSendIcon(const AppInfo& app, | 87 bool GenerateAndSendIcon(const mojom::AppInfo& app, |
| 87 ScaleFactor scale_factor, | 88 mojom::ScaleFactor scale_factor, |
| 88 std::string* png_data_as_string); | 89 std::string* png_data_as_string); |
| 89 void SetTaskInfo(int32_t task_id, | 90 void SetTaskInfo(int32_t task_id, |
| 90 const std::string& package_name, | 91 const std::string& package_name, |
| 91 const std::string& activity); | 92 const std::string& activity); |
| 92 | 93 |
| 93 int refresh_app_list_count() const { return refresh_app_list_count_; } | 94 int refresh_app_list_count() const { return refresh_app_list_count_; } |
| 94 | 95 |
| 95 const ScopedVector<Request>& launch_requests() const { | 96 const ScopedVector<Request>& launch_requests() const { |
| 96 return launch_requests_; | 97 return launch_requests_; |
| 97 } | 98 } |
| 98 | 99 |
| 99 const ScopedVector<IconRequest>& icon_requests() const { | 100 const ScopedVector<IconRequest>& icon_requests() const { |
| 100 return icon_requests_; | 101 return icon_requests_; |
| 101 } | 102 } |
| 102 | 103 |
| 103 // This method can be called on tests when a method is intended to | 104 // This method can be called on tests when a method is intended to |
| 104 // be called across a Mojo proxy. | 105 // be called across a Mojo proxy. |
| 105 void WaitForIncomingMethodCall(); | 106 void WaitForIncomingMethodCall(); |
| 106 | 107 |
| 107 // As part of the initialization process, the instance side calls | 108 // As part of the initialization process, the instance side calls |
| 108 // AppHost::OnAppInstanceReady(), which in turn calls AppInstance::Init() and | 109 // mojom::AppHost::OnAppInstanceReady(), which in turn calls |
| 109 // AppInstance::RefreshAppList(). This method should be called after a call | 110 // mojom::AppInstance::Init() and |
| 110 // to ArcBridgeHost::OnAppInstanceReady() to make sure all method calls have | 111 // mojom::AppInstance::RefreshAppList(). This method should be called after a |
| 112 // call |
| 113 // to mojom::ArcBridgeHost::OnAppInstanceReady() to make sure all method calls |
| 114 // have |
| 111 // been dispatched. | 115 // been dispatched. |
| 112 void WaitForOnAppInstanceReady(); | 116 void WaitForOnAppInstanceReady(); |
| 113 | 117 |
| 114 private: | 118 private: |
| 115 using TaskIdToInfo = std::map<int32_t, scoped_ptr<Request>>; | 119 using TaskIdToInfo = std::map<int32_t, scoped_ptr<Request>>; |
| 116 // Mojo endpoints. | 120 // Mojo endpoints. |
| 117 mojo::Binding<AppInstance> binding_; | 121 mojo::Binding<mojom::AppInstance> binding_; |
| 118 AppHost* app_host_; | 122 mojom::AppHost* app_host_; |
| 119 // Number of RefreshAppList calls. | 123 // Number of RefreshAppList calls. |
| 120 int refresh_app_list_count_ = 0; | 124 int refresh_app_list_count_ = 0; |
| 121 // Keeps information about launch requests. | 125 // Keeps information about launch requests. |
| 122 ScopedVector<Request> launch_requests_; | 126 ScopedVector<Request> launch_requests_; |
| 123 // Keeps information about icon load requests. | 127 // Keeps information about icon load requests. |
| 124 ScopedVector<IconRequest> icon_requests_; | 128 ScopedVector<IconRequest> icon_requests_; |
| 125 // Keeps information for running tasks. | 129 // Keeps information for running tasks. |
| 126 TaskIdToInfo task_id_to_info_; | 130 TaskIdToInfo task_id_to_info_; |
| 127 | 131 |
| 128 DISALLOW_COPY_AND_ASSIGN(FakeAppInstance); | 132 DISALLOW_COPY_AND_ASSIGN(FakeAppInstance); |
| 129 }; | 133 }; |
| 130 | 134 |
| 131 } // namespace arc | 135 } // namespace arc |
| 132 | 136 |
| 133 #endif // COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ | 137 #endif // COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ |
| OLD | NEW |