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

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

Issue 12578008: Move CrxFile, FileReader, ExtensionResource to src/extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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"
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/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "extensions/common/constants.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));
26 } 27 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 EXPECT_EQ("http://www.google.com/*", 68 EXPECT_EQ("http://www.google.com/*",
68 script.url_patterns().begin()->GetAsString()); 69 script.url_patterns().begin()->GetAsString());
69 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size()); 70 ASSERT_EQ(1u, script.exclude_url_patterns().patterns().size());
70 EXPECT_EQ("http://www.google.com/foo*", 71 EXPECT_EQ("http://www.google.com/foo*",
71 script.exclude_url_patterns().begin()->GetAsString()); 72 script.exclude_url_patterns().begin()->GetAsString());
72 73
73 // Make sure the files actually exist on disk. 74 // Make sure the files actually exist on disk.
74 EXPECT_TRUE(file_util::PathExists( 75 EXPECT_TRUE(file_util::PathExists(
75 extension->path().Append(script.js_scripts()[0].relative_path()))); 76 extension->path().Append(script.js_scripts()[0].relative_path())));
76 EXPECT_TRUE(file_util::PathExists( 77 EXPECT_TRUE(file_util::PathExists(
77 extension->path().Append(Extension::kManifestFilename))); 78 extension->path().Append(kManifestFilename)));
78 } 79 }
79 80
80 TEST(ExtensionFromUserScript, NoMetdata) { 81 TEST(ExtensionFromUserScript, NoMetdata) {
81 base::ScopedTempDir extensions_dir; 82 base::ScopedTempDir extensions_dir;
82 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 83 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
83 84
84 base::FilePath test_file; 85 base::FilePath test_file;
85 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 86 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
86 test_file = test_file.AppendASCII("extensions") 87 test_file = test_file.AppendASCII("extensions")
87 .AppendASCII("user_script_no_metadata.user.js"); 88 .AppendASCII("user_script_no_metadata.user.js");
(...skipping 25 matching lines...) Expand all
113 114
114 URLPatternSet expected; 115 URLPatternSet expected;
115 AddPattern(&expected, "http://*/*"); 116 AddPattern(&expected, "http://*/*");
116 AddPattern(&expected, "https://*/*"); 117 AddPattern(&expected, "https://*/*");
117 EXPECT_EQ(expected, script.url_patterns()); 118 EXPECT_EQ(expected, script.url_patterns());
118 119
119 // Make sure the files actually exist on disk. 120 // Make sure the files actually exist on disk.
120 EXPECT_TRUE(file_util::PathExists( 121 EXPECT_TRUE(file_util::PathExists(
121 extension->path().Append(script.js_scripts()[0].relative_path()))); 122 extension->path().Append(script.js_scripts()[0].relative_path())));
122 EXPECT_TRUE(file_util::PathExists( 123 EXPECT_TRUE(file_util::PathExists(
123 extension->path().Append(Extension::kManifestFilename))); 124 extension->path().Append(kManifestFilename)));
124 } 125 }
125 126
126 TEST(ExtensionFromUserScript, NotUTF8) { 127 TEST(ExtensionFromUserScript, NotUTF8) {
127 base::ScopedTempDir extensions_dir; 128 base::ScopedTempDir extensions_dir;
128 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); 129 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir());
129 130
130 base::FilePath test_file; 131 base::FilePath test_file;
131 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 132 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
132 test_file = test_file.AppendASCII("extensions") 133 test_file = test_file.AppendASCII("extensions")
133 .AppendASCII("user_script_not_utf8.user.js"); 134 .AppendASCII("user_script_not_utf8.user.js");
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 236 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
236 extension->public_key()); 237 extension->public_key());
237 238
238 // Validate run location. 239 // Validate run location.
239 ASSERT_EQ(1u, extension->content_scripts().size()); 240 ASSERT_EQ(1u, extension->content_scripts().size());
240 const UserScript& script = extension->content_scripts()[0]; 241 const UserScript& script = extension->content_scripts()[0];
241 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 242 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
242 } 243 }
243 244
244 } // namespace extensions 245 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/convert_user_script.cc ('k') | chrome/browser/extensions/convert_web_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698