OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 "extensions/browser/manifest_highlighter.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 namespace { |
| 16 |
| 17 const char kManifest[] = |
| 18 "{\n" |
| 19 " \"name\": \"Content Scripts\",\n" |
| 20 " \"version\": \"2.0\",\n" |
| 21 " // this is a comment with the word permissions.\n" |
| 22 " /* This is a multine\n" |
| 23 " comment with the word permissions\n" |
| 24 " that shouldn't be highlighted */\n" |
| 25 " \"permissions\": [\n" |
| 26 " /* This is a tricky comment because it has brackets }]*/\n" |
| 27 " \"tabs\"\n" |
| 28 " ],\n" |
| 29 " \"content_scripts\": [\n" |
| 30 " {\n" |
| 31 " \"matches\": [\"*://aaronboodman.com/*\", \"*://rdcronin.com/*\"],\n" |
| 32 " \"js\": [\"myscript.js\"]\n" |
| 33 " }\n" |
| 34 " ],\n" |
| 35 " \"test_key\": {\n" |
| 36 " \"escaped_quoted\\\"\",\n" |
| 37 " \"/*foo*/\"\n" |
| 38 " }\n" |
| 39 " \"manifest_version\": 2,\n" |
| 40 "}"; |
| 41 |
| 42 } // namespace |
| 43 |
| 44 TEST(ManifestHighlighterUnitTest, ManifestHighlighterUnitTest) { |
| 45 // Get a full key. |
| 46 const char kPermissionsFeature[] = |
| 47 "\"permissions\": [\n" |
| 48 " /* This is a tricky comment because it has brackets }]*/\n" |
| 49 " \"tabs\"\n" |
| 50 " ]"; |
| 51 ManifestHighlighter permissions(kManifest, "permissions", EmptyString()); |
| 52 EXPECT_EQ(kPermissionsFeature, permissions.GetFeature()); |
| 53 |
| 54 // Get a specific portion of a key. |
| 55 const char kTabsFeature[] = "\"tabs\""; |
| 56 ManifestHighlighter tabs(kManifest, "permissions", "tabs"); |
| 57 EXPECT_EQ(kTabsFeature, tabs.GetFeature()); |
| 58 |
| 59 // Get a single-character, non-quoted entity of a key. |
| 60 const char kManifestVersionFeature[] = "2"; |
| 61 ManifestHighlighter version(kManifest, "manifest_version", "2"); |
| 62 EXPECT_EQ(kManifestVersionFeature, version.GetFeature()); |
| 63 |
| 64 // Get a compound portion of a key, including quoted '//' (which shouldn't be |
| 65 // mistaken for comments). |
| 66 const char kMatchesFeature[] = |
| 67 "\"matches\": [\"*://aaronboodman.com/*\", \"*://rdcronin.com/*\"]"; |
| 68 ManifestHighlighter matches(kManifest, "content_scripts", "matches"); |
| 69 EXPECT_EQ(kMatchesFeature, matches.GetFeature()); |
| 70 |
| 71 // If a feature isn't present, we should get an empty string. |
| 72 ManifestHighlighter not_present(kManifest, "a_fake_feature", EmptyString()); |
| 73 EXPECT_EQ(EmptyString(), not_present.GetFeature()); |
| 74 |
| 75 // If we request a specific portion of a key which is not found, we should |
| 76 // get an empty string. |
| 77 ManifestHighlighter specific_portion_not_present( |
| 78 kManifest, "permissions", "a_fake_feature"); |
| 79 EXPECT_EQ(EmptyString(), specific_portion_not_present.GetFeature()); |
| 80 |
| 81 const char kEscapedQuotedFeature[] = "\"escaped_quoted\\\"\""; |
| 82 ManifestHighlighter escaped_quoted( |
| 83 kManifest, "test_key", "escaped_quoted\\\""); |
| 84 EXPECT_EQ(kEscapedQuotedFeature, escaped_quoted.GetFeature()); |
| 85 |
| 86 const char kFeatureWithComment[] = "\"/*foo*/\""; |
| 87 ManifestHighlighter feature_with_comment(kManifest, "test_key", "/*foo*/"); |
| 88 EXPECT_EQ(kFeatureWithComment, feature_with_comment.GetFeature()); |
| 89 } |
| 90 |
| 91 } // namespace extensions |
OLD | NEW |