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(const std::string& id, bool is_app) { | |
41 DictionaryValue manifest; | |
akalin
2011/10/28 06:04:54
I'm pretty sure there's a test function floating a
not at google - send to devlin
2011/10/31 00:02:23
There's only 1 caller of CreateWithId (surprisingl
| |
42 manifest.SetString("name", std::string("Test extension ") + id); | |
43 manifest.SetString("version", "1.0"); | |
44 if (is_app) { | |
45 DictionaryValue* app = new DictionaryValue(); | |
46 DictionaryValue* app_launch = new DictionaryValue(); | |
47 app_launch->SetString("local_path", "fake.html"); | |
48 app->Set("launch", app_launch); | |
49 manifest.Set("app", app); | |
50 } | |
51 | |
52 std::string error; | |
53 extensions_[id] = Extension::CreateWithId( | |
54 FilePath(), | |
55 Extension::INTERNAL, | |
56 manifest, | |
57 Extension::NO_FLAGS, | |
58 id, | |
59 &error); | |
60 DCHECK(error.empty()); | |
61 } | |
62 | |
63 MockProfile::MockProfile(const FilePath& file_path) | |
64 : TestingProfile(file_path) { | |
65 event_router_.reset(new ExtensionEventRouter(this)); | |
66 } | |
67 | |
68 MockProfile::~MockProfile() {} | |
69 | |
70 MockExtensionService* MockProfile::GetMockExtensionService() { | |
71 return &extension_service_; | |
72 } | |
73 | |
74 ExtensionService* MockProfile::GetExtensionService() { | |
75 ExtensionServiceInterface* as_interface = | |
76 static_cast<ExtensionServiceInterface*>(&extension_service_); | |
77 return static_cast<ExtensionService*>(as_interface); | |
78 } | |
79 | |
80 ExtensionEventRouter* MockProfile::GetExtensionEventRouter() { | |
81 return event_router_.get(); | |
82 } | |
83 | |
84 } // namespace extension_settings_test_util | |
OLD | NEW |