diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 02:15:20 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 02:15:20 +0000 |
commit | 6657afa65426f10f5dc51c0ac12d573c4826cb54 (patch) | |
tree | 3b24f83dd2f834bde93b7b7e27327701814379ac /chrome/browser/extensions/convert_user_script_unittest.cc | |
parent | 6c856ae733bf8d1f187ec5b93e07216ace0c4693 (diff) | |
download | chromium_src-6657afa65426f10f5dc51c0ac12d573c4826cb54.zip chromium_src-6657afa65426f10f5dc51c0ac12d573c4826cb54.tar.gz chromium_src-6657afa65426f10f5dc51c0ac12d573c4826cb54.tar.bz2 |
Add first class support for user scripts.
Original review: http://codereview.chromium.org/340057
TBR=mpcomplete@chromium.org
BUG=22103
TEST=Install a user script (such as from userscripts.org). You should get the extension install UI and the
script should show up in the extension management UI. It should also work, though some scripts use
Firefox-specific APIs and those won't work in Chromium.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/convert_user_script_unittest.cc')
-rw-r--r-- | chrome/browser/extensions/convert_user_script_unittest.cc | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/chrome/browser/extensions/convert_user_script_unittest.cc b/chrome/browser/extensions/convert_user_script_unittest.cc new file mode 100644 index 0000000..b7aea54 --- /dev/null +++ b/chrome/browser/extensions/convert_user_script_unittest.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string> +#include <vector> + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/extensions/convert_user_script.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/extensions/extension.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(ExtensionFromUserScript, Basic) { + FilePath test_file; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); + test_file = test_file.AppendASCII("extensions") + .AppendASCII("user_script_basic.user.js"); + + std::string error; + scoped_ptr<Extension> extension(ConvertUserScriptToExtension( + test_file, GURL("http://www.google.com/foo"), &error)); + + ASSERT_TRUE(extension.get()); + EXPECT_EQ("", error); + + // Validate generated extension metadata. + EXPECT_EQ("My user script", extension->name()); + EXPECT_EQ("1.0", extension->VersionString()); + EXPECT_EQ("Does totally awesome stuff.", extension->description()); + EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=", + extension->public_key()); + + ASSERT_EQ(1u, extension->content_scripts().size()); + const UserScript& script = extension->content_scripts()[0]; + ASSERT_EQ(2u, script.globs().size()); + EXPECT_EQ("http://www.google.com/*", script.globs().at(0)); + EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1)); + ASSERT_EQ(1u, script.exclude_globs().size()); + EXPECT_EQ("*foo*", script.exclude_globs().at(0)); + ASSERT_EQ(1u, script.url_patterns().size()); + EXPECT_EQ("http://www.google.com/*", script.url_patterns()[0].GetAsString()); + + // Make sure the files actually exist on disk. + EXPECT_TRUE(file_util::PathExists( + extension->path().Append(script.js_scripts()[0].relative_path()))); + EXPECT_TRUE(file_util::PathExists( + extension->path().AppendASCII(Extension::kManifestFilename))); +} + +TEST(ExtensionFromUserScript, NoMetdata) { + FilePath test_file; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); + test_file = test_file.AppendASCII("extensions") + .AppendASCII("user_script_no_metadata.user.js"); + + std::string error; + scoped_ptr<Extension> extension(ConvertUserScriptToExtension( + test_file, GURL("http://www.google.com/foo/bar.user.js?monkey"), &error)); + + ASSERT_TRUE(extension.get()); + EXPECT_EQ("", error); + + // Validate generated extension metadata. + EXPECT_EQ("bar.user.js", extension->name()); + EXPECT_EQ("1.0", extension->VersionString()); + EXPECT_EQ("", extension->description()); + EXPECT_EQ("k1WxKx54hX6tfl5gQaXD/m4d9QUMwRdXWM4RW+QkWcY=", + extension->public_key()); + + ASSERT_EQ(1u, extension->content_scripts().size()); + const UserScript& script = extension->content_scripts()[0]; + ASSERT_EQ(1u, script.globs().size()); + EXPECT_EQ("*", script.globs()[0]); + EXPECT_EQ(0u, script.exclude_globs().size()); + ASSERT_EQ(2u, script.url_patterns().size()); + EXPECT_EQ("http://*/*", script.url_patterns()[0].GetAsString()); + EXPECT_EQ("https://*/*", script.url_patterns()[1].GetAsString()); + + // Make sure the files actually exist on disk. + EXPECT_TRUE(file_util::PathExists( + extension->path().Append(script.js_scripts()[0].relative_path()))); + EXPECT_TRUE(file_util::PathExists( + extension->path().AppendASCII(Extension::kManifestFilename))); +} |