| OLD | NEW |
| 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/extensions/extension_info_map.h" | 7 #include "chrome/browser/extensions/extension_info_map.h" |
| 8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
| 9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/json_value_serializer.h" | 10 #include "chrome/common/json_value_serializer.h" |
| 11 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 35 #elif defined(OS_POSIX) | 35 #elif defined(OS_POSIX) |
| 36 FilePath path(FILE_PATH_LITERAL("/foo")); | 36 FilePath path(FILE_PATH_LITERAL("/foo")); |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 DictionaryValue manifest; | 39 DictionaryValue manifest; |
| 40 manifest.SetString(keys::kVersion, "1.0.0.0"); | 40 manifest.SetString(keys::kVersion, "1.0.0.0"); |
| 41 manifest.SetString(keys::kName, name); | 41 manifest.SetString(keys::kName, name); |
| 42 | 42 |
| 43 std::string error; | 43 std::string error; |
| 44 scoped_refptr<Extension> extension = Extension::Create( | 44 scoped_refptr<Extension> extension = Extension::Create( |
| 45 path.AppendASCII(name), Extension::INVALID, manifest, false, true, | 45 path.AppendASCII(name), Extension::INVALID, manifest, |
| 46 &error); | 46 Extension::STRICT_ERROR_CHECKS, &error); |
| 47 EXPECT_TRUE(extension) << error; | 47 EXPECT_TRUE(extension) << error; |
| 48 | 48 |
| 49 return extension; | 49 return extension; |
| 50 } | 50 } |
| 51 | 51 |
| 52 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 52 static scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| 53 const std::string& test_file) { | 53 const std::string& test_file) { |
| 54 FilePath path; | 54 FilePath path; |
| 55 PathService::Get(chrome::DIR_TEST_DATA, &path); | 55 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 56 path = path.AppendASCII("extensions") | 56 path = path.AppendASCII("extensions") |
| 57 .AppendASCII(dir) | 57 .AppendASCII(dir) |
| 58 .AppendASCII(test_file); | 58 .AppendASCII(test_file); |
| 59 | 59 |
| 60 JSONFileValueSerializer serializer(path); | 60 JSONFileValueSerializer serializer(path); |
| 61 scoped_ptr<Value> result(serializer.Deserialize(NULL, NULL)); | 61 scoped_ptr<Value> result(serializer.Deserialize(NULL, NULL)); |
| 62 if (!result.get()) | 62 if (!result.get()) |
| 63 return NULL; | 63 return NULL; |
| 64 | 64 |
| 65 std::string error; | 65 std::string error; |
| 66 scoped_refptr<Extension> extension = Extension::Create( | 66 scoped_refptr<Extension> extension = Extension::Create( |
| 67 path, Extension::INVALID, *static_cast<DictionaryValue*>(result.get()), | 67 path, Extension::INVALID, *static_cast<DictionaryValue*>(result.get()), |
| 68 false, true, &error); | 68 Extension::STRICT_ERROR_CHECKS, &error); |
| 69 EXPECT_TRUE(extension) << error; | 69 EXPECT_TRUE(extension) << error; |
| 70 | 70 |
| 71 return extension; | 71 return extension; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Test that the ExtensionInfoMap handles refcounting properly. | 74 // Test that the ExtensionInfoMap handles refcounting properly. |
| 75 TEST_F(ExtensionInfoMapTest, RefCounting) { | 75 TEST_F(ExtensionInfoMapTest, RefCounting) { |
| 76 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); | 76 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); |
| 77 | 77 |
| 78 // New extensions should have a single reference holding onto them. | 78 // New extensions should have a single reference holding onto them. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 extension->GetResourceURL("a.html"), Extension::kNotificationPermission)); | 155 extension->GetResourceURL("a.html"), Extension::kNotificationPermission)); |
| 156 | 156 |
| 157 // Random URL should not have any permissions. | 157 // Random URL should not have any permissions. |
| 158 EXPECT_FALSE(info_map->CheckURLAccessToExtensionPermission( | 158 EXPECT_FALSE(info_map->CheckURLAccessToExtensionPermission( |
| 159 GURL("http://evil.com/a.html"), Extension::kNotificationPermission)); | 159 GURL("http://evil.com/a.html"), Extension::kNotificationPermission)); |
| 160 EXPECT_FALSE(info_map->CheckURLAccessToExtensionPermission( | 160 EXPECT_FALSE(info_map->CheckURLAccessToExtensionPermission( |
| 161 GURL("http://evil.com/a.html"), Extension::kTabPermission)); | 161 GURL("http://evil.com/a.html"), Extension::kTabPermission)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace | 164 } // namespace |
| OLD | NEW |