| OLD | NEW |
| 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 "chrome/common/extensions/manifest_handler.h" | |
| 18 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | 17 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
| 19 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 20 |
| 22 namespace extensions { | 21 namespace extensions { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 25 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 27 int schemes = URLPattern::SCHEME_ALL; | 26 int schemes = URLPattern::SCHEME_ALL; |
| 28 extent->AddPattern(URLPattern(schemes, pattern)); | 27 extent->AddPattern(URLPattern(schemes, pattern)); |
| 29 } | 28 } |
| 30 | 29 |
| 31 } | 30 } |
| 32 | 31 |
| 33 class ExtensionFromUserScript : public testing::Test { | 32 class ExtensionFromUserScript : public testing::Test { |
| 34 public: | |
| 35 virtual void SetUp() OVERRIDE { | |
| 36 testing::Test::SetUp(); | |
| 37 (new ContentScriptsHandler)->Register(); | |
| 38 } | |
| 39 | |
| 40 virtual void TearDown() OVERRIDE { | |
| 41 testing::Test::TearDown(); | |
| 42 ManifestHandler::ClearRegistryForTesting(); | |
| 43 } | |
| 44 }; | 33 }; |
| 45 | 34 |
| 46 TEST_F(ExtensionFromUserScript, Basic) { | 35 TEST_F(ExtensionFromUserScript, Basic) { |
| 47 base::ScopedTempDir extensions_dir; | 36 base::ScopedTempDir extensions_dir; |
| 48 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); | 37 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 49 | 38 |
| 50 base::FilePath test_file; | 39 base::FilePath test_file; |
| 51 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); | 40 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); |
| 52 test_file = test_file.AppendASCII("extensions") | 41 test_file = test_file.AppendASCII("extensions") |
| 53 .AppendASCII("user_script_basic.user.js"); | 42 .AppendASCII("user_script_basic.user.js"); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 extension->public_key()); | 245 extension->public_key()); |
| 257 | 246 |
| 258 // Validate run location. | 247 // Validate run location. |
| 259 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); | 248 ASSERT_EQ(1u, ContentScriptsInfo::GetContentScripts(extension).size()); |
| 260 const UserScript& script = | 249 const UserScript& script = |
| 261 ContentScriptsInfo::GetContentScripts(extension)[0]; | 250 ContentScriptsInfo::GetContentScripts(extension)[0]; |
| 262 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); | 251 EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); |
| 263 } | 252 } |
| 264 | 253 |
| 265 } // namespace extensions | 254 } // namespace extensions |
| OLD | NEW |