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 "chrome/browser/chromeos/note_taking_helper.h" | 5 #include "chrome/browser/chromeos/note_taking_helper.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void OnAvailableNoteTakingAppsUpdated() override { num_updates_++; } | 110 void OnAvailableNoteTakingAppsUpdated() override { num_updates_++; } |
111 | 111 |
112 // Number of times that OnAvailableNoteTakingAppsUpdated() has been called. | 112 // Number of times that OnAvailableNoteTakingAppsUpdated() has been called. |
113 int num_updates_ = 0; | 113 int num_updates_ = 0; |
114 | 114 |
115 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 115 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
116 }; | 116 }; |
117 | 117 |
118 } // namespace | 118 } // namespace |
119 | 119 |
120 class NoteTakingHelperTest : public BrowserWithTestWindowTest { | 120 class NoteTakingHelperTest : public BrowserWithTestWindowTest, |
| 121 public ::testing::WithParamInterface<bool> { |
121 public: | 122 public: |
122 NoteTakingHelperTest() = default; | 123 NoteTakingHelperTest() = default; |
123 ~NoteTakingHelperTest() override = default; | 124 ~NoteTakingHelperTest() override = default; |
124 | 125 |
125 void SetUp() override { | 126 void SetUp() override { |
| 127 ArcAppTest::Init(GetParam()); |
| 128 |
126 // This is needed to avoid log spam due to ArcSessionManager's | 129 // This is needed to avoid log spam due to ArcSessionManager's |
127 // RemoveArcData() calls failing. | 130 // RemoveArcData() calls failing. |
128 if (DBusThreadManager::IsInitialized()) | 131 if (DBusThreadManager::IsInitialized()) |
129 DBusThreadManager::Shutdown(); | 132 DBusThreadManager::Shutdown(); |
130 session_manager_client_ = new FakeSessionManagerClient(); | 133 session_manager_client_ = new FakeSessionManagerClient(); |
131 session_manager_client_->set_arc_available(true); | 134 session_manager_client_->set_arc_available(true); |
132 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 135 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
133 std::unique_ptr<SessionManagerClient>(session_manager_client_)); | 136 std::unique_ptr<SessionManagerClient>(session_manager_client_)); |
134 | 137 |
135 profile_manager_.reset( | 138 profile_manager_.reset( |
136 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 139 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
137 ASSERT_TRUE(profile_manager_->SetUp()); | 140 ASSERT_TRUE(profile_manager_->SetUp()); |
138 BrowserWithTestWindowTest::SetUp(); | 141 BrowserWithTestWindowTest::SetUp(); |
139 InitExtensionService(profile()); | 142 InitExtensionService(profile()); |
140 } | 143 } |
141 | 144 |
142 void TearDown() override { | 145 void TearDown() override { |
143 if (initialized_) { | 146 if (initialized_) { |
144 NoteTakingHelper::Shutdown(); | 147 NoteTakingHelper::Shutdown(); |
145 arc_test_.TearDown(); | 148 arc_test_.TearDown(); |
146 } | 149 } |
147 extensions::ExtensionSystem::Get(profile())->Shutdown(); | 150 extensions::ExtensionSystem::Get(profile())->Shutdown(); |
148 BrowserWithTestWindowTest::TearDown(); | 151 BrowserWithTestWindowTest::TearDown(); |
149 DBusThreadManager::Shutdown(); | 152 DBusThreadManager::Shutdown(); |
150 } | 153 } |
151 | 154 |
| 155 bool IsPersistentArc() { |
| 156 return arc_test_.arc_session_manager()->IsPersistentArc(); |
| 157 } |
| 158 |
152 protected: | 159 protected: |
153 // Information about a Chrome app passed to LaunchChromeApp(). | 160 // Information about a Chrome app passed to LaunchChromeApp(). |
154 struct ChromeAppLaunchInfo { | 161 struct ChromeAppLaunchInfo { |
155 extensions::ExtensionId id; | 162 extensions::ExtensionId id; |
156 base::FilePath path; | 163 base::FilePath path; |
157 }; | 164 }; |
158 | 165 |
159 // Options that can be passed to Init(). | 166 // Options that can be passed to Init(). |
160 enum InitFlags { | 167 enum InitFlags { |
161 ENABLE_ARC = 1 << 0, | 168 ENABLE_PLAY = 1 << 0, |
162 ENABLE_PALETTE = 1 << 1, | 169 ENABLE_PALETTE = 1 << 1, |
163 }; | 170 }; |
164 | 171 |
165 static NoteTakingHelper* helper() { return NoteTakingHelper::Get(); } | 172 static NoteTakingHelper* helper() { return NoteTakingHelper::Get(); } |
166 | 173 |
167 // Initializes ARC and NoteTakingHelper. |flags| contains OR-ed together | 174 // Initializes ARC and NoteTakingHelper. |flags| contains OR-ed together |
168 // InitFlags values. | 175 // InitFlags values. |
169 void Init(uint32_t flags) { | 176 void Init(uint32_t flags) { |
170 ASSERT_FALSE(initialized_); | 177 ASSERT_FALSE(initialized_); |
171 initialized_ = true; | 178 initialized_ = true; |
172 | 179 |
173 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); | 180 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_PLAY); |
174 arc_test_.SetUp(profile()); | 181 arc_test_.SetUp(profile()); |
175 arc::ArcServiceManager::Get() | 182 arc::ArcServiceManager::Get() |
176 ->arc_bridge_service() | 183 ->arc_bridge_service() |
177 ->intent_helper() | 184 ->intent_helper() |
178 ->SetInstance(&intent_helper_); | 185 ->SetInstance(&intent_helper_); |
179 | 186 |
180 if (flags & ENABLE_PALETTE) { | 187 if (flags & ENABLE_PALETTE) { |
181 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 188 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
182 ash::switches::kAshForceEnablePalette); | 189 ash::switches::kAshForceEnablePalette); |
183 } | 190 } |
184 | 191 |
185 // TODO(derat): Sigh, something in ArcAppTest appears to be re-enabling ARC. | 192 // TODO(derat): Sigh, something in ArcAppTest appears to be re-enabling ARC. |
186 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); | 193 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_PLAY); |
187 NoteTakingHelper::Initialize(); | 194 NoteTakingHelper::Initialize(); |
188 NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( | 195 NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( |
189 &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); | 196 &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); |
190 } | 197 } |
191 | 198 |
192 // Creates an extension. | 199 // Creates an extension. |
193 scoped_refptr<const extensions::Extension> CreateExtension( | 200 scoped_refptr<const extensions::Extension> CreateExtension( |
194 const extensions::ExtensionId& id, | 201 const extensions::ExtensionId& id, |
195 const std::string& name) { | 202 const std::string& name) { |
196 return CreateExtension(id, name, nullptr); | 203 return CreateExtension(id, name, nullptr); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 288 |
282 // Has Init() been called? | 289 // Has Init() been called? |
283 bool initialized_ = false; | 290 bool initialized_ = false; |
284 | 291 |
285 FakeSessionManagerClient* session_manager_client_ = nullptr; // Not owned. | 292 FakeSessionManagerClient* session_manager_client_ = nullptr; // Not owned. |
286 ArcAppTest arc_test_; | 293 ArcAppTest arc_test_; |
287 | 294 |
288 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest); | 295 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest); |
289 }; | 296 }; |
290 | 297 |
291 TEST_F(NoteTakingHelperTest, PaletteNotEnabled) { | 298 INSTANTIATE_TEST_CASE_P(, NoteTakingHelperTest, ::testing::Values(false, true)); |
| 299 |
| 300 TEST_P(NoteTakingHelperTest, PaletteNotEnabled) { |
292 // Without the palette enabled, IsAppAvailable() should return false. | 301 // Without the palette enabled, IsAppAvailable() should return false. |
293 Init(0); | 302 Init(0); |
294 auto extension = | 303 auto extension = |
295 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); | 304 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); |
296 InstallExtension(extension.get(), profile()); | 305 InstallExtension(extension.get(), profile()); |
297 EXPECT_FALSE(helper()->IsAppAvailable(profile())); | 306 EXPECT_FALSE(helper()->IsAppAvailable(profile())); |
298 } | 307 } |
299 | 308 |
300 TEST_F(NoteTakingHelperTest, ListChromeApps) { | 309 TEST_P(NoteTakingHelperTest, ListChromeApps) { |
301 Init(ENABLE_PALETTE); | 310 Init(ENABLE_PALETTE); |
302 | 311 |
303 // Start out without any note-taking apps installed. | 312 // Start out without any note-taking apps installed. |
304 EXPECT_FALSE(helper()->IsAppAvailable(profile())); | 313 EXPECT_FALSE(helper()->IsAppAvailable(profile())); |
305 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); | 314 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); |
306 | 315 |
307 // If only the prod version of the app is installed, it should be returned. | 316 // If only the prod version of the app is installed, it should be returned. |
308 const std::string kProdName = "Google Keep [prod]"; | 317 const std::string kProdName = "Google Keep [prod]"; |
309 auto prod_extension = | 318 auto prod_extension = |
310 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, kProdName); | 319 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, kProdName); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 EXPECT_EQ( | 361 EXPECT_EQ( |
353 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), | 362 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), |
354 GetAppString(apps[0])); | 363 GetAppString(apps[0])); |
355 EXPECT_EQ( | 364 EXPECT_EQ( |
356 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), | 365 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), |
357 GetAppString(apps[1])); | 366 GetAppString(apps[1])); |
358 } | 367 } |
359 | 368 |
360 // Verify the note helper detects apps with "new_note" "action_handler" manifest | 369 // Verify the note helper detects apps with "new_note" "action_handler" manifest |
361 // entries. | 370 // entries. |
362 TEST_F(NoteTakingHelperTest, CustomChromeApps) { | 371 TEST_P(NoteTakingHelperTest, CustomChromeApps) { |
363 Init(ENABLE_PALETTE); | 372 Init(ENABLE_PALETTE); |
364 | 373 |
365 const extensions::ExtensionId kNewNoteId = crx_file::id_util::GenerateId("a"); | 374 const extensions::ExtensionId kNewNoteId = crx_file::id_util::GenerateId("a"); |
366 const extensions::ExtensionId kEmptyArrayId = | 375 const extensions::ExtensionId kEmptyArrayId = |
367 crx_file::id_util::GenerateId("b"); | 376 crx_file::id_util::GenerateId("b"); |
368 const extensions::ExtensionId kEmptyId = crx_file::id_util::GenerateId("c"); | 377 const extensions::ExtensionId kEmptyId = crx_file::id_util::GenerateId("c"); |
369 const std::string kName = "Some App"; | 378 const std::string kName = "Some App"; |
370 | 379 |
371 // "action_handlers": ["new_note"] | 380 // "action_handlers": ["new_note"] |
372 auto has_new_note = CreateExtension( | 381 auto has_new_note = CreateExtension( |
373 kNewNoteId, kName, | 382 kNewNoteId, kName, |
374 extensions::ListBuilder() | 383 extensions::ListBuilder() |
375 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE)) | 384 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE)) |
376 .Build()); | 385 .Build()); |
377 InstallExtension(has_new_note.get(), profile()); | 386 InstallExtension(has_new_note.get(), profile()); |
378 // "action_handlers": [] | 387 // "action_handlers": [] |
379 auto empty_array = | 388 auto empty_array = |
380 CreateExtension(kEmptyArrayId, kName, extensions::ListBuilder().Build()); | 389 CreateExtension(kEmptyArrayId, kName, extensions::ListBuilder().Build()); |
381 InstallExtension(empty_array.get(), profile()); | 390 InstallExtension(empty_array.get(), profile()); |
382 // (no action handler entry) | 391 // (no action handler entry) |
383 auto none = CreateExtension(kEmptyId, kName); | 392 auto none = CreateExtension(kEmptyId, kName); |
384 InstallExtension(none.get(), profile()); | 393 InstallExtension(none.get(), profile()); |
385 | 394 |
386 // Only the "new_note" extension is returned from GetAvailableApps. | 395 // Only the "new_note" extension is returned from GetAvailableApps. |
387 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); | 396 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); |
388 ASSERT_EQ(1u, apps.size()); | 397 ASSERT_EQ(1u, apps.size()); |
389 EXPECT_EQ(GetAppString(kNewNoteId, kName, false), GetAppString(apps[0])); | 398 EXPECT_EQ(GetAppString(kNewNoteId, kName, false), GetAppString(apps[0])); |
390 } | 399 } |
391 | 400 |
392 TEST_F(NoteTakingHelperTest, WhitelistedAndCustomAppsShowOnlyOnce) { | 401 TEST_P(NoteTakingHelperTest, WhitelistedAndCustomAppsShowOnlyOnce) { |
393 Init(ENABLE_PALETTE); | 402 Init(ENABLE_PALETTE); |
394 | 403 |
395 auto extension = CreateExtension( | 404 auto extension = CreateExtension( |
396 NoteTakingHelper::kProdKeepExtensionId, "Keep", | 405 NoteTakingHelper::kProdKeepExtensionId, "Keep", |
397 extensions::ListBuilder() | 406 extensions::ListBuilder() |
398 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE)) | 407 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE)) |
399 .Build()); | 408 .Build()); |
400 InstallExtension(extension.get(), profile()); | 409 InstallExtension(extension.get(), profile()); |
401 | 410 |
402 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); | 411 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); |
403 ASSERT_EQ(1u, apps.size()); | 412 ASSERT_EQ(1u, apps.size()); |
404 EXPECT_EQ(GetAppString(NoteTakingHelper::kProdKeepExtensionId, "Keep", false), | 413 EXPECT_EQ(GetAppString(NoteTakingHelper::kProdKeepExtensionId, "Keep", false), |
405 GetAppString(apps[0])); | 414 GetAppString(apps[0])); |
406 } | 415 } |
407 | 416 |
408 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { | 417 TEST_P(NoteTakingHelperTest, LaunchChromeApp) { |
409 Init(ENABLE_PALETTE); | 418 Init(ENABLE_PALETTE); |
410 auto extension = | 419 auto extension = |
411 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); | 420 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); |
412 InstallExtension(extension.get(), profile()); | 421 InstallExtension(extension.get(), profile()); |
413 | 422 |
414 // Check the Chrome app is launched with the correct parameters. | 423 // Check the Chrome app is launched with the correct parameters. |
415 HistogramTester histogram_tester; | 424 HistogramTester histogram_tester; |
416 const base::FilePath kPath("/foo/bar/photo.jpg"); | 425 const base::FilePath kPath("/foo/bar/photo.jpg"); |
417 helper()->LaunchAppForNewNote(profile(), kPath); | 426 helper()->LaunchAppForNewNote(profile(), kPath); |
418 ASSERT_EQ(1u, launched_chrome_apps_.size()); | 427 ASSERT_EQ(1u, launched_chrome_apps_.size()); |
419 EXPECT_EQ(NoteTakingHelper::kProdKeepExtensionId, | 428 EXPECT_EQ(NoteTakingHelper::kProdKeepExtensionId, |
420 launched_chrome_apps_[0].id); | 429 launched_chrome_apps_[0].id); |
421 EXPECT_EQ(kPath, launched_chrome_apps_[0].path); | 430 EXPECT_EQ(kPath, launched_chrome_apps_[0].path); |
422 | 431 |
423 histogram_tester.ExpectUniqueSample( | 432 histogram_tester.ExpectUniqueSample( |
424 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 433 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
425 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); | 434 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); |
426 histogram_tester.ExpectUniqueSample( | 435 histogram_tester.ExpectUniqueSample( |
427 NoteTakingHelper::kDefaultLaunchResultHistogramName, | 436 NoteTakingHelper::kDefaultLaunchResultHistogramName, |
428 static_cast<int>(LaunchResult::CHROME_SUCCESS), 1); | 437 static_cast<int>(LaunchResult::CHROME_SUCCESS), 1); |
429 } | 438 } |
430 | 439 |
431 TEST_F(NoteTakingHelperTest, FallBackIfPreferredAppUnavailable) { | 440 TEST_P(NoteTakingHelperTest, FallBackIfPreferredAppUnavailable) { |
432 Init(ENABLE_PALETTE); | 441 Init(ENABLE_PALETTE); |
433 auto prod_extension = | 442 auto prod_extension = |
434 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "prod"); | 443 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "prod"); |
435 InstallExtension(prod_extension.get(), profile()); | 444 InstallExtension(prod_extension.get(), profile()); |
436 auto dev_extension = | 445 auto dev_extension = |
437 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, "dev"); | 446 CreateExtension(NoteTakingHelper::kDevKeepExtensionId, "dev"); |
438 InstallExtension(dev_extension.get(), profile()); | 447 InstallExtension(dev_extension.get(), profile()); |
439 | 448 |
440 // Set the prod app as preferred and check that it's launched. | 449 // Set the prod app as preferred and check that it's launched. |
441 std::unique_ptr<HistogramTester> histogram_tester(new HistogramTester()); | 450 std::unique_ptr<HistogramTester> histogram_tester(new HistogramTester()); |
(...skipping 18 matching lines...) Expand all Loading... |
460 EXPECT_EQ(NoteTakingHelper::kDevKeepExtensionId, launched_chrome_apps_[0].id); | 469 EXPECT_EQ(NoteTakingHelper::kDevKeepExtensionId, launched_chrome_apps_[0].id); |
461 | 470 |
462 histogram_tester->ExpectUniqueSample( | 471 histogram_tester->ExpectUniqueSample( |
463 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 472 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
464 static_cast<int>(LaunchResult::CHROME_APP_MISSING), 1); | 473 static_cast<int>(LaunchResult::CHROME_APP_MISSING), 1); |
465 histogram_tester->ExpectUniqueSample( | 474 histogram_tester->ExpectUniqueSample( |
466 NoteTakingHelper::kDefaultLaunchResultHistogramName, | 475 NoteTakingHelper::kDefaultLaunchResultHistogramName, |
467 static_cast<int>(LaunchResult::CHROME_SUCCESS), 1); | 476 static_cast<int>(LaunchResult::CHROME_SUCCESS), 1); |
468 } | 477 } |
469 | 478 |
470 TEST_F(NoteTakingHelperTest, ArcInitiallyDisabled) { | 479 TEST_P(NoteTakingHelperTest, PlayInitiallyDisabled) { |
471 Init(ENABLE_PALETTE); | 480 Init(ENABLE_PALETTE); |
472 EXPECT_FALSE(helper()->android_enabled()); | 481 EXPECT_FALSE(helper()->play_enabled()); |
473 EXPECT_FALSE(helper()->android_apps_received()); | 482 EXPECT_FALSE(helper()->android_apps_received()); |
474 | 483 // TODO(victorhsieh): Imeplement opt-in. |
475 // When ARC is enabled, the helper's members should be updated accordingly. | 484 if (IsPersistentArc()) |
| 485 return; |
| 486 // When Play is enabled, the helper's members should be updated accordingly. |
476 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 487 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
477 EXPECT_TRUE(helper()->android_enabled()); | 488 EXPECT_TRUE(helper()->play_enabled()); |
478 EXPECT_FALSE(helper()->android_apps_received()); | 489 EXPECT_FALSE(helper()->android_apps_received()); |
479 | 490 |
480 // After the callback to receive intent handlers has run, the "apps received" | 491 // After the callback to receive intent handlers has run, the "apps received" |
481 // member should be updated (even if there aren't any apps). | 492 // member should be updated (even if there aren't any apps). |
482 helper()->OnIntentFiltersUpdated(); | 493 helper()->OnIntentFiltersUpdated(); |
483 base::RunLoop().RunUntilIdle(); | 494 base::RunLoop().RunUntilIdle(); |
484 EXPECT_TRUE(helper()->android_enabled()); | 495 EXPECT_TRUE(helper()->play_enabled()); |
485 EXPECT_TRUE(helper()->android_apps_received()); | 496 EXPECT_TRUE(helper()->android_apps_received()); |
486 } | 497 } |
487 | 498 |
488 TEST_F(NoteTakingHelperTest, ListAndroidApps) { | 499 TEST_P(NoteTakingHelperTest, ListAndroidApps) { |
489 // Add two Android apps. | 500 // Add two Android apps. |
490 std::vector<IntentHandlerInfoPtr> handlers; | 501 std::vector<IntentHandlerInfoPtr> handlers; |
491 const std::string kName1 = "App 1"; | 502 const std::string kName1 = "App 1"; |
492 const std::string kPackage1 = "org.chromium.package1"; | 503 const std::string kPackage1 = "org.chromium.package1"; |
493 handlers.emplace_back(CreateIntentHandlerInfo(kName1, kPackage1)); | 504 handlers.emplace_back(CreateIntentHandlerInfo(kName1, kPackage1)); |
494 const std::string kName2 = "App 2"; | 505 const std::string kName2 = "App 2"; |
495 const std::string kPackage2 = "org.chromium.package2"; | 506 const std::string kPackage2 = "org.chromium.package2"; |
496 handlers.emplace_back(CreateIntentHandlerInfo(kName2, kPackage2)); | 507 handlers.emplace_back(CreateIntentHandlerInfo(kName2, kPackage2)); |
497 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, | 508 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, |
498 std::move(handlers)); | 509 std::move(handlers)); |
499 | 510 |
500 // NoteTakingHelper should make an async request for Android apps when | 511 // NoteTakingHelper should make an async request for Android apps when |
501 // constructed. | 512 // constructed. |
502 Init(ENABLE_PALETTE | ENABLE_ARC); | 513 Init(ENABLE_PALETTE | ENABLE_PLAY); |
503 EXPECT_TRUE(helper()->android_enabled()); | 514 EXPECT_TRUE(helper()->play_enabled()); |
504 EXPECT_FALSE(helper()->android_apps_received()); | 515 EXPECT_FALSE(helper()->android_apps_received()); |
505 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); | 516 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); |
506 | 517 |
507 // The apps should be listed after the callback has had a chance to run. | 518 // The apps should be listed after the callback has had a chance to run. |
508 base::RunLoop().RunUntilIdle(); | 519 base::RunLoop().RunUntilIdle(); |
509 EXPECT_TRUE(helper()->android_enabled()); | 520 EXPECT_TRUE(helper()->play_enabled()); |
510 EXPECT_TRUE(helper()->android_apps_received()); | 521 EXPECT_TRUE(helper()->android_apps_received()); |
511 EXPECT_TRUE(helper()->IsAppAvailable(profile())); | 522 EXPECT_TRUE(helper()->IsAppAvailable(profile())); |
512 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); | 523 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); |
513 ASSERT_EQ(2u, apps.size()); | 524 ASSERT_EQ(2u, apps.size()); |
514 EXPECT_EQ(GetAppString(kPackage1, kName1, false), GetAppString(apps[0])); | 525 EXPECT_EQ(GetAppString(kPackage1, kName1, false), GetAppString(apps[0])); |
515 EXPECT_EQ(GetAppString(kPackage2, kName2, false), GetAppString(apps[1])); | 526 EXPECT_EQ(GetAppString(kPackage2, kName2, false), GetAppString(apps[1])); |
516 | 527 |
517 // Disable ARC and check that the apps are no longer returned. | 528 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until |
| 529 // implemented. |
| 530 if (IsPersistentArc()) |
| 531 return; |
| 532 // Disable Play and check that the apps are no longer returned. |
518 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 533 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
519 EXPECT_FALSE(helper()->android_enabled()); | 534 EXPECT_FALSE(helper()->play_enabled()); |
520 EXPECT_FALSE(helper()->android_apps_received()); | 535 EXPECT_FALSE(helper()->android_apps_received()); |
521 EXPECT_FALSE(helper()->IsAppAvailable(profile())); | 536 EXPECT_FALSE(helper()->IsAppAvailable(profile())); |
522 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); | 537 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); |
523 } | 538 } |
524 | 539 |
525 TEST_F(NoteTakingHelperTest, LaunchAndroidApp) { | 540 TEST_P(NoteTakingHelperTest, LaunchAndroidApp) { |
526 const std::string kPackage1 = "org.chromium.package1"; | 541 const std::string kPackage1 = "org.chromium.package1"; |
527 std::vector<IntentHandlerInfoPtr> handlers; | 542 std::vector<IntentHandlerInfoPtr> handlers; |
528 handlers.emplace_back(CreateIntentHandlerInfo("App 1", kPackage1)); | 543 handlers.emplace_back(CreateIntentHandlerInfo("App 1", kPackage1)); |
529 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, | 544 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, |
530 std::move(handlers)); | 545 std::move(handlers)); |
531 | 546 |
532 Init(ENABLE_PALETTE | ENABLE_ARC); | 547 Init(ENABLE_PALETTE | ENABLE_PLAY); |
533 base::RunLoop().RunUntilIdle(); | 548 base::RunLoop().RunUntilIdle(); |
534 ASSERT_TRUE(helper()->IsAppAvailable(profile())); | 549 ASSERT_TRUE(helper()->IsAppAvailable(profile())); |
535 | 550 |
536 // The installed app should be launched. | 551 // The installed app should be launched. |
537 std::unique_ptr<HistogramTester> histogram_tester(new HistogramTester()); | 552 std::unique_ptr<HistogramTester> histogram_tester(new HistogramTester()); |
538 helper()->LaunchAppForNewNote(profile(), base::FilePath()); | 553 helper()->LaunchAppForNewNote(profile(), base::FilePath()); |
539 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); | 554 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); |
540 EXPECT_EQ(GetIntentString(kPackage1, ""), | 555 EXPECT_EQ(GetIntentString(kPackage1, ""), |
541 GetIntentString(intent_helper_.handled_intents()[0])); | 556 GetIntentString(intent_helper_.handled_intents()[0])); |
542 | 557 |
(...skipping 22 matching lines...) Expand all Loading... |
565 EXPECT_EQ(GetIntentString(kPackage2, ""), | 580 EXPECT_EQ(GetIntentString(kPackage2, ""), |
566 GetIntentString(intent_helper_.handled_intents()[0])); | 581 GetIntentString(intent_helper_.handled_intents()[0])); |
567 | 582 |
568 histogram_tester->ExpectUniqueSample( | 583 histogram_tester->ExpectUniqueSample( |
569 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 584 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
570 static_cast<int>(LaunchResult::ANDROID_SUCCESS), 1); | 585 static_cast<int>(LaunchResult::ANDROID_SUCCESS), 1); |
571 histogram_tester->ExpectTotalCount( | 586 histogram_tester->ExpectTotalCount( |
572 NoteTakingHelper::kDefaultLaunchResultHistogramName, 0); | 587 NoteTakingHelper::kDefaultLaunchResultHistogramName, 0); |
573 } | 588 } |
574 | 589 |
575 TEST_F(NoteTakingHelperTest, LaunchAndroidAppWithPath) { | 590 TEST_P(NoteTakingHelperTest, LaunchAndroidAppWithPath) { |
576 const std::string kPackage = "org.chromium.package"; | 591 const std::string kPackage = "org.chromium.package"; |
577 std::vector<IntentHandlerInfoPtr> handlers; | 592 std::vector<IntentHandlerInfoPtr> handlers; |
578 handlers.emplace_back(CreateIntentHandlerInfo("App", kPackage)); | 593 handlers.emplace_back(CreateIntentHandlerInfo("App", kPackage)); |
579 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, | 594 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, |
580 std::move(handlers)); | 595 std::move(handlers)); |
581 | 596 |
582 Init(ENABLE_PALETTE | ENABLE_ARC); | 597 Init(ENABLE_PALETTE | ENABLE_PLAY); |
583 base::RunLoop().RunUntilIdle(); | 598 base::RunLoop().RunUntilIdle(); |
584 ASSERT_TRUE(helper()->IsAppAvailable(profile())); | 599 ASSERT_TRUE(helper()->IsAppAvailable(profile())); |
585 | 600 |
586 const base::FilePath kDownloadedPath( | 601 const base::FilePath kDownloadedPath( |
587 file_manager::util::GetDownloadsFolderForProfile(profile()).Append( | 602 file_manager::util::GetDownloadsFolderForProfile(profile()).Append( |
588 "image.jpg")); | 603 "image.jpg")); |
589 helper()->LaunchAppForNewNote(profile(), kDownloadedPath); | 604 helper()->LaunchAppForNewNote(profile(), kDownloadedPath); |
590 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); | 605 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); |
591 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kDownloadedPath)), | 606 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kDownloadedPath)), |
592 GetIntentString(intent_helper_.handled_intents()[0])); | 607 GetIntentString(intent_helper_.handled_intents()[0])); |
(...skipping 15 matching lines...) Expand all Loading... |
608 EXPECT_TRUE(intent_helper_.handled_intents().empty()); | 623 EXPECT_TRUE(intent_helper_.handled_intents().empty()); |
609 | 624 |
610 histogram_tester.ExpectUniqueSample( | 625 histogram_tester.ExpectUniqueSample( |
611 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 626 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
612 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); | 627 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); |
613 histogram_tester.ExpectUniqueSample( | 628 histogram_tester.ExpectUniqueSample( |
614 NoteTakingHelper::kDefaultLaunchResultHistogramName, | 629 NoteTakingHelper::kDefaultLaunchResultHistogramName, |
615 static_cast<int>(LaunchResult::ANDROID_FAILED_TO_CONVERT_PATH), 1); | 630 static_cast<int>(LaunchResult::ANDROID_FAILED_TO_CONVERT_PATH), 1); |
616 } | 631 } |
617 | 632 |
618 TEST_F(NoteTakingHelperTest, NoAppsAvailable) { | 633 TEST_P(NoteTakingHelperTest, NoAppsAvailable) { |
619 Init(ENABLE_PALETTE | ENABLE_ARC); | 634 Init(ENABLE_PALETTE | ENABLE_PLAY); |
620 | 635 |
621 // When no note-taking apps are installed, the histograms should just be | 636 // When no note-taking apps are installed, the histograms should just be |
622 // updated. | 637 // updated. |
623 HistogramTester histogram_tester; | 638 HistogramTester histogram_tester; |
624 helper()->LaunchAppForNewNote(profile(), base::FilePath()); | 639 helper()->LaunchAppForNewNote(profile(), base::FilePath()); |
625 histogram_tester.ExpectUniqueSample( | 640 histogram_tester.ExpectUniqueSample( |
626 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 641 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
627 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); | 642 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); |
628 histogram_tester.ExpectUniqueSample( | 643 histogram_tester.ExpectUniqueSample( |
629 NoteTakingHelper::kDefaultLaunchResultHistogramName, | 644 NoteTakingHelper::kDefaultLaunchResultHistogramName, |
630 static_cast<int>(LaunchResult::NO_APPS_AVAILABLE), 1); | 645 static_cast<int>(LaunchResult::NO_APPS_AVAILABLE), 1); |
631 } | 646 } |
632 | 647 |
633 TEST_F(NoteTakingHelperTest, NotifyObserverAboutAndroidApps) { | 648 TEST_P(NoteTakingHelperTest, NotifyObserverAboutAndroidApps) { |
634 Init(ENABLE_PALETTE | ENABLE_ARC); | 649 Init(ENABLE_PALETTE | ENABLE_PLAY); |
635 TestObserver observer; | 650 TestObserver observer; |
636 | 651 |
637 // Let the app-fetching callback run and check that the observer is notified. | 652 // Let the app-fetching callback run and check that the observer is notified. |
638 base::RunLoop().RunUntilIdle(); | 653 base::RunLoop().RunUntilIdle(); |
639 EXPECT_EQ(1, observer.num_updates()); | 654 EXPECT_EQ(1, observer.num_updates()); |
640 | 655 |
641 // Disabling and enabling ARC should also notify the observer (and enabling | 656 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until |
| 657 // implemented. |
| 658 if (IsPersistentArc()) |
| 659 return; |
| 660 |
| 661 // Disabling and enabling Play should also notify the observer (and enabling |
642 // should request apps again). | 662 // should request apps again). |
643 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 663 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
644 EXPECT_EQ(2, observer.num_updates()); | 664 EXPECT_EQ(2, observer.num_updates()); |
645 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 665 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
646 EXPECT_EQ(3, observer.num_updates()); | 666 EXPECT_EQ(3, observer.num_updates()); |
647 // Run ARC data removing operation. | 667 // Run ARC data removing operation. |
648 base::RunLoop().RunUntilIdle(); | 668 base::RunLoop().RunUntilIdle(); |
649 | 669 |
650 // Update intent filters and check that the observer is notified again after | 670 // Update intent filters and check that the observer is notified again after |
651 // apps are received. | 671 // apps are received. |
652 helper()->OnIntentFiltersUpdated(); | 672 helper()->OnIntentFiltersUpdated(); |
653 EXPECT_EQ(3, observer.num_updates()); | 673 EXPECT_EQ(3, observer.num_updates()); |
654 base::RunLoop().RunUntilIdle(); | 674 base::RunLoop().RunUntilIdle(); |
655 EXPECT_EQ(4, observer.num_updates()); | 675 EXPECT_EQ(4, observer.num_updates()); |
656 } | 676 } |
657 | 677 |
658 TEST_F(NoteTakingHelperTest, NotifyObserverAboutChromeApps) { | 678 TEST_P(NoteTakingHelperTest, NotifyObserverAboutChromeApps) { |
659 Init(ENABLE_PALETTE); | 679 Init(ENABLE_PALETTE); |
660 TestObserver observer; | 680 TestObserver observer; |
661 ASSERT_EQ(0, observer.num_updates()); | 681 ASSERT_EQ(0, observer.num_updates()); |
662 | 682 |
663 // Notify that the prod Keep app was installed for the initial profile. Chrome | 683 // Notify that the prod Keep app was installed for the initial profile. Chrome |
664 // extensions are queried dynamically when GetAvailableApps() is called, so we | 684 // extensions are queried dynamically when GetAvailableApps() is called, so we |
665 // don't need to actually install it. | 685 // don't need to actually install it. |
666 auto keep_extension = | 686 auto keep_extension = |
667 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); | 687 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); |
668 InstallExtension(keep_extension.get(), profile()); | 688 InstallExtension(keep_extension.get(), profile()); |
(...skipping 19 matching lines...) Expand all Loading... |
688 InitExtensionService(second_profile); | 708 InitExtensionService(second_profile); |
689 EXPECT_EQ(0, observer.num_updates()); | 709 EXPECT_EQ(0, observer.num_updates()); |
690 InstallExtension(keep_extension.get(), second_profile); | 710 InstallExtension(keep_extension.get(), second_profile); |
691 EXPECT_EQ(1, observer.num_updates()); | 711 EXPECT_EQ(1, observer.num_updates()); |
692 UninstallExtension(keep_extension.get(), second_profile); | 712 UninstallExtension(keep_extension.get(), second_profile); |
693 EXPECT_EQ(2, observer.num_updates()); | 713 EXPECT_EQ(2, observer.num_updates()); |
694 profile_manager_->DeleteTestingProfile(kSecondProfileName); | 714 profile_manager_->DeleteTestingProfile(kSecondProfileName); |
695 } | 715 } |
696 | 716 |
697 } // namespace chromeos | 717 } // namespace chromeos |
OLD | NEW |