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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 EXPECT_EQ("*foo*", script.exclude_globs().at(0)); 72 EXPECT_EQ("*foo*", script.exclude_globs().at(0));
73 ASSERT_EQ(1u, script.url_patterns().patterns().size()); 73 ASSERT_EQ(1u, script.url_patterns().patterns().size());
74 EXPECT_EQ("http://www.google.com/*", 74 EXPECT_EQ("http://www.google.com/*",
75 script.url_patterns().begin()->GetAsString()); 75 script.url_patterns().begin()->GetAsString());
76 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size()); 76 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size());
77 EXPECT_EQ("http://www.google.com/foo*", 77 EXPECT_EQ("http://www.google.com/foo*",
78 script.exclude_url_patterns().begin()->GetAsString()); 78 script.exclude_url_patterns().begin()->GetAsString());
79 EXPECT_TRUE(script.emulate_greasemonkey()); 79 EXPECT_TRUE(script.emulate_greasemonkey());
80 80
81 // Make sure the files actually exist on disk. 81 // Make sure the files actually exist on disk.
82 EXPECT_TRUE(file_util::PathExists( 82 EXPECT_TRUE(base::PathExists(
83 extension->path().Append(script.js_scripts()[0].relative_path()))); 83 extension->path().Append(script.js_scripts()[0].relative_path())));
84 EXPECT_TRUE(file_util::PathExists( 84 EXPECT_TRUE(base::PathExists(
85 extension->path().Append(kManifestFilename))); 85 extension->path().Append(kManifestFilename)));
86 } 86 }
87 87
88 TEST_F(ExtensionFromUserScript, NoMetadata) { 88 TEST_F(ExtensionFromUserScript, NoMetadata) {
89 base::ScopedTempDir extensions_dir; 89 base::ScopedTempDir extensions_dir;
90 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 90 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
91 91
92 base::FilePath test_file; 92 base::FilePath test_file;
93 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 93 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
94 test_file = test_file.AppendASCII("extensions") 94 test_file = test_file.AppendASCII("extensions")
(...skipping 26 matching lines...) Expand all
121 EXPECT_EQ("*", script.globs()[0]); 121 EXPECT_EQ("*", script.globs()[0]);
122 EXPECT_EQ(0u, script.exclude_globs().size()); 122 EXPECT_EQ(0u, script.exclude_globs().size());
123 EXPECT_TRUE(script.emulate_greasemonkey()); 123 EXPECT_TRUE(script.emulate_greasemonkey());
124 124
125 URLPatternSet expected; 125 URLPatternSet expected;
126 AddPattern(&expected, "http://*/*"); 126 AddPattern(&expected, "http://*/*");
127 AddPattern(&expected, "https://*/*"); 127 AddPattern(&expected, "https://*/*");
128 EXPECT_EQ(expected, script.url_patterns()); 128 EXPECT_EQ(expected, script.url_patterns());
129 129
130 // Make sure the files actually exist on disk. 130 // Make sure the files actually exist on disk.
131 EXPECT_TRUE(file_util::PathExists( 131 EXPECT_TRUE(base::PathExists(
132 extension->path().Append(script.js_scripts()[0].relative_path()))); 132 extension->path().Append(script.js_scripts()[0].relative_path())));
133 EXPECT_TRUE(file_util::PathExists( 133 EXPECT_TRUE(base::PathExists(
134 extension->path().Append(kManifestFilename))); 134 extension->path().Append(kManifestFilename)));
135 } 135 }
136 136
137 TEST_F(ExtensionFromUserScript, NotUTF8) { 137 TEST_F(ExtensionFromUserScript, NotUTF8) {
138 base::ScopedTempDir extensions_dir; 138 base::ScopedTempDir extensions_dir;
139 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 139 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
140 140
141 base::FilePath test_file; 141 base::FilePath test_file;
142 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 142 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
143 test_file = test_file.AppendASCII("extensions") 143 test_file = test_file.AppendASCII("extensions")
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 TEST_F(ExtensionFromUserScript, RunAtDocumentIdle) { 225 TEST_F(ExtensionFromUserScript, RunAtDocumentIdle) {
226 base::ScopedTempDir extensions_dir; 226 base::ScopedTempDir extensions_dir;
227 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 227 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
228 228
229 base::FilePath test_file; 229 base::FilePath test_file;
230 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 230 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
231 test_file = test_file.AppendASCII("extensions") 231 test_file = test_file.AppendASCII("extensions")
232 .AppendASCII("user_script_run_at_idle.user.js"); 232 .AppendASCII("user_script_run_at_idle.user.js");
233 ASSERT_TRUE(file_util::PathExists(test_file)) << test_file.value(); 233 ASSERT_TRUE(base::PathExists(test_file)) << test_file.value();
234 234
235 string16 error; 235 string16 error;
236 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 236 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
237 test_file, GURL("http://www.google.com/foo"), 237 test_file, GURL("http://www.google.com/foo"),
238 extensions_dir.path(), &error)); 238 extensions_dir.path(), &error));
239 239
240 ASSERT_TRUE(extension.get()); 240 ASSERT_TRUE(extension.get());
241 EXPECT_EQ(string16(), error); 241 EXPECT_EQ(string16(), error);
242 242
243 // Use a temp dir so that the extensions dir will clean itself up. 243 // Use a temp dir so that the extensions dir will clean itself up.
244 base::ScopedTempDir ext_dir; 244 base::ScopedTempDir ext_dir;
245 EXPECT_TRUE(ext_dir.Set(extension->path())); 245 EXPECT_TRUE(ext_dir.Set(extension->path()));
246 246
247 // Validate generated extension metadata. 247 // Validate generated extension metadata.
248 EXPECT_EQ("Document Idle Test", extension->name()); 248 EXPECT_EQ("Document Idle Test", extension->name());
249 EXPECT_EQ("This script tests document-idle", extension->description()); 249 EXPECT_EQ("This script tests document-idle", extension->description());
250 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 250 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
251 extension->public_key()); 251 extension->public_key());
252 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType()); 252 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
253 253
254 // Validate run location. 254 // Validate run location.
255 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size()); 255 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size());
256 const UserScript& script = 256 const UserScript& script =
257 ContentScriptsInfo::GetContentScripts(extension.get())[0]; 257 ContentScriptsInfo::GetContentScripts(extension.get())[0];
258 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 258 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
259 } 259 }
260 260
261 } // namespace extensions 261 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698