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

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

Issue 2227193002: Make UserScript non-copyable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott 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 (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 "chrome/browser/extensions/convert_user_script.h" 5 #include "chrome/browser/extensions/convert_user_script.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Validate generated extension metadata. 57 // Validate generated extension metadata.
58 EXPECT_EQ("My user script", extension->name()); 58 EXPECT_EQ("My user script", extension->name());
59 EXPECT_EQ("2.2.2", extension->VersionString()); 59 EXPECT_EQ("2.2.2", extension->VersionString());
60 EXPECT_EQ("Does totally awesome stuff.", extension->description()); 60 EXPECT_EQ("Does totally awesome stuff.", extension->description());
61 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=", 61 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=",
62 extension->public_key()); 62 extension->public_key());
63 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType()); 63 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
64 64
65 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size()); 65 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size());
66 const UserScript& script = 66 const UserScript& script =
67 ContentScriptsInfo::GetContentScripts(extension.get())[0]; 67 *ContentScriptsInfo::GetContentScripts(extension.get())[0];
68 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 68 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
69 ASSERT_EQ(2u, script.globs().size()); 69 ASSERT_EQ(2u, script.globs().size());
70 EXPECT_EQ("http://www.google.com/*", script.globs().at(0)); 70 EXPECT_EQ("http://www.google.com/*", script.globs().at(0));
71 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1)); 71 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1));
72 ASSERT_EQ(1u, script.exclude_globs().size()); 72 ASSERT_EQ(1u, script.exclude_globs().size());
73 EXPECT_EQ("*foo*", script.exclude_globs().at(0)); 73 EXPECT_EQ("*foo*", script.exclude_globs().at(0));
74 ASSERT_EQ(1u, script.url_patterns().patterns().size()); 74 ASSERT_EQ(1u, script.url_patterns().patterns().size());
75 EXPECT_EQ("http://www.google.com/*", 75 EXPECT_EQ("http://www.google.com/*",
76 script.url_patterns().begin()->GetAsString()); 76 script.url_patterns().begin()->GetAsString());
77 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size()); 77 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size());
78 EXPECT_EQ("http://www.google.com/foo*", 78 EXPECT_EQ("http://www.google.com/foo*",
79 script.exclude_url_patterns().begin()->GetAsString()); 79 script.exclude_url_patterns().begin()->GetAsString());
80 EXPECT_TRUE(script.emulate_greasemonkey()); 80 EXPECT_TRUE(script.emulate_greasemonkey());
81 81
82 // Make sure the files actually exist on disk. 82 // Make sure the files actually exist on disk.
83 EXPECT_TRUE(base::PathExists( 83 EXPECT_TRUE(base::PathExists(
84 extension->path().Append(script.js_scripts()[0].relative_path()))); 84 extension->path().Append(script.js_scripts()[0]->relative_path())));
85 EXPECT_TRUE(base::PathExists( 85 EXPECT_TRUE(base::PathExists(
86 extension->path().Append(kManifestFilename))); 86 extension->path().Append(kManifestFilename)));
87 } 87 }
88 88
89 TEST_F(ExtensionFromUserScript, NoMetadata) { 89 TEST_F(ExtensionFromUserScript, NoMetadata) {
90 base::ScopedTempDir extensions_dir; 90 base::ScopedTempDir extensions_dir;
91 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 91 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
92 92
93 base::FilePath test_file; 93 base::FilePath test_file;
94 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 94 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
(...skipping 15 matching lines...) Expand all
110 // Validate generated extension metadata. 110 // Validate generated extension metadata.
111 EXPECT_EQ("bar.user.js", extension->name()); 111 EXPECT_EQ("bar.user.js", extension->name());
112 EXPECT_EQ("1.0", extension->VersionString()); 112 EXPECT_EQ("1.0", extension->VersionString());
113 EXPECT_EQ("", extension->description()); 113 EXPECT_EQ("", extension->description());
114 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", 114 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=",
115 extension->public_key()); 115 extension->public_key());
116 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType()); 116 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
117 117
118 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size()); 118 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size());
119 const UserScript& script = 119 const UserScript& script =
120 ContentScriptsInfo::GetContentScripts(extension.get())[0]; 120 *ContentScriptsInfo::GetContentScripts(extension.get())[0];
121 ASSERT_EQ(1u, script.globs().size()); 121 ASSERT_EQ(1u, script.globs().size());
122 EXPECT_EQ("*", script.globs()[0]); 122 EXPECT_EQ("*", script.globs()[0]);
123 EXPECT_EQ(0u, script.exclude_globs().size()); 123 EXPECT_EQ(0u, script.exclude_globs().size());
124 EXPECT_TRUE(script.emulate_greasemonkey()); 124 EXPECT_TRUE(script.emulate_greasemonkey());
125 125
126 URLPatternSet expected; 126 URLPatternSet expected;
127 AddPattern(&expected, "http://*/*"); 127 AddPattern(&expected, "http://*/*");
128 AddPattern(&expected, "https://*/*"); 128 AddPattern(&expected, "https://*/*");
129 EXPECT_EQ(expected, script.url_patterns()); 129 EXPECT_EQ(expected, script.url_patterns());
130 130
131 // Make sure the files actually exist on disk. 131 // Make sure the files actually exist on disk.
132 EXPECT_TRUE(base::PathExists( 132 EXPECT_TRUE(base::PathExists(
133 extension->path().Append(script.js_scripts()[0].relative_path()))); 133 extension->path().Append(script.js_scripts()[0]->relative_path())));
134 EXPECT_TRUE(base::PathExists( 134 EXPECT_TRUE(base::PathExists(
135 extension->path().Append(kManifestFilename))); 135 extension->path().Append(kManifestFilename)));
136 } 136 }
137 137
138 TEST_F(ExtensionFromUserScript, NotUTF8) { 138 TEST_F(ExtensionFromUserScript, NotUTF8) {
139 base::ScopedTempDir extensions_dir; 139 base::ScopedTempDir extensions_dir;
140 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 140 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
141 141
142 base::FilePath test_file; 142 base::FilePath test_file;
143 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 143 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Validate generated extension metadata. 177 // Validate generated extension metadata.
178 EXPECT_EQ("Document Start Test", extension->name()); 178 EXPECT_EQ("Document Start Test", extension->name());
179 EXPECT_EQ("This script tests document-start", extension->description()); 179 EXPECT_EQ("This script tests document-start", extension->description());
180 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=", 180 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=",
181 extension->public_key()); 181 extension->public_key());
182 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType()); 182 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
183 183
184 // Validate run location. 184 // Validate run location.
185 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size()); 185 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size());
186 const UserScript& script = 186 const UserScript& script =
187 ContentScriptsInfo::GetContentScripts(extension.get())[0]; 187 *ContentScriptsInfo::GetContentScripts(extension.get())[0];
188 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location()); 188 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location());
189 } 189 }
190 190
191 TEST_F(ExtensionFromUserScript, RunAtDocumentEnd) { 191 TEST_F(ExtensionFromUserScript, RunAtDocumentEnd) {
192 base::ScopedTempDir extensions_dir; 192 base::ScopedTempDir extensions_dir;
193 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 193 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
194 194
195 base::FilePath test_file; 195 base::FilePath test_file;
196 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 196 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
197 test_file = test_file.AppendASCII("extensions") 197 test_file = test_file.AppendASCII("extensions")
(...skipping 14 matching lines...) Expand all
212 // Validate generated extension metadata. 212 // Validate generated extension metadata.
213 EXPECT_EQ("Document End Test", extension->name()); 213 EXPECT_EQ("Document End Test", extension->name());
214 EXPECT_EQ("This script tests document-end", extension->description()); 214 EXPECT_EQ("This script tests document-end", extension->description());
215 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=", 215 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=",
216 extension->public_key()); 216 extension->public_key());
217 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType()); 217 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
218 218
219 // Validate run location. 219 // Validate run location.
220 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size()); 220 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size());
221 const UserScript& script = 221 const UserScript& script =
222 ContentScriptsInfo::GetContentScripts(extension.get())[0]; 222 *ContentScriptsInfo::GetContentScripts(extension.get())[0];
223 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location()); 223 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location());
224 } 224 }
225 225
226 TEST_F(ExtensionFromUserScript, RunAtDocumentIdle) { 226 TEST_F(ExtensionFromUserScript, RunAtDocumentIdle) {
227 base::ScopedTempDir extensions_dir; 227 base::ScopedTempDir extensions_dir;
228 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 228 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
229 229
230 base::FilePath test_file; 230 base::FilePath test_file;
231 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 231 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
232 test_file = test_file.AppendASCII("extensions") 232 test_file = test_file.AppendASCII("extensions")
(...skipping 15 matching lines...) Expand all
248 // Validate generated extension metadata. 248 // Validate generated extension metadata.
249 EXPECT_EQ("Document Idle Test", extension->name()); 249 EXPECT_EQ("Document Idle Test", extension->name());
250 EXPECT_EQ("This script tests document-idle", extension->description()); 250 EXPECT_EQ("This script tests document-idle", extension->description());
251 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 251 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
252 extension->public_key()); 252 extension->public_key());
253 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType()); 253 EXPECT_EQ(Manifest::TYPE_USER_SCRIPT, extension->GetType());
254 254
255 // Validate run location. 255 // Validate run location.
256 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size()); 256 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension.get()).size());
257 const UserScript& script = 257 const UserScript& script =
258 ContentScriptsInfo::GetContentScripts(extension.get())[0]; 258 *ContentScriptsInfo::GetContentScripts(extension.get())[0];
259 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 259 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
260 } 260 }
261 261
262 } // namespace extensions 262 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698