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 " \"manifest_version\": 2,\n" |
| 36 "}"; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 TEST(ManifestHighlighterUnitTest, ManifestHighlighterUnitTest) { |
| 41 // Get a full key. |
| 42 const char kPermissionsFeature[] = |
| 43 "\"permissions\": [\n" |
| 44 " /* This is a tricky comment because it has brackets }]*/\n" |
| 45 " \"tabs\"\n" |
| 46 " ]"; |
| 47 ManifestHighlighter permissions(kManifest, "permissions", EmptyString()); |
| 48 EXPECT_EQ(kPermissionsFeature, permissions.GetFeature()); |
| 49 |
| 50 // Get a specific portion of a key. |
| 51 const char kTabsFeature[] = "\"tabs\""; |
| 52 ManifestHighlighter tabs(kManifest, "permissions", "tabs"); |
| 53 EXPECT_EQ(kTabsFeature, tabs.GetFeature()); |
| 54 |
| 55 // Get a single-character, non-quoted entity of a key. |
| 56 const char kManifestVersionFeature[] = "2"; |
| 57 ManifestHighlighter version(kManifest, "manifest_version", "2"); |
| 58 EXPECT_EQ(kManifestVersionFeature, version.GetFeature()); |
| 59 |
| 60 // Get a compound portion of a key, including quoted '//' (which shouldn't be |
| 61 // mistaken for comments). |
| 62 const char kMatchesFeature[] = |
| 63 "\"matches\": [\"*://aaronboodman.com/*\", \"*://rdcronin.com/*\"]"; |
| 64 ManifestHighlighter matches(kManifest, "content_scripts", "matches"); |
| 65 EXPECT_EQ(kMatchesFeature, matches.GetFeature()); |
| 66 |
| 67 // If a feature isn't present, we should get an empty string. |
| 68 ManifestHighlighter not_present(kManifest, "a_fake_feature", EmptyString()); |
| 69 EXPECT_EQ(EmptyString(), not_present.GetFeature()); |
| 70 |
| 71 // If we request a specific portion of a key which is not found, we should |
| 72 // get an empty string. |
| 73 ManifestHighlighter specific_portion_not_present( |
| 74 kManifest, "permissions", "a_fake_feature"); |
| 75 EXPECT_EQ(EmptyString(), specific_portion_not_present.GetFeature()); |
| 76 } |
| 77 |
| 78 } // namespace extensions |
OLD | NEW |