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

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

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 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) 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"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "chrome/browser/extensions/convert_user_script.h" 13 #include "chrome/browser/extensions/convert_user_script.h"
14 #include "chrome/common/chrome_paths.h" 14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace {
19
20 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
21 int schemes = URLPattern::SCHEME_ALL;
22 extent->AddPattern(URLPattern(schemes, pattern));
23 }
24
25 }
26
18 TEST(ExtensionFromUserScript, Basic) { 27 TEST(ExtensionFromUserScript, Basic) {
19 FilePath test_file; 28 FilePath test_file;
20 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); 29 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
21 test_file = test_file.AppendASCII("extensions") 30 test_file = test_file.AppendASCII("extensions")
22 .AppendASCII("user_script_basic.user.js"); 31 .AppendASCII("user_script_basic.user.js");
23 32
24 std::string error; 33 std::string error;
25 scoped_refptr<Extension> extension(ConvertUserScriptToExtension( 34 scoped_refptr<Extension> extension(ConvertUserScriptToExtension(
26 test_file, GURL("http://www.google.com/foo"), &error)); 35 test_file, GURL("http://www.google.com/foo"), &error));
27 36
(...skipping 12 matching lines...) Expand all
40 extension->public_key()); 49 extension->public_key());
41 50
42 ASSERT_EQ(1u, extension->content_scripts().size()); 51 ASSERT_EQ(1u, extension->content_scripts().size());
43 const UserScript& script = extension->content_scripts()[0]; 52 const UserScript& script = extension->content_scripts()[0];
44 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 53 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
45 ASSERT_EQ(2u, script.globs().size()); 54 ASSERT_EQ(2u, script.globs().size());
46 EXPECT_EQ("http://www.google.com/*", script.globs().at(0)); 55 EXPECT_EQ("http://www.google.com/*", script.globs().at(0));
47 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1)); 56 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1));
48 ASSERT_EQ(1u, script.exclude_globs().size()); 57 ASSERT_EQ(1u, script.exclude_globs().size());
49 EXPECT_EQ("*foo*", script.exclude_globs().at(0)); 58 EXPECT_EQ("*foo*", script.exclude_globs().at(0));
50 ASSERT_EQ(1u, script.url_patterns().size()); 59 ASSERT_EQ(1u, script.url_patterns().patterns().size());
51 EXPECT_EQ("http://www.google.com/*", script.url_patterns()[0].GetAsString()); 60 EXPECT_EQ("http://www.google.com/*",
61 script.url_patterns().begin()->GetAsString());
52 62
53 // Make sure the files actually exist on disk. 63 // Make sure the files actually exist on disk.
54 EXPECT_TRUE(file_util::PathExists( 64 EXPECT_TRUE(file_util::PathExists(
55 extension->path().Append(script.js_scripts()[0].relative_path()))); 65 extension->path().Append(script.js_scripts()[0].relative_path())));
56 EXPECT_TRUE(file_util::PathExists( 66 EXPECT_TRUE(file_util::PathExists(
57 extension->path().Append(Extension::kManifestFilename))); 67 extension->path().Append(Extension::kManifestFilename)));
58 } 68 }
59 69
60 TEST(ExtensionFromUserScript, NoMetdata) { 70 TEST(ExtensionFromUserScript, NoMetdata) {
61 FilePath test_file; 71 FilePath test_file;
(...skipping 17 matching lines...) Expand all
79 EXPECT_EQ("1.0", extension->VersionString()); 89 EXPECT_EQ("1.0", extension->VersionString());
80 EXPECT_EQ("", extension->description()); 90 EXPECT_EQ("", extension->description());
81 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", 91 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=",
82 extension->public_key()); 92 extension->public_key());
83 93
84 ASSERT_EQ(1u, extension->content_scripts().size()); 94 ASSERT_EQ(1u, extension->content_scripts().size());
85 const UserScript& script = extension->content_scripts()[0]; 95 const UserScript& script = extension->content_scripts()[0];
86 ASSERT_EQ(1u, script.globs().size()); 96 ASSERT_EQ(1u, script.globs().size());
87 EXPECT_EQ("*", script.globs()[0]); 97 EXPECT_EQ("*", script.globs()[0]);
88 EXPECT_EQ(0u, script.exclude_globs().size()); 98 EXPECT_EQ(0u, script.exclude_globs().size());
89 ASSERT_EQ(2u, script.url_patterns().size()); 99
90 EXPECT_EQ("http://*/*", script.url_patterns()[0].GetAsString()); 100 URLPatternSet expected;
91 EXPECT_EQ("https://*/*", script.url_patterns()[1].GetAsString()); 101 AddPattern(&expected, "http://*/*");
102 AddPattern(&expected, "https://*/*");
103 EXPECT_EQ(expected, script.url_patterns());
92 104
93 // Make sure the files actually exist on disk. 105 // Make sure the files actually exist on disk.
94 EXPECT_TRUE(file_util::PathExists( 106 EXPECT_TRUE(file_util::PathExists(
95 extension->path().Append(script.js_scripts()[0].relative_path()))); 107 extension->path().Append(script.js_scripts()[0].relative_path())));
96 EXPECT_TRUE(file_util::PathExists( 108 EXPECT_TRUE(file_util::PathExists(
97 extension->path().Append(Extension::kManifestFilename))); 109 extension->path().Append(Extension::kManifestFilename)));
98 } 110 }
99 111
100 TEST(ExtensionFromUserScript, NotUTF8) { 112 TEST(ExtensionFromUserScript, NotUTF8) {
101 FilePath test_file; 113 FilePath test_file;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 EXPECT_EQ("Document Idle Test", extension->name()); 204 EXPECT_EQ("Document Idle Test", extension->name());
193 EXPECT_EQ("This script tests document-idle", extension->description()); 205 EXPECT_EQ("This script tests document-idle", extension->description());
194 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=", 206 EXPECT_EQ("kHnHKec3O/RKKo5/Iu1hKqe4wQERthL0639isNtsfiY=",
195 extension->public_key()); 207 extension->public_key());
196 208
197 // Validate run location. 209 // Validate run location.
198 ASSERT_EQ(1u, extension->content_scripts().size()); 210 ASSERT_EQ(1u, extension->content_scripts().size());
199 const UserScript& script = extension->content_scripts()[0]; 211 const UserScript& script = extension->content_scripts()[0];
200 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 212 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
201 } 213 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/convert_user_script.cc ('k') | chrome/browser/extensions/convert_web_app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698