OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/arc/test/fake_intent_helper_instance.h" | 5 #include "components/arc/test/fake_intent_helper_instance.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 |
7 namespace arc { | 12 namespace arc { |
8 | 13 |
9 FakeIntentHelperInstance::FakeIntentHelperInstance() {} | 14 FakeIntentHelperInstance::FakeIntentHelperInstance() {} |
10 | 15 |
11 FakeIntentHelperInstance::Broadcast::Broadcast(const std::string& action, | 16 FakeIntentHelperInstance::Broadcast::Broadcast(const std::string& action, |
12 const std::string& package_name, | 17 const std::string& package_name, |
13 const std::string& cls, | 18 const std::string& cls, |
14 const std::string& extras) | 19 const std::string& extras) |
15 : action(action), package_name(package_name), cls(cls), extras(extras) {} | 20 : action(action), package_name(package_name), cls(cls), extras(extras) {} |
16 | 21 |
17 FakeIntentHelperInstance::Broadcast::Broadcast(const Broadcast& broadcast) | 22 FakeIntentHelperInstance::Broadcast::Broadcast(const Broadcast& broadcast) |
18 : action(broadcast.action), | 23 : action(broadcast.action), |
19 package_name(broadcast.package_name), | 24 package_name(broadcast.package_name), |
20 cls(broadcast.cls), | 25 cls(broadcast.cls), |
21 extras(broadcast.extras) {} | 26 extras(broadcast.extras) {} |
22 | 27 |
23 FakeIntentHelperInstance::Broadcast::~Broadcast() {} | 28 FakeIntentHelperInstance::Broadcast::~Broadcast() {} |
24 | 29 |
| 30 FakeIntentHelperInstance::HandledIntent::HandledIntent( |
| 31 mojom::IntentInfoPtr intent, |
| 32 mojom::ActivityNamePtr activity) |
| 33 : intent(std::move(intent)), activity(std::move(activity)) {} |
| 34 |
| 35 FakeIntentHelperInstance::HandledIntent::HandledIntent(HandledIntent&& other) = |
| 36 default; |
| 37 |
| 38 FakeIntentHelperInstance::HandledIntent& |
| 39 FakeIntentHelperInstance::HandledIntent::operator=(HandledIntent&& other) = |
| 40 default; |
| 41 |
| 42 FakeIntentHelperInstance::HandledIntent::~HandledIntent() = default; |
| 43 |
| 44 void FakeIntentHelperInstance::SetIntentHandlers( |
| 45 const std::string& action, |
| 46 std::vector<mojom::IntentHandlerInfoPtr> handlers) { |
| 47 intent_handlers_[action] = std::move(handlers); |
| 48 } |
| 49 |
25 FakeIntentHelperInstance::~FakeIntentHelperInstance() {} | 50 FakeIntentHelperInstance::~FakeIntentHelperInstance() {} |
26 | 51 |
27 void FakeIntentHelperInstance::AddPreferredPackage( | 52 void FakeIntentHelperInstance::AddPreferredPackage( |
28 const std::string& package_name) {} | 53 const std::string& package_name) {} |
29 | 54 |
30 void FakeIntentHelperInstance::GetFileSizeDeprecated( | 55 void FakeIntentHelperInstance::GetFileSizeDeprecated( |
31 const std::string& url, | 56 const std::string& url, |
32 const GetFileSizeDeprecatedCallback& callback) {} | 57 const GetFileSizeDeprecatedCallback& callback) {} |
33 | 58 |
34 void FakeIntentHelperInstance::HandleIntent(mojom::IntentInfoPtr intent, | 59 void FakeIntentHelperInstance::HandleIntent(mojom::IntentInfoPtr intent, |
35 mojom::ActivityNamePtr activity) {} | 60 mojom::ActivityNamePtr activity) { |
| 61 handled_intents_.emplace_back(std::move(intent), std::move(activity)); |
| 62 } |
36 | 63 |
37 void FakeIntentHelperInstance::HandleUrl(const std::string& url, | 64 void FakeIntentHelperInstance::HandleUrl(const std::string& url, |
38 const std::string& package_name) {} | 65 const std::string& package_name) {} |
39 | 66 |
40 void FakeIntentHelperInstance::HandleUrlList( | 67 void FakeIntentHelperInstance::HandleUrlList( |
41 std::vector<mojom::UrlWithMimeTypePtr> urls, | 68 std::vector<mojom::UrlWithMimeTypePtr> urls, |
42 mojom::ActivityNamePtr activity, | 69 mojom::ActivityNamePtr activity, |
43 mojom::ActionType action) {} | 70 mojom::ActionType action) {} |
44 | 71 |
45 void FakeIntentHelperInstance::Init(mojom::IntentHelperHostPtr host_ptr) {} | 72 void FakeIntentHelperInstance::Init(mojom::IntentHelperHostPtr host_ptr) {} |
46 | 73 |
47 void FakeIntentHelperInstance::OpenFileToReadDeprecated( | 74 void FakeIntentHelperInstance::OpenFileToReadDeprecated( |
48 const std::string& url, | 75 const std::string& url, |
49 const OpenFileToReadDeprecatedCallback& callback) {} | 76 const OpenFileToReadDeprecatedCallback& callback) {} |
50 | 77 |
51 void FakeIntentHelperInstance::RequestActivityIcons( | 78 void FakeIntentHelperInstance::RequestActivityIcons( |
52 std::vector<mojom::ActivityNamePtr> activities, | 79 std::vector<mojom::ActivityNamePtr> activities, |
53 ::arc::mojom::ScaleFactor scale_factor, | 80 ::arc::mojom::ScaleFactor scale_factor, |
54 const RequestActivityIconsCallback& callback) {} | 81 const RequestActivityIconsCallback& callback) {} |
55 | 82 |
56 void FakeIntentHelperInstance::RequestIntentHandlerList( | 83 void FakeIntentHelperInstance::RequestIntentHandlerList( |
57 mojom::IntentInfoPtr intent, | 84 mojom::IntentInfoPtr intent, |
58 const RequestIntentHandlerListCallback& callback) {} | 85 const RequestIntentHandlerListCallback& callback) { |
| 86 std::vector<mojom::IntentHandlerInfoPtr> handlers; |
| 87 const auto it = intent_handlers_.find(intent->action); |
| 88 if (it != intent_handlers_.end()) { |
| 89 handlers.reserve(it->second.size()); |
| 90 for (const auto& handler : it->second) { |
| 91 handlers.emplace_back(handler.Clone()); |
| 92 } |
| 93 } |
| 94 // Post the reply to run asynchronously to match the real implementation. |
| 95 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 96 FROM_HERE, base::Bind(callback, base::Passed(std::move(handlers)))); |
| 97 } |
59 | 98 |
60 void FakeIntentHelperInstance::RequestUrlHandlerList( | 99 void FakeIntentHelperInstance::RequestUrlHandlerList( |
61 const std::string& url, | 100 const std::string& url, |
62 const RequestUrlHandlerListCallback& callback) {} | 101 const RequestUrlHandlerListCallback& callback) {} |
63 | 102 |
64 void FakeIntentHelperInstance::RequestUrlListHandlerList( | 103 void FakeIntentHelperInstance::RequestUrlListHandlerList( |
65 std::vector<mojom::UrlWithMimeTypePtr> urls, | 104 std::vector<mojom::UrlWithMimeTypePtr> urls, |
66 const RequestUrlListHandlerListCallback& callback) {} | 105 const RequestUrlListHandlerListCallback& callback) {} |
67 | 106 |
68 void FakeIntentHelperInstance::SendBroadcast(const std::string& action, | 107 void FakeIntentHelperInstance::SendBroadcast(const std::string& action, |
69 const std::string& package_name, | 108 const std::string& package_name, |
70 const std::string& cls, | 109 const std::string& cls, |
71 const std::string& extras) { | 110 const std::string& extras) { |
72 broadcasts_.emplace_back(action, package_name, cls, extras); | 111 broadcasts_.emplace_back(action, package_name, cls, extras); |
73 } | 112 } |
74 | 113 |
75 } // namespace arc | 114 } // namespace arc |
OLD | NEW |