| 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 "chrome/browser/extensions/test_extension_environment.h" | 5 #include "chrome/browser/extensions/test_extension_environment.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/chromeos/settings/cros_settings.h" | 30 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 31 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 31 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 namespace extensions { | 34 namespace extensions { |
| 35 | 35 |
| 36 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 scoped_ptr<base::DictionaryValue> MakeExtensionManifest( | 40 std::unique_ptr<base::DictionaryValue> MakeExtensionManifest( |
| 41 const base::Value& manifest_extra) { | 41 const base::Value& manifest_extra) { |
| 42 scoped_ptr<base::DictionaryValue> manifest = DictionaryBuilder() | 42 std::unique_ptr<base::DictionaryValue> manifest = |
| 43 .Set("name", "Extension") | 43 DictionaryBuilder() |
| 44 .Set("version", "1.0") | 44 .Set("name", "Extension") |
| 45 .Set("manifest_version", 2) | 45 .Set("version", "1.0") |
| 46 .Build(); | 46 .Set("manifest_version", 2) |
| 47 .Build(); |
| 47 const base::DictionaryValue* manifest_extra_dict; | 48 const base::DictionaryValue* manifest_extra_dict; |
| 48 if (manifest_extra.GetAsDictionary(&manifest_extra_dict)) { | 49 if (manifest_extra.GetAsDictionary(&manifest_extra_dict)) { |
| 49 manifest->MergeDictionary(manifest_extra_dict); | 50 manifest->MergeDictionary(manifest_extra_dict); |
| 50 } else { | 51 } else { |
| 51 std::string manifest_json; | 52 std::string manifest_json; |
| 52 base::JSONWriter::Write(manifest_extra, &manifest_json); | 53 base::JSONWriter::Write(manifest_extra, &manifest_json); |
| 53 ADD_FAILURE() << "Expected dictionary; got \"" << manifest_json << "\""; | 54 ADD_FAILURE() << "Expected dictionary; got \"" << manifest_json << "\""; |
| 54 } | 55 } |
| 55 return manifest; | 56 return manifest; |
| 56 } | 57 } |
| 57 | 58 |
| 58 scoped_ptr<base::DictionaryValue> MakePackagedAppManifest() { | 59 std::unique_ptr<base::DictionaryValue> MakePackagedAppManifest() { |
| 59 return extensions::DictionaryBuilder() | 60 return extensions::DictionaryBuilder() |
| 60 .Set("name", "Test App Name") | 61 .Set("name", "Test App Name") |
| 61 .Set("version", "2.0") | 62 .Set("version", "2.0") |
| 62 .Set("manifest_version", 2) | 63 .Set("manifest_version", 2) |
| 63 .Set("app", extensions::DictionaryBuilder() | 64 .Set("app", extensions::DictionaryBuilder() |
| 64 .Set("background", | 65 .Set("background", |
| 65 extensions::DictionaryBuilder() | 66 extensions::DictionaryBuilder() |
| 66 .Set("scripts", extensions::ListBuilder() | 67 .Set("scripts", extensions::ListBuilder() |
| 67 .Append("background.js") | 68 .Append("background.js") |
| 68 .Build()) | 69 .Build()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 extension_service_ = CreateExtensionServiceForProfile(profile()); | 134 extension_service_ = CreateExtensionServiceForProfile(profile()); |
| 134 return extension_service_; | 135 return extension_service_; |
| 135 } | 136 } |
| 136 | 137 |
| 137 ExtensionPrefs* TestExtensionEnvironment::GetExtensionPrefs() { | 138 ExtensionPrefs* TestExtensionEnvironment::GetExtensionPrefs() { |
| 138 return ExtensionPrefs::Get(profile_.get()); | 139 return ExtensionPrefs::Get(profile_.get()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 const Extension* TestExtensionEnvironment::MakeExtension( | 142 const Extension* TestExtensionEnvironment::MakeExtension( |
| 142 const base::Value& manifest_extra) { | 143 const base::Value& manifest_extra) { |
| 143 scoped_ptr<base::DictionaryValue> manifest = | 144 std::unique_ptr<base::DictionaryValue> manifest = |
| 144 MakeExtensionManifest(manifest_extra); | 145 MakeExtensionManifest(manifest_extra); |
| 145 scoped_refptr<Extension> result = | 146 scoped_refptr<Extension> result = |
| 146 ExtensionBuilder().SetManifest(std::move(manifest)).Build(); | 147 ExtensionBuilder().SetManifest(std::move(manifest)).Build(); |
| 147 GetExtensionService()->AddExtension(result.get()); | 148 GetExtensionService()->AddExtension(result.get()); |
| 148 return result.get(); | 149 return result.get(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 const Extension* TestExtensionEnvironment::MakeExtension( | 152 const Extension* TestExtensionEnvironment::MakeExtension( |
| 152 const base::Value& manifest_extra, | 153 const base::Value& manifest_extra, |
| 153 const std::string& id) { | 154 const std::string& id) { |
| 154 scoped_ptr<base::DictionaryValue> manifest = | 155 std::unique_ptr<base::DictionaryValue> manifest = |
| 155 MakeExtensionManifest(manifest_extra); | 156 MakeExtensionManifest(manifest_extra); |
| 156 scoped_refptr<Extension> result = | 157 scoped_refptr<Extension> result = |
| 157 ExtensionBuilder().SetManifest(std::move(manifest)).SetID(id).Build(); | 158 ExtensionBuilder().SetManifest(std::move(manifest)).SetID(id).Build(); |
| 158 GetExtensionService()->AddExtension(result.get()); | 159 GetExtensionService()->AddExtension(result.get()); |
| 159 return result.get(); | 160 return result.get(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 scoped_refptr<Extension> TestExtensionEnvironment::MakePackagedApp( | 163 scoped_refptr<Extension> TestExtensionEnvironment::MakePackagedApp( |
| 163 const std::string& id, | 164 const std::string& id, |
| 164 bool install) { | 165 bool install) { |
| 165 scoped_refptr<Extension> result = ExtensionBuilder() | 166 scoped_refptr<Extension> result = ExtensionBuilder() |
| 166 .SetManifest(MakePackagedAppManifest()) | 167 .SetManifest(MakePackagedAppManifest()) |
| 167 .AddFlags(Extension::FROM_WEBSTORE) | 168 .AddFlags(Extension::FROM_WEBSTORE) |
| 168 .SetID(id) | 169 .SetID(id) |
| 169 .Build(); | 170 .Build(); |
| 170 if (install) | 171 if (install) |
| 171 GetExtensionService()->AddExtension(result.get()); | 172 GetExtensionService()->AddExtension(result.get()); |
| 172 return result; | 173 return result; |
| 173 } | 174 } |
| 174 | 175 |
| 175 scoped_ptr<content::WebContents> TestExtensionEnvironment::MakeTab() const { | 176 std::unique_ptr<content::WebContents> TestExtensionEnvironment::MakeTab() |
| 176 scoped_ptr<content::WebContents> contents( | 177 const { |
| 178 std::unique_ptr<content::WebContents> contents( |
| 177 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 179 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
| 178 // Create a tab id. | 180 // Create a tab id. |
| 179 SessionTabHelper::CreateForWebContents(contents.get()); | 181 SessionTabHelper::CreateForWebContents(contents.get()); |
| 180 return contents; | 182 return contents; |
| 181 } | 183 } |
| 182 | 184 |
| 183 void TestExtensionEnvironment::DeleteProfile() { | 185 void TestExtensionEnvironment::DeleteProfile() { |
| 184 profile_.reset(); | 186 profile_.reset(); |
| 185 extension_service_ = nullptr; | 187 extension_service_ = nullptr; |
| 186 } | 188 } |
| 187 | 189 |
| 188 } // namespace extensions | 190 } // namespace extensions |
| OLD | NEW |