Chromium Code Reviews| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); | 185 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, flags & ENABLE_ARC); |
| 186 NoteTakingHelper::Initialize(); | 186 NoteTakingHelper::Initialize(); |
| 187 NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( | 187 NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( |
| 188 &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); | 188 &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Creates an extension. | 191 // Creates an extension. |
| 192 scoped_refptr<const extensions::Extension> CreateExtension( | 192 scoped_refptr<const extensions::Extension> CreateExtension( |
| 193 const extensions::ExtensionId& id, | 193 const extensions::ExtensionId& id, |
| 194 const std::string& name) { | 194 const std::string& name) { |
| 195 return CreateExtension(id, name, nullptr); | |
| 196 } | |
| 197 scoped_refptr<const extensions::Extension> CreateExtension( | |
| 198 const extensions::ExtensionId& id, | |
| 199 const std::string& name, | |
| 200 std::unique_ptr<base::Value> action_handlers) { | |
| 195 std::unique_ptr<base::DictionaryValue> manifest = | 201 std::unique_ptr<base::DictionaryValue> manifest = |
| 196 extensions::DictionaryBuilder() | 202 extensions::DictionaryBuilder() |
| 197 .Set("name", name) | 203 .Set("name", name) |
| 198 .Set("version", "1.0") | 204 .Set("version", "1.0") |
| 199 .Set("manifest_version", 2) | 205 .Set("manifest_version", 2) |
| 200 .Set("app", | 206 .Set("app", |
| 201 extensions::DictionaryBuilder() | 207 extensions::DictionaryBuilder() |
| 202 .Set("background", | 208 .Set("background", |
| 203 extensions::DictionaryBuilder() | 209 extensions::DictionaryBuilder() |
| 204 .Set("scripts", extensions::ListBuilder() | 210 .Set("scripts", extensions::ListBuilder() |
| 205 .Append("background.js") | 211 .Append("background.js") |
| 206 .Build()) | 212 .Build()) |
| 207 .Build()) | 213 .Build()) |
| 208 .Build()) | 214 .Build()) |
| 209 .Build(); | 215 .Build(); |
| 216 | |
| 217 if (action_handlers) | |
| 218 manifest->Set("action_handlers", std::move(action_handlers)); | |
| 219 | |
| 210 return extensions::ExtensionBuilder() | 220 return extensions::ExtensionBuilder() |
| 211 .SetManifest(std::move(manifest)) | 221 .SetManifest(std::move(manifest)) |
| 212 .SetID(id) | 222 .SetID(id) |
| 213 .Build(); | 223 .Build(); |
| 214 } | 224 } |
| 215 | 225 |
| 216 // Initializes extensions-related objects for |profile|. Tests only need to | 226 // Initializes extensions-related objects for |profile|. Tests only need to |
| 217 // call this if they create additional profiles of their own. | 227 // call this if they create additional profiles of their own. |
| 218 void InitExtensionService(Profile* profile) { | 228 void InitExtensionService(Profile* profile) { |
| 219 extensions::TestExtensionSystem* extension_system = | 229 extensions::TestExtensionSystem* extension_system = |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 apps = helper()->GetAvailableApps(profile()); | 349 apps = helper()->GetAvailableApps(profile()); |
| 340 ASSERT_EQ(2u, apps.size()); | 350 ASSERT_EQ(2u, apps.size()); |
| 341 EXPECT_EQ( | 351 EXPECT_EQ( |
| 342 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), | 352 GetAppString(NoteTakingHelper::kDevKeepExtensionId, kDevName, false), |
| 343 GetAppString(apps[0])); | 353 GetAppString(apps[0])); |
| 344 EXPECT_EQ( | 354 EXPECT_EQ( |
| 345 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), | 355 GetAppString(NoteTakingHelper::kProdKeepExtensionId, kProdName, true), |
| 346 GetAppString(apps[1])); | 356 GetAppString(apps[1])); |
| 347 } | 357 } |
| 348 | 358 |
| 359 // Verify the note helper detects apps with "new_note" "action_handler" manifest | |
| 360 // entries. | |
| 361 TEST_F(NoteTakingHelperTest, CustomChromeApps) { | |
| 362 Init(ENABLE_PALETTE); | |
| 363 | |
| 364 const extensions::ExtensionId kNewNoteId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |
| 365 const extensions::ExtensionId kInvalidNewNoteId = | |
|
Daniel Erat
2017/01/12 23:55:03
i think you aren't using this. did you mean to cre
jdufault
2017/01/14 00:30:42
Artifact from a previous patch before extension pa
| |
| 366 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; | |
| 367 const extensions::ExtensionId kEmptyArrayId = | |
| 368 "cccccccccccccccccccccccccccccccc"; | |
| 369 const extensions::ExtensionId kEmptyId = "dddddddddddddddddddddddddddddddd"; | |
| 370 const std::string kName = "Some App"; | |
| 371 | |
| 372 // "action_handlers": ["new_note"] | |
| 373 auto has_new_note = CreateExtension( | |
| 374 kNewNoteId, kName, | |
| 375 extensions::ListBuilder() | |
| 376 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE)) | |
| 377 .Build()); | |
| 378 InstallExtension(has_new_note.get(), profile()); | |
| 379 // "action_handlers": [] | |
| 380 auto empty_array = | |
| 381 CreateExtension(kEmptyArrayId, kName, extensions::ListBuilder().Build()); | |
| 382 InstallExtension(empty_array.get(), profile()); | |
| 383 // (no action handler entry) | |
| 384 auto none = CreateExtension(kEmptyId, kName); | |
| 385 InstallExtension(none.get(), profile()); | |
| 386 | |
| 387 // Only the "new_note" extension is returned from GetAvailableApps. | |
| 388 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile()); | |
| 389 ASSERT_EQ(1u, apps.size()); | |
| 390 EXPECT_EQ(GetAppString(kNewNoteId, kName, false), GetAppString(apps[0])); | |
|
Daniel Erat
2017/01/12 23:55:03
consider adding a test to check that whitelisted a
jdufault
2017/01/14 00:30:42
Done.
| |
| 391 } | |
| 392 | |
| 349 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { | 393 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { |
| 350 Init(ENABLE_PALETTE); | 394 Init(ENABLE_PALETTE); |
| 351 auto extension = | 395 auto extension = |
| 352 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); | 396 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); |
| 353 InstallExtension(extension.get(), profile()); | 397 InstallExtension(extension.get(), profile()); |
| 354 | 398 |
| 355 // Check the Chrome app is launched with the correct parameters. | 399 // Check the Chrome app is launched with the correct parameters. |
| 356 HistogramTester histogram_tester; | 400 HistogramTester histogram_tester; |
| 357 const base::FilePath kPath("/foo/bar/photo.jpg"); | 401 const base::FilePath kPath("/foo/bar/photo.jpg"); |
| 358 helper()->LaunchAppForNewNote(profile(), kPath); | 402 helper()->LaunchAppForNewNote(profile(), kPath); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 InitExtensionService(second_profile); | 673 InitExtensionService(second_profile); |
| 630 EXPECT_EQ(0, observer.num_updates()); | 674 EXPECT_EQ(0, observer.num_updates()); |
| 631 InstallExtension(keep_extension.get(), second_profile); | 675 InstallExtension(keep_extension.get(), second_profile); |
| 632 EXPECT_EQ(1, observer.num_updates()); | 676 EXPECT_EQ(1, observer.num_updates()); |
| 633 UninstallExtension(keep_extension.get(), second_profile); | 677 UninstallExtension(keep_extension.get(), second_profile); |
| 634 EXPECT_EQ(2, observer.num_updates()); | 678 EXPECT_EQ(2, observer.num_updates()); |
| 635 profile_manager_->DeleteTestingProfile(kSecondProfileName); | 679 profile_manager_->DeleteTestingProfile(kSecondProfileName); |
| 636 } | 680 } |
| 637 | 681 |
| 638 } // namespace chromeos | 682 } // namespace chromeos |
| OLD | NEW |