| 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 namespace { | |
| 20 | |
| 21 std::string GetProfileName(Profile* profile) { | |
| 22 const std::string& name = profile->GetPath().BaseName().MaybeAsASCII(); | |
| 23 EXPECT_FALSE(name.empty()); | |
| 24 return name; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 LiveSyncExtensionHelper::LiveSyncExtensionHelper() {} | 19 LiveSyncExtensionHelper::LiveSyncExtensionHelper() {} |
| 30 | 20 |
| 31 LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {} | 21 LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {} |
| 32 | 22 |
| 33 // static | 23 // static |
| 34 std::string LiveSyncExtensionHelper::NameToId(const std::string& name) { | 24 std::string LiveSyncExtensionHelper::NameToId(const std::string& name) { |
| 35 std::string id; | 25 std::string id; |
| 36 EXPECT_TRUE(Extension::GenerateId(name, &id)); | 26 EXPECT_TRUE(Extension::GenerateId(name, &id)); |
| 37 return id; | 27 return id; |
| 38 } | 28 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 pending_extension_manager->end()); | 74 pending_extension_manager->end()); |
| 85 for (PendingExtensionManager::const_iterator it = pending_extensions.begin(); | 75 for (PendingExtensionManager::const_iterator it = pending_extensions.begin(); |
| 86 it != pending_extensions.end(); ++it) { | 76 it != pending_extensions.end(); ++it) { |
| 87 if (!it->second.is_from_sync()) { | 77 if (!it->second.is_from_sync()) { |
| 88 continue; | 78 continue; |
| 89 } | 79 } |
| 90 const std::string& id = it->first; | 80 const std::string& id = it->first; |
| 91 StringMap::const_iterator it2 = id_to_name_.find(id); | 81 StringMap::const_iterator it2 = id_to_name_.find(id); |
| 92 if (it2 == id_to_name_.end()) { | 82 if (it2 == id_to_name_.end()) { |
| 93 ADD_FAILURE() << "Could not get name for id " << id | 83 ADD_FAILURE() << "Could not get name for id " << id |
| 94 << " (profile = " << GetProfileName(profile) << ")"; | 84 << " (profile = " << profile->GetDebugName() << ")"; |
| 95 continue; | 85 continue; |
| 96 } | 86 } |
| 97 InstallExtension(profile, it2->second, type); | 87 InstallExtension(profile, it2->second, type); |
| 98 } | 88 } |
| 99 } | 89 } |
| 100 | 90 |
| 101 LiveSyncExtensionHelper::ExtensionStateMap | 91 LiveSyncExtensionHelper::ExtensionStateMap |
| 102 LiveSyncExtensionHelper::GetExtensionStates( | 92 LiveSyncExtensionHelper::GetExtensionStates( |
| 103 Profile* profile) const { | 93 Profile* profile) const { |
| 104 const std::string& profile_name = GetProfileName(profile); | 94 const std::string& profile_debug_name = profile->GetDebugName(); |
| 105 | 95 |
| 106 ExtensionStateMap extension_state_map; | 96 ExtensionStateMap extension_state_map; |
| 107 | 97 |
| 108 ExtensionService* extension_service = profile->GetExtensionService(); | 98 ExtensionService* extension_service = profile->GetExtensionService(); |
| 109 | 99 |
| 110 const ExtensionList* extensions = extension_service->extensions(); | 100 const ExtensionList* extensions = extension_service->extensions(); |
| 111 for (ExtensionList::const_iterator it = extensions->begin(); | 101 for (ExtensionList::const_iterator it = extensions->begin(); |
| 112 it != extensions->end(); ++it) { | 102 it != extensions->end(); ++it) { |
| 113 extension_state_map[(*it)->id()] = ENABLED; | 103 extension_state_map[(*it)->id()] = ENABLED; |
| 114 VLOG(2) << "Extension " << (*it)->id() << " in profile " | 104 VLOG(2) << "Extension " << (*it)->id() << " in profile " |
| 115 << profile_name << " is enabled"; | 105 << profile_debug_name << " is enabled"; |
| 116 } | 106 } |
| 117 | 107 |
| 118 const ExtensionList* disabled_extensions = | 108 const ExtensionList* disabled_extensions = |
| 119 extension_service->disabled_extensions(); | 109 extension_service->disabled_extensions(); |
| 120 for (ExtensionList::const_iterator it = disabled_extensions->begin(); | 110 for (ExtensionList::const_iterator it = disabled_extensions->begin(); |
| 121 it != disabled_extensions->end(); ++it) { | 111 it != disabled_extensions->end(); ++it) { |
| 122 extension_state_map[(*it)->id()] = DISABLED; | 112 extension_state_map[(*it)->id()] = DISABLED; |
| 123 VLOG(2) << "Extension " << (*it)->id() << " in profile " | 113 VLOG(2) << "Extension " << (*it)->id() << " in profile " |
| 124 << profile_name << " is disabled"; | 114 << profile_debug_name << " is disabled"; |
| 125 } | 115 } |
| 126 | 116 |
| 127 const PendingExtensionManager* pending_extension_manager = | 117 const PendingExtensionManager* pending_extension_manager = |
| 128 extension_service->pending_extension_manager(); | 118 extension_service->pending_extension_manager(); |
| 129 PendingExtensionManager::const_iterator it; | 119 PendingExtensionManager::const_iterator it; |
| 130 for (it = pending_extension_manager->begin(); | 120 for (it = pending_extension_manager->begin(); |
| 131 it != pending_extension_manager->end(); ++it) { | 121 it != pending_extension_manager->end(); ++it) { |
| 132 extension_state_map[it->first] = PENDING; | 122 extension_state_map[it->first] = PENDING; |
| 133 VLOG(2) << "Extension " << it->first << " in profile " | 123 VLOG(2) << "Extension " << it->first << " in profile " |
| 134 << profile_name << " is pending"; | 124 << profile_debug_name << " is pending"; |
| 135 } | 125 } |
| 136 | 126 |
| 137 return extension_state_map; | 127 return extension_state_map; |
| 138 } | 128 } |
| 139 | 129 |
| 140 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) { | 130 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) { |
| 141 profile->InitExtensions(true); | 131 profile->InitExtensions(true); |
| 142 profile_extensions_.insert(make_pair(profile, ExtensionNameMap())); | 132 profile_extensions_.insert(make_pair(profile, ExtensionNameMap())); |
| 143 } | 133 } |
| 144 | 134 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (extension->id() != expected_id) { | 232 if (extension->id() != expected_id) { |
| 243 EXPECT_EQ(expected_id, extension->id()); | 233 EXPECT_EQ(expected_id, extension->id()); |
| 244 return NULL; | 234 return NULL; |
| 245 } | 235 } |
| 246 VLOG(2) << "created extension with name = " | 236 VLOG(2) << "created extension with name = " |
| 247 << name << ", id = " << expected_id; | 237 << name << ", id = " << expected_id; |
| 248 (it->second)[name] = extension; | 238 (it->second)[name] = extension; |
| 249 id_to_name_[expected_id] = name; | 239 id_to_name_[expected_id] = name; |
| 250 return extension; | 240 return extension; |
| 251 } | 241 } |
| OLD | NEW |