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

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

Issue 340057: Add first-class support for user scripts (Closed)
Patch Set: newness Created 11 years, 1 month 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
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6 #include <vector>
7
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/path_service.h"
11 #include "base/scoped_ptr.h"
12 #include "chrome/browser/extensions/convert_user_script.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/extension.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 TEST(ExtensionFromUserScript, Basic) {
18 FilePath test_file;
19 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
20 test_file = test_file.AppendASCII("extensions")
21 .AppendASCII("user_script_basic.user.js");
22
23 std::string error;
24 scoped_ptr<Extension> extension(ConvertUserScriptToExtension(
25 test_file, GURL("http://www.google.com/foo"), &error));
26
27 ASSERT_TRUE(extension.get());
28 EXPECT_EQ("", error);
29
30 // Validate generated extension metadata.
31 EXPECT_EQ("My user script", extension->name());
32 EXPECT_EQ("1.0", extension->VersionString());
33 EXPECT_EQ("Does totally awesome stuff.", extension->description());
34 EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovrMzMzMzMzMzA==",
35 extension->public_key());
36
37 ASSERT_EQ(1, extension->content_scripts().size());
38 const UserScript& script = extension->content_scripts()[0];
39 ASSERT_EQ(2, script.globs().size());
40 EXPECT_EQ("http://www.google.com/*", script.globs().at(0));
41 EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1));
42 ASSERT_EQ(1, script.exclude_globs().size());
43 EXPECT_EQ("*foo*", script.exclude_globs().at(0));
44 ASSERT_EQ(1, script.url_patterns().size());
45 EXPECT_EQ("http://www.google.com/*", script.url_patterns()[0].GetAsString());
46
47 // Make sure the files actually exist on disk.
48 EXPECT_TRUE(file_util::PathExists(
49 extension->path().Append(script.js_scripts()[0].relative_path())));
50 EXPECT_TRUE(file_util::PathExists(
51 extension->path().AppendASCII(Extension::kManifestFilename)));
52 }
53
54 TEST(ExtensionFromUserScript, NoMetdata) {
55 FilePath test_file;
56 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file));
57 test_file = test_file.AppendASCII("extensions")
58 .AppendASCII("user_script_no_metadata.user.js");
59
60 std::string error;
61 scoped_ptr<Extension> extension(ConvertUserScriptToExtension(
62 test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), &error));
63
64 ASSERT_TRUE(extension.get());
65 EXPECT_EQ("", error);
66
67 // Validate generated extension metadata.
68 EXPECT_EQ("bar.user.js", extension->name());
69 EXPECT_EQ("1.0", extension->VersionString());
70 EXPECT_EQ("", extension->description());
71 EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcbMzMzMzMzMzA==",
72 extension->public_key());
73
74 ASSERT_EQ(1, extension->content_scripts().size());
75 const UserScript& script = extension->content_scripts()[0];
76 ASSERT_EQ(1, script.globs().size());
77 EXPECT_EQ("*", script.globs()[0]);
78 EXPECT_EQ(0, script.exclude_globs().size());
79 ASSERT_EQ(3, script.url_patterns().size());
80 EXPECT_EQ("http://*/*", script.url_patterns()[0].GetAsString());
81 EXPECT_EQ("https://*/*", script.url_patterns()[1].GetAsString());
82 EXPECT_EQ("file:///*", script.url_patterns()[2].GetAsString());
83
84 // Make sure the files actually exist on disk.
85 EXPECT_TRUE(file_util::PathExists(
86 extension->path().Append(script.js_scripts()[0].relative_path())));
87 EXPECT_TRUE(file_util::PathExists(
88 extension->path().AppendASCII(Extension::kManifestFilename)));
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698