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_iTEST_FAKE_APP_INSTANCE_H_ |
6 #define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ | 6 #define COMPONENTS_ARC_iTEST_FAKE_APP_INSTANCE_H_ |
xiyuan
2015/12/16 17:17:51
nit: fix typo, iTEST-> TEST
Luis Héctor Chávez
2015/12/16 17:58:34
Done.
| |
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 RefreshAppList() override; | 66 void LaunchApp(const mojo::String& package, |
75 bool LaunchApp(const std::string& package, | 67 const mojo::String& activity) override; |
76 const std::string& activity) override; | 68 void RequestAppIcon(const mojo::String& package, |
77 bool RequestAppIcon(const std::string& package, | 69 const mojo::String& activity, |
78 const std::string& activity, | |
79 ScaleFactor scale_factor) override; | 70 ScaleFactor scale_factor) override; |
80 bool SendNotificationEventToAndroid(const std::string& key, | 71 |
81 ArcNotificationEvent event) override; | 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); | |
82 | 77 |
83 int refresh_app_list_count() const { return refresh_app_list_count_; } | 78 int refresh_app_list_count() const { return refresh_app_list_count_; } |
84 | 79 |
85 const ScopedVector<Request>& launch_requests() const { | 80 const ScopedVector<Request>& launch_requests() const { |
86 return launch_requests_; | 81 return launch_requests_; |
87 } | 82 } |
88 | 83 |
89 const ScopedVector<IconRequest>& icon_requests() const { | 84 const ScopedVector<IconRequest>& icon_requests() const { |
90 return icon_requests_; | 85 return icon_requests_; |
91 } | 86 } |
92 | 87 |
93 void SetReady(); | |
94 | |
95 void SetStopped(); | |
96 | |
97 bool HasObserver(const Observer* observer); | |
98 bool HasAppObserver(const AppObserver* observer); | |
99 | |
100 void SendRefreshAppList(const std::vector<AppInfo>& apps); | |
101 | |
102 bool GenerateAndSendIcon(const AppInfo& app, | |
103 ScaleFactor scale_factor, | |
104 std::string* png_data); | |
105 | |
106 private: | 88 private: |
89 // Mojo endpoints. | |
90 mojo::Binding<AppInstance> binding_; | |
91 AppHost* app_host_; | |
107 // Number of RefreshAppList calls. | 92 // Number of RefreshAppList calls. |
108 int refresh_app_list_count_ = 0; | 93 int refresh_app_list_count_ = 0; |
109 // Keeps information about launch requests. | 94 // Keeps information about launch requests. |
110 ScopedVector<Request> launch_requests_; | 95 ScopedVector<Request> launch_requests_; |
111 // Keeps information about icon load requests. | 96 // Keeps information about icon load requests. |
112 ScopedVector<IconRequest> icon_requests_; | 97 ScopedVector<IconRequest> icon_requests_; |
113 | |
114 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeService); | |
115 }; | 98 }; |
116 | 99 |
117 } // namespace arc | 100 } // namespace arc |
118 | 101 |
119 #endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ | 102 #endif // COMPONENTS_ARC_iTEST_FAKE_APP_INSTANCE_H_ |
OLD | NEW |