summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorasargent <asargent@chromium.org>2015-01-16 13:34:16 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-16 21:34:55 +0000
commit12a9cab7ee804fd898dca62004f750cc5a1ad685 (patch)
tree6734137f0cc7c889fa7c5f4059d12c43642b30d0 /extensions
parent79126efc4e18a879657667f39b438b6e58523e58 (diff)
downloadchromium_src-12a9cab7ee804fd898dca62004f750cc5a1ad685.zip
chromium_src-12a9cab7ee804fd898dca62004f750cc5a1ad685.tar.gz
chromium_src-12a9cab7ee804fd898dca62004f750cc5a1ad685.tar.bz2
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}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/BUILD.gn1
-rw-r--r--extensions/extensions.gyp1
-rw-r--r--extensions/test/data/unpacker/bad_image.crxbin0 -> 1243 bytes
-rw-r--r--extensions/test/data/unpacker/bad_image/background.js5
-rw-r--r--extensions/test/data/unpacker/bad_image/manifest.json7
-rw-r--r--extensions/test/data/unpacker/bad_image/not_really_an_image.png1
-rw-r--r--extensions/test/data/unpacker/bad_zip.crxbin0 -> 8498 bytes
-rw-r--r--extensions/test/data/unpacker/bad_zip/background.js5
-rw-r--r--extensions/test/data/unpacker/bad_zip/bad_zip.pem16
-rwxr-xr-xextensions/test/data/unpacker/bad_zip/bad_zip.sh41
-rw-r--r--extensions/test/data/unpacker/bad_zip/manifest.json9
-rw-r--r--extensions/test/data/unpacker/bad_zip/product_logo_128.pngbin0 -> 10100 bytes
-rw-r--r--extensions/test/data/unpacker/empty_default_locale.crxbin0 -> 521 bytes
-rw-r--r--extensions/test/data/unpacker/empty_default_locale/manifest.json6
-rw-r--r--extensions/test/data/unpacker/good_l10n.crxbin0 -> 1185 bytes
-rw-r--r--extensions/test/data/unpacker/good_l10n/_locales/en_US/messages.json5
-rw-r--r--extensions/test/data/unpacker/good_l10n/_locales/sr/messages.json5
-rw-r--r--extensions/test/data/unpacker/good_l10n/manifest.json6
-rw-r--r--extensions/test/data/unpacker/good_package.crxbin0 -> 11054 bytes
-rw-r--r--extensions/test/data/unpacker/good_package/manifest.json9
-rw-r--r--extensions/test/data/unpacker/good_package/product_logo_128.pngbin0 -> 10100 bytes
-rw-r--r--extensions/test/data/unpacker/has_default_missing_locales.crxbin0 -> 539 bytes
-rw-r--r--extensions/test/data/unpacker/has_default_missing_locales/manifest.json6
-rw-r--r--extensions/test/data/unpacker/invalid_default_locale.crxbin0 -> 542 bytes
-rw-r--r--extensions/test/data/unpacker/invalid_default_locale/manifest.json6
-rw-r--r--extensions/test/data/unpacker/invalid_messages_file.crxbin0 -> 911 bytes
-rw-r--r--extensions/test/data/unpacker/invalid_messages_file/_locales/en_US/messages.json3
-rw-r--r--extensions/test/data/unpacker/invalid_messages_file/manifest.json6
-rw-r--r--extensions/test/data/unpacker/missing_default_data.crxbin0 -> 924 bytes
-rw-r--r--extensions/test/data/unpacker/missing_default_data/_locales/en_US/messages.json5
-rw-r--r--extensions/test/data/unpacker/missing_default_data/manifest.json6
-rw-r--r--extensions/test/data/unpacker/missing_default_has_locales.crxbin0 -> 634 bytes
-rw-r--r--extensions/test/data/unpacker/missing_default_has_locales/manifest.json5
-rw-r--r--extensions/test/data/unpacker/missing_messages_file.crxbin0 -> 748 bytes
-rw-r--r--extensions/test/data/unpacker/missing_messages_file/manifest.json6
-rw-r--r--extensions/test/data/unpacker/no_l10n.crxbin0 -> 513 bytes
-rw-r--r--extensions/test/data/unpacker/no_l10n/manifest.json5
-rw-r--r--extensions/test/data/unpacker/no_locale_data.crxbin0 -> 620 bytes
-rw-r--r--extensions/test/data/unpacker/no_locale_data/manifest.json6
-rw-r--r--extensions/test/test_extensions_client.cc20
-rw-r--r--extensions/test/test_extensions_client.h15
-rw-r--r--extensions/utility/unpacker_unittest.cc205
42 files changed, 411 insertions, 0 deletions
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
--- /dev/null
+++ b/extensions/test/data/unpacker/bad_image.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/bad_zip.crx
Binary files 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 <extension dir> <pem path>"
+ 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
--- /dev/null
+++ b/extensions/test/data/unpacker/bad_zip/product_logo_128.png
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/empty_default_locale.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/good_l10n.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/good_package.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/good_package/product_logo_128.png
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/has_default_missing_locales.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/invalid_default_locale.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/invalid_messages_file.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/missing_default_data.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/missing_default_has_locales.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/missing_messages_file.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/no_l10n.crx
Binary files 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
--- /dev/null
+++ b/extensions/test/data/unpacker/no_locale_data.crx
Binary files 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<base::FilePath> TestExtensionsClient::GetBrowserImagePaths(
+ const Extension* extension) {
+ std::set<base::FilePath> 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<base::FilePath>* 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<base::FilePath> 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<BrowserImagePathsFilter*> 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> 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<base::FilePath>* 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<TestExtensionsClient*>(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