| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 18 matching lines...) Expand all Loading... |
| 29 FilePath test_file; | 29 FilePath test_file; |
| 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); | 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); |
| 31 test_file = test_file.AppendASCII("extensions") | 31 test_file = test_file.AppendASCII("extensions") |
| 32 .AppendASCII("user_script_basic.user.js"); | 32 .AppendASCII("user_script_basic.user.js"); |
| 33 | 33 |
| 34 string16 error; | 34 string16 error; |
| 35 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( | 35 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( |
| 36 test_file, GURL("http://www.google.com/foo"), &error)); | 36 test_file, GURL("http://www.google.com/foo"), &error)); |
| 37 | 37 |
| 38 ASSERT_TRUE(extension.get()); | 38 ASSERT_TRUE(extension.get()); |
| 39 EXPECT_EQ(ASCIIToUTF16(""), error); | 39 EXPECT_EQ(string16(), error); |
| 40 | 40 |
| 41 // Use a temp dir so that the extensions dir will clean itself up. | 41 // Use a temp dir so that the extensions dir will clean itself up. |
| 42 ScopedTempDir ext_dir; | 42 ScopedTempDir ext_dir; |
| 43 EXPECT_TRUE(ext_dir.Set(extension->path())); | 43 EXPECT_TRUE(ext_dir.Set(extension->path())); |
| 44 | 44 |
| 45 // Validate generated extension metadata. | 45 // Validate generated extension metadata. |
| 46 EXPECT_EQ("My user script", extension->name()); | 46 EXPECT_EQ("My user script", extension->name()); |
| 47 EXPECT_EQ("2.2.2", extension->VersionString()); | 47 EXPECT_EQ("2.2.2", extension->VersionString()); |
| 48 EXPECT_EQ("Does totally awesome stuff.", extension->description()); | 48 EXPECT_EQ("Does totally awesome stuff.", extension->description()); |
| 49 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=", | 49 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=", |
| (...skipping 25 matching lines...) Expand all Loading... |
| 75 FilePath test_file; | 75 FilePath test_file; |
| 76 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); | 76 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); |
| 77 test_file = test_file.AppendASCII("extensions") | 77 test_file = test_file.AppendASCII("extensions") |
| 78 .AppendASCII("user_script_no_metadata.user.js"); | 78 .AppendASCII("user_script_no_metadata.user.js"); |
| 79 | 79 |
| 80 string16 error; | 80 string16 error; |
| 81 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( | 81 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( |
| 82 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), &error)); | 82 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), &error)); |
| 83 | 83 |
| 84 ASSERT_TRUE(extension.get()); | 84 ASSERT_TRUE(extension.get()); |
| 85 EXPECT_EQ(ASCIIToUTF16(""), error); | 85 EXPECT_EQ(string16(), error); |
| 86 | 86 |
| 87 // Use a temp dir so that the extensions dir will clean itself up. | 87 // Use a temp dir so that the extensions dir will clean itself up. |
| 88 ScopedTempDir ext_dir; | 88 ScopedTempDir ext_dir; |
| 89 EXPECT_TRUE(ext_dir.Set(extension->path())); | 89 EXPECT_TRUE(ext_dir.Set(extension->path())); |
| 90 | 90 |
| 91 // Validate generated extension metadata. | 91 // Validate generated extension metadata. |
| 92 EXPECT_EQ("bar.user.js", extension->name()); | 92 EXPECT_EQ("bar.user.js", extension->name()); |
| 93 EXPECT_EQ("1.0", extension->VersionString()); | 93 EXPECT_EQ("1.0", extension->VersionString()); |
| 94 EXPECT_EQ("", extension->description()); | 94 EXPECT_EQ("", extension->description()); |
| 95 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", | 95 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 FilePath test_file; | 132 FilePath test_file; |
| 133 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); | 133 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); |
| 134 test_file = test_file.AppendASCII("extensions") | 134 test_file = test_file.AppendASCII("extensions") |
| 135 .AppendASCII("user_script_run_at_start.user.js"); | 135 .AppendASCII("user_script_run_at_start.user.js"); |
| 136 | 136 |
| 137 string16 error; | 137 string16 error; |
| 138 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( | 138 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( |
| 139 test_file, GURL("http://www.google.com/foo"), &error)); | 139 test_file, GURL("http://www.google.com/foo"), &error)); |
| 140 | 140 |
| 141 ASSERT_TRUE(extension.get()); | 141 ASSERT_TRUE(extension.get()); |
| 142 EXPECT_EQ(ASCIIToUTF16(""), error); | 142 EXPECT_EQ(string16(), error); |
| 143 | 143 |
| 144 // Use a temp dir so that the extensions dir will clean itself up. | 144 // Use a temp dir so that the extensions dir will clean itself up. |
| 145 ScopedTempDir ext_dir; | 145 ScopedTempDir ext_dir; |
| 146 EXPECT_TRUE(ext_dir.Set(extension->path())); | 146 EXPECT_TRUE(ext_dir.Set(extension->path())); |
| 147 | 147 |
| 148 // Validate generated extension metadata. | 148 // Validate generated extension metadata. |
| 149 EXPECT_EQ("Document Start Test", extension->name()); | 149 EXPECT_EQ("Document Start Test", extension->name()); |
| 150 EXPECT_EQ("This script tests document-start", extension->description()); | 150 EXPECT_EQ("This script tests document-start", extension->description()); |
| 151 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=", | 151 EXPECT_EQ("RjmyI7+Gp/YHcW1qnu4xDxkJcL4cV4kTzdCA4BajCbk=", |
| 152 extension->public_key()); | 152 extension->public_key()); |
| 153 | 153 |
| 154 // Validate run location. | 154 // Validate run location. |
| 155 ASSERT_EQ(1u, extension->content_scripts().size()); | 155 ASSERT_EQ(1u, extension->content_scripts().size()); |
| 156 const UserScript& script = extension->content_scripts()[0]; | 156 const UserScript& script = extension->content_scripts()[0]; |
| 157 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location()); | 157 EXPECT_EQ(UserScript::DOCUMENT_START, script.run_location()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 TEST(ExtensionFromUserScript, RunAtDocumentEnd) { | 160 TEST(ExtensionFromUserScript, RunAtDocumentEnd) { |
| 161 FilePath test_file; | 161 FilePath test_file; |
| 162 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); | 162 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); |
| 163 test_file = test_file.AppendASCII("extensions") | 163 test_file = test_file.AppendASCII("extensions") |
| 164 .AppendASCII("user_script_run_at_end.user.js"); | 164 .AppendASCII("user_script_run_at_end.user.js"); |
| 165 | 165 |
| 166 string16 error; | 166 string16 error; |
| 167 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( | 167 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( |
| 168 test_file, GURL("http://www.google.com/foo"), &error)); | 168 test_file, GURL("http://www.google.com/foo"), &error)); |
| 169 | 169 |
| 170 ASSERT_TRUE(extension.get()); | 170 ASSERT_TRUE(extension.get()); |
| 171 EXPECT_EQ(ASCIIToUTF16(""), error); | 171 EXPECT_EQ(string16(), error); |
| 172 | 172 |
| 173 // Use a temp dir so that the extensions dir will clean itself up. | 173 // Use a temp dir so that the extensions dir will clean itself up. |
| 174 ScopedTempDir ext_dir; | 174 ScopedTempDir ext_dir; |
| 175 EXPECT_TRUE(ext_dir.Set(extension->path())); | 175 EXPECT_TRUE(ext_dir.Set(extension->path())); |
| 176 | 176 |
| 177 // Validate generated extension metadata. | 177 // Validate generated extension metadata. |
| 178 EXPECT_EQ("Document End Test", extension->name()); | 178 EXPECT_EQ("Document End Test", extension->name()); |
| 179 EXPECT_EQ("This script tests document-end", extension->description()); | 179 EXPECT_EQ("This script tests document-end", extension->description()); |
| 180 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=", | 180 EXPECT_EQ("cpr5i8Mi24FzECV8UJe6tanwlU8SWesZosJ915YISvQ=", |
| 181 extension->public_key()); | 181 extension->public_key()); |
| 182 | 182 |
| 183 // Validate run location. | 183 // Validate run location. |
| 184 ASSERT_EQ(1u, extension->content_scripts().size()); | 184 ASSERT_EQ(1u, extension->content_scripts().size()); |
| 185 const UserScript& script = extension->content_scripts()[0]; | 185 const UserScript& script = extension->content_scripts()[0]; |
| 186 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location()); | 186 EXPECT_EQ(UserScript::DOCUMENT_END, script.run_location()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST(ExtensionFromUserScript, RunAtDocumentIdle) { | 189 TEST(ExtensionFromUserScript, RunAtDocumentIdle) { |
| 190 FilePath test_file; | 190 FilePath test_file; |
| 191 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); | 191 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); |
| 192 test_file = test_file.AppendASCII("extensions") | 192 test_file = test_file.AppendASCII("extensions") |
| 193 .AppendASCII("user_script_run_at_idle.user.js"); | 193 .AppendASCII("user_script_run_at_idle.user.js"); |
| 194 ASSERT_TRUE(file_util::PathExists(test_file)) << test_file.value(); | 194 ASSERT_TRUE(file_util::PathExists(test_file)) << test_file.value(); |
| 195 | 195 |
| 196 string16 error; | 196 string16 error; |
| 197 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( | 197 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( |
| 198 test_file, GURL("http://www.google.com/foo"), &error)); | 198 test_file, GURL("http://www.google.com/foo"), &error)); |
| 199 | 199 |
| 200 ASSERT_TRUE(extension.get()); | 200 ASSERT_TRUE(extension.get()); |
| 201 EXPECT_EQ(ASCIIToUTF16(""), error); | 201 EXPECT_EQ(string16(), error); |
| 202 | 202 |
| 203 // Use a temp dir so that the extensions dir will clean itself up. | 203 // Use a temp dir so that the extensions dir will clean itself up. |
| 204 ScopedTempDir ext_dir; | 204 ScopedTempDir ext_dir; |
| 205 EXPECT_TRUE(ext_dir.Set(extension->path())); | 205 EXPECT_TRUE(ext_dir.Set(extension->path())); |
| 206 | 206 |
| 207 // Validate generated extension metadata. | 207 // Validate generated extension metadata. |
| 208 EXPECT_EQ("Document Idle Test", extension->name()); | 208 EXPECT_EQ("Document Idle Test", extension->name()); |
| 209 EXPECT_EQ("This script tests document-idle", extension->description()); | 209 EXPECT_EQ("This script tests document-idle", extension->description()); |
| 210 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", | 210 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", |
| 211 extension->public_key()); | 211 extension->public_key()); |
| 212 | 212 |
| 213 // Validate run location. | 213 // Validate run location. |
| 214 ASSERT_EQ(1u, extension->content_scripts().size()); | 214 ASSERT_EQ(1u, extension->content_scripts().size()); |
| 215 const UserScript& script = extension->content_scripts()[0]; | 215 const UserScript& script = extension->content_scripts()[0]; |
| 216 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); | 216 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); |
| 217 } | 217 } |
| OLD | NEW |