| OLD | NEW |
| 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 "chrome/browser/extensions/test_extension_prefs.h" | 5 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 extension_pref_value_map_.get())); | 94 extension_pref_value_map_.get())); |
| 95 } | 95 } |
| 96 | 96 |
| 97 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { | 97 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { |
| 98 DictionaryValue dictionary; | 98 DictionaryValue dictionary; |
| 99 dictionary.SetString(extension_manifest_keys::kName, name); | 99 dictionary.SetString(extension_manifest_keys::kName, name); |
| 100 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 100 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 101 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); | 101 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); |
| 102 } | 102 } |
| 103 | 103 |
| 104 scoped_refptr<Extension> TestExtensionPrefs::AddApp(std::string name) { |
| 105 DictionaryValue dictionary; |
| 106 dictionary.SetString(extension_manifest_keys::kName, name); |
| 107 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 108 dictionary.SetString(extension_manifest_keys::kApp, "true"); |
| 109 dictionary.SetString(extension_manifest_keys::kLaunchWebURL, |
| 110 "http://example.com"); |
| 111 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); |
| 112 |
| 113 } |
| 114 |
| 104 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( | 115 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( |
| 105 const DictionaryValue& manifest, Extension::Location location) { | 116 const DictionaryValue& manifest, Extension::Location location) { |
| 106 return AddExtensionWithManifestAndFlags(manifest, location, | 117 return AddExtensionWithManifestAndFlags(manifest, location, |
| 107 Extension::STRICT_ERROR_CHECKS); | 118 Extension::STRICT_ERROR_CHECKS); |
| 108 } | 119 } |
| 109 | 120 |
| 110 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifestAndFlags( | 121 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifestAndFlags( |
| 111 const DictionaryValue& manifest, | 122 const DictionaryValue& manifest, |
| 112 Extension::Location location, | 123 Extension::Location location, |
| 113 int extra_flags) { | 124 int extra_flags) { |
| 114 std::string name; | 125 std::string name; |
| 115 EXPECT_TRUE(manifest.GetString(extension_manifest_keys::kName, &name)); | 126 EXPECT_TRUE(manifest.GetString(extension_manifest_keys::kName, &name)); |
| 116 FilePath path = extensions_dir_.AppendASCII(name); | 127 FilePath path = extensions_dir_.AppendASCII(name); |
| 117 std::string errors; | 128 std::string errors; |
| 118 scoped_refptr<Extension> extension = Extension::Create( | 129 scoped_refptr<Extension> extension = Extension::Create( |
| 119 path, location, manifest, extra_flags, &errors); | 130 path, location, manifest, extra_flags, &errors); |
| 120 EXPECT_TRUE(extension); | 131 EXPECT_TRUE(extension) << errors; |
| 121 if (!extension) | 132 if (!extension) |
| 122 return NULL; | 133 return NULL; |
| 123 | 134 |
| 124 EXPECT_TRUE(Extension::IdIsValid(extension->id())); | 135 EXPECT_TRUE(Extension::IdIsValid(extension->id())); |
| 125 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, | 136 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, |
| 126 extra_flags & Extension::FROM_WEBSTORE, 0); | 137 extra_flags & Extension::FROM_WEBSTORE, 0); |
| 127 return extension; | 138 return extension; |
| 128 } | 139 } |
| 129 | 140 |
| 130 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { | 141 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { |
| 131 scoped_refptr<Extension> extension(AddExtension(name)); | 142 scoped_refptr<Extension> extension(AddExtension(name)); |
| 132 return extension->id(); | 143 return extension->id(); |
| 133 } | 144 } |
| 134 | 145 |
| 135 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | 146 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { |
| 136 return pref_service_->CreateIncognitoPrefService( | 147 return pref_service_->CreateIncognitoPrefService( |
| 137 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | 148 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); |
| 138 } | 149 } |
| OLD | NEW |