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

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

Issue 2245143004: Make sure there is no crash on parsing empty manifest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup! Make sure there is no crash on parsing empty manifest Created 4 years, 4 months 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
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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", std::string()); 94 kManifest, "international_key", std::string());
95 EXPECT_EQ(kInternationalFeature, international_feature.GetFeature()); 95 EXPECT_EQ(kInternationalFeature, international_feature.GetFeature());
96
97 // Empty manifest. Check that there is no crash.
98 const char kEmptyManifest[] = "";
99 ManifestHighlighter no_feature(kEmptyManifest, std::string(), std::string());
100 EXPECT_EQ(std::string(), no_feature.GetFeature());
96 } 101 }
97 102
98 TEST(SouceHighlighterUnitTest, SourceHighlighterUnitTest) { 103 TEST(SouceHighlighterUnitTest, SourceHighlighterUnitTest) {
99 const char kBasicSourceFile[] = "line one\nline two\nline three"; 104 const char kBasicSourceFile[] = "line one\nline two\nline three";
100 105
101 SourceHighlighter basic1(kBasicSourceFile, 1u); 106 SourceHighlighter basic1(kBasicSourceFile, 1u);
102 EXPECT_EQ("line one", basic1.GetFeature()); 107 EXPECT_EQ("line one", basic1.GetFeature());
103 SourceHighlighter basic2(kBasicSourceFile, 2u); 108 SourceHighlighter basic2(kBasicSourceFile, 2u);
104 EXPECT_EQ("line two", basic2.GetFeature()); 109 EXPECT_EQ("line two", basic2.GetFeature());
105 SourceHighlighter basic3(kBasicSourceFile, 3u); 110 SourceHighlighter basic3(kBasicSourceFile, 3u);
106 EXPECT_EQ("line three", basic3.GetFeature()); 111 EXPECT_EQ("line three", basic3.GetFeature());
107 112
108 const char kNoNewlineSourceFile[] = "thisisonelonglinewithnobreaksinit"; 113 const char kNoNewlineSourceFile[] = "thisisonelonglinewithnobreaksinit";
109 114
110 SourceHighlighter full_line(kNoNewlineSourceFile, 1u); 115 SourceHighlighter full_line(kNoNewlineSourceFile, 1u);
111 EXPECT_EQ(kNoNewlineSourceFile, full_line.GetFeature()); 116 EXPECT_EQ(kNoNewlineSourceFile, full_line.GetFeature());
112 117
113 SourceHighlighter line_zero(kNoNewlineSourceFile, 0u); 118 SourceHighlighter line_zero(kNoNewlineSourceFile, 0u);
114 EXPECT_EQ(std::string(), line_zero.GetFeature()); 119 EXPECT_EQ(std::string(), line_zero.GetFeature());
115 120
116 SourceHighlighter out_of_bounds(kNoNewlineSourceFile, 2u); 121 SourceHighlighter out_of_bounds(kNoNewlineSourceFile, 2u);
117 EXPECT_EQ(std::string(), out_of_bounds.GetFeature()); 122 EXPECT_EQ(std::string(), out_of_bounds.GetFeature());
118 } 123 }
119 124
120 } // namespace extensions 125 } // namespace extensions
OLDNEW
« extensions/browser/file_highlighter.cc ('K') | « extensions/browser/file_highlighter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698