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/test/live_sync/live_sync_extension_helper.h" | 5 #include "chrome/test/live_sync/live_sync_extension_helper.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/pending_extension_info.h" | 12 #include "chrome/browser/extensions/pending_extension_info.h" |
13 #include "chrome/browser/extensions/pending_extension_manager.h" | 13 #include "chrome/browser/extensions/pending_extension_manager.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
16 #include "chrome/test/live_sync/live_sync_test.h" | 16 #include "chrome/test/live_sync/live_sync_test.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 LiveSyncExtensionHelper::ExtensionState::ExtensionState() | |
20 : enabled_state(ENABLED), incognito_enabled(false) {} | |
21 | |
22 LiveSyncExtensionHelper::ExtensionState::~ExtensionState() {} | |
23 | |
24 bool LiveSyncExtensionHelper::ExtensionState::Equals( | |
25 const LiveSyncExtensionHelper::ExtensionState &other) const { | |
26 return ((enabled_state == other.enabled_state) && | |
27 (incognito_enabled == other.incognito_enabled)); | |
28 } | |
29 | |
19 LiveSyncExtensionHelper::LiveSyncExtensionHelper() {} | 30 LiveSyncExtensionHelper::LiveSyncExtensionHelper() {} |
20 | 31 |
21 LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {} | 32 LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {} |
22 | 33 |
23 // static | 34 // static |
24 std::string LiveSyncExtensionHelper::NameToId(const std::string& name) { | 35 std::string LiveSyncExtensionHelper::NameToId(const std::string& name) { |
25 std::string id; | 36 std::string id; |
26 EXPECT_TRUE(Extension::GenerateId(name, &id)); | 37 EXPECT_TRUE(Extension::GenerateId(name, &id)); |
27 return id; | 38 return id; |
28 } | 39 } |
(...skipping 12 matching lines...) Expand all Loading... | |
41 << " (profile = " << profile << ")"; | 52 << " (profile = " << profile << ")"; |
42 profile->GetExtensionService()->OnExtensionInstalled(extension); | 53 profile->GetExtensionService()->OnExtensionInstalled(extension); |
43 } | 54 } |
44 | 55 |
45 void LiveSyncExtensionHelper::UninstallExtension( | 56 void LiveSyncExtensionHelper::UninstallExtension( |
46 Profile* profile, const std::string& name) { | 57 Profile* profile, const std::string& name) { |
47 ExtensionService::UninstallExtensionHelper(profile->GetExtensionService(), | 58 ExtensionService::UninstallExtensionHelper(profile->GetExtensionService(), |
48 NameToId(name)); | 59 NameToId(name)); |
49 } | 60 } |
50 | 61 |
62 void LiveSyncExtensionHelper::EnableExtension(Profile* profile, | |
63 const std::string& name) { | |
64 profile->GetExtensionService()->EnableExtension(NameToId(name)); | |
65 } | |
66 | |
67 void LiveSyncExtensionHelper::DisableExtension(Profile* profile, | |
68 const std::string& name) { | |
69 profile->GetExtensionService()->DisableExtension(NameToId(name)); | |
70 } | |
71 | |
72 void LiveSyncExtensionHelper::IncognitoEnableExtension( | |
73 Profile* profile, const std::string& name) { | |
74 profile->GetExtensionService()->SetIsIncognitoEnabled(NameToId(name), true); | |
75 } | |
76 | |
77 void LiveSyncExtensionHelper::IncognitoDisableExtension( | |
78 Profile* profile, const std::string& name) { | |
79 profile->GetExtensionService()->SetIsIncognitoEnabled(NameToId(name), false); | |
80 } | |
81 | |
51 bool LiveSyncExtensionHelper::IsExtensionPendingInstallForSync( | 82 bool LiveSyncExtensionHelper::IsExtensionPendingInstallForSync( |
52 Profile* profile, const std::string& id) const { | 83 Profile* profile, const std::string& id) const { |
53 const PendingExtensionManager* pending_extension_manager = | 84 const PendingExtensionManager* pending_extension_manager = |
54 profile->GetExtensionService()->pending_extension_manager(); | 85 profile->GetExtensionService()->pending_extension_manager(); |
55 PendingExtensionInfo info; | 86 PendingExtensionInfo info; |
56 if (!pending_extension_manager->GetById(id, &info)) { | 87 if (!pending_extension_manager->GetById(id, &info)) { |
57 return false; | 88 return false; |
58 } | 89 } |
59 return info.is_from_sync(); | 90 return info.is_from_sync(); |
60 } | 91 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 Profile* profile) const { | 124 Profile* profile) const { |
94 const std::string& profile_debug_name = profile->GetDebugName(); | 125 const std::string& profile_debug_name = profile->GetDebugName(); |
95 | 126 |
96 ExtensionStateMap extension_state_map; | 127 ExtensionStateMap extension_state_map; |
97 | 128 |
98 ExtensionService* extension_service = profile->GetExtensionService(); | 129 ExtensionService* extension_service = profile->GetExtensionService(); |
99 | 130 |
100 const ExtensionList* extensions = extension_service->extensions(); | 131 const ExtensionList* extensions = extension_service->extensions(); |
101 for (ExtensionList::const_iterator it = extensions->begin(); | 132 for (ExtensionList::const_iterator it = extensions->begin(); |
102 it != extensions->end(); ++it) { | 133 it != extensions->end(); ++it) { |
103 extension_state_map[(*it)->id()] = ENABLED; | 134 const std::string& id = (*it)->id(); |
135 extension_state_map[id].enabled_state = ExtensionState::ENABLED; | |
136 extension_state_map[id].incognito_enabled = | |
137 extension_service->IsIncognitoEnabled(id); | |
104 VLOG(2) << "Extension " << (*it)->id() << " in profile " | 138 VLOG(2) << "Extension " << (*it)->id() << " in profile " |
105 << profile_debug_name << " is enabled"; | 139 << profile_debug_name << " is enabled"; |
106 } | 140 } |
107 | 141 |
108 const ExtensionList* disabled_extensions = | 142 const ExtensionList* disabled_extensions = |
109 extension_service->disabled_extensions(); | 143 extension_service->disabled_extensions(); |
110 for (ExtensionList::const_iterator it = disabled_extensions->begin(); | 144 for (ExtensionList::const_iterator it = disabled_extensions->begin(); |
111 it != disabled_extensions->end(); ++it) { | 145 it != disabled_extensions->end(); ++it) { |
112 extension_state_map[(*it)->id()] = DISABLED; | 146 const std::string& id = (*it)->id(); |
147 extension_state_map[id].enabled_state = ExtensionState::DISABLED; | |
148 extension_state_map[id].incognito_enabled = | |
149 extension_service->IsIncognitoEnabled(id); | |
113 VLOG(2) << "Extension " << (*it)->id() << " in profile " | 150 VLOG(2) << "Extension " << (*it)->id() << " in profile " |
114 << profile_debug_name << " is disabled"; | 151 << profile_debug_name << " is disabled"; |
115 } | 152 } |
116 | 153 |
117 const PendingExtensionManager* pending_extension_manager = | 154 const PendingExtensionManager* pending_extension_manager = |
118 extension_service->pending_extension_manager(); | 155 extension_service->pending_extension_manager(); |
119 PendingExtensionManager::const_iterator it; | 156 PendingExtensionManager::const_iterator it; |
120 for (it = pending_extension_manager->begin(); | 157 for (it = pending_extension_manager->begin(); |
121 it != pending_extension_manager->end(); ++it) { | 158 it != pending_extension_manager->end(); ++it) { |
122 extension_state_map[it->first] = PENDING; | 159 const std::string& id = it->first; |
160 extension_state_map[id].enabled_state = ExtensionState::PENDING; | |
161 extension_state_map[id].incognito_enabled = | |
162 extension_service->IsIncognitoEnabled(id); | |
123 VLOG(2) << "Extension " << it->first << " in profile " | 163 VLOG(2) << "Extension " << it->first << " in profile " |
124 << profile_debug_name << " is pending"; | 164 << profile_debug_name << " is pending"; |
125 } | 165 } |
126 | 166 |
127 return extension_state_map; | 167 return extension_state_map; |
128 } | 168 } |
129 | 169 |
170 bool LiveSyncExtensionHelper::ExtensionStatesMatch( | |
171 Profile* profile1, Profile* profile2) const { | |
172 const ExtensionStateMap& state_map1 = GetExtensionStates(profile1); | |
173 const ExtensionStateMap& state_map2 = GetExtensionStates(profile2); | |
174 if (state_map1.size() != state_map2.size()) { | |
175 VLOG(1) << "Number of extensions for profile " << profile1->GetDebugName() | |
176 << " does not match profile " << profile2->GetDebugName(); | |
177 return false; | |
178 } | |
179 | |
180 ExtensionStateMap::const_iterator it1 = state_map1.begin(); | |
181 ExtensionStateMap::const_iterator it2 = state_map2.begin(); | |
182 while (it1 != state_map1.end()) { | |
183 if (it1->first != it2->first) { | |
184 VLOG(1) << "Extensions for profile " << profile1->GetDebugName() | |
185 << " do not match profile " << profile2->GetDebugName(); | |
186 return false; | |
187 } else if (!(it1->second.Equals(it2->second))) { | |
akalin
2011/06/10 01:56:44
usual Google/Chrome style is to not have parenthes
| |
188 VLOG(1) << "Extension states for profile " << profile1->GetDebugName() | |
braffert
2011/06/10 16:49:17
Done. I had thought that without the parentheses
| |
189 << " do not match profile " << profile2->GetDebugName(); | |
190 return false; | |
191 } | |
192 ++it1; | |
193 ++it2; | |
194 } | |
195 return true; | |
196 } | |
197 | |
130 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) { | 198 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) { |
131 profile->InitExtensions(true); | 199 profile->InitExtensions(true); |
132 profile_extensions_.insert(make_pair(profile, ExtensionNameMap())); | 200 profile_extensions_.insert(make_pair(profile, ExtensionNameMap())); |
133 } | 201 } |
134 | 202 |
135 namespace { | 203 namespace { |
136 | 204 |
137 std::string NameToPublicKey(const std::string& name) { | 205 std::string NameToPublicKey(const std::string& name) { |
138 std::string public_key; | 206 std::string public_key; |
139 std::string pem; | 207 std::string pem; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 if (extension->id() != expected_id) { | 300 if (extension->id() != expected_id) { |
233 EXPECT_EQ(expected_id, extension->id()); | 301 EXPECT_EQ(expected_id, extension->id()); |
234 return NULL; | 302 return NULL; |
235 } | 303 } |
236 VLOG(2) << "created extension with name = " | 304 VLOG(2) << "created extension with name = " |
237 << name << ", id = " << expected_id; | 305 << name << ", id = " << expected_id; |
238 (it->second)[name] = extension; | 306 (it->second)[name] = extension; |
239 id_to_name_[expected_id] = name; | 307 id_to_name_[expected_id] = name; |
240 return extension; | 308 return extension; |
241 } | 309 } |
OLD | NEW |