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

Side by Side Diff: chrome/browser/extensions/extensions_service_unittest.cc

Issue 118328: chrome.exe --package-extension (Closed)
Patch Set: final Created 11 years, 6 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
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json_reader.h" 10 #include "base/json_reader.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/extensions/extension_creator.h"
15 #include "chrome/browser/extensions/extensions_service.h" 16 #include "chrome/browser/extensions/extensions_service.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/url_pattern.h" 18 #include "chrome/common/extensions/url_pattern.h"
18 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/extensions/extension_error_reporter.h" 21 #include "chrome/common/extensions/extension_error_reporter.h"
21 #include "chrome/common/json_value_serializer.h" 22 #include "chrome/common/json_value_serializer.h"
22 #include "chrome/common/notification_registrar.h" 23 #include "chrome/common/notification_registrar.h"
23 #include "chrome/common/notification_service.h" 24 #include "chrome/common/notification_service.h"
24 #include "chrome/common/notification_type.h" 25 #include "chrome/common/notification_type.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 414
414 // Incorrect zip hash. 415 // Incorrect zip hash.
415 path = extensions_path.AppendASCII("bad_hash.crx"); 416 path = extensions_path.AppendASCII("bad_hash.crx");
416 InstallExtension(path, false); 417 InstallExtension(path, false);
417 ValidatePrefKeyCount(pref_count); 418 ValidatePrefKeyCount(pref_count);
418 419
419 // TODO(erikkay): add more tests for many of the failure cases. 420 // TODO(erikkay): add more tests for many of the failure cases.
420 // TODO(erikkay): add tests for upgrade cases. 421 // TODO(erikkay): add tests for upgrade cases.
421 } 422 }
422 423
424 #if defined(OS_WIN) // TODO(port)
425 // Test Packaging and installing an extension.
426 // TODO(aa): add a test that uses an openssl-generate private key.
427 // TODO(rafaelw): add more tests for failure cases.
428 TEST_F(ExtensionsServiceTest, PackExtension) {
429 SetExtensionsEnabled(true);
430
431 FilePath extensions_path;
432 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
433 extensions_path = extensions_path.AppendASCII("extensions");
434 FilePath input_directory = extensions_path.AppendASCII("good")
435 .AppendASCII("extension1").AppendASCII("1");
436
437 FilePath output_directory;
438 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"),
439 &output_directory);
440 FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
441 FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
442
443 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
444 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(),
445 privkey_path));
446
447 InstallExtension(crx_path, true);
448
449 ASSERT_TRUE(file_util::PathExists(privkey_path));
450
451 file_util::Delete(crx_path, false);
452 file_util::Delete(privkey_path, false);
453 }
454
455 // Test Packaging and installing an extension using an openssl generated key.
456 // The openssl is generated with the following:
457 // > openssl genrsa -out privkey.pem 1024
458 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem
459 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
460 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
461 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) {
462 SetExtensionsEnabled(true);
463
464 FilePath extensions_path;
465 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
466 extensions_path = extensions_path.AppendASCII("extensions");
467 FilePath input_directory = extensions_path.AppendASCII("good")
468 .AppendASCII("extension1").AppendASCII("1");
469 FilePath privkey_path(extensions_path.AppendASCII(
470 "openssl_privkey_asn1.pem"));
471 ASSERT_TRUE(file_util::PathExists(privkey_path));
472
473 FilePath output_directory;
474 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"),
475 &output_directory);
476 FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
477
478 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
479 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
480 FilePath()));
481
482 InstallExtension(crx_path, true);
483
484 file_util::Delete(crx_path, false);
485 }
486 #endif // defined(OS_WIN)
487
423 TEST_F(ExtensionsServiceTest, InstallTheme) { 488 TEST_F(ExtensionsServiceTest, InstallTheme) {
424 FilePath extensions_path; 489 FilePath extensions_path;
425 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 490 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
426 extensions_path = extensions_path.AppendASCII("extensions"); 491 extensions_path = extensions_path.AppendASCII("extensions");
427 492
428 // A theme. 493 // A theme.
429 FilePath path = extensions_path.AppendASCII("theme.crx"); 494 FilePath path = extensions_path.AppendASCII("theme.crx");
430 InstallExtension(path, true); 495 InstallExtension(path, true);
431 int pref_count = 0; 496 int pref_count = 0;
432 ValidatePrefKeyCount(++pref_count); 497 ValidatePrefKeyCount(++pref_count);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 ValidatePrefKeyCount(1); 889 ValidatePrefKeyCount(1);
825 ValidatePref(good_crx, L"state", Extension::KILLBIT); 890 ValidatePref(good_crx, L"state", Extension::KILLBIT);
826 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); 891 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF);
827 892
828 // The extension should also be gone from disk. 893 // The extension should also be gone from disk.
829 FilePath extension_path = install_path.DirName(); 894 FilePath extension_path = install_path.DirName();
830 extension_path = extension_path.AppendASCII(good_crx); 895 extension_path = extension_path.AppendASCII(good_crx);
831 EXPECT_FALSE(file_util::PathExists(extension_path)) << 896 EXPECT_FALSE(file_util::PathExists(extension_path)) <<
832 extension_path.ToWStringHack(); 897 extension_path.ToWStringHack();
833 } 898 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698