Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: chrome/browser/chromeos/note_taking_helper_unittest.cc

Issue 2618493002: Chrome app manifest support for action handlers. (Closed)
Patch Set: Address comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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";
Devlin 2017/01/30 21:19:59 drive-by nit: prefer crx_file::id_util::GenerateId
jdufault 2017/02/03 20:29:43 Done.
365 const extensions::ExtensionId kEmptyArrayId =
366 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
367 const extensions::ExtensionId kEmptyId = "cccccccccccccccccccccccccccccccc";
368 const std::string kName = "Some App";
369
370 // "action_handlers": ["new_note"]
371 auto has_new_note = CreateExtension(
372 kNewNoteId, kName,
373 extensions::ListBuilder()
374 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE))
375 .Build());
376 InstallExtension(has_new_note.get(), profile());
377 // "action_handlers": []
378 auto empty_array =
379 CreateExtension(kEmptyArrayId, kName, extensions::ListBuilder().Build());
380 InstallExtension(empty_array.get(), profile());
381 // (no action handler entry)
382 auto none = CreateExtension(kEmptyId, kName);
383 InstallExtension(none.get(), profile());
384
385 // Only the "new_note" extension is returned from GetAvailableApps.
386 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile());
387 ASSERT_EQ(1u, apps.size());
388 EXPECT_EQ(GetAppString(kNewNoteId, kName, false), GetAppString(apps[0]));
389 }
390
391 TEST_F(NoteTakingHelperTest, WhitelistedAndCustomAppsShowOnlyOnce) {
392 Init(ENABLE_PALETTE);
393
394 auto extension = CreateExtension(
395 NoteTakingHelper::kProdKeepExtensionId, "Keep",
396 extensions::ListBuilder()
397 .Append(app_runtime::ToString(app_runtime::ACTION_TYPE_NEW_NOTE))
398 .Build());
399 InstallExtension(extension.get(), profile());
400
401 std::vector<NoteTakingAppInfo> apps = helper()->GetAvailableApps(profile());
402 ASSERT_EQ(1u, apps.size());
403 EXPECT_EQ(GetAppString(NoteTakingHelper::kProdKeepExtensionId, "Keep", false),
404 GetAppString(apps[0]));
405 }
406
349 TEST_F(NoteTakingHelperTest, LaunchChromeApp) { 407 TEST_F(NoteTakingHelperTest, LaunchChromeApp) {
350 Init(ENABLE_PALETTE); 408 Init(ENABLE_PALETTE);
351 auto extension = 409 auto extension =
352 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep"); 410 CreateExtension(NoteTakingHelper::kProdKeepExtensionId, "Keep");
353 InstallExtension(extension.get(), profile()); 411 InstallExtension(extension.get(), profile());
354 412
355 // Check the Chrome app is launched with the correct parameters. 413 // Check the Chrome app is launched with the correct parameters.
356 HistogramTester histogram_tester; 414 HistogramTester histogram_tester;
357 const base::FilePath kPath("/foo/bar/photo.jpg"); 415 const base::FilePath kPath("/foo/bar/photo.jpg");
358 helper()->LaunchAppForNewNote(profile(), kPath); 416 helper()->LaunchAppForNewNote(profile(), kPath);
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 InitExtensionService(second_profile); 687 InitExtensionService(second_profile);
630 EXPECT_EQ(0, observer.num_updates()); 688 EXPECT_EQ(0, observer.num_updates());
631 InstallExtension(keep_extension.get(), second_profile); 689 InstallExtension(keep_extension.get(), second_profile);
632 EXPECT_EQ(1, observer.num_updates()); 690 EXPECT_EQ(1, observer.num_updates());
633 UninstallExtension(keep_extension.get(), second_profile); 691 UninstallExtension(keep_extension.get(), second_profile);
634 EXPECT_EQ(2, observer.num_updates()); 692 EXPECT_EQ(2, observer.num_updates());
635 profile_manager_->DeleteTestingProfile(kSecondProfileName); 693 profile_manager_->DeleteTestingProfile(kSecondProfileName);
636 } 694 }
637 695
638 } // namespace chromeos 696 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698