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

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

Issue 11724002: Move ContentScripts out of Extension (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Created 7 years, 11 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 <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/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/extensions/convert_user_script.h" 14 #include "chrome/browser/extensions/convert_user_script.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/api/content_scripts/content_scripts_handler.h "
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 namespace { 22 namespace {
22 23
23 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 24 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
24 int schemes = URLPattern::SCHEME_ALL; 25 int schemes = URLPattern::SCHEME_ALL;
25 extent->AddPattern(URLPattern(schemes, pattern)); 26 extent->AddPattern(URLPattern(schemes, pattern));
(...skipping 22 matching lines...) Expand all
48 base::ScopedTempDir ext_dir; 49 base::ScopedTempDir ext_dir;
49 EXPECT_TRUE(ext_dir.Set(extension->path())); 50 EXPECT_TRUE(ext_dir.Set(extension->path()));
50 51
51 // Validate generated extension metadata. 52 // Validate generated extension metadata.
52 EXPECT_EQ("My user script", extension->name()); 53 EXPECT_EQ("My user script", extension->name());
53 EXPECT_EQ("2.2.2", extension->VersionString()); 54 EXPECT_EQ("2.2.2", extension->VersionString());
54 EXPECT_EQ("Does totally awesome stuff.", extension->description()); 55 EXPECT_EQ("Does totally awesome stuff.", extension->description());
55 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=", 56 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=",
56 extension->public_key()); 57 extension->public_key());
57 58
58 ASSERT_EQ(1u, extension->content_scripts().size()); 59 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
59 const UserScript& script = extension->content_scripts()[0]; 60 const UserScript& script =
61 ContentScriptsInfo::GetContentScripts(extension)[0];
60 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 62 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
61 ASSERT_EQ(2u, script.globs().size()); 63 ASSERT_EQ(2u, script.globs().size());
62 EXPECT_EQ("http://www.google.com/*", script.globs().at(0)); 64 EXPECT_EQ("http://www.google.com/*", script.globs().at(0));
63 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1)); 65 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1));
64 ASSERT_EQ(1u, script.exclude_globs().size()); 66 ASSERT_EQ(1u, script.exclude_globs().size());
65 EXPECT_EQ("*foo*", script.exclude_globs().at(0)); 67 EXPECT_EQ("*foo*", script.exclude_globs().at(0));
66 ASSERT_EQ(1u, script.url_patterns().patterns().size()); 68 ASSERT_EQ(1u, script.url_patterns().patterns().size());
67 EXPECT_EQ("http://www.google.com/*", 69 EXPECT_EQ("http://www.google.com/*",
68 script.url_patterns().begin()->GetAsString()); 70 script.url_patterns().begin()->GetAsString());
69 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size()); 71 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size());
(...skipping 28 matching lines...) Expand all
98 base::ScopedTempDir ext_dir; 100 base::ScopedTempDir ext_dir;
99 EXPECT_TRUE(ext_dir.Set(extension->path())); 101 EXPECT_TRUE(ext_dir.Set(extension->path()));
100 102
101 // Validate generated extension metadata. 103 // Validate generated extension metadata.
102 EXPECT_EQ("bar.user.js", extension->name()); 104 EXPECT_EQ("bar.user.js", extension->name());
103 EXPECT_EQ("1.0", extension->VersionString()); 105 EXPECT_EQ("1.0", extension->VersionString());
104 EXPECT_EQ("", extension->description()); 106 EXPECT_EQ("", extension->description());
105 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", 107 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=",
106 extension->public_key()); 108 extension->public_key());
107 109
108 ASSERT_EQ(1u, extension->content_scripts().size()); 110 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
109 const UserScript& script = extension->content_scripts()[0]; 111 const UserScript& script =
112 ContentScriptsInfo::GetContentScripts(extension)[0];
110 ASSERT_EQ(1u, script.globs().size()); 113 ASSERT_EQ(1u, script.globs().size());
111 EXPECT_EQ("*", script.globs()[0]); 114 EXPECT_EQ("*", script.globs()[0]);
112 EXPECT_EQ(0u, script.exclude_globs().size()); 115 EXPECT_EQ(0u, script.exclude_globs().size());
113 116
114 URLPatternSet expected; 117 URLPatternSet expected;
115 AddPattern(&expected, "http://*/*"); 118 AddPattern(&expected, "http://*/*");
116 AddPattern(&expected, "https://*/*"); 119 AddPattern(&expected, "https://*/*");
117 EXPECT_EQ(expected, script.url_patterns()); 120 EXPECT_EQ(expected, script.url_patterns());
118 121
119 // Make sure the files actually exist on disk. 122 // Make sure the files actually exist on disk.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 base::ScopedTempDir ext_dir; 165 base::ScopedTempDir ext_dir;
163 EXPECT_TRUE(ext_dir.Set(extension->path())); 166 EXPECT_TRUE(ext_dir.Set(extension->path()));
164 167
165 // Validate generated extension metadata. 168 // Validate generated extension metadata.
166 EXPECT_EQ("Document Start Test", extension->name()); 169 EXPECT_EQ("Document Start Test", extension->name());
167 EXPECT_EQ("This script tests document-start", extension->description()); 170 EXPECT_EQ("This script tests document-start", extension->description());
168 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=", 171 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=",
169 extension->public_key()); 172 extension->public_key());
170 173
171 // Validate run location. 174 // Validate run location.
172 ASSERT_EQ(1u, extension->content_scripts().size()); 175 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
173 const UserScript& script = extension->content_scripts()[0]; 176 const UserScript& script =
177 ContentScriptsInfo::GetContentScripts(extension)[0];
174 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location()); 178 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location());
175 } 179 }
176 180
177 TEST(ExtensionFromUserScript, RunAtDocumentEnd) { 181 TEST(ExtensionFromUserScript, RunAtDocumentEnd) {
178 base::ScopedTempDir extensions_dir; 182 base::ScopedTempDir extensions_dir;
179 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 183 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
180 184
181 FilePath test_file; 185 FilePath test_file;
182 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 186 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
183 test_file = test_file.AppendASCII("extensions") 187 test_file = test_file.AppendASCII("extensions")
(...skipping 11 matching lines...) Expand all
195 base::ScopedTempDir ext_dir; 199 base::ScopedTempDir ext_dir;
196 EXPECT_TRUE(ext_dir.Set(extension->path())); 200 EXPECT_TRUE(ext_dir.Set(extension->path()));
197 201
198 // Validate generated extension metadata. 202 // Validate generated extension metadata.
199 EXPECT_EQ("Document End Test", extension->name()); 203 EXPECT_EQ("Document End Test", extension->name());
200 EXPECT_EQ("This script tests document-end", extension->description()); 204 EXPECT_EQ("This script tests document-end", extension->description());
201 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=", 205 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=",
202 extension->public_key()); 206 extension->public_key());
203 207
204 // Validate run location. 208 // Validate run location.
205 ASSERT_EQ(1u, extension->content_scripts().size()); 209 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
206 const UserScript& script = extension->content_scripts()[0]; 210 const UserScript& script =
211 ContentScriptsInfo::GetContentScripts(extension)[0];
207 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location()); 212 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location());
208 } 213 }
209 214
210 TEST(ExtensionFromUserScript, RunAtDocumentIdle) { 215 TEST(ExtensionFromUserScript, RunAtDocumentIdle) {
211 base::ScopedTempDir extensions_dir; 216 base::ScopedTempDir extensions_dir;
212 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 217 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
213 218
214 FilePath test_file; 219 FilePath test_file;
215 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 220 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
216 test_file = test_file.AppendASCII("extensions") 221 test_file = test_file.AppendASCII("extensions")
(...skipping 12 matching lines...) Expand all
229 base::ScopedTempDir ext_dir; 234 base::ScopedTempDir ext_dir;
230 EXPECT_TRUE(ext_dir.Set(extension->path())); 235 EXPECT_TRUE(ext_dir.Set(extension->path()));
231 236
232 // Validate generated extension metadata. 237 // Validate generated extension metadata.
233 EXPECT_EQ("Document Idle Test", extension->name()); 238 EXPECT_EQ("Document Idle Test", extension->name());
234 EXPECT_EQ("This script tests document-idle", extension->description()); 239 EXPECT_EQ("This script tests document-idle", extension->description());
235 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 240 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
236 extension->public_key()); 241 extension->public_key());
237 242
238 // Validate run location. 243 // Validate run location.
239 ASSERT_EQ(1u, extension->content_scripts().size()); 244 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size());
240 const UserScript& script = extension->content_scripts()[0]; 245 const UserScript& script =
246 ContentScriptsInfo::GetContentScripts(extension)[0];
241 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 247 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
242 } 248 }
243 249
244 } // namespace extensions 250 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698