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