Index: chrome/browser/ui/app_list/test/fake_arc_bridge_service_for_app_launcher.cc |
diff --git a/chrome/browser/ui/app_list/test/fake_arc_bridge_service_for_app_launcher.cc b/chrome/browser/ui/app_list/test/fake_arc_bridge_service_for_app_launcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a1eb4b4a36d600bab384feec15b2b0e3f3a7136d |
--- /dev/null |
+++ b/chrome/browser/ui/app_list/test/fake_arc_bridge_service_for_app_launcher.cc |
@@ -0,0 +1,127 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/app_list/test/fake_arc_bridge_service_for_app_launcher.h" |
+ |
+#include "chrome/browser/ui/app_list/arc_app_list_prefs.h" |
+#include "ui/app_list/app_list_constants.h" |
+#include "ui/base/layout.h" |
+#include "ui/gfx/codec/png_codec.h" |
+ |
+FakeArcBridgeServiceForAppLauncher::FakeArcBridgeServiceForAppLauncher() |
+ : refresh_apps_cnt_(0) { |
+} |
+ |
+FakeArcBridgeServiceForAppLauncher::~FakeArcBridgeServiceForAppLauncher() { |
+ if (state() != State::STOPPED) { |
+ SetState(State::STOPPED); |
+ } |
+} |
+ |
+void FakeArcBridgeServiceForAppLauncher::HandleStartup() { |
+} |
+ |
+void FakeArcBridgeServiceForAppLauncher::Shutdown() { |
+} |
+ |
+bool FakeArcBridgeServiceForAppLauncher::RegisterInputDevice( |
+ const std::string& name, |
+ const std::string& device_type, |
+ base::ScopedFD fd) { |
+ return true; |
+} |
+ |
+bool FakeArcBridgeServiceForAppLauncher::RefreshApps() { |
+ ++refresh_apps_cnt_; |
+ return true; |
+} |
+ |
+bool FakeArcBridgeServiceForAppLauncher::LaunchApp( |
+ const std::string& package, |
+ const std::string& activity) { |
+ launch_requests_.push_back(ArcAppListPrefs::GetAppId(package, activity)); |
+ return true; |
+} |
+ |
+bool FakeArcBridgeServiceForAppLauncher::RequestIcon( |
+ const std::string& package, |
+ const std::string& activity, |
+ int scale_factor) { |
+ IconRequest request; |
+ request.package = package; |
+ request.activity = activity; |
+ request.scale_factor = scale_factor; |
+ icon_requests_.push_back(request); |
+ return true; |
+} |
+ |
+void FakeArcBridgeServiceForAppLauncher::SetReady() { |
+ SetState(State::READY); |
+} |
+ |
+void FakeArcBridgeServiceForAppLauncher::SetStopped() { |
+ SetState(State::STOPPED); |
+} |
+ |
+bool FakeArcBridgeServiceForAppLauncher::HasObserver( |
+ const Observer* observer) const { |
+ return observer_list_.HasObserver(observer); |
+} |
+ |
+void FakeArcBridgeServiceForAppLauncher::SendRefreshApps(size_t size, |
+ const AppInfo* apps) { |
+ std::vector<std::string> names(size); |
+ std::vector<std::string> packages(size); |
+ std::vector<std::string> activities(size); |
+ for (size_t i = 0; i < size; ++i) { |
+ names[i] = apps[i].name; |
+ packages[i] = apps[i].package; |
+ activities[i] = apps[i].activity; |
+ } |
+ |
+ FOR_EACH_OBSERVER(Observer, |
+ observer_list_, |
+ OnAppsRefreshed(names, packages, activities)); |
+} |
+ |
+bool FakeArcBridgeServiceForAppLauncher::GenerateAndSendIcon( |
+ const AppInfo& app, |
+ ui::ScaleFactor scale_factor, |
+ std::vector<unsigned char>* png_data) { |
+ const float scale = ui::GetScaleForScaleFactor(scale_factor); |
+ const int icon_size = static_cast<int>( |
+ app_list::kGridIconDimension * scale + 0.5f); |
+ |
+ const int row_width = icon_size * 4; |
+ const int data_size = icon_size * row_width; |
+ |
+ // Generate random content. |
+ std::vector<unsigned char> pixels(data_size); |
+ for (int i = 0; i < icon_size; ++i) { |
+ memset(&pixels[i * row_width], rand(), row_width); |
+ } |
+ |
+ std::vector<unsigned char> result; |
xiyuan
2015/11/18 03:42:16
|result| seems unused.
khmel1
2015/11/18 06:10:04
Done.
|
+ if (!gfx::PNGCodec::Encode(&pixels[0], |
+ gfx::PNGCodec::FORMAT_RGBA, |
+ gfx::Size(icon_size, icon_size), |
+ row_width, |
+ false, |
+ std::vector<gfx::PNGCodec::Comment>(), |
+ png_data)) { |
+ return false; |
+ } |
+ |
+ FOR_EACH_OBSERVER(Observer, |
+ observer_list_, |
+ OnAppIcon(app.package, |
+ app.activity, |
+ scale_factor, |
+ *png_data)); |
+ return true; |
+} |
+ |
+std::string FakeArcBridgeServiceForAppLauncher::AppInfo::id() const { |
+ return ArcAppListPrefs::GetAppId(package, activity); |
+} |