| 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 #include "components/arc/test/fake_app_instance.h" | 5 #include "components/arc/test/fake_app_instance.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 | 19 |
| 20 template <> | 20 template <> |
| 21 struct TypeConverter<arc::AppInfoPtr, arc::AppInfo> { | 21 struct TypeConverter<arc::mojom::AppInfoPtr, arc::mojom::AppInfo> { |
| 22 static arc::AppInfoPtr Convert(const arc::AppInfo& app_info) { | 22 static arc::mojom::AppInfoPtr Convert(const arc::mojom::AppInfo& app_info) { |
| 23 return app_info.Clone(); | 23 return app_info.Clone(); |
| 24 } | 24 } |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 } // namespace mojo | 27 } // namespace mojo |
| 28 | 28 |
| 29 namespace arc { | 29 namespace arc { |
| 30 | 30 |
| 31 FakeAppInstance::FakeAppInstance(AppHost* app_host) | 31 FakeAppInstance::FakeAppInstance(mojom::AppHost* app_host) |
| 32 : binding_(this), app_host_(app_host) {} | 32 : binding_(this), app_host_(app_host) {} |
| 33 FakeAppInstance::~FakeAppInstance() {} | 33 FakeAppInstance::~FakeAppInstance() {} |
| 34 | 34 |
| 35 void FakeAppInstance::RefreshAppList() { | 35 void FakeAppInstance::RefreshAppList() { |
| 36 ++refresh_app_list_count_; | 36 ++refresh_app_list_count_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void FakeAppInstance::LaunchApp(const mojo::String& package_name, | 39 void FakeAppInstance::LaunchApp(const mojo::String& package_name, |
| 40 const mojo::String& activity, | 40 const mojo::String& activity, |
| 41 ScreenRectPtr dimension) { | 41 mojom::ScreenRectPtr dimension) { |
| 42 launch_requests_.push_back(new Request(package_name, activity)); | 42 launch_requests_.push_back(new Request(package_name, activity)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void FakeAppInstance::RequestAppIcon(const mojo::String& package_name, | 45 void FakeAppInstance::RequestAppIcon(const mojo::String& package_name, |
| 46 const mojo::String& activity, | 46 const mojo::String& activity, |
| 47 ScaleFactor scale_factor) { | 47 mojom::ScaleFactor scale_factor) { |
| 48 icon_requests_.push_back( | 48 icon_requests_.push_back( |
| 49 new IconRequest(package_name, activity, scale_factor)); | 49 new IconRequest(package_name, activity, scale_factor)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void FakeAppInstance::SendRefreshAppList(const std::vector<AppInfo>& apps) { | 52 void FakeAppInstance::SendRefreshAppList( |
| 53 app_host_->OnAppListRefreshed(mojo::Array<AppInfoPtr>::From(apps)); | 53 const std::vector<mojom::AppInfo>& apps) { |
| 54 app_host_->OnAppListRefreshed(mojo::Array<mojom::AppInfoPtr>::From(apps)); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool FakeAppInstance::GenerateAndSendIcon(const AppInfo& app, | 57 bool FakeAppInstance::GenerateAndSendIcon(const mojom::AppInfo& app, |
| 57 ScaleFactor scale_factor, | 58 mojom::ScaleFactor scale_factor, |
| 58 std::string* png_data_as_string) { | 59 std::string* png_data_as_string) { |
| 59 CHECK(png_data_as_string != nullptr); | 60 CHECK(png_data_as_string != nullptr); |
| 60 std::string icon_file_name; | 61 std::string icon_file_name; |
| 61 switch (scale_factor) { | 62 switch (scale_factor) { |
| 62 case ScaleFactor::SCALE_FACTOR_100P: | 63 case mojom::ScaleFactor::SCALE_FACTOR_100P: |
| 63 icon_file_name = "icon_100p.png"; | 64 icon_file_name = "icon_100p.png"; |
| 64 break; | 65 break; |
| 65 case ScaleFactor::SCALE_FACTOR_125P: | 66 case mojom::ScaleFactor::SCALE_FACTOR_125P: |
| 66 icon_file_name = "icon_125p.png"; | 67 icon_file_name = "icon_125p.png"; |
| 67 break; | 68 break; |
| 68 case ScaleFactor::SCALE_FACTOR_133P: | 69 case mojom::ScaleFactor::SCALE_FACTOR_133P: |
| 69 icon_file_name = "icon_133p.png"; | 70 icon_file_name = "icon_133p.png"; |
| 70 break; | 71 break; |
| 71 case ScaleFactor::SCALE_FACTOR_140P: | 72 case mojom::ScaleFactor::SCALE_FACTOR_140P: |
| 72 icon_file_name = "icon_140p.png"; | 73 icon_file_name = "icon_140p.png"; |
| 73 break; | 74 break; |
| 74 case ScaleFactor::SCALE_FACTOR_150P: | 75 case mojom::ScaleFactor::SCALE_FACTOR_150P: |
| 75 icon_file_name = "icon_150p.png"; | 76 icon_file_name = "icon_150p.png"; |
| 76 break; | 77 break; |
| 77 case ScaleFactor::SCALE_FACTOR_180P: | 78 case mojom::ScaleFactor::SCALE_FACTOR_180P: |
| 78 icon_file_name = "icon_180p.png"; | 79 icon_file_name = "icon_180p.png"; |
| 79 break; | 80 break; |
| 80 case ScaleFactor::SCALE_FACTOR_200P: | 81 case mojom::ScaleFactor::SCALE_FACTOR_200P: |
| 81 icon_file_name = "icon_200p.png"; | 82 icon_file_name = "icon_200p.png"; |
| 82 break; | 83 break; |
| 83 case ScaleFactor::SCALE_FACTOR_250P: | 84 case mojom::ScaleFactor::SCALE_FACTOR_250P: |
| 84 icon_file_name = "icon_250p.png"; | 85 icon_file_name = "icon_250p.png"; |
| 85 break; | 86 break; |
| 86 case ScaleFactor::SCALE_FACTOR_300P: | 87 case mojom::ScaleFactor::SCALE_FACTOR_300P: |
| 87 icon_file_name = "icon_300p.png"; | 88 icon_file_name = "icon_300p.png"; |
| 88 break; | 89 break; |
| 89 default: | 90 default: |
| 90 NOTREACHED(); | 91 NOTREACHED(); |
| 91 return false; | 92 return false; |
| 92 } | 93 } |
| 93 | 94 |
| 94 base::FilePath base_path; | 95 base::FilePath base_path; |
| 95 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &base_path)); | 96 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &base_path)); |
| 96 base::FilePath icon_file_path = base_path.AppendASCII("components") | 97 base::FilePath icon_file_path = base_path.AppendASCII("components") |
| (...skipping 28 matching lines...) Expand all Loading... |
| 125 // RunUntilIdle() is required to correctly dispatch it. On slower machines | 126 // RunUntilIdle() is required to correctly dispatch it. On slower machines |
| 126 // (and when running under Valgrind), the two thread hops needed to send and | 127 // (and when running under Valgrind), the two thread hops needed to send and |
| 127 // dispatch each Mojo message might not be picked up by a single | 128 // dispatch each Mojo message might not be picked up by a single |
| 128 // RunUntilIdle(), so keep pumping the message loop until all expected | 129 // RunUntilIdle(), so keep pumping the message loop until all expected |
| 129 // messages are. | 130 // messages are. |
| 130 while (refresh_app_list_count_ != 1) { | 131 while (refresh_app_list_count_ != 1) { |
| 131 base::RunLoop().RunUntilIdle(); | 132 base::RunLoop().RunUntilIdle(); |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 void FakeAppInstance::CanHandleResolution(const mojo::String& package_name, | 136 void FakeAppInstance::CanHandleResolution( |
| 137 const mojo::String& package_name, |
| 136 const mojo::String& activity, | 138 const mojo::String& activity, |
| 137 ScreenRectPtr dimension, | 139 mojom::ScreenRectPtr dimension, |
| 138 const CanHandleResolutionCallback& callback) { | 140 const CanHandleResolutionCallback& callback) { |
| 139 callback.Run(true); | 141 callback.Run(true); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void FakeAppInstance::UninstallPackage(const mojo::String& package_name) { | 144 void FakeAppInstance::UninstallPackage(const mojo::String& package_name) { |
| 143 } | 145 } |
| 144 | 146 |
| 145 void FakeAppInstance::GetTaskInfo(int32_t task_id, | 147 void FakeAppInstance::GetTaskInfo(int32_t task_id, |
| 146 const GetTaskInfoCallback& callback) { | 148 const GetTaskInfoCallback& callback) { |
| 147 TaskIdToInfo::const_iterator it = task_id_to_info_.find(task_id); | 149 TaskIdToInfo::const_iterator it = task_id_to_info_.find(task_id); |
| 148 if (it != task_id_to_info_.end()) | 150 if (it != task_id_to_info_.end()) |
| 149 callback.Run(it->second->package_name(), it->second->activity()); | 151 callback.Run(it->second->package_name(), it->second->activity()); |
| 150 else | 152 else |
| 151 callback.Run(mojo::String(), mojo::String()); | 153 callback.Run(mojo::String(), mojo::String()); |
| 152 } | 154 } |
| 153 | 155 |
| 154 } // namespace arc | 156 } // namespace arc |
| OLD | NEW |