From 12a9cab7ee804fd898dca62004f750cc5a1ad685 Mon Sep 17 00:00:00 2001 From: asargent Date: Fri, 16 Jan 2015 13:34:16 -0800 Subject: Move unpacker_unittests.cc and data files from chrome/ to extensions/ Most of the changes here are just moves, with only a few more notable changes: Add "manifest_version : 2" and change from theme to extension -extensions/test/data/unpacker/bad_zip/manifest.json -extensions/test/data/unpacker/bad_image/manifest.json -extensions/test/data/unpacker/good_package/manifest.json Changed BadPathError test and misc cleanup -extensions/utility/unpacker_unittest.cc Support for changes to the above mentioned BadPathError test -extensions/test/test_extensions_client.h -extensions/test/test_extensions_client.cc Entire directory just deleted, not moved -chrome/test/data/extensions/unpacker/bad_path/ BUG=447014 Review URL: https://codereview.chromium.org/849803004 Cr-Commit-Position: refs/heads/master@{#311954} --- .../extensions/sandboxed_unpacker_unittest.cc | 7 +- chrome/chrome_tests_unit.gypi | 1 - chrome/test/data/extensions/unpacker/bad_image.crx | Bin 841 -> 0 bytes .../extensions/unpacker/bad_image/background.js | 5 - .../extensions/unpacker/bad_image/manifest.json | 6 - .../unpacker/bad_image/not_really_an_image.png | 1 - chrome/test/data/extensions/unpacker/bad_path.crx | Bin 12933 -> 0 bytes .../extensions/unpacker/bad_path/background.js | 5 - .../data/extensions/unpacker/bad_path/bad_path.pem | 16 -- .../data/extensions/unpacker/bad_path/bad_path.sh | 39 ---- .../extensions/unpacker/bad_path/manifest.json | 6 - .../unpacker/bad_path/product_logo_128.png | Bin 10100 -> 0 bytes chrome/test/data/extensions/unpacker/bad_zip.crx | Bin 8498 -> 0 bytes .../data/extensions/unpacker/bad_zip/background.js | 5 - .../data/extensions/unpacker/bad_zip/bad_zip.pem | 16 -- .../data/extensions/unpacker/bad_zip/bad_zip.sh | 41 ----- .../data/extensions/unpacker/bad_zip/manifest.json | 6 - .../unpacker/bad_zip/product_logo_128.png | Bin 10100 -> 0 bytes .../extensions/unpacker/empty_default_locale.crx | Bin 521 -> 0 bytes .../unpacker/empty_default_locale/manifest.json | 6 - chrome/test/data/extensions/unpacker/good_l10n.crx | Bin 1185 -> 0 bytes .../good_l10n/_locales/en_US/messages.json | 5 - .../unpacker/good_l10n/_locales/sr/messages.json | 5 - .../extensions/unpacker/good_l10n/manifest.json | 6 - .../test/data/extensions/unpacker/good_package.crx | Bin 10784 -> 0 bytes .../extensions/unpacker/good_package/manifest.json | 6 - .../unpacker/good_package/product_logo_128.png | Bin 10100 -> 0 bytes .../unpacker/has_default_missing_locales.crx | Bin 539 -> 0 bytes .../has_default_missing_locales/manifest.json | 6 - .../extensions/unpacker/invalid_default_locale.crx | Bin 542 -> 0 bytes .../unpacker/invalid_default_locale/manifest.json | 6 - .../extensions/unpacker/invalid_messages_file.crx | Bin 911 -> 0 bytes .../_locales/en_US/messages.json | 3 - .../unpacker/invalid_messages_file/manifest.json | 6 - .../extensions/unpacker/missing_default_data.crx | Bin 924 -> 0 bytes .../_locales/en_US/messages.json | 5 - .../unpacker/missing_default_data/manifest.json | 6 - .../unpacker/missing_default_has_locales.crx | Bin 634 -> 0 bytes .../missing_default_has_locales/manifest.json | 5 - .../extensions/unpacker/missing_messages_file.crx | Bin 748 -> 0 bytes .../unpacker/missing_messages_file/manifest.json | 6 - chrome/test/data/extensions/unpacker/no_l10n.crx | Bin 513 -> 0 bytes .../data/extensions/unpacker/no_l10n/manifest.json | 5 - .../data/extensions/unpacker/no_locale_data.crx | Bin 620 -> 0 bytes .../unpacker/no_locale_data/manifest.json | 6 - chrome/utility/extensions/unpacker_unittest.cc | 174 ----------------- extensions/BUILD.gn | 1 + extensions/extensions.gyp | 1 + extensions/test/data/unpacker/bad_image.crx | Bin 0 -> 1243 bytes .../test/data/unpacker/bad_image/background.js | 5 + .../test/data/unpacker/bad_image/manifest.json | 7 + .../unpacker/bad_image/not_really_an_image.png | 1 + extensions/test/data/unpacker/bad_zip.crx | Bin 0 -> 8498 bytes .../test/data/unpacker/bad_zip/background.js | 5 + extensions/test/data/unpacker/bad_zip/bad_zip.pem | 16 ++ extensions/test/data/unpacker/bad_zip/bad_zip.sh | 41 +++++ .../test/data/unpacker/bad_zip/manifest.json | 9 + .../data/unpacker/bad_zip/product_logo_128.png | Bin 0 -> 10100 bytes .../test/data/unpacker/empty_default_locale.crx | Bin 0 -> 521 bytes .../unpacker/empty_default_locale/manifest.json | 6 + extensions/test/data/unpacker/good_l10n.crx | Bin 0 -> 1185 bytes .../good_l10n/_locales/en_US/messages.json | 5 + .../unpacker/good_l10n/_locales/sr/messages.json | 5 + .../test/data/unpacker/good_l10n/manifest.json | 6 + extensions/test/data/unpacker/good_package.crx | Bin 0 -> 11054 bytes .../test/data/unpacker/good_package/manifest.json | 9 + .../unpacker/good_package/product_logo_128.png | Bin 0 -> 10100 bytes .../data/unpacker/has_default_missing_locales.crx | Bin 0 -> 539 bytes .../has_default_missing_locales/manifest.json | 6 + .../test/data/unpacker/invalid_default_locale.crx | Bin 0 -> 542 bytes .../unpacker/invalid_default_locale/manifest.json | 6 + .../test/data/unpacker/invalid_messages_file.crx | Bin 0 -> 911 bytes .../_locales/en_US/messages.json | 3 + .../unpacker/invalid_messages_file/manifest.json | 6 + .../test/data/unpacker/missing_default_data.crx | Bin 0 -> 924 bytes .../_locales/en_US/messages.json | 5 + .../unpacker/missing_default_data/manifest.json | 6 + .../data/unpacker/missing_default_has_locales.crx | Bin 0 -> 634 bytes .../missing_default_has_locales/manifest.json | 5 + .../test/data/unpacker/missing_messages_file.crx | Bin 0 -> 748 bytes .../unpacker/missing_messages_file/manifest.json | 6 + extensions/test/data/unpacker/no_l10n.crx | Bin 0 -> 513 bytes .../test/data/unpacker/no_l10n/manifest.json | 5 + extensions/test/data/unpacker/no_locale_data.crx | Bin 0 -> 620 bytes .../data/unpacker/no_locale_data/manifest.json | 6 + extensions/test/test_extensions_client.cc | 20 ++ extensions/test/test_extensions_client.h | 15 ++ extensions/utility/unpacker_unittest.cc | 205 +++++++++++++++++++++ 88 files changed, 414 insertions(+), 407 deletions(-) delete mode 100644 chrome/test/data/extensions/unpacker/bad_image.crx delete mode 100644 chrome/test/data/extensions/unpacker/bad_image/background.js delete mode 100644 chrome/test/data/extensions/unpacker/bad_image/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/bad_image/not_really_an_image.png delete mode 100644 chrome/test/data/extensions/unpacker/bad_path.crx delete mode 100644 chrome/test/data/extensions/unpacker/bad_path/background.js delete mode 100644 chrome/test/data/extensions/unpacker/bad_path/bad_path.pem delete mode 100755 chrome/test/data/extensions/unpacker/bad_path/bad_path.sh delete mode 100644 chrome/test/data/extensions/unpacker/bad_path/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/bad_path/product_logo_128.png delete mode 100644 chrome/test/data/extensions/unpacker/bad_zip.crx delete mode 100644 chrome/test/data/extensions/unpacker/bad_zip/background.js delete mode 100644 chrome/test/data/extensions/unpacker/bad_zip/bad_zip.pem delete mode 100755 chrome/test/data/extensions/unpacker/bad_zip/bad_zip.sh delete mode 100644 chrome/test/data/extensions/unpacker/bad_zip/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/bad_zip/product_logo_128.png delete mode 100644 chrome/test/data/extensions/unpacker/empty_default_locale.crx delete mode 100644 chrome/test/data/extensions/unpacker/empty_default_locale/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/good_l10n.crx delete mode 100644 chrome/test/data/extensions/unpacker/good_l10n/_locales/en_US/messages.json delete mode 100644 chrome/test/data/extensions/unpacker/good_l10n/_locales/sr/messages.json delete mode 100644 chrome/test/data/extensions/unpacker/good_l10n/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/good_package.crx delete mode 100644 chrome/test/data/extensions/unpacker/good_package/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/good_package/product_logo_128.png delete mode 100644 chrome/test/data/extensions/unpacker/has_default_missing_locales.crx delete mode 100644 chrome/test/data/extensions/unpacker/has_default_missing_locales/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/invalid_default_locale.crx delete mode 100644 chrome/test/data/extensions/unpacker/invalid_default_locale/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/invalid_messages_file.crx delete mode 100644 chrome/test/data/extensions/unpacker/invalid_messages_file/_locales/en_US/messages.json delete mode 100644 chrome/test/data/extensions/unpacker/invalid_messages_file/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/missing_default_data.crx delete mode 100644 chrome/test/data/extensions/unpacker/missing_default_data/_locales/en_US/messages.json delete mode 100644 chrome/test/data/extensions/unpacker/missing_default_data/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/missing_default_has_locales.crx delete mode 100644 chrome/test/data/extensions/unpacker/missing_default_has_locales/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/missing_messages_file.crx delete mode 100644 chrome/test/data/extensions/unpacker/missing_messages_file/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/no_l10n.crx delete mode 100644 chrome/test/data/extensions/unpacker/no_l10n/manifest.json delete mode 100644 chrome/test/data/extensions/unpacker/no_locale_data.crx delete mode 100644 chrome/test/data/extensions/unpacker/no_locale_data/manifest.json delete mode 100644 chrome/utility/extensions/unpacker_unittest.cc create mode 100644 extensions/test/data/unpacker/bad_image.crx create mode 100644 extensions/test/data/unpacker/bad_image/background.js create mode 100644 extensions/test/data/unpacker/bad_image/manifest.json create mode 100644 extensions/test/data/unpacker/bad_image/not_really_an_image.png create mode 100644 extensions/test/data/unpacker/bad_zip.crx create mode 100644 extensions/test/data/unpacker/bad_zip/background.js create mode 100644 extensions/test/data/unpacker/bad_zip/bad_zip.pem create mode 100755 extensions/test/data/unpacker/bad_zip/bad_zip.sh create mode 100644 extensions/test/data/unpacker/bad_zip/manifest.json create mode 100644 extensions/test/data/unpacker/bad_zip/product_logo_128.png create mode 100644 extensions/test/data/unpacker/empty_default_locale.crx create mode 100644 extensions/test/data/unpacker/empty_default_locale/manifest.json create mode 100644 extensions/test/data/unpacker/good_l10n.crx create mode 100644 extensions/test/data/unpacker/good_l10n/_locales/en_US/messages.json create mode 100644 extensions/test/data/unpacker/good_l10n/_locales/sr/messages.json create mode 100644 extensions/test/data/unpacker/good_l10n/manifest.json create mode 100644 extensions/test/data/unpacker/good_package.crx create mode 100644 extensions/test/data/unpacker/good_package/manifest.json create mode 100644 extensions/test/data/unpacker/good_package/product_logo_128.png create mode 100644 extensions/test/data/unpacker/has_default_missing_locales.crx create mode 100644 extensions/test/data/unpacker/has_default_missing_locales/manifest.json create mode 100644 extensions/test/data/unpacker/invalid_default_locale.crx create mode 100644 extensions/test/data/unpacker/invalid_default_locale/manifest.json create mode 100644 extensions/test/data/unpacker/invalid_messages_file.crx create mode 100644 extensions/test/data/unpacker/invalid_messages_file/_locales/en_US/messages.json create mode 100644 extensions/test/data/unpacker/invalid_messages_file/manifest.json create mode 100644 extensions/test/data/unpacker/missing_default_data.crx create mode 100644 extensions/test/data/unpacker/missing_default_data/_locales/en_US/messages.json create mode 100644 extensions/test/data/unpacker/missing_default_data/manifest.json create mode 100644 extensions/test/data/unpacker/missing_default_has_locales.crx create mode 100644 extensions/test/data/unpacker/missing_default_has_locales/manifest.json create mode 100644 extensions/test/data/unpacker/missing_messages_file.crx create mode 100644 extensions/test/data/unpacker/missing_messages_file/manifest.json create mode 100644 extensions/test/data/unpacker/no_l10n.crx create mode 100644 extensions/test/data/unpacker/no_l10n/manifest.json create mode 100644 extensions/test/data/unpacker/no_locale_data.crx create mode 100644 extensions/test/data/unpacker/no_locale_data/manifest.json create mode 100644 extensions/utility/unpacker_unittest.cc diff --git a/chrome/browser/extensions/sandboxed_unpacker_unittest.cc b/chrome/browser/extensions/sandboxed_unpacker_unittest.cc index 8b70ccf..4d46e7c 100644 --- a/chrome/browser/extensions/sandboxed_unpacker_unittest.cc +++ b/chrome/browser/extensions/sandboxed_unpacker_unittest.cc @@ -16,6 +16,7 @@ #include "content/public/test/test_utils.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" +#include "extensions/common/extension_paths.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -75,10 +76,8 @@ class SandboxedUnpackerTest : public testing::Test { void SetupUnpacker(const std::string& crx_name) { base::FilePath original_path; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); - original_path = original_path.AppendASCII("extensions") - .AppendASCII("unpacker") - .AppendASCII(crx_name); + ASSERT_TRUE(PathService::Get(extensions::DIR_TEST_DATA, &original_path)); + original_path = original_path.AppendASCII("unpacker").AppendASCII(crx_name); ASSERT_TRUE(base::PathExists(original_path)) << original_path.value(); sandboxed_unpacker_ = new SandboxedUnpacker( diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 68aa276..e8ee39e 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -926,7 +926,6 @@ 'renderer/extensions/extension_localization_peer_unittest.cc', 'renderer/extensions/renderer_permissions_policy_delegate_unittest.cc', 'renderer/media/cast_ipc_dispatcher_unittest.cc', - 'utility/extensions/unpacker_unittest.cc', 'utility/image_writer/image_writer_unittest.cc', 'utility/media_galleries/image_metadata_extractor_unittest.cc', ], diff --git a/chrome/test/data/extensions/unpacker/bad_image.crx b/chrome/test/data/extensions/unpacker/bad_image.crx deleted file mode 100644 index 044c0a4..0000000 Binary files a/chrome/test/data/extensions/unpacker/bad_image.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/bad_image/background.js b/chrome/test/data/extensions/unpacker/bad_image/background.js deleted file mode 100644 index 8c00bb1..0000000 --- a/chrome/test/data/extensions/unpacker/bad_image/background.js +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Not doing anything. diff --git a/chrome/test/data/extensions/unpacker/bad_image/manifest.json b/chrome/test/data/extensions/unpacker/bad_image/manifest.json deleted file mode 100644 index b3b7fa9..0000000 --- a/chrome/test/data/extensions/unpacker/bad_image/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Bad Image", - "version": "1.0", - "description": "Package with a bad image to be used for unit testing.", - "theme": {"images" : {"bad" : "not_really_an_image.png"}} -} diff --git a/chrome/test/data/extensions/unpacker/bad_image/not_really_an_image.png b/chrome/test/data/extensions/unpacker/bad_image/not_really_an_image.png deleted file mode 100644 index 9516805..0000000 --- a/chrome/test/data/extensions/unpacker/bad_image/not_really_an_image.png +++ /dev/null @@ -1 +0,0 @@ -Thu Aug 23 09:01:45 PDT 2012 diff --git a/chrome/test/data/extensions/unpacker/bad_path.crx b/chrome/test/data/extensions/unpacker/bad_path.crx deleted file mode 100644 index dbdcb22..0000000 Binary files a/chrome/test/data/extensions/unpacker/bad_path.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/bad_path/background.js b/chrome/test/data/extensions/unpacker/bad_path/background.js deleted file mode 100644 index 8c00bb1..0000000 --- a/chrome/test/data/extensions/unpacker/bad_path/background.js +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Not doing anything. diff --git a/chrome/test/data/extensions/unpacker/bad_path/bad_path.pem b/chrome/test/data/extensions/unpacker/bad_path/bad_path.pem deleted file mode 100644 index e338fc8..0000000 --- a/chrome/test/data/extensions/unpacker/bad_path/bad_path.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMHOSbN+rhH8WhvmM -e0l7CwJ8+K0ZmYwKFuJIgQTJIMBZhsZyMYse0l6jrurgr0n8UkCqWfOEvyxFxqtxp -osb7bm3AKg/SsdiDDzZQLwQK5Sy6gBh3hXk+K4aLVv3rQsdRRMQPhgDvZJGBEWsjQ -kJ3dalslli/cEpbwm0USp1fWtAgMBAAECgYEAlqR/OysjqM1LSVZTxm7stYqC7Num -oJWcORJNw3cRsVbcBAK1wfx/VC0UVyHIfLlYXpTYEtzme043lEAxGFOj/N/3+9tH0 -0HhuVnAPh8JAfCXVZfGy/C3DWzatLx4iZMctBSE+3ViNscZtJHP65bgfqVBatAiyK -IrPPz7xe/GGS0CQQDjqBKM/9IvWvpRw1YMoX9f4jC7lp3FDfr7MtBLj/sq9d+QtTb -MArTQzwVlb4WZ0jVe7ceUl/ZG8VWs5FAYM0RvAkEA2e9RCYiIpfJCTt1pxfN5lBIi -vrwkwUtxnKzfvl7YEJEV4WMUnIwpdjuHaSIXBRf3D29Vw1s7Mmz/kdFSKiRNowJBA -JPRGKJ2pMncv7YBKEkxP1xJqKzUwgIl7rXWK4s0pLgjR5NVJoxWoYMHOJDBVbUn2U -GXEMS52s37e060PBFKkH8CQD8SgtqGeD3GsigO7mjKwTn4UbPv0ZdblULpyUtYOaH -5y2JSgYmZCvrb2aG0qwLfX7JI34JNagF7CDAUa3okzY8CQQCr8/LcdzM24XjJXySN -AqWAtBk8iAp5DheO7GHgS1Xyrcbl3VRWctjYJjQlFBkIKvMAI5dXl+FCM1+mZD5+2 -qPu ------END PRIVATE KEY----- diff --git a/chrome/test/data/extensions/unpacker/bad_path/bad_path.sh b/chrome/test/data/extensions/unpacker/bad_path/bad_path.sh deleted file mode 100755 index 96371cb..0000000 --- a/chrome/test/data/extensions/unpacker/bad_path/bad_path.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -e - -## Copyright (c) 2012 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Purpose: Create a Chromium crx even if paths are invalid. -if test $# -ne 2; then - echo "Usage: bad_path.sh " - exit 1 -fi -dir=$1 -key=$2 -name=$(basename "$dir") -crx="$name.crx" -pub="$name.pub" -sig="$name.sig" -zip="$name.zip" -trap 'rm -f "$pub" "$sig" "$zip"' EXIT -# zip up the crx dir -cwd=$(pwd -P) -(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .) -# signature -openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig" -# public key -openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null -byte_swap () { - # Take "abcdefgh" and return it as "ghefcdab" - echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" -} -crmagic_hex="4372 3234" # Cr24 -version_hex="0200 0000" # 2 -pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) -sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) -( - echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p - cat "$pub" "$sig" "$zip" -) > "$crx" -echo "Wrote $crx with possibly invalid path" diff --git a/chrome/test/data/extensions/unpacker/bad_path/manifest.json b/chrome/test/data/extensions/unpacker/bad_path/manifest.json deleted file mode 100644 index d19b7f8..0000000 --- a/chrome/test/data/extensions/unpacker/bad_path/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Bad Path", - "version": "1.0", - "description": "Package with an invalid path to be used for unit testing. The path below is carefully chosen so: 1) it contains '..'; and 2) it resolves to a valid file at package installation time so no invalid-image-error is raised before the invalid-image-path-error one is. Because of the invalid path, this package needs to be packaged with bad_path.sh rather than Chromium.", - "theme": {"images" : {"bad_path" : "../CRX_INSTALL/product_logo_128.png"}} -} diff --git a/chrome/test/data/extensions/unpacker/bad_path/product_logo_128.png b/chrome/test/data/extensions/unpacker/bad_path/product_logo_128.png deleted file mode 100644 index b70cd25..0000000 Binary files a/chrome/test/data/extensions/unpacker/bad_path/product_logo_128.png and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/bad_zip.crx b/chrome/test/data/extensions/unpacker/bad_zip.crx deleted file mode 100644 index 6bf7f1f..0000000 Binary files a/chrome/test/data/extensions/unpacker/bad_zip.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/bad_zip/background.js b/chrome/test/data/extensions/unpacker/bad_zip/background.js deleted file mode 100644 index 8c00bb1..0000000 --- a/chrome/test/data/extensions/unpacker/bad_zip/background.js +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Not doing anything. diff --git a/chrome/test/data/extensions/unpacker/bad_zip/bad_zip.pem b/chrome/test/data/extensions/unpacker/bad_zip/bad_zip.pem deleted file mode 100644 index 0599802..0000000 --- a/chrome/test/data/extensions/unpacker/bad_zip/bad_zip.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOjf84gztCkAgocAh -eFUD1ktpLIVH8IjUFjLQ6P5pB9hAN4sNO/mBH+LC/Q6WDpKN+ei9Shh82NbLlKeVN -j8I/hKPjWpGuGjMqYfEl5y1Uq1Z788s6pATT1KYNzXJVy6HBkNYr8iyZsqSIP3zyY -7VXLfx7gG5CgWUKrLxnGv9/i7AgMBAAECgYAn3WagM1GtDzRJDhLdHvm9p22hOrKE -Fm2DtdAveuXYpU9zuRea1cKBXvk95tsBp4Doe2ICdromkQ5eAFLADnHNlKiL5camn -w1L3YhtqAl+lM1IDsDv5cIVQnzis8b6ydUyG8nJ6J3JQuNQ7rCRMVEPV1HEI+FmF3 -CK/SIodZS5SQJBAP11ozwyxml1XF/dGzXAi5Ci3vsNEOa6ZOBo9pzxkRAx3z48hq5 -gfpmBfucdXgGTVXAU+yZvQB+35yURFAdFMNUCQQDrNX6Wvj+PLGptQqcasLJQGrje -++b8M3bCxj34z9xZKS7m/zU6Y+lp/uf+kLK14oCNCk3xDmIutzG8FgLe0ctPAkB4X -K7h3XLfjb4KQCO1yPP+AXpGWhQWnZleADpsmUK8IBLVqUSD9oroNtiexBFqSh8elL -gXrmkTJu/7aDrMoQzpAkAsTyWLzEc494sNDjNgqczNnlsZVqcK9771rlbaWn4OJd3 -6EjW6zDuahjS6FhQ0g3joGPrZ4HXKiyRJZHQh+a+tAkEAmxPXDhummz7bJnfulB1D -5yk9l/7xfei0/o4uKiHKtg5RbdEQVuQtNKoGDrinN41HtJy6xIlUs0B3uGIDSWddB -w== ------END PRIVATE KEY----- diff --git a/chrome/test/data/extensions/unpacker/bad_zip/bad_zip.sh b/chrome/test/data/extensions/unpacker/bad_zip/bad_zip.sh deleted file mode 100755 index bb147f2..0000000 --- a/chrome/test/data/extensions/unpacker/bad_zip/bad_zip.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -e - -## Copyright (c) 2012 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Purpose: Create a corrupt (invalid ZIP) version of a Chromium crx. -if test $# -ne 2; then - echo "Usage: bad_zip.sh " - exit 1 -fi -dir=$1 -key=$2 -name=$(basename "$dir") -crx="$name.crx" -pub="$name.pub" -sig="$name.sig" -zip="$name.zip" -trap 'rm -f "$pub" "$sig" "$zip"' EXIT -# zip up the crx dir -cwd=$(pwd -P) -(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .) -# truncate the zip to 8K so it's invalid -dd if=$zip of=$zip+ bs=1024 count=8 2>/dev/null && mv $zip+ $zip -# signature -openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig" -# public key -openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null -byte_swap () { - # Take "abcdefgh" and return it as "ghefcdab" - echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" -} -crmagic_hex="4372 3234" # Cr24 -version_hex="0200 0000" # 2 -pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) -sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) -( - echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p - cat "$pub" "$sig" "$zip" -) > "$crx" -echo "Wrote $crx with invalid ZIP" diff --git a/chrome/test/data/extensions/unpacker/bad_zip/manifest.json b/chrome/test/data/extensions/unpacker/bad_zip/manifest.json deleted file mode 100644 index 5df0fb5..0000000 --- a/chrome/test/data/extensions/unpacker/bad_zip/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Bad ZIP", - "version": "1.0", - "description": "Good package to be mangled by bad_zip.sh for unit testing.", - "theme": {"images" : {"logo" : "product_logo_128.png"}} -} diff --git a/chrome/test/data/extensions/unpacker/bad_zip/product_logo_128.png b/chrome/test/data/extensions/unpacker/bad_zip/product_logo_128.png deleted file mode 100644 index b70cd25..0000000 Binary files a/chrome/test/data/extensions/unpacker/bad_zip/product_logo_128.png and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/empty_default_locale.crx b/chrome/test/data/extensions/unpacker/empty_default_locale.crx deleted file mode 100644 index d8f1e0e..0000000 Binary files a/chrome/test/data/extensions/unpacker/empty_default_locale.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/empty_default_locale/manifest.json b/chrome/test/data/extensions/unpacker/empty_default_locale/manifest.json deleted file mode 100644 index 6f43cf2..0000000 --- a/chrome/test/data/extensions/unpacker/empty_default_locale/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "Default locale can't be empty", - "name": "empty_default_locale", - "default_locale": "", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/good_l10n.crx b/chrome/test/data/extensions/unpacker/good_l10n.crx deleted file mode 100644 index ee56569..0000000 Binary files a/chrome/test/data/extensions/unpacker/good_l10n.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/good_l10n/_locales/en_US/messages.json b/chrome/test/data/extensions/unpacker/good_l10n/_locales/en_US/messages.json deleted file mode 100644 index b5b53c6..0000000 --- a/chrome/test/data/extensions/unpacker/good_l10n/_locales/en_US/messages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "eh": { - "message": "this is valid catalog" - } -} diff --git a/chrome/test/data/extensions/unpacker/good_l10n/_locales/sr/messages.json b/chrome/test/data/extensions/unpacker/good_l10n/_locales/sr/messages.json deleted file mode 100644 index b5b53c6..0000000 --- a/chrome/test/data/extensions/unpacker/good_l10n/_locales/sr/messages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "eh": { - "message": "this is valid catalog" - } -} diff --git a/chrome/test/data/extensions/unpacker/good_l10n/manifest.json b/chrome/test/data/extensions/unpacker/good_l10n/manifest.json deleted file mode 100644 index cf2e2a9..0000000 --- a/chrome/test/data/extensions/unpacker/good_l10n/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "All is well", - "name": "good_l10n", - "default_locale": "sr", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/good_package.crx b/chrome/test/data/extensions/unpacker/good_package.crx deleted file mode 100644 index e9d4114..0000000 Binary files a/chrome/test/data/extensions/unpacker/good_package.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/good_package/manifest.json b/chrome/test/data/extensions/unpacker/good_package/manifest.json deleted file mode 100644 index 0a185bc..0000000 --- a/chrome/test/data/extensions/unpacker/good_package/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Good Package", - "version": "1.0", - "description": "Good (valid) package to be used for unit testing.", - "theme": {"images" : {"logo" : "product_logo_128.png"}} -} diff --git a/chrome/test/data/extensions/unpacker/good_package/product_logo_128.png b/chrome/test/data/extensions/unpacker/good_package/product_logo_128.png deleted file mode 100644 index b70cd25..0000000 Binary files a/chrome/test/data/extensions/unpacker/good_package/product_logo_128.png and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/has_default_missing_locales.crx b/chrome/test/data/extensions/unpacker/has_default_missing_locales.crx deleted file mode 100644 index 8d2808e..0000000 Binary files a/chrome/test/data/extensions/unpacker/has_default_missing_locales.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/has_default_missing_locales/manifest.json b/chrome/test/data/extensions/unpacker/has_default_missing_locales/manifest.json deleted file mode 100644 index e572fc2..0000000 --- a/chrome/test/data/extensions/unpacker/has_default_missing_locales/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "Cannot have default_locale but skip _locales", - "name": "has_default_missing_locales", - "default_locale": "en_US", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/invalid_default_locale.crx b/chrome/test/data/extensions/unpacker/invalid_default_locale.crx deleted file mode 100644 index 8a426c9..0000000 Binary files a/chrome/test/data/extensions/unpacker/invalid_default_locale.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/invalid_default_locale/manifest.json b/chrome/test/data/extensions/unpacker/invalid_default_locale/manifest.json deleted file mode 100644 index ecf7d82..0000000 --- a/chrome/test/data/extensions/unpacker/invalid_default_locale/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "Default locale has to be string and can't be empty", - "name": "invalid_default_locale", - "default_locale": 5, - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/invalid_messages_file.crx b/chrome/test/data/extensions/unpacker/invalid_messages_file.crx deleted file mode 100644 index 15691d4..0000000 Binary files a/chrome/test/data/extensions/unpacker/invalid_messages_file.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/invalid_messages_file/_locales/en_US/messages.json b/chrome/test/data/extensions/unpacker/invalid_messages_file/_locales/en_US/messages.json deleted file mode 100644 index a992f8f..0000000 --- a/chrome/test/data/extensions/unpacker/invalid_messages_file/_locales/en_US/messages.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "eh: -} diff --git a/chrome/test/data/extensions/unpacker/invalid_messages_file/manifest.json b/chrome/test/data/extensions/unpacker/invalid_messages_file/manifest.json deleted file mode 100644 index 7a4b9ef..0000000 --- a/chrome/test/data/extensions/unpacker/invalid_messages_file/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "Fail if messages.json is not valid (check JSON syntax only)", - "name": "invalid_messages_file", - "default_locale": "en_US", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/missing_default_data.crx b/chrome/test/data/extensions/unpacker/missing_default_data.crx deleted file mode 100644 index eeb76fe..0000000 Binary files a/chrome/test/data/extensions/unpacker/missing_default_data.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/missing_default_data/_locales/en_US/messages.json b/chrome/test/data/extensions/unpacker/missing_default_data/_locales/en_US/messages.json deleted file mode 100644 index b5b53c6..0000000 --- a/chrome/test/data/extensions/unpacker/missing_default_data/_locales/en_US/messages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "eh": { - "message": "this is valid catalog" - } -} diff --git a/chrome/test/data/extensions/unpacker/missing_default_data/manifest.json b/chrome/test/data/extensions/unpacker/missing_default_data/manifest.json deleted file mode 100644 index 03ecc4a..0000000 --- a/chrome/test/data/extensions/unpacker/missing_default_data/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "Data for default_locale has to be present", - "name": "missing_default_data", - "default_locale": "sr", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/missing_default_has_locales.crx b/chrome/test/data/extensions/unpacker/missing_default_has_locales.crx deleted file mode 100644 index 0bf345d..0000000 Binary files a/chrome/test/data/extensions/unpacker/missing_default_has_locales.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/missing_default_has_locales/manifest.json b/chrome/test/data/extensions/unpacker/missing_default_has_locales/manifest.json deleted file mode 100644 index 13a5d4b..0000000 --- a/chrome/test/data/extensions/unpacker/missing_default_has_locales/manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "description": "If _locales is present, default_locale has to be defined too.", - "name": "missing_default_has_locales", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/missing_messages_file.crx b/chrome/test/data/extensions/unpacker/missing_messages_file.crx deleted file mode 100644 index 4ca3634..0000000 Binary files a/chrome/test/data/extensions/unpacker/missing_messages_file.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/missing_messages_file/manifest.json b/chrome/test/data/extensions/unpacker/missing_messages_file/manifest.json deleted file mode 100644 index a3ccf4b..0000000 --- a/chrome/test/data/extensions/unpacker/missing_messages_file/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "Each locale has to have messages.json file", - "name": "missing_messages_file", - "default_locale": "en_US", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/no_l10n.crx b/chrome/test/data/extensions/unpacker/no_l10n.crx deleted file mode 100644 index d9edd9e..0000000 Binary files a/chrome/test/data/extensions/unpacker/no_l10n.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/no_l10n/manifest.json b/chrome/test/data/extensions/unpacker/no_l10n/manifest.json deleted file mode 100644 index 8ba809f..0000000 --- a/chrome/test/data/extensions/unpacker/no_l10n/manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "description": "This extension is not localized.", - "name": "no_l10n", - "version": "1.0" -} diff --git a/chrome/test/data/extensions/unpacker/no_locale_data.crx b/chrome/test/data/extensions/unpacker/no_locale_data.crx deleted file mode 100644 index 30a8f40..0000000 Binary files a/chrome/test/data/extensions/unpacker/no_locale_data.crx and /dev/null differ diff --git a/chrome/test/data/extensions/unpacker/no_locale_data/manifest.json b/chrome/test/data/extensions/unpacker/no_locale_data/manifest.json deleted file mode 100644 index c4d68b4..0000000 --- a/chrome/test/data/extensions/unpacker/no_locale_data/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "_locales can't be empty", - "name": "no_locale_data", - "default_locale": "en_US", - "version": "1.0" -} diff --git a/chrome/utility/extensions/unpacker_unittest.cc b/chrome/utility/extensions/unpacker_unittest.cc deleted file mode 100644 index 891d15c..0000000 --- a/chrome/utility/extensions/unpacker_unittest.cc +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/files/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/path_service.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/common/chrome_paths.h" -#include "extensions/common/constants.h" -#include "extensions/common/extension.h" -#include "extensions/common/manifest_constants.h" -#include "extensions/utility/unpacker.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkBitmap.h" - -using base::ASCIIToUTF16; - -namespace extensions { - -namespace errors = manifest_errors; -namespace keys = manifest_keys; - -class UnpackerTest : public testing::Test { - public: - ~UnpackerTest() override { - LOG(WARNING) << "Deleting temp dir: " - << temp_dir_.path().LossyDisplayName(); - LOG(WARNING) << temp_dir_.Delete(); - } - - void SetupUnpacker(const std::string& crx_name) { - base::FilePath original_path; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); - original_path = original_path.AppendASCII("extensions") - .AppendASCII("unpacker") - .AppendASCII(crx_name); - ASSERT_TRUE(base::PathExists(original_path)) << original_path.value(); - - // Try bots won't let us write into DIR_TEST_DATA, so we have to create - // a temp folder to play in. - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - - base::FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); - ASSERT_TRUE(base::CopyFile(original_path, crx_path)) - << "Original path " << original_path.value() << ", Crx path " - << crx_path.value(); - - unpacker_.reset(new Unpacker(crx_path, std::string(), Manifest::INTERNAL, - Extension::NO_FLAGS)); - } - - protected: - base::ScopedTempDir temp_dir_; - scoped_ptr unpacker_; -}; - -TEST_F(UnpackerTest, EmptyDefaultLocale) { - SetupUnpacker("empty_default_locale.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), - unpacker_->error_message()); -} - -TEST_F(UnpackerTest, HasDefaultLocaleMissingLocalesFolder) { - SetupUnpacker("has_default_missing_locales.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(errors::kLocalesTreeMissing), - unpacker_->error_message()); -} - -TEST_F(UnpackerTest, InvalidDefaultLocale) { - SetupUnpacker("invalid_default_locale.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), - unpacker_->error_message()); -} - -TEST_F(UnpackerTest, InvalidMessagesFile) { - SetupUnpacker("invalid_messages_file.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_TRUE( - MatchPattern(unpacker_->error_message(), - ASCIIToUTF16( - "*_locales?en_US?messages.json: Line: 2, column: 11," - " Syntax error."))) - << unpacker_->error_message(); -} - -TEST_F(UnpackerTest, MissingDefaultData) { - SetupUnpacker("missing_default_data.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), - unpacker_->error_message()); -} - -TEST_F(UnpackerTest, MissingDefaultLocaleHasLocalesFolder) { - SetupUnpacker("missing_default_has_locales.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), - unpacker_->error_message()); -} - -TEST_F(UnpackerTest, MissingMessagesFile) { - SetupUnpacker("missing_messages_file.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_TRUE(MatchPattern(unpacker_->error_message(), - ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + - ASCIIToUTF16("*_locales?en_US?messages.json"))); -} - -TEST_F(UnpackerTest, NoLocaleData) { - SetupUnpacker("no_locale_data.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), - unpacker_->error_message()); -} - -TEST_F(UnpackerTest, GoodL10n) { - SetupUnpacker("good_l10n.crx"); - EXPECT_TRUE(unpacker_->Run()); - EXPECT_TRUE(unpacker_->error_message().empty()); - ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); -} - -TEST_F(UnpackerTest, NoL10n) { - SetupUnpacker("no_l10n.crx"); - EXPECT_TRUE(unpacker_->Run()); - EXPECT_TRUE(unpacker_->error_message().empty()); - EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); -} - -TEST_F(UnpackerTest, UnzipDirectoryError) { - const char kExpected[] = "Could not create directory for unzipping: "; - SetupUnpacker("good_package.crx"); - base::FilePath path = temp_dir_.path().AppendASCII(kTempExtensionName); - ASSERT_TRUE(base::WriteFile(path, "foo", 3)); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_TRUE( - StartsWith(unpacker_->error_message(), ASCIIToUTF16(kExpected), false)) - << "Expected prefix: \"" << kExpected << "\", actual error: \"" - << unpacker_->error_message() << "\""; -} - -TEST_F(UnpackerTest, UnzipError) { - const char kExpected[] = "Could not unzip extension"; - SetupUnpacker("bad_zip.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_EQ(ASCIIToUTF16(kExpected), unpacker_->error_message()); -} - -TEST_F(UnpackerTest, BadPathError) { - const char kExpected[] = "Illegal path (absolute or relative with '..'): "; - SetupUnpacker("bad_path.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_TRUE( - StartsWith(unpacker_->error_message(), ASCIIToUTF16(kExpected), false)) - << "Expected prefix: \"" << kExpected << "\", actual error: \"" - << unpacker_->error_message() << "\""; -} - -TEST_F(UnpackerTest, ImageDecodingError) { - const char kExpected[] = "Could not decode image: "; - SetupUnpacker("bad_image.crx"); - EXPECT_FALSE(unpacker_->Run()); - EXPECT_TRUE( - StartsWith(unpacker_->error_message(), ASCIIToUTF16(kExpected), false)) - << "Expected prefix: \"" << kExpected << "\", actual error: \"" - << unpacker_->error_message() << "\""; -} - -} // namespace extensions diff --git a/extensions/BUILD.gn b/extensions/BUILD.gn index 0006144..c900458 100644 --- a/extensions/BUILD.gn +++ b/extensions/BUILD.gn @@ -255,6 +255,7 @@ if (false) { "renderer/script_context_unittest.cc", "renderer/utils_unittest.cc", "test/extensions_unittests_main.cc", + "utility/unpacker_unittest.cc", ] deps = [ diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index a31f302..a1f2f8b 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -1304,6 +1304,7 @@ 'renderer/script_context_unittest.cc', 'renderer/utils_unittest.cc', 'test/extensions_unittests_main.cc', + 'utility/unpacker_unittest.cc', ], # Disable c4267 warnings until we fix size_t to int truncations. 'msvs_disabled_warnings': [ 4267, ], diff --git a/extensions/test/data/unpacker/bad_image.crx b/extensions/test/data/unpacker/bad_image.crx new file mode 100644 index 0000000..192bd09 Binary files /dev/null and b/extensions/test/data/unpacker/bad_image.crx differ diff --git a/extensions/test/data/unpacker/bad_image/background.js b/extensions/test/data/unpacker/bad_image/background.js new file mode 100644 index 0000000..8c00bb1 --- /dev/null +++ b/extensions/test/data/unpacker/bad_image/background.js @@ -0,0 +1,5 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Not doing anything. diff --git a/extensions/test/data/unpacker/bad_image/manifest.json b/extensions/test/data/unpacker/bad_image/manifest.json new file mode 100644 index 0000000..9048606 --- /dev/null +++ b/extensions/test/data/unpacker/bad_image/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "Bad Image", + "version": "1.0", + "manifest_version": 2, + "description": "Package with a bad image to be used for unit testing.", + "icons": { "128": "not_really_an_image.png" } +} diff --git a/extensions/test/data/unpacker/bad_image/not_really_an_image.png b/extensions/test/data/unpacker/bad_image/not_really_an_image.png new file mode 100644 index 0000000..9516805 --- /dev/null +++ b/extensions/test/data/unpacker/bad_image/not_really_an_image.png @@ -0,0 +1 @@ +Thu Aug 23 09:01:45 PDT 2012 diff --git a/extensions/test/data/unpacker/bad_zip.crx b/extensions/test/data/unpacker/bad_zip.crx new file mode 100644 index 0000000..3bd8ed7 Binary files /dev/null and b/extensions/test/data/unpacker/bad_zip.crx differ diff --git a/extensions/test/data/unpacker/bad_zip/background.js b/extensions/test/data/unpacker/bad_zip/background.js new file mode 100644 index 0000000..8c00bb1 --- /dev/null +++ b/extensions/test/data/unpacker/bad_zip/background.js @@ -0,0 +1,5 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Not doing anything. diff --git a/extensions/test/data/unpacker/bad_zip/bad_zip.pem b/extensions/test/data/unpacker/bad_zip/bad_zip.pem new file mode 100644 index 0000000..0599802 --- /dev/null +++ b/extensions/test/data/unpacker/bad_zip/bad_zip.pem @@ -0,0 +1,16 @@ +-----BEGIN PRIVATE KEY----- +MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOjf84gztCkAgocAh +eFUD1ktpLIVH8IjUFjLQ6P5pB9hAN4sNO/mBH+LC/Q6WDpKN+ei9Shh82NbLlKeVN +j8I/hKPjWpGuGjMqYfEl5y1Uq1Z788s6pATT1KYNzXJVy6HBkNYr8iyZsqSIP3zyY +7VXLfx7gG5CgWUKrLxnGv9/i7AgMBAAECgYAn3WagM1GtDzRJDhLdHvm9p22hOrKE +Fm2DtdAveuXYpU9zuRea1cKBXvk95tsBp4Doe2ICdromkQ5eAFLADnHNlKiL5camn +w1L3YhtqAl+lM1IDsDv5cIVQnzis8b6ydUyG8nJ6J3JQuNQ7rCRMVEPV1HEI+FmF3 +CK/SIodZS5SQJBAP11ozwyxml1XF/dGzXAi5Ci3vsNEOa6ZOBo9pzxkRAx3z48hq5 +gfpmBfucdXgGTVXAU+yZvQB+35yURFAdFMNUCQQDrNX6Wvj+PLGptQqcasLJQGrje +++b8M3bCxj34z9xZKS7m/zU6Y+lp/uf+kLK14oCNCk3xDmIutzG8FgLe0ctPAkB4X +K7h3XLfjb4KQCO1yPP+AXpGWhQWnZleADpsmUK8IBLVqUSD9oroNtiexBFqSh8elL +gXrmkTJu/7aDrMoQzpAkAsTyWLzEc494sNDjNgqczNnlsZVqcK9771rlbaWn4OJd3 +6EjW6zDuahjS6FhQ0g3joGPrZ4HXKiyRJZHQh+a+tAkEAmxPXDhummz7bJnfulB1D +5yk9l/7xfei0/o4uKiHKtg5RbdEQVuQtNKoGDrinN41HtJy6xIlUs0B3uGIDSWddB +w== +-----END PRIVATE KEY----- diff --git a/extensions/test/data/unpacker/bad_zip/bad_zip.sh b/extensions/test/data/unpacker/bad_zip/bad_zip.sh new file mode 100755 index 0000000..bb147f2 --- /dev/null +++ b/extensions/test/data/unpacker/bad_zip/bad_zip.sh @@ -0,0 +1,41 @@ +#!/bin/bash -e + +## Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Purpose: Create a corrupt (invalid ZIP) version of a Chromium crx. +if test $# -ne 2; then + echo "Usage: bad_zip.sh " + exit 1 +fi +dir=$1 +key=$2 +name=$(basename "$dir") +crx="$name.crx" +pub="$name.pub" +sig="$name.sig" +zip="$name.zip" +trap 'rm -f "$pub" "$sig" "$zip"' EXIT +# zip up the crx dir +cwd=$(pwd -P) +(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .) +# truncate the zip to 8K so it's invalid +dd if=$zip of=$zip+ bs=1024 count=8 2>/dev/null && mv $zip+ $zip +# signature +openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig" +# public key +openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null +byte_swap () { + # Take "abcdefgh" and return it as "ghefcdab" + echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" +} +crmagic_hex="4372 3234" # Cr24 +version_hex="0200 0000" # 2 +pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) +sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) +( + echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p + cat "$pub" "$sig" "$zip" +) > "$crx" +echo "Wrote $crx with invalid ZIP" diff --git a/extensions/test/data/unpacker/bad_zip/manifest.json b/extensions/test/data/unpacker/bad_zip/manifest.json new file mode 100644 index 0000000..5bed7ba --- /dev/null +++ b/extensions/test/data/unpacker/bad_zip/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "Bad ZIP", + "manifest_version": 2, + "version": "1.0", + "description": "Good package to be mangled by bad_zip.sh for unit testing.", + "icons": { + "128" : "product_logo_128.png" + } +} diff --git a/extensions/test/data/unpacker/bad_zip/product_logo_128.png b/extensions/test/data/unpacker/bad_zip/product_logo_128.png new file mode 100644 index 0000000..b70cd25 Binary files /dev/null and b/extensions/test/data/unpacker/bad_zip/product_logo_128.png differ diff --git a/extensions/test/data/unpacker/empty_default_locale.crx b/extensions/test/data/unpacker/empty_default_locale.crx new file mode 100644 index 0000000..d8f1e0e Binary files /dev/null and b/extensions/test/data/unpacker/empty_default_locale.crx differ diff --git a/extensions/test/data/unpacker/empty_default_locale/manifest.json b/extensions/test/data/unpacker/empty_default_locale/manifest.json new file mode 100644 index 0000000..6f43cf2 --- /dev/null +++ b/extensions/test/data/unpacker/empty_default_locale/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "Default locale can't be empty", + "name": "empty_default_locale", + "default_locale": "", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/good_l10n.crx b/extensions/test/data/unpacker/good_l10n.crx new file mode 100644 index 0000000..ee56569 Binary files /dev/null and b/extensions/test/data/unpacker/good_l10n.crx differ diff --git a/extensions/test/data/unpacker/good_l10n/_locales/en_US/messages.json b/extensions/test/data/unpacker/good_l10n/_locales/en_US/messages.json new file mode 100644 index 0000000..b5b53c6 --- /dev/null +++ b/extensions/test/data/unpacker/good_l10n/_locales/en_US/messages.json @@ -0,0 +1,5 @@ +{ + "eh": { + "message": "this is valid catalog" + } +} diff --git a/extensions/test/data/unpacker/good_l10n/_locales/sr/messages.json b/extensions/test/data/unpacker/good_l10n/_locales/sr/messages.json new file mode 100644 index 0000000..b5b53c6 --- /dev/null +++ b/extensions/test/data/unpacker/good_l10n/_locales/sr/messages.json @@ -0,0 +1,5 @@ +{ + "eh": { + "message": "this is valid catalog" + } +} diff --git a/extensions/test/data/unpacker/good_l10n/manifest.json b/extensions/test/data/unpacker/good_l10n/manifest.json new file mode 100644 index 0000000..cf2e2a9 --- /dev/null +++ b/extensions/test/data/unpacker/good_l10n/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "All is well", + "name": "good_l10n", + "default_locale": "sr", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/good_package.crx b/extensions/test/data/unpacker/good_package.crx new file mode 100644 index 0000000..c77e191 Binary files /dev/null and b/extensions/test/data/unpacker/good_package.crx differ diff --git a/extensions/test/data/unpacker/good_package/manifest.json b/extensions/test/data/unpacker/good_package/manifest.json new file mode 100644 index 0000000..f1aa747 --- /dev/null +++ b/extensions/test/data/unpacker/good_package/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "Good Package", + "manifest_version": 2, + "version": "1.0", + "description": "Good (valid) package to be used for unit testing.", + "icons": { + "128": "product_logo_128.png" + } +} diff --git a/extensions/test/data/unpacker/good_package/product_logo_128.png b/extensions/test/data/unpacker/good_package/product_logo_128.png new file mode 100644 index 0000000..b70cd25 Binary files /dev/null and b/extensions/test/data/unpacker/good_package/product_logo_128.png differ diff --git a/extensions/test/data/unpacker/has_default_missing_locales.crx b/extensions/test/data/unpacker/has_default_missing_locales.crx new file mode 100644 index 0000000..8d2808e Binary files /dev/null and b/extensions/test/data/unpacker/has_default_missing_locales.crx differ diff --git a/extensions/test/data/unpacker/has_default_missing_locales/manifest.json b/extensions/test/data/unpacker/has_default_missing_locales/manifest.json new file mode 100644 index 0000000..e572fc2 --- /dev/null +++ b/extensions/test/data/unpacker/has_default_missing_locales/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "Cannot have default_locale but skip _locales", + "name": "has_default_missing_locales", + "default_locale": "en_US", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/invalid_default_locale.crx b/extensions/test/data/unpacker/invalid_default_locale.crx new file mode 100644 index 0000000..8a426c9 Binary files /dev/null and b/extensions/test/data/unpacker/invalid_default_locale.crx differ diff --git a/extensions/test/data/unpacker/invalid_default_locale/manifest.json b/extensions/test/data/unpacker/invalid_default_locale/manifest.json new file mode 100644 index 0000000..ecf7d82 --- /dev/null +++ b/extensions/test/data/unpacker/invalid_default_locale/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "Default locale has to be string and can't be empty", + "name": "invalid_default_locale", + "default_locale": 5, + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/invalid_messages_file.crx b/extensions/test/data/unpacker/invalid_messages_file.crx new file mode 100644 index 0000000..15691d4 Binary files /dev/null and b/extensions/test/data/unpacker/invalid_messages_file.crx differ diff --git a/extensions/test/data/unpacker/invalid_messages_file/_locales/en_US/messages.json b/extensions/test/data/unpacker/invalid_messages_file/_locales/en_US/messages.json new file mode 100644 index 0000000..a992f8f --- /dev/null +++ b/extensions/test/data/unpacker/invalid_messages_file/_locales/en_US/messages.json @@ -0,0 +1,3 @@ +{ + "eh: +} diff --git a/extensions/test/data/unpacker/invalid_messages_file/manifest.json b/extensions/test/data/unpacker/invalid_messages_file/manifest.json new file mode 100644 index 0000000..7a4b9ef --- /dev/null +++ b/extensions/test/data/unpacker/invalid_messages_file/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "Fail if messages.json is not valid (check JSON syntax only)", + "name": "invalid_messages_file", + "default_locale": "en_US", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/missing_default_data.crx b/extensions/test/data/unpacker/missing_default_data.crx new file mode 100644 index 0000000..eeb76fe Binary files /dev/null and b/extensions/test/data/unpacker/missing_default_data.crx differ diff --git a/extensions/test/data/unpacker/missing_default_data/_locales/en_US/messages.json b/extensions/test/data/unpacker/missing_default_data/_locales/en_US/messages.json new file mode 100644 index 0000000..b5b53c6 --- /dev/null +++ b/extensions/test/data/unpacker/missing_default_data/_locales/en_US/messages.json @@ -0,0 +1,5 @@ +{ + "eh": { + "message": "this is valid catalog" + } +} diff --git a/extensions/test/data/unpacker/missing_default_data/manifest.json b/extensions/test/data/unpacker/missing_default_data/manifest.json new file mode 100644 index 0000000..03ecc4a --- /dev/null +++ b/extensions/test/data/unpacker/missing_default_data/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "Data for default_locale has to be present", + "name": "missing_default_data", + "default_locale": "sr", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/missing_default_has_locales.crx b/extensions/test/data/unpacker/missing_default_has_locales.crx new file mode 100644 index 0000000..0bf345d Binary files /dev/null and b/extensions/test/data/unpacker/missing_default_has_locales.crx differ diff --git a/extensions/test/data/unpacker/missing_default_has_locales/manifest.json b/extensions/test/data/unpacker/missing_default_has_locales/manifest.json new file mode 100644 index 0000000..13a5d4b --- /dev/null +++ b/extensions/test/data/unpacker/missing_default_has_locales/manifest.json @@ -0,0 +1,5 @@ +{ + "description": "If _locales is present, default_locale has to be defined too.", + "name": "missing_default_has_locales", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/missing_messages_file.crx b/extensions/test/data/unpacker/missing_messages_file.crx new file mode 100644 index 0000000..4ca3634 Binary files /dev/null and b/extensions/test/data/unpacker/missing_messages_file.crx differ diff --git a/extensions/test/data/unpacker/missing_messages_file/manifest.json b/extensions/test/data/unpacker/missing_messages_file/manifest.json new file mode 100644 index 0000000..a3ccf4b --- /dev/null +++ b/extensions/test/data/unpacker/missing_messages_file/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "Each locale has to have messages.json file", + "name": "missing_messages_file", + "default_locale": "en_US", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/no_l10n.crx b/extensions/test/data/unpacker/no_l10n.crx new file mode 100644 index 0000000..d9edd9e Binary files /dev/null and b/extensions/test/data/unpacker/no_l10n.crx differ diff --git a/extensions/test/data/unpacker/no_l10n/manifest.json b/extensions/test/data/unpacker/no_l10n/manifest.json new file mode 100644 index 0000000..8ba809f --- /dev/null +++ b/extensions/test/data/unpacker/no_l10n/manifest.json @@ -0,0 +1,5 @@ +{ + "description": "This extension is not localized.", + "name": "no_l10n", + "version": "1.0" +} diff --git a/extensions/test/data/unpacker/no_locale_data.crx b/extensions/test/data/unpacker/no_locale_data.crx new file mode 100644 index 0000000..30a8f40 Binary files /dev/null and b/extensions/test/data/unpacker/no_locale_data.crx differ diff --git a/extensions/test/data/unpacker/no_locale_data/manifest.json b/extensions/test/data/unpacker/no_locale_data/manifest.json new file mode 100644 index 0000000..c4d68b4 --- /dev/null +++ b/extensions/test/data/unpacker/no_locale_data/manifest.json @@ -0,0 +1,6 @@ +{ + "description": "_locales can't be empty", + "name": "no_locale_data", + "default_locale": "en_US", + "version": "1.0" +} diff --git a/extensions/test/test_extensions_client.cc b/extensions/test/test_extensions_client.cc index bc3fd49..bd64c58 100644 --- a/extensions/test/test_extensions_client.cc +++ b/extensions/test/test_extensions_client.cc @@ -4,6 +4,7 @@ #include "extensions/test/test_extensions_client.h" +#include "base/stl_util.h" #include "extensions/common/api/generated_schemas.h" #include "extensions/common/common_manifest_handlers.h" #include "extensions/common/extension_urls.h" @@ -38,6 +39,16 @@ TestExtensionsClient::TestExtensionsClient() { TestExtensionsClient::~TestExtensionsClient() { } +void TestExtensionsClient::AddBrowserImagePathsFilter( + BrowserImagePathsFilter* filter) { + browser_image_filters_.insert(filter); +} + +void TestExtensionsClient::RemoveBrowserImagePathsFilter( + BrowserImagePathsFilter* filter) { + browser_image_filters_.erase(filter); +} + void TestExtensionsClient::Initialize() { // Registration could already be finalized in unit tests, where the utility // thread runs in-process. @@ -167,4 +178,13 @@ bool TestExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const { return true; } +std::set TestExtensionsClient::GetBrowserImagePaths( + const Extension* extension) { + std::set result = + ExtensionsClient::GetBrowserImagePaths(extension); + for (auto filter : browser_image_filters_) + filter->Filter(extension, &result); + return result; +} + } // namespace extensions diff --git a/extensions/test/test_extensions_client.h b/extensions/test/test_extensions_client.h index bc8fe7c..964cbf9 100644 --- a/extensions/test/test_extensions_client.h +++ b/extensions/test/test_extensions_client.h @@ -12,9 +12,20 @@ namespace extensions { class TestExtensionsClient : public ExtensionsClient { public: + // An interface that lets tests change the set of image paths before they are + // returned by TestExtensionClient::GetBrowserImagePaths. + class BrowserImagePathsFilter { + public: + virtual void Filter(const Extension* extension, + std::set* paths) = 0; + }; + TestExtensionsClient(); ~TestExtensionsClient() override; + void AddBrowserImagePathsFilter(BrowserImagePathsFilter* filter); + void RemoveBrowserImagePathsFilter(BrowserImagePathsFilter* filter); + private: void Initialize() override; const PermissionMessageProvider& GetPermissionMessageProvider() @@ -44,6 +55,8 @@ class TestExtensionsClient : public ExtensionsClient { std::string GetWebstoreBaseURL() const override; std::string GetWebstoreUpdateURL() const override; bool IsBlacklistUpdateURL(const GURL& url) const override; + std::set GetBrowserImagePaths( + const Extension* extension) override; // A whitelist of extensions that can script anywhere. Do not add to this // list (except in tests) without consulting the Extensions team first. @@ -51,6 +64,8 @@ class TestExtensionsClient : public ExtensionsClient { // added to this list. ScriptingWhitelist scripting_whitelist_; + std::set browser_image_filters_; + DISALLOW_COPY_AND_ASSIGN(TestExtensionsClient); }; diff --git a/extensions/utility/unpacker_unittest.cc b/extensions/utility/unpacker_unittest.cc new file mode 100644 index 0000000..917f66e --- /dev/null +++ b/extensions/utility/unpacker_unittest.cc @@ -0,0 +1,205 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/files/file_util.h" +#include "base/files/scoped_temp_dir.h" +#include "base/path_service.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" +#include "extensions/common/constants.h" +#include "extensions/common/extension.h" +#include "extensions/common/extension_paths.h" +#include "extensions/common/manifest_constants.h" +#include "extensions/test/test_extensions_client.h" +#include "extensions/utility/unpacker.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" + +using base::ASCIIToUTF16; + +namespace extensions { + +namespace errors = manifest_errors; +namespace keys = manifest_keys; + +class UnpackerTest : public testing::Test { + public: + ~UnpackerTest() override { + VLOG(1) << "Deleting temp dir: " << temp_dir_.path().LossyDisplayName(); + VLOG(1) << temp_dir_.Delete(); + } + + void SetupUnpacker(const std::string& crx_name) { + base::FilePath original_path; + ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_path)); + original_path = original_path.AppendASCII("unpacker").AppendASCII(crx_name); + ASSERT_TRUE(base::PathExists(original_path)) << original_path.value(); + + // Try bots won't let us write into DIR_TEST_DATA, so we have to create + // a temp folder to play in. + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + + base::FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); + ASSERT_TRUE(base::CopyFile(original_path, crx_path)) + << "Original path " << original_path.value() << ", Crx path " + << crx_path.value(); + + unpacker_.reset(new Unpacker(crx_path, std::string(), Manifest::INTERNAL, + Extension::NO_FLAGS)); + } + + protected: + base::ScopedTempDir temp_dir_; + scoped_ptr unpacker_; +}; + +TEST_F(UnpackerTest, EmptyDefaultLocale) { + SetupUnpacker("empty_default_locale.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), + unpacker_->error_message()); +} + +TEST_F(UnpackerTest, HasDefaultLocaleMissingLocalesFolder) { + SetupUnpacker("has_default_missing_locales.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(errors::kLocalesTreeMissing), + unpacker_->error_message()); +} + +TEST_F(UnpackerTest, InvalidDefaultLocale) { + SetupUnpacker("invalid_default_locale.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), + unpacker_->error_message()); +} + +TEST_F(UnpackerTest, InvalidMessagesFile) { + SetupUnpacker("invalid_messages_file.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_TRUE( + MatchPattern(unpacker_->error_message(), + ASCIIToUTF16( + "*_locales?en_US?messages.json: Line: 2, column: 11," + " Syntax error."))) + << unpacker_->error_message(); +} + +TEST_F(UnpackerTest, MissingDefaultData) { + SetupUnpacker("missing_default_data.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), + unpacker_->error_message()); +} + +TEST_F(UnpackerTest, MissingDefaultLocaleHasLocalesFolder) { + SetupUnpacker("missing_default_has_locales.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), + unpacker_->error_message()); +} + +TEST_F(UnpackerTest, MissingMessagesFile) { + SetupUnpacker("missing_messages_file.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_TRUE(MatchPattern(unpacker_->error_message(), + ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + + ASCIIToUTF16("*_locales?en_US?messages.json"))); +} + +TEST_F(UnpackerTest, NoLocaleData) { + SetupUnpacker("no_locale_data.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), + unpacker_->error_message()); +} + +TEST_F(UnpackerTest, GoodL10n) { + SetupUnpacker("good_l10n.crx"); + EXPECT_TRUE(unpacker_->Run()); + EXPECT_TRUE(unpacker_->error_message().empty()); + ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); +} + +TEST_F(UnpackerTest, NoL10n) { + SetupUnpacker("no_l10n.crx"); + EXPECT_TRUE(unpacker_->Run()); + EXPECT_TRUE(unpacker_->error_message().empty()); + EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); +} + +TEST_F(UnpackerTest, UnzipDirectoryError) { + const char kExpected[] = "Could not create directory for unzipping: "; + SetupUnpacker("good_package.crx"); + base::FilePath path = temp_dir_.path().AppendASCII(kTempExtensionName); + ASSERT_TRUE(base::WriteFile(path, "foo", 3)); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_TRUE( + StartsWith(unpacker_->error_message(), ASCIIToUTF16(kExpected), false)) + << "Expected prefix: \"" << kExpected << "\", actual error: \"" + << unpacker_->error_message() << "\""; +} + +TEST_F(UnpackerTest, UnzipError) { + const char kExpected[] = "Could not unzip extension"; + SetupUnpacker("bad_zip.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_EQ(ASCIIToUTF16(kExpected), unpacker_->error_message()); +} + +namespace { + +// Inserts an illegal path into the browser images returned by +// TestExtensionsClient for any extension. +class IllegalImagePathInserter + : public TestExtensionsClient::BrowserImagePathsFilter { + public: + IllegalImagePathInserter(TestExtensionsClient* client) : client_(client) { + client_->AddBrowserImagePathsFilter(this); + } + + virtual ~IllegalImagePathInserter() { + client_->RemoveBrowserImagePathsFilter(this); + } + + void Filter(const Extension* extension, + std::set* paths) override { + base::FilePath illegal_path = + base::FilePath(base::FilePath::kParentDirectory) + .AppendASCII(kTempExtensionName) + .AppendASCII("product_logo_128.png"); + paths->insert(illegal_path); + } + + private: + TestExtensionsClient* client_; +}; + +} // namespace + +TEST_F(UnpackerTest, BadPathError) { + const char kExpected[] = "Illegal path (absolute or relative with '..'): "; + SetupUnpacker("good_package.crx"); + IllegalImagePathInserter inserter( + static_cast(ExtensionsClient::Get())); + + EXPECT_FALSE(unpacker_->Run()); + EXPECT_TRUE( + StartsWith(unpacker_->error_message(), ASCIIToUTF16(kExpected), false)) + << "Expected prefix: \"" << kExpected << "\", actual error: \"" + << unpacker_->error_message() << "\""; +} + +TEST_F(UnpackerTest, ImageDecodingError) { + const char kExpected[] = "Could not decode image: "; + SetupUnpacker("bad_image.crx"); + EXPECT_FALSE(unpacker_->Run()); + EXPECT_TRUE( + StartsWith(unpacker_->error_message(), ASCIIToUTF16(kExpected), false)) + << "Expected prefix: \"" << kExpected << "\", actual error: \"" + << unpacker_->error_message() << "\""; +} + +} // namespace extensions -- cgit v1.1