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

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

Issue 15685013: Test for user scripts getting greasemonkey APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // Use a temp dir so that the extensions dir will clean itself up. 52 // Use a temp dir so that the extensions dir will clean itself up.
53 base::ScopedTempDir ext_dir; 53 base::ScopedTempDir ext_dir;
54 EXPECT_TRUE(ext_dir.Set(extension->path())); 54 EXPECT_TRUE(ext_dir.Set(extension->path()));
55 55
56 // Validate generated extension metadata. 56 // Validate generated extension metadata.
57 EXPECT_EQ("My user script", extension->name()); 57 EXPECT_EQ("My user script", extension->name());
58 EXPECT_EQ("2.2.2", extension->VersionString()); 58 EXPECT_EQ("2.2.2", extension->VersionString());
59 EXPECT_EQ("Does totally awesome stuff.", extension->description()); 59 EXPECT_EQ("Does totally awesome stuff.", extension->description());
60 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=", 60 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=",
61 extension->public_key()); 61 extension->public_key());
62 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
62 63
63 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); 64 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
64 const UserScript& script = 65 const UserScript& script =
65 ContentScriptsInfo::GetContentScripts(extension)[0]; 66 ContentScriptsInfo::GetContentScripts(extension)[0];
66 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 67 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
67 ASSERT_EQ(2u, script.globs().size()); 68 ASSERT_EQ(2u, script.globs().size());
68 EXPECT_EQ("http://www.google.com/*", script.globs().at(0)); 69 EXPECT_EQ("http://www.google.com/*", script.globs().at(0));
69 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1)); 70 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1));
70 ASSERT_EQ(1u, script.exclude_globs().size()); 71 ASSERT_EQ(1u, script.exclude_globs().size());
71 EXPECT_EQ("*foo*", script.exclude_globs().at(0)); 72 EXPECT_EQ("*foo*", script.exclude_globs().at(0));
72 ASSERT_EQ(1u, script.url_patterns().patterns().size()); 73 ASSERT_EQ(1u, script.url_patterns().patterns().size());
73 EXPECT_EQ("http://www.google.com/*", 74 EXPECT_EQ("http://www.google.com/*",
74 script.url_patterns().begin()->GetAsString()); 75 script.url_patterns().begin()->GetAsString());
75 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size()); 76 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size());
76 EXPECT_EQ("http://www.google.com/foo*", 77 EXPECT_EQ("http://www.google.com/foo*",
77 script.exclude_url_patterns().begin()->GetAsString()); 78 script.exclude_url_patterns().begin()->GetAsString());
79 EXPECT_TRUE(script.emulate_greasemonkey());
78 80
79 // Make sure the files actually exist on disk. 81 // Make sure the files actually exist on disk.
80 EXPECT_TRUE(file_util::PathExists( 82 EXPECT_TRUE(file_util::PathExists(
81 extension->path().Append(script.js_scripts()[0].relative_path()))); 83 extension->path().Append(script.js_scripts()[0].relative_path())));
82 EXPECT_TRUE(file_util::PathExists( 84 EXPECT_TRUE(file_util::PathExists(
83 extension->path().Append(kManifestFilename))); 85 extension->path().Append(kManifestFilename)));
84 } 86 }
85 87
86 TEST_F(ExtensionFromUserScript, NoMetdata) { 88 TEST_F(ExtensionFromUserScript, NoMetadata) {
87 base::ScopedTempDir extensions_dir; 89 base::ScopedTempDir extensions_dir;
88 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 90 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
89 91
90 base::FilePath test_file; 92 base::FilePath test_file;
91 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 93 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
92 test_file = test_file.AppendASCII("extensions") 94 test_file = test_file.AppendASCII("extensions")
93 .AppendASCII("user_script_no_metadata.user.js"); 95 .AppendASCII("user_script_no_metadata.user.js");
94 96
95 string16 error; 97 string16 error;
96 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 98 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
97 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), 99 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"),
98 extensions_dir.path(), &error)); 100 extensions_dir.path(), &error));
99 101
100 ASSERT_TRUE(extension.get()); 102 ASSERT_TRUE(extension.get());
101 EXPECT_EQ(string16(), error); 103 EXPECT_EQ(string16(), error);
102 104
103 // Use a temp dir so that the extensions dir will clean itself up. 105 // Use a temp dir so that the extensions dir will clean itself up.
104 base::ScopedTempDir ext_dir; 106 base::ScopedTempDir ext_dir;
105 EXPECT_TRUE(ext_dir.Set(extension->path())); 107 EXPECT_TRUE(ext_dir.Set(extension->path()));
106 108
107 // Validate generated extension metadata. 109 // Validate generated extension metadata.
108 EXPECT_EQ("bar.user.js", extension->name()); 110 EXPECT_EQ("bar.user.js", extension->name());
109 EXPECT_EQ("1.0", extension->VersionString()); 111 EXPECT_EQ("1.0", extension->VersionString());
110 EXPECT_EQ("", extension->description()); 112 EXPECT_EQ("", extension->description());
111 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", 113 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=",
112 extension->public_key()); 114 extension->public_key());
115 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
113 116
114 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); 117 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
115 const UserScript& script = 118 const UserScript& script =
116 ContentScriptsInfo::GetContentScripts(extension)[0]; 119 ContentScriptsInfo::GetContentScripts(extension)[0];
117 ASSERT_EQ(1u, script.globs().size()); 120 ASSERT_EQ(1u, script.globs().size());
118 EXPECT_EQ("*", script.globs()[0]); 121 EXPECT_EQ("*", script.globs()[0]);
119 EXPECT_EQ(0u, script.exclude_globs().size()); 122 EXPECT_EQ(0u, script.exclude_globs().size());
123 EXPECT_TRUE(script.emulate_greasemonkey());
120 124
121 URLPatternSet expected; 125 URLPatternSet expected;
122 AddPattern(&expected, "http://*/*"); 126 AddPattern(&expected, "http://*/*");
123 AddPattern(&expected, "https://*/*"); 127 AddPattern(&expected, "https://*/*");
124 EXPECT_EQ(expected, script.url_patterns()); 128 EXPECT_EQ(expected, script.url_patterns());
125 129
126 // Make sure the files actually exist on disk. 130 // Make sure the files actually exist on disk.
127 EXPECT_TRUE(file_util::PathExists( 131 EXPECT_TRUE(file_util::PathExists(
128 extension->path().Append(script.js_scripts()[0].relative_path()))); 132 extension->path().Append(script.js_scripts()[0].relative_path())));
129 EXPECT_TRUE(file_util::PathExists( 133 EXPECT_TRUE(file_util::PathExists(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 171
168 // Use a temp dir so that the extensions dir will clean itself up. 172 // Use a temp dir so that the extensions dir will clean itself up.
169 base::ScopedTempDir ext_dir; 173 base::ScopedTempDir ext_dir;
170 EXPECT_TRUE(ext_dir.Set(extension->path())); 174 EXPECT_TRUE(ext_dir.Set(extension->path()));
171 175
172 // Validate generated extension metadata. 176 // Validate generated extension metadata.
173 EXPECT_EQ("Document Start Test", extension->name()); 177 EXPECT_EQ("Document Start Test", extension->name());
174 EXPECT_EQ("This script tests document-start", extension->description()); 178 EXPECT_EQ("This script tests document-start", extension->description());
175 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=", 179 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=",
176 extension->public_key()); 180 extension->public_key());
181 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
177 182
178 // Validate run location. 183 // Validate run location.
179 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); 184 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
180 const UserScript& script = 185 const UserScript& script =
181 ContentScriptsInfo::GetContentScripts(extension)[0]; 186 ContentScriptsInfo::GetContentScripts(extension)[0];
182 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location()); 187 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location());
183 } 188 }
184 189
185 TEST_F(ExtensionFromUserScript, RunAtDocumentEnd) { 190 TEST_F(ExtensionFromUserScript, RunAtDocumentEnd) {
186 base::ScopedTempDir extensions_dir; 191 base::ScopedTempDir extensions_dir;
(...skipping 14 matching lines...) Expand all
201 206
202 // Use a temp dir so that the extensions dir will clean itself up. 207 // Use a temp dir so that the extensions dir will clean itself up.
203 base::ScopedTempDir ext_dir; 208 base::ScopedTempDir ext_dir;
204 EXPECT_TRUE(ext_dir.Set(extension->path())); 209 EXPECT_TRUE(ext_dir.Set(extension->path()));
205 210
206 // Validate generated extension metadata. 211 // Validate generated extension metadata.
207 EXPECT_EQ("Document End Test", extension->name()); 212 EXPECT_EQ("Document End Test", extension->name());
208 EXPECT_EQ("This script tests document-end", extension->description()); 213 EXPECT_EQ("This script tests document-end", extension->description());
209 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=", 214 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=",
210 extension->public_key()); 215 extension->public_key());
216 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
211 217
212 // Validate run location. 218 // Validate run location.
213 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); 219 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
214 const UserScript& script = 220 const UserScript& script =
215 ContentScriptsInfo::GetContentScripts(extension)[0]; 221 ContentScriptsInfo::GetContentScripts(extension)[0];
216 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location()); 222 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location());
217 } 223 }
218 224
219 TEST_F(ExtensionFromUserScript, RunAtDocumentIdle) { 225 TEST_F(ExtensionFromUserScript, RunAtDocumentIdle) {
220 base::ScopedTempDir extensions_dir; 226 base::ScopedTempDir extensions_dir;
(...skipping 15 matching lines...) Expand all
236 242
237 // 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.
238 base::ScopedTempDir ext_dir; 244 base::ScopedTempDir ext_dir;
239 EXPECT_TRUE(ext_dir.Set(extension->path())); 245 EXPECT_TRUE(ext_dir.Set(extension->path()));
240 246
241 // Validate generated extension metadata. 247 // Validate generated extension metadata.
242 EXPECT_EQ("Document Idle Test", extension->name()); 248 EXPECT_EQ("Document Idle Test", extension->name());
243 EXPECT_EQ("This script tests document-idle", extension->description()); 249 EXPECT_EQ("This script tests document-idle", extension->description());
244 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 250 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
245 extension->public_key()); 251 extension->public_key());
252 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
246 253
247 // Validate run location. 254 // Validate run location.
248 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); 255 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
249 const UserScript& script = 256 const UserScript& script =
250 ContentScriptsInfo::GetContentScripts(extension)[0]; 257 ContentScriptsInfo::GetContentScripts(extension)[0];
251 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 258 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
252 } 259 }
253 260
254 } // namespace extensions 261 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698