Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / manifest_tests / extension_manifests_manifest_version_unittest.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
6
7 #include "extensions/common/manifest_constants.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10
11 using extensions::Extension;
12
13 namespace errors = extensions::manifest_errors;
14
15 TEST_F(ChromeManifestTest, ManifestVersionError) {
16   scoped_ptr<base::DictionaryValue> manifest1(new base::DictionaryValue());
17   manifest1->SetString("name", "Miles");
18   manifest1->SetString("version", "0.55");
19
20   scoped_ptr<base::DictionaryValue> manifest2(manifest1->DeepCopy());
21   manifest2->SetInteger("manifest_version", 1);
22
23   scoped_ptr<base::DictionaryValue> manifest3(manifest1->DeepCopy());
24   manifest3->SetInteger("manifest_version", 2);
25
26   struct {
27     const char* test_name;
28     bool require_modern_manifest_version;
29     base::DictionaryValue* manifest;
30     bool expect_error;
31   } test_data[] = {
32     { "require_modern_with_default", true, manifest1.get(), true },
33     { "require_modern_with_v1", true, manifest2.get(), true },
34     { "require_modern_with_v2", true, manifest3.get(), false },
35     { "dont_require_modern_with_default", false, manifest1.get(), false },
36     { "dont_require_modern_with_v1", false, manifest2.get(), false },
37     { "dont_require_modern_with_v2", false, manifest3.get(), false },
38   };
39
40   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
41     int create_flags = Extension::NO_FLAGS;
42     if (test_data[i].require_modern_manifest_version)
43       create_flags |= Extension::REQUIRE_MODERN_MANIFEST_VERSION;
44     if (test_data[i].expect_error) {
45         LoadAndExpectError(
46             ManifestData(test_data[i].manifest,
47                      test_data[i].test_name),
48             errors::kInvalidManifestVersionOld,
49             extensions::Manifest::UNPACKED,
50             create_flags);
51     } else {
52       LoadAndExpectSuccess(ManifestData(test_data[i].manifest,
53                                     test_data[i].test_name),
54                            extensions::Manifest::UNPACKED,
55                            create_flags);
56     }
57   }
58 }