Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 1523643002: arc-bridge: Move most methods to Mojo interfaces (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Fixed unit tests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | components/arc.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/path_service.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/task_runner_util.h" 16 #include "base/task_runner_util.h"
16 #include "chrome/browser/ui/app_list/app_list_test_util.h" 17 #include "chrome/browser/ui/app_list/app_list_test_util.h"
17 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" 18 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h"
18 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" 19 #include "chrome/browser/ui/app_list/arc/arc_app_item.h"
19 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 20 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
20 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" 21 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h"
21 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" 22 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/arc/arc_bridge_service.h" 24 #include "components/arc/arc_bridge_service.h"
24 #include "components/arc/test/fake_arc_bridge_service.h" 25 #include "components/arc/test/fake_arc_bridge_service.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "mojo/public/cpp/bindings/binding.h"
26 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/app_list/app_list_model.h" 29 #include "ui/app_list/app_list_model.h"
28 #include "ui/gfx/image/image_skia.h" 30 #include "ui/gfx/image/image_skia.h"
29 31
32 namespace mojo {
33
34 template <>
35 struct TypeConverter<arc::AppInfoPtr, arc::AppInfo> {
36 static arc::AppInfoPtr Convert(const arc::AppInfo& app_info) {
37 return app_info.Clone();
38 }
39 };
40
41 } // namespace mojo
42
30 namespace { 43 namespace {
31 44
32 std::string GetAppId(const arc::AppInfo& app_info) { 45 std::string GetAppId(const arc::AppInfo& app_info) {
33 return ArcAppListPrefs::GetAppId(app_info.package, app_info.activity); 46 return ArcAppListPrefs::GetAppId(app_info.package, app_info.activity);
34 } 47 }
35 48
49 class FakeAppInstance : public arc::AppInstance {
xiyuan 2015/12/14 22:52:02 nit: Think it would be better to put this into its
Luis Héctor Chávez 2015/12/16 17:07:22 Done.
50 public:
51 class Request {
52 public:
53 Request(const std::string& package, const std::string& activity)
54 : package_(package), activity_(activity) {}
55 ~Request() {}
56
57 const std::string& package() const { return package_; }
58
59 const std::string& activity() const { return activity_; }
60
61 bool IsForApp(const arc::AppInfo& app_info) const {
62 return package_ == app_info.package && activity_ == app_info.activity;
63 }
64
65 private:
66 std::string package_;
67 std::string activity_;
68
69 DISALLOW_COPY_AND_ASSIGN(Request);
70 };
71
72 class IconRequest : public Request {
73 public:
74 IconRequest(const std::string& package,
75 const std::string& activity,
76 arc::ScaleFactor scale_factor)
77 : Request(package, activity), scale_factor_(scale_factor) {}
78 ~IconRequest() {}
79
80 int scale_factor() const { return scale_factor_; }
81
82 private:
83 int scale_factor_;
84
85 DISALLOW_COPY_AND_ASSIGN(IconRequest);
86 };
87
88 explicit FakeAppInstance(arc::AppHost* app_host)
89 : binding_(this), app_host_(app_host) {}
90 ~FakeAppInstance() override {}
91
92 void Bind(mojo::InterfaceRequest<arc::AppInstance> interface_request) {
93 binding_.Bind(std::move(interface_request));
94 }
95
96 // arc::AppInstance overrides:
97 void Init(arc::AppHostPtr host_ptr) override {}
98 void RefreshAppList() override;
99 void LaunchApp(const mojo::String& package,
100 const mojo::String& activity) override;
101 void RequestAppIcon(const mojo::String& package,
102 const mojo::String& activity,
103 arc::ScaleFactor scale_factor) override;
104
105 // Methods to reply messages.
106 void SendRefreshAppList(const std::vector<arc::AppInfo>& apps);
107 bool GenerateAndSendIcon(const arc::AppInfo& app,
108 arc::ScaleFactor scale_factor,
109 std::string* png_data_as_string);
110
111 int refresh_app_list_count() const { return refresh_app_list_count_; }
112
113 const ScopedVector<Request>& launch_requests() const {
114 return launch_requests_;
115 }
116
117 const ScopedVector<IconRequest>& icon_requests() const {
118 return icon_requests_;
119 }
120
121 private:
122 // Mojo endpoints.
123 mojo::Binding<arc::AppInstance> binding_;
124 arc::AppHost* app_host_;
125 // Number of RefreshAppList calls.
126 int refresh_app_list_count_ = 0;
127 // Keeps information about launch requests.
128 ScopedVector<Request> launch_requests_;
129 // Keeps information about icon load requests.
130 ScopedVector<IconRequest> icon_requests_;
131 };
132
133 void FakeAppInstance::RefreshAppList() {
134 ++refresh_app_list_count_;
135 }
136
137 void FakeAppInstance::LaunchApp(const mojo::String& package,
138 const mojo::String& activity) {
139 launch_requests_.push_back(new Request(package, activity));
140 }
141
142 void FakeAppInstance::RequestAppIcon(const mojo::String& package,
143 const mojo::String& activity,
144 arc::ScaleFactor scale_factor) {
145 icon_requests_.push_back(new IconRequest(package, activity, scale_factor));
146 }
147
148 void FakeAppInstance::SendRefreshAppList(
149 const std::vector<arc::AppInfo>& apps) {
150 app_host_->OnAppListRefreshed(mojo::Array<arc::AppInfoPtr>::From(apps));
151 }
152
153 bool FakeAppInstance::GenerateAndSendIcon(const arc::AppInfo& app,
154 arc::ScaleFactor scale_factor,
155 std::string* png_data_as_string) {
156 CHECK(png_data_as_string != nullptr);
157 std::string icon_file_name;
158 switch (scale_factor) {
159 case arc::SCALE_FACTOR_SCALE_FACTOR_100P:
160 icon_file_name = "icon_100p.png";
161 break;
162 case arc::SCALE_FACTOR_SCALE_FACTOR_125P:
163 icon_file_name = "icon_125p.png";
164 break;
165 case arc::SCALE_FACTOR_SCALE_FACTOR_133P:
166 icon_file_name = "icon_133p.png";
167 break;
168 case arc::SCALE_FACTOR_SCALE_FACTOR_140P:
169 icon_file_name = "icon_140p.png";
170 break;
171 case arc::SCALE_FACTOR_SCALE_FACTOR_150P:
172 icon_file_name = "icon_150p.png";
173 break;
174 case arc::SCALE_FACTOR_SCALE_FACTOR_180P:
175 icon_file_name = "icon_180p.png";
176 break;
177 case arc::SCALE_FACTOR_SCALE_FACTOR_200P:
178 icon_file_name = "icon_200p.png";
179 break;
180 case arc::SCALE_FACTOR_SCALE_FACTOR_250P:
181 icon_file_name = "icon_250p.png";
182 break;
183 case arc::SCALE_FACTOR_SCALE_FACTOR_300P:
184 icon_file_name = "icon_300p.png";
185 break;
186 default:
187 NOTREACHED();
188 return false;
189 }
190
191 base::FilePath base_path;
192 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &base_path));
193 base::FilePath icon_file_path = base_path.AppendASCII("components")
194 .AppendASCII("test")
195 .AppendASCII("data")
196 .AppendASCII("arc")
197 .AppendASCII(icon_file_name);
198 CHECK(base::PathExists(icon_file_path));
199 CHECK(base::ReadFileToString(icon_file_path, png_data_as_string));
200
201 std::vector<uint8_t> png_data(png_data_as_string->begin(),
202 png_data_as_string->end());
203
204 app_host_->OnAppIcon(app.package, app.activity, scale_factor,
205 mojo::Array<uint8_t>::From(png_data));
206
207 return true;
208 }
209
36 } // namespace 210 } // namespace
37 211
38 class ArcAppModelBuilderTest : public AppListTestBase { 212 class ArcAppModelBuilderTest : public AppListTestBase {
39 public: 213 public:
40 ArcAppModelBuilderTest() {} 214 ArcAppModelBuilderTest() {}
41 ~ArcAppModelBuilderTest() override { 215 ~ArcAppModelBuilderTest() override {
42 // Release profile file in order to keep right sequence. 216 // Release profile file in order to keep right sequence.
43 profile_.reset(); 217 profile_.reset();
44 } 218 }
45 219
46 void SetUp() override { 220 void SetUp() override {
47 AppListTestBase::SetUp(); 221 AppListTestBase::SetUp();
48 222
49 // Make sure we have enough data for test. 223 // Make sure we have enough data for test.
50 for (int i = 0; i < 3; ++i) { 224 for (int i = 0; i < 3; ++i) {
51 arc::AppInfo app; 225 arc::AppInfo app;
52 char buffer[16]; 226 char buffer[16];
53 base::snprintf(buffer, arraysize(buffer), "Fake App %d", i); 227 base::snprintf(buffer, arraysize(buffer), "Fake App %d", i);
54 app.name = buffer; 228 app.name = buffer;
55 base::snprintf(buffer, arraysize(buffer), "fake.app.%d", i); 229 base::snprintf(buffer, arraysize(buffer), "fake.app.%d", i);
56 app.package = buffer; 230 app.package = buffer;
57 base::snprintf(buffer, arraysize(buffer), "fake.app.%d.activity", i); 231 base::snprintf(buffer, arraysize(buffer), "fake.app.%d.activity", i);
58 app.activity = buffer; 232 app.activity = buffer;
59 fake_apps_.push_back(app); 233 fake_apps_.push_back(app);
60 } 234 }
61 235
62 bridge_service_.reset(new arc::FakeArcBridgeService()); 236 bridge_service_.reset(new arc::FakeArcBridgeService());
237 app_instance_.reset(
238 new FakeAppInstance(ArcAppListPrefs::Get(profile_.get())));
239 arc::AppInstancePtr instance;
240 app_instance_->Bind(mojo::GetProxy(&instance));
241 bridge_service_->SetAppInstance(std::move(instance));
63 242
64 // Check initial conditions. 243 // Check initial conditions.
65 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); 244 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get());
66 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available()); 245 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available());
67 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, 246 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED,
68 arc::ArcBridgeService::Get()->state()); 247 arc::ArcBridgeService::Get()->state());
69 248
70 CreateBuilder(); 249 CreateBuilder();
71 250
72 // At this point we should have ArcAppListPrefs as observer of service. 251 // At this point we should have ArcAppListPrefs as observer of service.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 361
183 // Process the rest of the apps. 362 // Process the rest of the apps.
184 for (auto& id : ids) { 363 for (auto& id : ids) {
185 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id); 364 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id);
186 ASSERT_NE(nullptr, app_info.get()); 365 ASSERT_NE(nullptr, app_info.get());
187 EXPECT_NE(ready, app_info->ready); 366 EXPECT_NE(ready, app_info->ready);
188 const ArcAppItem* app_item = FindArcItem(id); 367 const ArcAppItem* app_item = FindArcItem(id);
189 ASSERT_NE(nullptr, app_item); 368 ASSERT_NE(nullptr, app_item);
190 EXPECT_NE(ready, app_item->ready()); 369 EXPECT_NE(ready, app_item->ready());
191 } 370 }
192
193 } 371 }
194 372
195 AppListControllerDelegate* controller() { return controller_.get(); } 373 AppListControllerDelegate* controller() { return controller_.get(); }
196 374
197 arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } 375 arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); }
198 376
377 FakeAppInstance* app_instance() { return app_instance_.get(); }
378
199 const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; } 379 const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; }
200 380
201 private: 381 private:
202 scoped_ptr<app_list::AppListModel> model_; 382 scoped_ptr<app_list::AppListModel> model_;
203 scoped_ptr<test::TestAppListControllerDelegate> controller_; 383 scoped_ptr<test::TestAppListControllerDelegate> controller_;
204 scoped_ptr<ArcAppModelBuilder> builder_; 384 scoped_ptr<ArcAppModelBuilder> builder_;
205 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; 385 scoped_ptr<arc::FakeArcBridgeService> bridge_service_;
386 scoped_ptr<FakeAppInstance> app_instance_;
206 std::vector<arc::AppInfo> fake_apps_; 387 std::vector<arc::AppInfo> fake_apps_;
207 388
208 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); 389 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest);
209 }; 390 };
210 391
211 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { 392 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) {
212 EXPECT_EQ(0, bridge_service()->refresh_app_list_count()); 393 EXPECT_EQ(0, app_instance()->refresh_app_list_count());
213 bridge_service()->SetReady(); 394 bridge_service()->SetReady();
214 EXPECT_EQ(1, bridge_service()->refresh_app_list_count()); 395 app_instance()->RefreshAppList();
396 EXPECT_EQ(1, app_instance()->refresh_app_list_count());
215 } 397 }
216 398
217 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { 399 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) {
218 ValidateHaveApps(std::vector<arc::AppInfo>()); 400 ValidateHaveApps(std::vector<arc::AppInfo>());
219 bridge_service()->SetReady(); 401 bridge_service()->SetReady();
220 bridge_service()->SendRefreshAppList(fake_apps()); 402 app_instance()->RefreshAppList();
403 app_instance()->SendRefreshAppList(fake_apps());
221 ValidateHaveApps(fake_apps()); 404 ValidateHaveApps(fake_apps());
222 } 405 }
223 406
224 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { 407 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) {
225 ValidateHaveApps(std::vector<arc::AppInfo>()); 408 ValidateHaveApps(std::vector<arc::AppInfo>());
226 bridge_service()->SetReady(); 409 bridge_service()->SetReady();
410 app_instance()->RefreshAppList();
227 // Send info about all fake apps except last. 411 // Send info about all fake apps except last.
228 std::vector<arc::AppInfo> apps1(fake_apps().begin(), fake_apps().end() - 1); 412 std::vector<arc::AppInfo> apps1(fake_apps().begin(), fake_apps().end() - 1);
229 bridge_service()->SendRefreshAppList(apps1); 413 app_instance()->SendRefreshAppList(apps1);
230 // At this point all apps (except last) should exist and be ready. 414 // At this point all apps (except last) should exist and be ready.
231 ValidateHaveApps(apps1); 415 ValidateHaveApps(apps1);
232 ValidateAppReadyState(apps1, true); 416 ValidateAppReadyState(apps1, true);
233 417
234 // Send info about all fake apps except first. 418 // Send info about all fake apps except first.
235 std::vector<arc::AppInfo> apps2(fake_apps().begin() + 1, fake_apps().end()); 419 std::vector<arc::AppInfo> apps2(fake_apps().begin() + 1, fake_apps().end());
236 bridge_service()->SendRefreshAppList(apps2); 420 app_instance()->SendRefreshAppList(apps2);
237 // At this point all apps should exist but first one should be non-ready. 421 // At this point all apps should exist but first one should be non-ready.
238 ValidateHaveApps(fake_apps()); 422 ValidateHaveApps(fake_apps());
239 ValidateAppReadyState(apps2, true); 423 ValidateAppReadyState(apps2, true);
240 424
241 // Send info about all fake apps. 425 // Send info about all fake apps.
242 bridge_service()->SendRefreshAppList(fake_apps()); 426 app_instance()->SendRefreshAppList(fake_apps());
243 // At this point all apps should exist and be ready. 427 // At this point all apps should exist and be ready.
244 ValidateHaveApps(fake_apps()); 428 ValidateHaveApps(fake_apps());
245 ValidateAppReadyState(fake_apps(), true); 429 ValidateAppReadyState(fake_apps(), true);
246 430
247 // Send info no app available. 431 // Send info no app available.
248 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>()); 432 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>());
249 // At this point all apps should exist and be non-ready. 433 // At this point all apps should exist and be non-ready.
250 ValidateHaveApps(fake_apps()); 434 ValidateHaveApps(fake_apps());
251 ValidateAppReadyState(fake_apps(), false); 435 ValidateAppReadyState(fake_apps(), false);
252 } 436 }
253 437
254 TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) { 438 TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) {
255 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 439 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
256 ASSERT_NE(nullptr, prefs); 440 ASSERT_NE(nullptr, prefs);
257 441
258 bridge_service()->SetReady(); 442 bridge_service()->SetReady();
443 app_instance()->RefreshAppList();
259 EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount()); 444 EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount());
260 EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size()); 445 EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size());
261 446
262 bridge_service()->SendRefreshAppList(fake_apps()); 447 app_instance()->SendRefreshAppList(fake_apps());
263 std::vector<std::string> ids = prefs->GetAppIds(); 448 std::vector<std::string> ids = prefs->GetAppIds();
264 EXPECT_EQ(fake_apps().size(), ids.size()); 449 EXPECT_EQ(fake_apps().size(), ids.size());
265 ValidateAppReadyState(fake_apps(), true); 450 ValidateAppReadyState(fake_apps(), true);
266 451
267 // Stopping service does not delete items. It makes them non-ready. 452 // Stopping service does not delete items. It makes them non-ready.
268 bridge_service()->SetStopped(); 453 bridge_service()->SetStopped();
269 // Ids should be the same. 454 // Ids should be the same.
270 EXPECT_EQ(ids, prefs->GetAppIds()); 455 EXPECT_EQ(ids, prefs->GetAppIds());
271 ValidateAppReadyState(fake_apps(), false); 456 ValidateAppReadyState(fake_apps(), false);
272 } 457 }
273 458
274 TEST_F(ArcAppModelBuilderTest, LaunchApps) { 459 TEST_F(ArcAppModelBuilderTest, LaunchApps) {
275 // Disable attempts to dismiss app launcher view. 460 // Disable attempts to dismiss app launcher view.
276 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 461 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
277 462
278 bridge_service()->SetReady(); 463 bridge_service()->SetReady();
279 bridge_service()->SendRefreshAppList(fake_apps()); 464 app_instance()->RefreshAppList();
465 app_instance()->SendRefreshAppList(fake_apps());
280 466
281 // Simulate item activate. 467 // Simulate item activate.
282 const arc::AppInfo& app_first = fake_apps()[0]; 468 const arc::AppInfo& app_first = fake_apps()[0];
283 const arc::AppInfo& app_last = fake_apps()[0]; 469 const arc::AppInfo& app_last = fake_apps()[0];
284 ArcAppItem* item_first = FindArcItem(GetAppId(app_first)); 470 ArcAppItem* item_first = FindArcItem(GetAppId(app_first));
285 ArcAppItem* item_last = FindArcItem(GetAppId(app_last)); 471 ArcAppItem* item_last = FindArcItem(GetAppId(app_last));
286 ASSERT_NE(nullptr, item_first); 472 ASSERT_NE(nullptr, item_first);
287 ASSERT_NE(nullptr, item_last); 473 ASSERT_NE(nullptr, item_last);
288 item_first->Activate(0); 474 item_first->Activate(0);
289 item_last->Activate(0); 475 item_last->Activate(0);
290 item_first->Activate(0); 476 item_first->Activate(0);
291 477
292 const ScopedVector<arc::FakeArcBridgeService::Request>& launch_requests = 478 // Process pending tasks.
293 bridge_service()->launch_requests(); 479 base::RunLoop().RunUntilIdle();
294 EXPECT_EQ(static_cast<size_t>(3), launch_requests.size()); 480
481 const ScopedVector<FakeAppInstance::Request>& launch_requests =
482 app_instance()->launch_requests();
483 ASSERT_EQ(static_cast<size_t>(3), launch_requests.size());
295 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); 484 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first));
296 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); 485 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last));
297 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); 486 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first));
298 487
299 // Test an attempt to launch of a not-ready app. 488 // Test an attempt to launch of a not-ready app.
300 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>()); 489 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>());
301 item_first = FindArcItem(GetAppId(app_first)); 490 item_first = FindArcItem(GetAppId(app_first));
302 ASSERT_NE(nullptr, item_first); 491 ASSERT_NE(nullptr, item_first);
303 size_t launch_request_count_before = 492 size_t launch_request_count_before = app_instance()->launch_requests().size();
304 bridge_service()->launch_requests().size();
305 item_first->Activate(0); 493 item_first->Activate(0);
306 // Number of launch requests must not change. 494 // Number of launch requests must not change.
307 EXPECT_EQ(launch_request_count_before, 495 EXPECT_EQ(launch_request_count_before,
308 bridge_service()->launch_requests().size()); 496 app_instance()->launch_requests().size());
309 } 497 }
310 498
311 TEST_F(ArcAppModelBuilderTest, RequestIcons) { 499 TEST_F(ArcAppModelBuilderTest, RequestIcons) {
312 // Make sure we are on UI thread. 500 // Make sure we are on UI thread.
313 ASSERT_EQ(true, 501 ASSERT_EQ(true,
314 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 502 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
315 503
316 bridge_service()->SetReady(); 504 bridge_service()->SetReady();
317 bridge_service()->SendRefreshAppList(fake_apps()); 505 app_instance()->RefreshAppList();
506 app_instance()->SendRefreshAppList(fake_apps());
318 507
319 // Validate that no icon exists at the beginning and request icon for 508 // Validate that no icon exists at the beginning and request icon for
320 // each supported scale factor. This will start asynchronous loading. 509 // each supported scale factor. This will start asynchronous loading.
321 uint32_t expected_mask = 0; 510 uint32_t expected_mask = 0;
322 const std::vector<ui::ScaleFactor>& scale_factors = 511 const std::vector<ui::ScaleFactor>& scale_factors =
323 ui::GetSupportedScaleFactors(); 512 ui::GetSupportedScaleFactors();
324 for (auto& scale_factor : scale_factors) { 513 for (auto& scale_factor : scale_factors) {
325 expected_mask |= 1 << scale_factor; 514 expected_mask |= 1 << scale_factor;
326 for (auto& app : fake_apps()) { 515 for (auto& app : fake_apps()) {
327 ArcAppItem* app_item = FindArcItem(GetAppId(app)); 516 ArcAppItem* app_item = FindArcItem(GetAppId(app));
328 ASSERT_NE(nullptr, app_item); 517 ASSERT_NE(nullptr, app_item);
329 const float scale = ui::GetScaleForScaleFactor(scale_factor); 518 const float scale = ui::GetScaleForScaleFactor(scale_factor);
330 app_item->icon().GetRepresentation(scale); 519 app_item->icon().GetRepresentation(scale);
331 } 520 }
332 } 521 }
333 522
334 // Process pending tasks. 523 // Process pending tasks.
335 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 524 content::BrowserThread::GetBlockingPool()->FlushForTesting();
336 base::RunLoop().RunUntilIdle(); 525 base::RunLoop().RunUntilIdle();
337 526
338 // At this moment we should receive all requests for icon loading. 527 // At this moment we should receive all requests for icon loading.
339 const ScopedVector<arc::FakeArcBridgeService::IconRequest>& icon_requests = 528 const ScopedVector<FakeAppInstance::IconRequest>& icon_requests =
340 bridge_service()->icon_requests(); 529 app_instance()->icon_requests();
341 EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size()); 530 EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size());
342 std::map<std::string, uint32_t> app_masks; 531 std::map<std::string, uint32_t> app_masks;
343 for (size_t i = 0; i < icon_requests.size(); ++i) { 532 for (size_t i = 0; i < icon_requests.size(); ++i) {
344 const arc::FakeArcBridgeService::IconRequest* icon_request = 533 const FakeAppInstance::IconRequest* icon_request = icon_requests[i];
345 icon_requests[i];
346 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(), 534 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(),
347 icon_request->activity()); 535 icon_request->activity());
348 // Make sure no double requests. 536 // Make sure no double requests.
349 EXPECT_NE(app_masks[id], 537 EXPECT_NE(app_masks[id],
350 app_masks[id] | (1 << icon_request->scale_factor())); 538 app_masks[id] | (1 << icon_request->scale_factor()));
351 app_masks[id] |= (1 << icon_request->scale_factor()); 539 app_masks[id] |= (1 << icon_request->scale_factor());
352 } 540 }
353 541
354 // Validate that we have a request for each icon for each supported scale 542 // Validate that we have a request for each icon for each supported scale
355 // factor. 543 // factor.
356 EXPECT_EQ(fake_apps().size(), app_masks.size()); 544 EXPECT_EQ(fake_apps().size(), app_masks.size());
357 for (auto& app : fake_apps()) { 545 for (auto& app : fake_apps()) {
358 const std::string id = GetAppId(app); 546 const std::string id = GetAppId(app);
359 ASSERT_NE(app_masks.find(id), app_masks.end()); 547 ASSERT_NE(app_masks.find(id), app_masks.end());
360 EXPECT_EQ(app_masks[id], expected_mask); 548 EXPECT_EQ(app_masks[id], expected_mask);
361 } 549 }
362 } 550 }
363 551
364 TEST_F(ArcAppModelBuilderTest, InstallIcon) { 552 TEST_F(ArcAppModelBuilderTest, InstallIcon) {
365 // Make sure we are on UI thread. 553 // Make sure we are on UI thread.
366 ASSERT_EQ(true, 554 ASSERT_EQ(true,
367 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 555 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
368 556
369 557
370 bridge_service()->SetReady(); 558 bridge_service()->SetReady();
371 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>( 559 app_instance()->RefreshAppList();
372 fake_apps().begin(), fake_apps().begin() + 1)); 560 app_instance()->SendRefreshAppList(
561 std::vector<arc::AppInfo>(fake_apps().begin(), fake_apps().begin() + 1));
373 const arc::AppInfo& app = fake_apps()[0]; 562 const arc::AppInfo& app = fake_apps()[0];
374 563
375 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 564 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
376 ASSERT_NE(nullptr, prefs); 565 ASSERT_NE(nullptr, prefs);
377 566
378 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; 567 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0];
379 const float scale = ui::GetScaleForScaleFactor(scale_factor); 568 const float scale = ui::GetScaleForScaleFactor(scale_factor);
380 const base::FilePath icon_path = prefs->GetIconPath(GetAppId(app), 569 const base::FilePath icon_path = prefs->GetIconPath(GetAppId(app),
381 scale_factor); 570 scale_factor);
382 EXPECT_EQ(true, !base::PathExists(icon_path)); 571 EXPECT_EQ(true, !base::PathExists(icon_path));
383 572
384 const ArcAppItem* app_item = FindArcItem(GetAppId(app)); 573 const ArcAppItem* app_item = FindArcItem(GetAppId(app));
385 EXPECT_NE(nullptr, app_item); 574 EXPECT_NE(nullptr, app_item);
386 // This initiates async loading. 575 // This initiates async loading.
387 app_item->icon().GetRepresentation(scale); 576 app_item->icon().GetRepresentation(scale);
388 577
389 // Process pending tasks. 578 // Process pending tasks.
390 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 579 content::BrowserThread::GetBlockingPool()->FlushForTesting();
391 base::RunLoop().RunUntilIdle(); 580 base::RunLoop().RunUntilIdle();
392 581
393 // Validating decoded content does not fit well for unit tests. 582 // Validating decoded content does not fit well for unit tests.
394 ArcAppIcon::DisableDecodingForTesting(); 583 ArcAppIcon::DisableDecodingForTesting();
395 584
396 // Now send generated icon for the app. 585 // Now send generated icon for the app.
397 std::string png_data; 586 std::string png_data;
398 EXPECT_EQ(true, bridge_service()->GenerateAndSendIcon( 587 EXPECT_EQ(true,
399 app, 588 app_instance()->GenerateAndSendIcon(
400 static_cast<arc::ScaleFactor>(scale_factor), 589 app, static_cast<arc::ScaleFactor>(scale_factor), &png_data));
401 &png_data));
402 590
403 // Process pending tasks. 591 // Process pending tasks.
404 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 592 content::BrowserThread::GetBlockingPool()->FlushForTesting();
405 base::RunLoop().RunUntilIdle(); 593 base::RunLoop().RunUntilIdle();
406 594
407 // Validate that icons are installed, have right content and icon is 595 // Validate that icons are installed, have right content and icon is
408 // refreshed for ARC app item. 596 // refreshed for ARC app item.
409 EXPECT_EQ(true, base::PathExists(icon_path)); 597 EXPECT_EQ(true, base::PathExists(icon_path));
410 598
411 std::string icon_data; 599 std::string icon_data;
412 // Read the file from disk and compare with reference data. 600 // Read the file from disk and compare with reference data.
413 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data)); 601 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data));
414 ASSERT_EQ(icon_data, png_data); 602 ASSERT_EQ(icon_data, png_data);
415 } 603 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | components/arc.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698