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

Unified Diff: extensions/common/manifest_handlers/icons_handler_unittest.cc

Issue 1618073002: Extensions - Check for too big or too small product icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/common/manifest_handlers/icons_handler_unittest.cc
diff --git a/extensions/common/manifest_handlers/icons_handler_unittest.cc b/extensions/common/manifest_handlers/icons_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b5c4ad385518373f8377aab93bbb94c9bc39fe8a
--- /dev/null
+++ b/extensions/common/manifest_handlers/icons_handler_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright 2016 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/test/values_test_util.h"
+#include "extensions/common/manifest_constants.h"
+#include "extensions/common/manifest_handlers/icons_handler.h"
+#include "extensions/common/manifest_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+namespace {
+
+// Produces extension ID = "mdbihdcgjmagbcapkhhkjbbdlkflmbfo".
+const char kExtensionKey[] =
+ "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCV9PlZjcTIXfnlB3HXo50OlM/CnIq0y7jm"
+ "KfPVyStaWsmFB7NaVnqUXoGb9swBDfVnZ6BrupwnxL76TWEJPo+KQMJ6uz0PPdJWi2jQfZiG"
+ "iheDiKH5Gv+dVd67qf7ly8QWW0o8qmFpqBZQpksm1hOGbfsupv9W4c42tMEIicDMLQIDAQAB";
+
+} // namespace
+
+class ProductIconManifestTest : public ManifestTest {
+ public:
+ ProductIconManifestTest() {}
+
+ protected:
+ scoped_ptr<base::DictionaryValue> CreateManifest(
+ const std::string& extra_icons) {
+ scoped_ptr<base::DictionaryValue> manifest = base::DictionaryValue::From(
Devlin 2016/01/22 23:41:56 IMO, extensions::DictionaryBuilder makes this clea
Evan Stade 2016/01/23 02:28:37 Acknowledged.
+ base::test::ParseJson("{ \n"
+ " \"name\": \"test\", \n"
+ " \"version\": \"0.1\", \n"
+ " \"manifest_version\": 2, \n"
+ " \"icons\": { \n" +
+ extra_icons + " \"16\": \"icon1.png\", \n"
+ " \"32\": \"icon2.png\" \n"
+ " } \n"
+ "} \n"));
+ EXPECT_TRUE(manifest);
+ manifest->SetString(manifest_keys::kKey, kExtensionKey);
Devlin 2016/01/22 23:41:56 Is this needed for anything?
Evan Stade 2016/01/23 02:28:37 Done.
+ return manifest;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ProductIconManifestTest);
+};
+
+TEST_F(ProductIconManifestTest, Sizes) {
+ // Too big.
+ {
+ scoped_ptr<base::DictionaryValue> ext_manifest =
+ CreateManifest("\"100000\": \"icon3.png\", \n");
+ ManifestData manifest(std::move(ext_manifest), "test");
+ LoadAndExpectError(manifest, "Invalid value for 'icons[\"100000\"]'.");
+ }
+ // Too small.
+ {
+ scoped_ptr<base::DictionaryValue> ext_manifest =
+ CreateManifest("\"0\": \"icon3.png\", \n");
+ ManifestData manifest(std::move(ext_manifest), "test");
+ LoadAndExpectError(manifest, "Invalid value for 'icons[\"0\"]'.");
+ }
+ // NaN.
+ {
+ scoped_ptr<base::DictionaryValue> ext_manifest =
+ CreateManifest("\"sixteen\": \"icon3.png\", \n");
+ ManifestData manifest(std::move(ext_manifest), "test");
+ LoadAndExpectError(manifest, "Invalid value for 'icons[\"sixteen\"]'.");
+ }
+ // Just right.
+ {
+ scoped_ptr<base::DictionaryValue> ext_manifest =
+ CreateManifest("\"512\": \"icon3.png\", \n");
+ ManifestData manifest(std::move(ext_manifest), "test");
+ scoped_refptr<extensions::Extension> extension =
+ LoadAndExpectSuccess(manifest);
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698