Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/sync/test/integration/sync_extension_helper.cc

Issue 11308072: Include v2 packaged apps in sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment explaining index Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/sync/test/integration/sync_extension_helper.h" 5 #include "chrome/browser/sync/test/integration/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"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 Profile* profile, const std::string& id) const { 133 Profile* profile, const std::string& id) const {
134 const extensions::PendingExtensionManager* pending_extension_manager = 134 const extensions::PendingExtensionManager* pending_extension_manager =
135 profile->GetExtensionService()->pending_extension_manager(); 135 profile->GetExtensionService()->pending_extension_manager();
136 const extensions::PendingExtensionInfo* info = 136 const extensions::PendingExtensionInfo* info =
137 pending_extension_manager->GetById(id); 137 pending_extension_manager->GetById(id);
138 if (!info) 138 if (!info)
139 return false; 139 return false;
140 return info->is_from_sync(); 140 return info->is_from_sync();
141 } 141 }
142 142
143 void SyncExtensionHelper::InstallExtensionsPendingForSync( 143 void SyncExtensionHelper::InstallExtensionsPendingForSync(Profile* profile) {
144 Profile* profile, Extension::Type type) {
145 // TODO(akalin): Mock out the servers that the extensions auto-update 144 // TODO(akalin): Mock out the servers that the extensions auto-update
146 // mechanism talk to so as to more closely match what actually happens. 145 // mechanism talk to so as to more closely match what actually happens.
147 // Background networking will need to be re-enabled for extensions tests. 146 // Background networking will need to be re-enabled for extensions tests.
148 147
149 // We make a copy here since InstallExtension() removes the 148 // We make a copy here since InstallExtension() removes the
150 // extension from the extensions service's copy. 149 // extension from the extensions service's copy.
151 const extensions::PendingExtensionManager* pending_extension_manager = 150 const extensions::PendingExtensionManager* pending_extension_manager =
152 profile->GetExtensionService()->pending_extension_manager(); 151 profile->GetExtensionService()->pending_extension_manager();
153 152
154 std::list<std::string> pending_crx_ids; 153 std::list<std::string> pending_crx_ids;
155 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); 154 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids);
156 155
157 std::list<std::string>::const_iterator iter; 156 std::list<std::string>::const_iterator iter;
158 const extensions::PendingExtensionInfo* info = NULL; 157 const extensions::PendingExtensionInfo* info = NULL;
159 for (iter = pending_crx_ids.begin(); iter != pending_crx_ids.end(); ++iter) { 158 for (iter = pending_crx_ids.begin(); iter != pending_crx_ids.end(); ++iter) {
160 ASSERT_TRUE((info = pending_extension_manager->GetById(*iter))); 159 ASSERT_TRUE((info = pending_extension_manager->GetById(*iter)));
161 if (!info->is_from_sync()) 160 if (!info->is_from_sync())
162 continue; 161 continue;
163 162
164 StringMap::const_iterator iter2 = id_to_name_.find(*iter); 163 StringMap::const_iterator iter2 = id_to_name_.find(*iter);
165 if (iter2 == id_to_name_.end()) { 164 if (iter2 == id_to_name_.end()) {
166 ADD_FAILURE() << "Could not get name for id " << *iter 165 ADD_FAILURE() << "Could not get name for id " << *iter
167 << " (profile = " << profile->GetDebugName() << ")"; 166 << " (profile = " << profile->GetDebugName() << ")";
168 continue; 167 continue;
169 } 168 }
170 InstallExtension(profile, iter2->second, type); 169 TypeMap::const_iterator iter3 = id_to_type_.find(*iter);
170 if (iter3 == id_to_type_.end()) {
171 ADD_FAILURE() << "Could not get type for id " << *iter
172 << " (profile = " << profile->GetDebugName() << ")";
173 }
174 InstallExtension(profile, iter2->second, iter3->second);
171 } 175 }
172 } 176 }
173 177
174 SyncExtensionHelper::ExtensionStateMap 178 SyncExtensionHelper::ExtensionStateMap
175 SyncExtensionHelper::GetExtensionStates(Profile* profile) { 179 SyncExtensionHelper::GetExtensionStates(Profile* profile) {
176 const std::string& profile_debug_name = profile->GetDebugName(); 180 const std::string& profile_debug_name = profile->GetDebugName();
177 181
178 ExtensionStateMap extension_state_map; 182 ExtensionStateMap extension_state_map;
179 183
180 ExtensionService* extension_service = profile->GetExtensionService(); 184 ExtensionService* extension_service = profile->GetExtensionService();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 break; 279 break;
276 case Extension::TYPE_THEME: 280 case Extension::TYPE_THEME:
277 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); 281 source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
278 break; 282 break;
279 case Extension::TYPE_HOSTED_APP: 283 case Extension::TYPE_HOSTED_APP:
280 case Extension::TYPE_LEGACY_PACKAGED_APP: 284 case Extension::TYPE_LEGACY_PACKAGED_APP:
281 source.Set(extension_manifest_keys::kApp, new DictionaryValue()); 285 source.Set(extension_manifest_keys::kApp, new DictionaryValue());
282 source.SetString(extension_manifest_keys::kLaunchWebURL, 286 source.SetString(extension_manifest_keys::kLaunchWebURL,
283 "http://www.example.com"); 287 "http://www.example.com");
284 break; 288 break;
289 case Extension::TYPE_PLATFORM_APP: {
290 source.Set(extension_manifest_keys::kApp, new DictionaryValue());
291 source.Set(extension_manifest_keys::kPlatformAppBackground,
292 new DictionaryValue());
293 ListValue* scripts = new ListValue();
294 scripts->AppendString("main.js");
295 source.Set(extension_manifest_keys::kPlatformAppBackgroundScripts,
296 scripts);
297 break;
298 }
285 default: 299 default:
286 ADD_FAILURE(); 300 ADD_FAILURE();
287 return NULL; 301 return NULL;
288 } 302 }
289 const FilePath sub_dir = FilePath().AppendASCII(name); 303 const FilePath sub_dir = FilePath().AppendASCII(name);
290 FilePath extension_dir; 304 FilePath extension_dir;
291 if (!file_util::PathExists(base_dir) && 305 if (!file_util::PathExists(base_dir) &&
292 !file_util::CreateDirectory(base_dir) && 306 !file_util::CreateDirectory(base_dir)) {
293 !file_util::CreateTemporaryDirInDir( 307 ADD_FAILURE();
308 return NULL;
309 }
310 if (!file_util::CreateTemporaryDirInDir(
294 base_dir, sub_dir.value(), &extension_dir)) { 311 base_dir, sub_dir.value(), &extension_dir)) {
295 ADD_FAILURE(); 312 ADD_FAILURE();
296 return NULL; 313 return NULL;
297 } 314 }
298 std::string error; 315 std::string error;
299 scoped_refptr<Extension> extension = 316 scoped_refptr<Extension> extension =
300 Extension::Create(extension_dir, Extension::INTERNAL, source, 317 Extension::Create(extension_dir, Extension::INTERNAL, source,
301 Extension::NO_FLAGS, &error); 318 Extension::NO_FLAGS, &error);
302 if (!error.empty()) { 319 if (!error.empty()) {
303 ADD_FAILURE() << error; 320 ADD_FAILURE() << error;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 363 }
347 const std::string& expected_id = NameToId(name); 364 const std::string& expected_id = NameToId(name);
348 if (extension->id() != expected_id) { 365 if (extension->id() != expected_id) {
349 EXPECT_EQ(expected_id, extension->id()); 366 EXPECT_EQ(expected_id, extension->id());
350 return NULL; 367 return NULL;
351 } 368 }
352 DVLOG(2) << "created extension with name = " 369 DVLOG(2) << "created extension with name = "
353 << name << ", id = " << expected_id; 370 << name << ", id = " << expected_id;
354 (it->second)[name] = extension; 371 (it->second)[name] = extension;
355 id_to_name_[expected_id] = name; 372 id_to_name_[expected_id] = name;
373 id_to_type_[expected_id] = type;
356 return extension; 374 return extension;
357 } 375 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_extension_helper.h ('k') | chrome/browser/sync/test/integration/sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698