| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); | 180 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); |
| 181 NoteTakingHelper::Initialize(); | 181 NoteTakingHelper::Initialize(); |
| 182 NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( | 182 NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( |
| 183 &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); | 183 &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Creates an extension. | 186 // Creates an extension. |
| 187 scoped_refptr<const extensions::Extension> CreateExtension( | 187 scoped_refptr<const extensions::Extension> CreateExtension( |
| 188 const extensions::ExtensionId& id, | 188 const extensions::ExtensionId& id, |
| 189 const std::string& name) { | 189 const std::string& name) { |
| 190 return CreateExtension(id, name, nullptr); |
| 191 } |
| 192 scoped_refptr<const extensions::Extension> CreateExtension( |
| 193 const extensions::ExtensionId& id, |
| 194 const std::string& name, |
| 195 std::unique_ptr<base::Value> action_handlers) { |
| 190 std::unique_ptr<base::DictionaryValue> manifest = | 196 std::unique_ptr<base::DictionaryValue> manifest = |
| 191 extensions::DictionaryBuilder() | 197 extensions::DictionaryBuilder() |
| 192 .Set("name", name) | 198 .Set("name", name) |
| 193 .Set("version", "1.0") | 199 .Set("version", "1.0") |
| 194 .Set("manifest_version", 2) | 200 .Set("manifest_version", 2) |
| 195 .Set("app", | 201 .Set("app", |
| 196 extensions::DictionaryBuilder() | 202 extensions::DictionaryBuilder() |
| 197 .Set("background", | 203 .Set("background", |
| 198 extensions::DictionaryBuilder() | 204 extensions::DictionaryBuilder() |
| 199 .Set("scripts", extensions::ListBuilder() | 205 .Set("scripts", extensions::ListBuilder() |
| 200 .Append("background.js") | 206 .Append("background.js") |
| 201 .Build()) | 207 .Build()) |
| 202 .Build()) | 208 .Build()) |
| 203 .Build()) | 209 .Build()) |
| 204 .Build(); | 210 .Build(); |
| 211 |
| 212 if (action_handlers) |
| 213 manifest->Set("action_handlers", std::move(action_handlers)); |
| 214 |
| 205 return extensions::ExtensionBuilder() | 215 return extensions::ExtensionBuilder() |
| 206 .SetManifest(std::move(manifest)) | 216 .SetManifest(std::move(manifest)) |
| 207 .SetID(id) | 217 .SetID(id) |
| 208 .Build(); | 218 .Build(); |
| 209 } | 219 } |
| 210 | 220 |
| 211 // Initializes extensions-related objects for |profile|. Tests only need to | 221 // Initializes extensions-related objects for |profile|. Tests only need to |
| 212 // call this if they create additional profiles of their own. | 222 // call this if they create additional profiles of their own. |
| 213 void InitExtensionService(Profile* profile) { | 223 void InitExtensionService(Profile* profile) { |
| 214 extensions::TestExtensionSystem* extension_system = | 224 extensions::TestExtensionSystem* extension_system = |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 apps = helper()->GetAvailableApps(profile()); | 344 apps = helper()->GetAvailableApps(profile()); |
| 335 ASSERT_EQ(2u, apps.size()); | 345 ASSERT_EQ(2u, apps.size()); |
| 336 EXPECT_EQ( | 346 EXPECT_EQ( |
| 337 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), | 347 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), |
| 338 GetAppString(apps[0])); | 348 GetAppString(apps[0])); |
| 339 EXPECT_EQ( | 349 EXPECT_EQ( |
| 340 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), | 350 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), |
| 341 GetAppString(apps[1])); | 351 GetAppString(apps[1])); |
| 342 } | 352 } |
| 343 | 353 |
| 354 // Verify the note helper detects apps with "new_note" "action_handler" manifest |
| 355 // entries. |
| 356 TEST_F(NoteTakingHelperTest, CustomChromeApps) { |
| 357 Init(ENABLE_PALETTE); |
| 358 |
| 359 const extensions::ExtensionId kNewNoteId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 360 const extensions::ExtensionId kInvalidNewNoteId = |
| 361 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
| 362 const extensions::ExtensionId kEmptyArrayId = |
| 363 "cccccccccccccccccccccccccccccccc"; |
| 364 const extensions::ExtensionId kEmptyId = "dddddddddddddddddddddddddddddddd"; |
| 365 const std::string kName = "Some App"; |
| 366 |
| 367 // "action_handlers": ["new_note"] |
| 368 auto has_new_note = CreateExtension( |
| 369 kNewNoteId, kName, extensions::ListBuilder() |
| 370 .Append(NoteTakingHelper::kChromeNewNoteAction) |
| 371 .Build()); |
| 372 InstallExtension(has_new_note.get(), profile()); |
| 373 // "action_handlers": ["invalid", "new_note"] |
| 374 auto invalid_new_note = |
| 375 CreateExtension(kInvalidNewNoteId, kName, |
| 376 extensions::ListBuilder() |
| 377 .Append("invalid") |
| 378 .Append(NoteTakingHelper::kChromeNewNoteAction) |
| 379 .Build()); |
| 380 InstallExtension(invalid_new_note.get(), profile()); |
| 381 // "action_handlers": [] |
| 382 auto empty_array = |
| 383 CreateExtension(kEmptyArrayId, kName, extensions::ListBuilder().Build()); |
| 384 InstallExtension(empty_array.get(), profile()); |
| 385 // (no action handler entry) |
| 386 auto none = CreateExtension(kEmptyId, kName); |
| 387 InstallExtension(none.get(), profile()); |
| 388 |
| 389 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); |
| 390 ASSERT_EQ(2u, apps.size()); |
| 391 EXPECT_EQ(GetAppString(kNewNoteId, kName, false), GetAppString(apps[0])); |
| 392 EXPECT_EQ(GetAppString(kInvalidNewNoteId, kName, false), |
| 393 GetAppString(apps[1])); |
| 394 } |
| 395 |
| 344 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { | 396 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { |
| 345 Init(ENABLE_PALETTE); | 397 Init(ENABLE_PALETTE); |
| 346 auto extension = | 398 auto extension = |
| 347 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); | 399 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); |
| 348 InstallExtension(extension.get(), profile()); | 400 InstallExtension(extension.get(), profile()); |
| 349 | 401 |
| 350 // Check the Chrome app is launched with the correct parameters. | 402 // Check the Chrome app is launched with the correct parameters. |
| 351 const base::FilePath kPath("/foo/bar/photo.jpg"); | 403 const base::FilePath kPath("/foo/bar/photo.jpg"); |
| 352 helper()->LaunchAppForNewNote(profile(), kPath); | 404 helper()->LaunchAppForNewNote(profile(), kPath); |
| 353 ASSERT_EQ(1u, launched_chrome_apps_.size()); | 405 ASSERT_EQ(1u, launched_chrome_apps_.size()); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 InitExtensionService(second_profile); | 615 InitExtensionService(second_profile); |
| 564 EXPECT_EQ(0, observer.num_updates()); | 616 EXPECT_EQ(0, observer.num_updates()); |
| 565 InstallExtension(keep_extension.get(), second_profile); | 617 InstallExtension(keep_extension.get(), second_profile); |
| 566 EXPECT_EQ(1, observer.num_updates()); | 618 EXPECT_EQ(1, observer.num_updates()); |
| 567 UninstallExtension(keep_extension.get(), second_profile); | 619 UninstallExtension(keep_extension.get(), second_profile); |
| 568 EXPECT_EQ(2, observer.num_updates()); | 620 EXPECT_EQ(2, observer.num_updates()); |
| 569 profile_manager_->DeleteTestingProfile(kSecondProfileName); | 621 profile_manager_->DeleteTestingProfile(kSecondProfileName); |
| 570 } | 622 } |
| 571 | 623 |
| 572 } // namespace chromeos | 624 } // namespace chromeos |
| OLD | NEW |