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

Side by Side Diff: chrome/browser/extensions/convert_user_script_unittest.cc

Issue 11198067: Move extension unpack intermediate dir to Extensions/Temp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: standardize names Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 21 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
22 int schemes = URLPattern::SCHEME_ALL; 22 int schemes = URLPattern::SCHEME_ALL;
23 extent->AddPattern(URLPattern(schemes, pattern)); 23 extent->AddPattern(URLPattern(schemes, pattern));
24 } 24 }
25 25
26 } 26 }
27 27
28 namespace extensions { 28 namespace extensions {
29 29
30 TEST(ExtensionFromUserScript, Basic) { 30 TEST(ExtensionFromUserScript, Basic) {
31 ScopedTempDir extensions_dir;
32 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
33
31 FilePath test_file; 34 FilePath test_file;
32 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
33 test_file = test_file.AppendASCII("extensions") 36 test_file = test_file.AppendASCII("extensions")
34 .AppendASCII("user_script_basic.user.js"); 37 .AppendASCII("user_script_basic.user.js");
35 38
36 string16 error; 39 string16 error;
37 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 40 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
38 test_file, GURL("http://www.google.com/foo"), &error)); 41 test_file, GURL("http://www.google.com/foo"),
42 extensions_dir.path(), &error));
39 43
40 ASSERT_TRUE(extension.get()); 44 ASSERT_TRUE(extension.get());
41 EXPECT_EQ(string16(), error); 45 EXPECT_EQ(string16(), error);
42 46
43 // Use a temp dir so that the extensions dir will clean itself up. 47 // Use a temp dir so that the extensions dir will clean itself up.
44 ScopedTempDir ext_dir; 48 ScopedTempDir ext_dir;
45 EXPECT_TRUE(ext_dir.Set(extension->path())); 49 EXPECT_TRUE(ext_dir.Set(extension->path()));
46 50
47 // Validate generated extension metadata. 51 // Validate generated extension metadata.
48 EXPECT_EQ("My user script", extension->name()); 52 EXPECT_EQ("My user script", extension->name());
(...skipping 18 matching lines...) Expand all
67 script.exclude_url_patterns().begin()->GetAsString()); 71 script.exclude_url_patterns().begin()->GetAsString());
68 72
69 // Make sure the files actually exist on disk. 73 // Make sure the files actually exist on disk.
70 EXPECT_TRUE(file_util::PathExists( 74 EXPECT_TRUE(file_util::PathExists(
71 extension->path().Append(script.js_scripts()[0].relative_path()))); 75 extension->path().Append(script.js_scripts()[0].relative_path())));
72 EXPECT_TRUE(file_util::PathExists( 76 EXPECT_TRUE(file_util::PathExists(
73 extension->path().Append(Extension::kManifestFilename))); 77 extension->path().Append(Extension::kManifestFilename)));
74 } 78 }
75 79
76 TEST(ExtensionFromUserScript, NoMetdata) { 80 TEST(ExtensionFromUserScript, NoMetdata) {
81 ScopedTempDir extensions_dir;
82 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
83
77 FilePath test_file; 84 FilePath test_file;
78 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 85 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
79 test_file = test_file.AppendASCII("extensions") 86 test_file = test_file.AppendASCII("extensions")
80 .AppendASCII("user_script_no_metadata.user.js"); 87 .AppendASCII("user_script_no_metadata.user.js");
81 88
82 string16 error; 89 string16 error;
83 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 90 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
84 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), &error)); 91 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"),
92 extensions_dir.path(), &error));
85 93
86 ASSERT_TRUE(extension.get()); 94 ASSERT_TRUE(extension.get());
87 EXPECT_EQ(string16(), error); 95 EXPECT_EQ(string16(), error);
88 96
89 // Use a temp dir so that the extensions dir will clean itself up. 97 // Use a temp dir so that the extensions dir will clean itself up.
90 ScopedTempDir ext_dir; 98 ScopedTempDir ext_dir;
91 EXPECT_TRUE(ext_dir.Set(extension->path())); 99 EXPECT_TRUE(ext_dir.Set(extension->path()));
92 100
93 // Validate generated extension metadata. 101 // Validate generated extension metadata.
94 EXPECT_EQ("bar.user.js", extension->name()); 102 EXPECT_EQ("bar.user.js", extension->name());
(...skipping 14 matching lines...) Expand all
109 EXPECT_EQ(expected, script.url_patterns()); 117 EXPECT_EQ(expected, script.url_patterns());
110 118
111 // Make sure the files actually exist on disk. 119 // Make sure the files actually exist on disk.
112 EXPECT_TRUE(file_util::PathExists( 120 EXPECT_TRUE(file_util::PathExists(
113 extension->path().Append(script.js_scripts()[0].relative_path()))); 121 extension->path().Append(script.js_scripts()[0].relative_path())));
114 EXPECT_TRUE(file_util::PathExists( 122 EXPECT_TRUE(file_util::PathExists(
115 extension->path().Append(Extension::kManifestFilename))); 123 extension->path().Append(Extension::kManifestFilename)));
116 } 124 }
117 125
118 TEST(ExtensionFromUserScript, NotUTF8) { 126 TEST(ExtensionFromUserScript, NotUTF8) {
127 ScopedTempDir extensions_dir;
128 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
129
119 FilePath test_file; 130 FilePath test_file;
120
121 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 131 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
122 test_file = test_file.AppendASCII("extensions") 132 test_file = test_file.AppendASCII("extensions")
123 .AppendASCII("user_script_not_utf8.user.js"); 133 .AppendASCII("user_script_not_utf8.user.js");
124 134
125 string16 error; 135 string16 error;
126 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 136 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
127 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), &error)); 137 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"),
138 extensions_dir.path(), &error));
128 139
129 ASSERT_FALSE(extension.get()); 140 ASSERT_FALSE(extension.get());
130 EXPECT_EQ(ASCIIToUTF16("User script must be UTF8 encoded."), error); 141 EXPECT_EQ(ASCIIToUTF16("User script must be UTF8 encoded."), error);
131 } 142 }
132 143
133 TEST(ExtensionFromUserScript, RunAtDocumentStart) { 144 TEST(ExtensionFromUserScript, RunAtDocumentStart) {
145 ScopedTempDir extensions_dir;
146 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
147
134 FilePath test_file; 148 FilePath test_file;
135 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 149 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
136 test_file = test_file.AppendASCII("extensions") 150 test_file = test_file.AppendASCII("extensions")
137 .AppendASCII("user_script_run_at_start.user.js"); 151 .AppendASCII("user_script_run_at_start.user.js");
138 152
139 string16 error; 153 string16 error;
140 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 154 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
141 test_file, GURL("http://www.google.com/foo"), &error)); 155 test_file, GURL("http://www.google.com/foo"),
156 extensions_dir.path(), &error));
142 157
143 ASSERT_TRUE(extension.get()); 158 ASSERT_TRUE(extension.get());
144 EXPECT_EQ(string16(), error); 159 EXPECT_EQ(string16(), error);
145 160
146 // Use a temp dir so that the extensions dir will clean itself up. 161 // Use a temp dir so that the extensions dir will clean itself up.
147 ScopedTempDir ext_dir; 162 ScopedTempDir ext_dir;
148 EXPECT_TRUE(ext_dir.Set(extension->path())); 163 EXPECT_TRUE(ext_dir.Set(extension->path()));
149 164
150 // Validate generated extension metadata. 165 // Validate generated extension metadata.
151 EXPECT_EQ("Document Start Test", extension->name()); 166 EXPECT_EQ("Document Start Test", extension->name());
152 EXPECT_EQ("This script tests document-start", extension->description()); 167 EXPECT_EQ("This script tests document-start", extension->description());
153 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=", 168 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=",
154 extension->public_key()); 169 extension->public_key());
155 170
156 // Validate run location. 171 // Validate run location.
157 ASSERT_EQ(1u, extension->content_scripts().size()); 172 ASSERT_EQ(1u, extension->content_scripts().size());
158 const UserScript& script = extension->content_scripts()[0]; 173 const UserScript& script = extension->content_scripts()[0];
159 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location()); 174 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location());
160 } 175 }
161 176
162 TEST(ExtensionFromUserScript, RunAtDocumentEnd) { 177 TEST(ExtensionFromUserScript, RunAtDocumentEnd) {
178 ScopedTempDir extensions_dir;
179 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
180
163 FilePath test_file; 181 FilePath test_file;
164 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 182 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
165 test_file = test_file.AppendASCII("extensions") 183 test_file = test_file.AppendASCII("extensions")
166 .AppendASCII("user_script_run_at_end.user.js"); 184 .AppendASCII("user_script_run_at_end.user.js");
167 185
168 string16 error; 186 string16 error;
169 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 187 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
170 test_file, GURL("http://www.google.com/foo"), &error)); 188 test_file, GURL("http://www.google.com/foo"),
189 extensions_dir.path(), &error));
171 190
172 ASSERT_TRUE(extension.get()); 191 ASSERT_TRUE(extension.get());
173 EXPECT_EQ(string16(), error); 192 EXPECT_EQ(string16(), error);
174 193
175 // Use a temp dir so that the extensions dir will clean itself up. 194 // Use a temp dir so that the extensions dir will clean itself up.
176 ScopedTempDir ext_dir; 195 ScopedTempDir ext_dir;
177 EXPECT_TRUE(ext_dir.Set(extension->path())); 196 EXPECT_TRUE(ext_dir.Set(extension->path()));
178 197
179 // Validate generated extension metadata. 198 // Validate generated extension metadata.
180 EXPECT_EQ("Document End Test", extension->name()); 199 EXPECT_EQ("Document End Test", extension->name());
181 EXPECT_EQ("This script tests document-end", extension->description()); 200 EXPECT_EQ("This script tests document-end", extension->description());
182 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=", 201 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=",
183 extension->public_key()); 202 extension->public_key());
184 203
185 // Validate run location. 204 // Validate run location.
186 ASSERT_EQ(1u, extension->content_scripts().size()); 205 ASSERT_EQ(1u, extension->content_scripts().size());
187 const UserScript& script = extension->content_scripts()[0]; 206 const UserScript& script = extension->content_scripts()[0];
188 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location()); 207 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location());
189 } 208 }
190 209
191 TEST(ExtensionFromUserScript, RunAtDocumentIdle) { 210 TEST(ExtensionFromUserScript, RunAtDocumentIdle) {
211 ScopedTempDir extensions_dir;
212 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
213
192 FilePath test_file; 214 FilePath test_file;
193 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 215 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
194 test_file = test_file.AppendASCII("extensions") 216 test_file = test_file.AppendASCII("extensions")
195 .AppendASCII("user_script_run_at_idle.user.js"); 217 .AppendASCII("user_script_run_at_idle.user.js");
196 ASSERT_TRUE(file_util::PathExists(test_file)) << test_file.value(); 218 ASSERT_TRUE(file_util::PathExists(test_file)) << test_file.value();
197 219
198 string16 error; 220 string16 error;
199 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 221 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
200 test_file, GURL("http://www.google.com/foo"), &error)); 222 test_file, GURL("http://www.google.com/foo"),
223 extensions_dir.path(), &error));
201 224
202 ASSERT_TRUE(extension.get()); 225 ASSERT_TRUE(extension.get());
203 EXPECT_EQ(string16(), error); 226 EXPECT_EQ(string16(), error);
204 227
205 // Use a temp dir so that the extensions dir will clean itself up. 228 // Use a temp dir so that the extensions dir will clean itself up.
206 ScopedTempDir ext_dir; 229 ScopedTempDir ext_dir;
207 EXPECT_TRUE(ext_dir.Set(extension->path())); 230 EXPECT_TRUE(ext_dir.Set(extension->path()));
208 231
209 // Validate generated extension metadata. 232 // Validate generated extension metadata.
210 EXPECT_EQ("Document Idle Test", extension->name()); 233 EXPECT_EQ("Document Idle Test", extension->name());
211 EXPECT_EQ("This script tests document-idle", extension->description()); 234 EXPECT_EQ("This script tests document-idle", extension->description());
212 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 235 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
213 extension->public_key()); 236 extension->public_key());
214 237
215 // Validate run location. 238 // Validate run location.
216 ASSERT_EQ(1u, extension->content_scripts().size()); 239 ASSERT_EQ(1u, extension->content_scripts().size());
217 const UserScript& script = extension->content_scripts()[0]; 240 const UserScript& script = extension->content_scripts()[0];
218 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 241 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
219 } 242 }
220 243
221 } // namespace extensions 244 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/convert_user_script.cc ('k') | chrome/browser/extensions/convert_web_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698