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

Side by Side Diff: extensions/browser/file_highlighter_unittest.cc

Issue 89243003: Move EmptyString, kWhitespace and the BOM to base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/file_highlighter.h" 5 #include "extensions/browser/file_highlighter.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 } // namespace 43 } // namespace
44 44
45 TEST(ManifestHighlighterUnitTest, ManifestHighlighterUnitTest) { 45 TEST(ManifestHighlighterUnitTest, ManifestHighlighterUnitTest) {
46 // Get a full key. 46 // Get a full key.
47 const char kPermissionsFeature[] = 47 const char kPermissionsFeature[] =
48 "\"permissions\": [\n" 48 "\"permissions\": [\n"
49 " /* This is a tricky comment because it has brackets }]*/\n" 49 " /* This is a tricky comment because it has brackets }]*/\n"
50 " \"tabs\"\n" 50 " \"tabs\"\n"
51 " ]"; 51 " ]";
52 ManifestHighlighter permissions(kManifest, "permissions", EmptyString()); 52 ManifestHighlighter permissions(kManifest, "permissions", std::string());
53 EXPECT_EQ(kPermissionsFeature, permissions.GetFeature()); 53 EXPECT_EQ(kPermissionsFeature, permissions.GetFeature());
54 54
55 // Get a specific portion of a key. 55 // Get a specific portion of a key.
56 const char kTabsFeature[] = "\"tabs\""; 56 const char kTabsFeature[] = "\"tabs\"";
57 ManifestHighlighter tabs(kManifest, "permissions", "tabs"); 57 ManifestHighlighter tabs(kManifest, "permissions", "tabs");
58 EXPECT_EQ(kTabsFeature, tabs.GetFeature()); 58 EXPECT_EQ(kTabsFeature, tabs.GetFeature());
59 59
60 // Get a single-character, non-quoted entity of a key. 60 // Get a single-character, non-quoted entity of a key.
61 const char kManifestVersionFeature[] = "2"; 61 const char kManifestVersionFeature[] = "2";
62 ManifestHighlighter version(kManifest, "manifest_version", "2"); 62 ManifestHighlighter version(kManifest, "manifest_version", "2");
63 EXPECT_EQ(kManifestVersionFeature, version.GetFeature()); 63 EXPECT_EQ(kManifestVersionFeature, version.GetFeature());
64 64
65 // Get a compound portion of a key, including quoted '//' (which shouldn't be 65 // Get a compound portion of a key, including quoted '//' (which shouldn't be
66 // mistaken for comments). 66 // mistaken for comments).
67 const char kMatchesFeature[] = 67 const char kMatchesFeature[] =
68 "\"matches\": [\"*://aaronboodman.com/*\", \"*://rdcronin.com/*\"]"; 68 "\"matches\": [\"*://aaronboodman.com/*\", \"*://rdcronin.com/*\"]";
69 ManifestHighlighter matches(kManifest, "content_scripts", "matches"); 69 ManifestHighlighter matches(kManifest, "content_scripts", "matches");
70 EXPECT_EQ(kMatchesFeature, matches.GetFeature()); 70 EXPECT_EQ(kMatchesFeature, matches.GetFeature());
71 71
72 // If a feature isn't present, we should get an empty string. 72 // If a feature isn't present, we should get an empty string.
73 ManifestHighlighter not_present(kManifest, "a_fake_feature", EmptyString()); 73 ManifestHighlighter not_present(kManifest, "a_fake_feature", std::string());
74 EXPECT_EQ(EmptyString(), not_present.GetFeature()); 74 EXPECT_EQ(std::string(), not_present.GetFeature());
75 75
76 // If we request a specific portion of a key which is not found, we should 76 // If we request a specific portion of a key which is not found, we should
77 // get an empty string. 77 // get an empty string.
78 ManifestHighlighter specific_portion_not_present( 78 ManifestHighlighter specific_portion_not_present(
79 kManifest, "permissions", "a_fake_feature"); 79 kManifest, "permissions", "a_fake_feature");
80 EXPECT_EQ(EmptyString(), specific_portion_not_present.GetFeature()); 80 EXPECT_EQ(std::string(), specific_portion_not_present.GetFeature());
81 81
82 const char kEscapedQuotedFeature[] = "\"escaped_quoted\\\"\""; 82 const char kEscapedQuotedFeature[] = "\"escaped_quoted\\\"\"";
83 ManifestHighlighter escaped_quoted( 83 ManifestHighlighter escaped_quoted(
84 kManifest, "test_key", "escaped_quoted\\\""); 84 kManifest, "test_key", "escaped_quoted\\\"");
85 EXPECT_EQ(kEscapedQuotedFeature, escaped_quoted.GetFeature()); 85 EXPECT_EQ(kEscapedQuotedFeature, escaped_quoted.GetFeature());
86 86
87 const char kFeatureWithComment[] = "\"/*foo*/\""; 87 const char kFeatureWithComment[] = "\"/*foo*/\"";
88 ManifestHighlighter feature_with_comment(kManifest, "test_key", "/*foo*/"); 88 ManifestHighlighter feature_with_comment(kManifest, "test_key", "/*foo*/");
89 EXPECT_EQ(kFeatureWithComment, feature_with_comment.GetFeature()); 89 EXPECT_EQ(kFeatureWithComment, feature_with_comment.GetFeature());
90 90
91 // Check with non-ascii characters. 91 // Check with non-ascii characters.
92 const char kInternationalFeature[] = "\"international_key\": \"還是不要\""; 92 const char kInternationalFeature[] = "\"international_key\": \"還是不要\"";
93 ManifestHighlighter international_feature( 93 ManifestHighlighter international_feature(
94 kManifest, "international_key", EmptyString()); 94 kManifest, "international_key", std::string());
95 EXPECT_EQ(kInternationalFeature, international_feature.GetFeature()); 95 EXPECT_EQ(kInternationalFeature, international_feature.GetFeature());
96 } 96 }
97 97
98 TEST(SouceHighlighterUnitTest, SourceHighlighterUnitTest) { 98 TEST(SouceHighlighterUnitTest, SourceHighlighterUnitTest) {
99 const char kBasicSourceFile[] = "line one\nline two\nline three"; 99 const char kBasicSourceFile[] = "line one\nline two\nline three";
100 100
101 SourceHighlighter basic1(kBasicSourceFile, 1u); 101 SourceHighlighter basic1(kBasicSourceFile, 1u);
102 EXPECT_EQ("line one", basic1.GetFeature()); 102 EXPECT_EQ("line one", basic1.GetFeature());
103 SourceHighlighter basic2(kBasicSourceFile, 2u); 103 SourceHighlighter basic2(kBasicSourceFile, 2u);
104 EXPECT_EQ("line two", basic2.GetFeature()); 104 EXPECT_EQ("line two", basic2.GetFeature());
105 SourceHighlighter basic3(kBasicSourceFile, 3u); 105 SourceHighlighter basic3(kBasicSourceFile, 3u);
106 EXPECT_EQ("line three", basic3.GetFeature()); 106 EXPECT_EQ("line three", basic3.GetFeature());
107 107
108 const char kNoNewlineSourceFile[] = "thisisonelonglinewithnobreaksinit"; 108 const char kNoNewlineSourceFile[] = "thisisonelonglinewithnobreaksinit";
109 109
110 SourceHighlighter full_line(kNoNewlineSourceFile, 1u); 110 SourceHighlighter full_line(kNoNewlineSourceFile, 1u);
111 EXPECT_EQ(kNoNewlineSourceFile, full_line.GetFeature()); 111 EXPECT_EQ(kNoNewlineSourceFile, full_line.GetFeature());
112 112
113 SourceHighlighter line_zero(kNoNewlineSourceFile, 0u); 113 SourceHighlighter line_zero(kNoNewlineSourceFile, 0u);
114 EXPECT_EQ(EmptyString(), line_zero.GetFeature()); 114 EXPECT_EQ(std::string(), line_zero.GetFeature());
115 115
116 SourceHighlighter out_of_bounds(kNoNewlineSourceFile, 2u); 116 SourceHighlighter out_of_bounds(kNoNewlineSourceFile, 2u);
117 EXPECT_EQ(EmptyString(), out_of_bounds.GetFeature()); 117 EXPECT_EQ(std::string(), out_of_bounds.GetFeature());
118 } 118 }
119 119
120 } // namespace extensions 120 } // namespace extensions
OLDNEW
« no previous file with comments | « content/renderer/media/crypto/proxy_decryptor.cc ('k') | extensions/common/manifest_handlers/csp_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698