summaryrefslogtreecommitdiffstats
path: root/extensions/common/manifest_handlers/icons_handler_unittest.cc
blob: fa644a940ce4f434f250cc93be4c9aa0e382f8a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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_handlers/icons_handler.h"
#include "extensions/common/manifest_test.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace extensions {

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(
        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);
    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 key in 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 key in icons: \"0\".");
  }
  // NaN.
  {
    scoped_ptr<base::DictionaryValue> ext_manifest =
        CreateManifest("\"sixteen\": \"icon3.png\", \n");
    ManifestData manifest(std::move(ext_manifest), "test");
    LoadAndExpectError(manifest, "Invalid key in 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