| 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::SetArcAlwaysStartForTesting(); |
| 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_STORE = 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, |
| 179 flags & ENABLE_PLAY_STORE); |
| 174 arc_test_.SetUp(profile()); | 180 arc_test_.SetUp(profile()); |
| 175 arc::ArcServiceManager::Get() | 181 arc::ArcServiceManager::Get() |
| 176 ->arc_bridge_service() | 182 ->arc_bridge_service() |
| 177 ->intent_helper() | 183 ->intent_helper() |
| 178 ->SetInstance(&intent_helper_); | 184 ->SetInstance(&intent_helper_); |
| 179 | 185 |
| 180 if (flags & ENABLE_PALETTE) { | 186 if (flags & ENABLE_PALETTE) { |
| 181 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 187 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 182 ash::switches::kAshForceEnablePalette); | 188 ash::switches::kAshForceEnablePalette); |
| 183 } | 189 } |
| 184 | 190 |
| 185 // TODO(derat): Sigh, something in ArcAppTest appears to be re-enabling ARC. | 191 // TODO(derat): Sigh, something in ArcAppTest appears to be re-enabling ARC. |
| 186 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); | 192 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, |
| 193 flags & ENABLE_PLAY_STORE); |
| 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, PlayStoreInitiallyDisabled) { |
| 471 Init(ENABLE_PALETTE); | 480 Init(ENABLE_PALETTE); |
| 472 EXPECT_FALSE(helper()->android_enabled()); | 481 EXPECT_FALSE(helper()->play_store_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 (arc::ShouldArcAlwaysStart()) |
| 485 return; |
| 486 // When Play Store is enabled, the helper's members should be updated |
| 487 // accordingly. |
| 476 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 488 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 477 EXPECT_TRUE(helper()->android_enabled()); | 489 EXPECT_TRUE(helper()->play_store_enabled()); |
| 478 EXPECT_FALSE(helper()->android_apps_received()); | 490 EXPECT_FALSE(helper()->android_apps_received()); |
| 479 | 491 |
| 480 // After the callback to receive intent handlers has run, the "apps received" | 492 // After the callback to receive intent handlers has run, the "apps received" |
| 481 // member should be updated (even if there aren't any apps). | 493 // member should be updated (even if there aren't any apps). |
| 482 helper()->OnIntentFiltersUpdated(); | 494 helper()->OnIntentFiltersUpdated(); |
| 483 base::RunLoop().RunUntilIdle(); | 495 base::RunLoop().RunUntilIdle(); |
| 484 EXPECT_TRUE(helper()->android_enabled()); | 496 EXPECT_TRUE(helper()->play_store_enabled()); |
| 485 EXPECT_TRUE(helper()->android_apps_received()); | 497 EXPECT_TRUE(helper()->android_apps_received()); |
| 486 } | 498 } |
| 487 | 499 |
| 488 TEST_F(NoteTakingHelperTest, ListAndroidApps) { | 500 TEST_P(NoteTakingHelperTest, ListAndroidApps) { |
| 489 // Add two Android apps. | 501 // Add two Android apps. |
| 490 std::vector<IntentHandlerInfoPtr> handlers; | 502 std::vector<IntentHandlerInfoPtr> handlers; |
| 491 const std::string kName1 = "App 1"; | 503 const std::string kName1 = "App 1"; |
| 492 const std::string kPackage1 = "org.chromium.package1"; | 504 const std::string kPackage1 = "org.chromium.package1"; |
| 493 handlers.emplace_back(CreateIntentHandlerInfo(kName1, kPackage1)); | 505 handlers.emplace_back(CreateIntentHandlerInfo(kName1, kPackage1)); |
| 494 const std::string kName2 = "App 2"; | 506 const std::string kName2 = "App 2"; |
| 495 const std::string kPackage2 = "org.chromium.package2"; | 507 const std::string kPackage2 = "org.chromium.package2"; |
| 496 handlers.emplace_back(CreateIntentHandlerInfo(kName2, kPackage2)); | 508 handlers.emplace_back(CreateIntentHandlerInfo(kName2, kPackage2)); |
| 497 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, | 509 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, |
| 498 std::move(handlers)); | 510 std::move(handlers)); |
| 499 | 511 |
| 500 // NoteTakingHelper should make an async request for Android apps when | 512 // NoteTakingHelper should make an async request for Android apps when |
| 501 // constructed. | 513 // constructed. |
| 502 Init(ENABLE_PALETTE | ENABLE_ARC); | 514 Init(ENABLE_PALETTE | ENABLE_PLAY_STORE); |
| 503 EXPECT_TRUE(helper()->android_enabled()); | 515 EXPECT_TRUE(helper()->play_store_enabled()); |
| 504 EXPECT_FALSE(helper()->android_apps_received()); | 516 EXPECT_FALSE(helper()->android_apps_received()); |
| 505 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); | 517 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); |
| 506 | 518 |
| 507 // The apps should be listed after the callback has had a chance to run. | 519 // The apps should be listed after the callback has had a chance to run. |
| 508 base::RunLoop().RunUntilIdle(); | 520 base::RunLoop().RunUntilIdle(); |
| 509 EXPECT_TRUE(helper()->android_enabled()); | 521 EXPECT_TRUE(helper()->play_store_enabled()); |
| 510 EXPECT_TRUE(helper()->android_apps_received()); | 522 EXPECT_TRUE(helper()->android_apps_received()); |
| 511 EXPECT_TRUE(helper()->IsAppAvailable(profile())); | 523 EXPECT_TRUE(helper()->IsAppAvailable(profile())); |
| 512 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); | 524 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); |
| 513 ASSERT_EQ(2u, apps.size()); | 525 ASSERT_EQ(2u, apps.size()); |
| 514 EXPECT_EQ(GetAppString(kPackage1, kName1, false), GetAppString(apps[0])); | 526 EXPECT_EQ(GetAppString(kPackage1, kName1, false), GetAppString(apps[0])); |
| 515 EXPECT_EQ(GetAppString(kPackage2, kName2, false), GetAppString(apps[1])); | 527 EXPECT_EQ(GetAppString(kPackage2, kName2, false), GetAppString(apps[1])); |
| 516 | 528 |
| 517 // Disable ARC and check that the apps are no longer returned. | 529 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until |
| 530 // implemented. |
| 531 if (arc::ShouldArcAlwaysStart()) |
| 532 return; |
| 533 // Disable Play Store and check that the apps are no longer returned. |
| 518 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 534 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 519 EXPECT_FALSE(helper()->android_enabled()); | 535 EXPECT_FALSE(helper()->play_store_enabled()); |
| 520 EXPECT_FALSE(helper()->android_apps_received()); | 536 EXPECT_FALSE(helper()->android_apps_received()); |
| 521 EXPECT_FALSE(helper()->IsAppAvailable(profile())); | 537 EXPECT_FALSE(helper()->IsAppAvailable(profile())); |
| 522 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); | 538 EXPECT_TRUE(helper()->GetAvailableApps(profile()).empty()); |
| 523 } | 539 } |
| 524 | 540 |
| 525 TEST_F(NoteTakingHelperTest, LaunchAndroidApp) { | 541 TEST_P(NoteTakingHelperTest, LaunchAndroidApp) { |
| 526 const std::string kPackage1 = "org.chromium.package1"; | 542 const std::string kPackage1 = "org.chromium.package1"; |
| 527 std::vector<IntentHandlerInfoPtr> handlers; | 543 std::vector<IntentHandlerInfoPtr> handlers; |
| 528 handlers.emplace_back(CreateIntentHandlerInfo("App 1", kPackage1)); | 544 handlers.emplace_back(CreateIntentHandlerInfo("App 1", kPackage1)); |
| 529 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, | 545 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, |
| 530 std::move(handlers)); | 546 std::move(handlers)); |
| 531 | 547 |
| 532 Init(ENABLE_PALETTE | ENABLE_ARC); | 548 Init(ENABLE_PALETTE | ENABLE_PLAY_STORE); |
| 533 base::RunLoop().RunUntilIdle(); | 549 base::RunLoop().RunUntilIdle(); |
| 534 ASSERT_TRUE(helper()->IsAppAvailable(profile())); | 550 ASSERT_TRUE(helper()->IsAppAvailable(profile())); |
| 535 | 551 |
| 536 // The installed app should be launched. | 552 // The installed app should be launched. |
| 537 std::unique_ptr<HistogramTester> histogram_tester(new HistogramTester()); | 553 std::unique_ptr<HistogramTester> histogram_tester(new HistogramTester()); |
| 538 helper()->LaunchAppForNewNote(profile(), base::FilePath()); | 554 helper()->LaunchAppForNewNote(profile(), base::FilePath()); |
| 539 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); | 555 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); |
| 540 EXPECT_EQ(GetIntentString(kPackage1, ""), | 556 EXPECT_EQ(GetIntentString(kPackage1, ""), |
| 541 GetIntentString(intent_helper_.handled_intents()[0])); | 557 GetIntentString(intent_helper_.handled_intents()[0])); |
| 542 | 558 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 565 EXPECT_EQ(GetIntentString(kPackage2, ""), | 581 EXPECT_EQ(GetIntentString(kPackage2, ""), |
| 566 GetIntentString(intent_helper_.handled_intents()[0])); | 582 GetIntentString(intent_helper_.handled_intents()[0])); |
| 567 | 583 |
| 568 histogram_tester->ExpectUniqueSample( | 584 histogram_tester->ExpectUniqueSample( |
| 569 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 585 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
| 570 static_cast<int>(LaunchResult::ANDROID_SUCCESS), 1); | 586 static_cast<int>(LaunchResult::ANDROID_SUCCESS), 1); |
| 571 histogram_tester->ExpectTotalCount( | 587 histogram_tester->ExpectTotalCount( |
| 572 NoteTakingHelper::kDefaultLaunchResultHistogramName, 0); | 588 NoteTakingHelper::kDefaultLaunchResultHistogramName, 0); |
| 573 } | 589 } |
| 574 | 590 |
| 575 TEST_F(NoteTakingHelperTest, LaunchAndroidAppWithPath) { | 591 TEST_P(NoteTakingHelperTest, LaunchAndroidAppWithPath) { |
| 576 const std::string kPackage = "org.chromium.package"; | 592 const std::string kPackage = "org.chromium.package"; |
| 577 std::vector<IntentHandlerInfoPtr> handlers; | 593 std::vector<IntentHandlerInfoPtr> handlers; |
| 578 handlers.emplace_back(CreateIntentHandlerInfo("App", kPackage)); | 594 handlers.emplace_back(CreateIntentHandlerInfo("App", kPackage)); |
| 579 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, | 595 intent_helper_.SetIntentHandlers(NoteTakingHelper::kIntentAction, |
| 580 std::move(handlers)); | 596 std::move(handlers)); |
| 581 | 597 |
| 582 Init(ENABLE_PALETTE | ENABLE_ARC); | 598 Init(ENABLE_PALETTE | ENABLE_PLAY_STORE); |
| 583 base::RunLoop().RunUntilIdle(); | 599 base::RunLoop().RunUntilIdle(); |
| 584 ASSERT_TRUE(helper()->IsAppAvailable(profile())); | 600 ASSERT_TRUE(helper()->IsAppAvailable(profile())); |
| 585 | 601 |
| 586 const base::FilePath kDownloadedPath( | 602 const base::FilePath kDownloadedPath( |
| 587 file_manager::util::GetDownloadsFolderForProfile(profile()).Append( | 603 file_manager::util::GetDownloadsFolderForProfile(profile()).Append( |
| 588 "image.jpg")); | 604 "image.jpg")); |
| 589 helper()->LaunchAppForNewNote(profile(), kDownloadedPath); | 605 helper()->LaunchAppForNewNote(profile(), kDownloadedPath); |
| 590 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); | 606 ASSERT_EQ(1u, intent_helper_.handled_intents().size()); |
| 591 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kDownloadedPath)), | 607 EXPECT_EQ(GetIntentString(kPackage, GetArcUrl(kDownloadedPath)), |
| 592 GetIntentString(intent_helper_.handled_intents()[0])); | 608 GetIntentString(intent_helper_.handled_intents()[0])); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 608 EXPECT_TRUE(intent_helper_.handled_intents().empty()); | 624 EXPECT_TRUE(intent_helper_.handled_intents().empty()); |
| 609 | 625 |
| 610 histogram_tester.ExpectUniqueSample( | 626 histogram_tester.ExpectUniqueSample( |
| 611 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 627 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
| 612 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); | 628 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); |
| 613 histogram_tester.ExpectUniqueSample( | 629 histogram_tester.ExpectUniqueSample( |
| 614 NoteTakingHelper::kDefaultLaunchResultHistogramName, | 630 NoteTakingHelper::kDefaultLaunchResultHistogramName, |
| 615 static_cast<int>(LaunchResult::ANDROID_FAILED_TO_CONVERT_PATH), 1); | 631 static_cast<int>(LaunchResult::ANDROID_FAILED_TO_CONVERT_PATH), 1); |
| 616 } | 632 } |
| 617 | 633 |
| 618 TEST_F(NoteTakingHelperTest, NoAppsAvailable) { | 634 TEST_P(NoteTakingHelperTest, NoAppsAvailable) { |
| 619 Init(ENABLE_PALETTE | ENABLE_ARC); | 635 Init(ENABLE_PALETTE | ENABLE_PLAY_STORE); |
| 620 | 636 |
| 621 // When no note-taking apps are installed, the histograms should just be | 637 // When no note-taking apps are installed, the histograms should just be |
| 622 // updated. | 638 // updated. |
| 623 HistogramTester histogram_tester; | 639 HistogramTester histogram_tester; |
| 624 helper()->LaunchAppForNewNote(profile(), base::FilePath()); | 640 helper()->LaunchAppForNewNote(profile(), base::FilePath()); |
| 625 histogram_tester.ExpectUniqueSample( | 641 histogram_tester.ExpectUniqueSample( |
| 626 NoteTakingHelper::kPreferredLaunchResultHistogramName, | 642 NoteTakingHelper::kPreferredLaunchResultHistogramName, |
| 627 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); | 643 static_cast<int>(LaunchResult::NO_APP_SPECIFIED), 1); |
| 628 histogram_tester.ExpectUniqueSample( | 644 histogram_tester.ExpectUniqueSample( |
| 629 NoteTakingHelper::kDefaultLaunchResultHistogramName, | 645 NoteTakingHelper::kDefaultLaunchResultHistogramName, |
| 630 static_cast<int>(LaunchResult::NO_APPS_AVAILABLE), 1); | 646 static_cast<int>(LaunchResult::NO_APPS_AVAILABLE), 1); |
| 631 } | 647 } |
| 632 | 648 |
| 633 TEST_F(NoteTakingHelperTest, NotifyObserverAboutAndroidApps) { | 649 TEST_P(NoteTakingHelperTest, NotifyObserverAboutAndroidApps) { |
| 634 Init(ENABLE_PALETTE | ENABLE_ARC); | 650 Init(ENABLE_PALETTE | ENABLE_PLAY_STORE); |
| 635 TestObserver observer; | 651 TestObserver observer; |
| 636 | 652 |
| 637 // Let the app-fetching callback run and check that the observer is notified. | 653 // Let the app-fetching callback run and check that the observer is notified. |
| 638 base::RunLoop().RunUntilIdle(); | 654 base::RunLoop().RunUntilIdle(); |
| 639 EXPECT_EQ(1, observer.num_updates()); | 655 EXPECT_EQ(1, observer.num_updates()); |
| 640 | 656 |
| 641 // Disabling and enabling ARC should also notify the observer (and enabling | 657 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until |
| 642 // should request apps again). | 658 // implemented. |
| 659 if (arc::ShouldArcAlwaysStart()) |
| 660 return; |
| 661 |
| 662 // Disabling and enabling Play Store should also notify the observer (and |
| 663 // enabling should request apps again). |
| 643 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 664 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 644 EXPECT_EQ(2, observer.num_updates()); | 665 EXPECT_EQ(2, observer.num_updates()); |
| 645 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 666 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 646 EXPECT_EQ(3, observer.num_updates()); | 667 EXPECT_EQ(3, observer.num_updates()); |
| 647 // Run ARC data removing operation. | 668 // Run ARC data removing operation. |
| 648 base::RunLoop().RunUntilIdle(); | 669 base::RunLoop().RunUntilIdle(); |
| 649 | 670 |
| 650 // Update intent filters and check that the observer is notified again after | 671 // Update intent filters and check that the observer is notified again after |
| 651 // apps are received. | 672 // apps are received. |
| 652 helper()->OnIntentFiltersUpdated(); | 673 helper()->OnIntentFiltersUpdated(); |
| 653 EXPECT_EQ(3, observer.num_updates()); | 674 EXPECT_EQ(3, observer.num_updates()); |
| 654 base::RunLoop().RunUntilIdle(); | 675 base::RunLoop().RunUntilIdle(); |
| 655 EXPECT_EQ(4, observer.num_updates()); | 676 EXPECT_EQ(4, observer.num_updates()); |
| 656 } | 677 } |
| 657 | 678 |
| 658 TEST_F(NoteTakingHelperTest, NotifyObserverAboutChromeApps) { | 679 TEST_P(NoteTakingHelperTest, NotifyObserverAboutChromeApps) { |
| 659 Init(ENABLE_PALETTE); | 680 Init(ENABLE_PALETTE); |
| 660 TestObserver observer; | 681 TestObserver observer; |
| 661 ASSERT_EQ(0, observer.num_updates()); | 682 ASSERT_EQ(0, observer.num_updates()); |
| 662 | 683 |
| 663 // Notify that the prod Keep app was installed for the initial profile. Chrome | 684 // Notify that the prod Keep app was installed for the initial profile. Chrome |
| 664 // extensions are queried dynamically when GetAvailableApps() is called, so we | 685 // extensions are queried dynamically when GetAvailableApps() is called, so we |
| 665 // don't need to actually install it. | 686 // don't need to actually install it. |
| 666 auto keep_extension = | 687 auto keep_extension = |
| 667 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); | 688 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); |
| 668 InstallExtension(keep_extension.get(), profile()); | 689 InstallExtension(keep_extension.get(), profile()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 688 InitExtensionService(second_profile); | 709 InitExtensionService(second_profile); |
| 689 EXPECT_EQ(0, observer.num_updates()); | 710 EXPECT_EQ(0, observer.num_updates()); |
| 690 InstallExtension(keep_extension.get(), second_profile); | 711 InstallExtension(keep_extension.get(), second_profile); |
| 691 EXPECT_EQ(1, observer.num_updates()); | 712 EXPECT_EQ(1, observer.num_updates()); |
| 692 UninstallExtension(keep_extension.get(), second_profile); | 713 UninstallExtension(keep_extension.get(), second_profile); |
| 693 EXPECT_EQ(2, observer.num_updates()); | 714 EXPECT_EQ(2, observer.num_updates()); |
| 694 profile_manager_->DeleteTestingProfile(kSecondProfileName); | 715 profile_manager_->DeleteTestingProfile(kSecondProfileName); |
| 695 } | 716 } |
| 696 | 717 |
| 697 } // namespace chromeos | 718 } // namespace chromeos |
| OLD | NEW |