OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ | |
6 #define COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/scoped_vector.h" | |
12 #include "components/arc/common/app.mojom.h" | |
13 #include "mojo/public/cpp/bindings/binding.h" | |
14 | |
15 namespace arc { | |
16 | |
17 class FakeAppInstance : public AppInstance { | |
18 public: | |
19 class Request { | |
20 public: | |
21 Request(const std::string& package, const std::string& activity) | |
22 : package_(package), activity_(activity) {} | |
23 ~Request() {} | |
24 | |
25 const std::string& package() const { return package_; } | |
26 | |
27 const std::string& activity() const { return activity_; } | |
28 | |
29 bool IsForApp(const AppInfo& app_info) const { | |
30 return package_ == app_info.package && activity_ == app_info.activity; | |
31 } | |
32 | |
33 private: | |
34 std::string package_; | |
35 std::string activity_; | |
36 | |
37 DISALLOW_COPY_AND_ASSIGN(Request); | |
38 }; | |
39 | |
40 class IconRequest : public Request { | |
41 public: | |
42 IconRequest(const std::string& package, | |
43 const std::string& activity, | |
44 ScaleFactor scale_factor) | |
45 : Request(package, activity), scale_factor_(scale_factor) {} | |
46 ~IconRequest() {} | |
47 | |
48 int scale_factor() const { return scale_factor_; } | |
49 | |
50 private: | |
51 int scale_factor_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(IconRequest); | |
54 }; | |
55 | |
56 explicit FakeAppInstance(AppHost* app_host); | |
57 ~FakeAppInstance() override; | |
58 | |
59 void Bind(mojo::InterfaceRequest<AppInstance> interface_request) { | |
60 binding_.Bind(std::move(interface_request)); | |
61 } | |
62 | |
63 // AppInstance overrides: | |
64 void Init(AppHostPtr host_ptr) override {} | |
65 void RefreshAppList() override; | |
66 void LaunchApp(const mojo::String& package, | |
67 const mojo::String& activity) override; | |
68 void RequestAppIcon(const mojo::String& package, | |
69 const mojo::String& activity, | |
70 ScaleFactor scale_factor) override; | |
71 | |
72 // Methods to reply messages. | |
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); | |
77 | |
78 int refresh_app_list_count() const { return refresh_app_list_count_; } | |
79 | |
80 const ScopedVector<Request>& launch_requests() const { | |
81 return launch_requests_; | |
82 } | |
83 | |
84 const ScopedVector<IconRequest>& icon_requests() const { | |
85 return icon_requests_; | |
86 } | |
87 | |
88 private: | |
89 // Mojo endpoints. | |
90 mojo::Binding<AppInstance> binding_; | |
91 AppHost* app_host_; | |
92 // Number of RefreshAppList calls. | |
93 int refresh_app_list_count_ = 0; | |
94 // Keeps information about launch requests. | |
95 ScopedVector<Request> launch_requests_; | |
96 // Keeps information about icon load requests. | |
97 ScopedVector<IconRequest> icon_requests_; | |
98 }; | |
99 | |
100 } // namespace arc | |
101 | |
102 #endif // COMPONENTS_ARC_TEST_FAKE_APP_INSTANCE_H_ | |
OLD | NEW |