OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_settings_test_util.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "chrome/common/extensions/extension.h" |
| 9 |
| 10 namespace extension_settings_test_util { |
| 11 |
| 12 // Intended as a StorageCallback from GetStorage. |
| 13 static void AssignStorage( |
| 14 ExtensionSettingsStorage** dst, ExtensionSettingsStorage* src) { |
| 15 *dst = src; |
| 16 } |
| 17 |
| 18 ExtensionSettingsStorage* GetStorage( |
| 19 const std::string& extension_id, ExtensionSettingsFrontend* frontend) { |
| 20 ExtensionSettingsStorage* storage = NULL; |
| 21 frontend->RunWithStorage( |
| 22 extension_id, |
| 23 base::Bind(&AssignStorage, &storage)); |
| 24 MessageLoop::current()->RunAllPending(); |
| 25 return storage; |
| 26 } |
| 27 |
| 28 MockExtensionService::MockExtensionService() {} |
| 29 |
| 30 MockExtensionService::~MockExtensionService() {} |
| 31 |
| 32 const Extension* MockExtensionService::GetExtensionById( |
| 33 const std::string& id, bool include_disabled) const { |
| 34 std::map<std::string, scoped_refptr<Extension> >::const_iterator |
| 35 maybe_extension = extensions_.find(id); |
| 36 return maybe_extension == extensions_.end() ? |
| 37 NULL : maybe_extension->second.get(); |
| 38 } |
| 39 |
| 40 void MockExtensionService::AddExtension( |
| 41 const std::string& id, Extension::Type type) { |
| 42 DictionaryValue manifest; |
| 43 manifest.SetString("name", std::string("Test extension ") + id); |
| 44 manifest.SetString("version", "1.0"); |
| 45 |
| 46 switch (type) { |
| 47 case Extension::TYPE_EXTENSION: |
| 48 break; |
| 49 |
| 50 case Extension::TYPE_PACKAGED_APP: { |
| 51 DictionaryValue* app = new DictionaryValue(); |
| 52 DictionaryValue* app_launch = new DictionaryValue(); |
| 53 app_launch->SetString("local_path", "fake.html"); |
| 54 app->Set("launch", app_launch); |
| 55 manifest.Set("app", app); |
| 56 break; |
| 57 } |
| 58 |
| 59 default: |
| 60 NOTREACHED(); |
| 61 } |
| 62 |
| 63 std::string error; |
| 64 extensions_[id] = Extension::CreateWithId( |
| 65 FilePath(), |
| 66 Extension::INTERNAL, |
| 67 manifest, |
| 68 Extension::NO_FLAGS, |
| 69 id, |
| 70 &error); |
| 71 DCHECK(error.empty()); |
| 72 } |
| 73 |
| 74 MockProfile::MockProfile(const FilePath& file_path) |
| 75 : TestingProfile(file_path) { |
| 76 event_router_.reset(new ExtensionEventRouter(this)); |
| 77 } |
| 78 |
| 79 MockProfile::~MockProfile() {} |
| 80 |
| 81 MockExtensionService* MockProfile::GetMockExtensionService() { |
| 82 return &extension_service_; |
| 83 } |
| 84 |
| 85 ExtensionService* MockProfile::GetExtensionService() { |
| 86 ExtensionServiceInterface* as_interface = |
| 87 static_cast<ExtensionServiceInterface*>(&extension_service_); |
| 88 return static_cast<ExtensionService*>(as_interface); |
| 89 } |
| 90 |
| 91 ExtensionEventRouter* MockProfile::GetExtensionEventRouter() { |
| 92 return event_router_.get(); |
| 93 } |
| 94 |
| 95 } // namespace extension_settings_test_util |
OLD | NEW |