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

Side by Side Diff: chrome/test/live_sync/live_sync_extension_helper.cc

Issue 7104072: Adding new extension sync integration tests. Also modified the way that profile (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix spacing Created 9 years, 6 months 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) 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
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
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::ExtensionStateMapsMatch(
171 Profile* profile1, Profile* profile2) {
172 ExtensionStateMap state_map1 = GetExtensionStates(profile1);
173 ExtensionStateMap state_map2 = GetExtensionStates(profile2);
174 for (ExtensionStateMap::iterator it = state_map1.begin();
175 it != state_map1.end(); ++it) {
176 if (!it->second.Equals(state_map2[it->first])) {
akalin 2011/06/09 23:44:39 this isn't quite correct. state_map2[...] auto-cr
braffert 2011/06/10 01:23:58 Done.
177 return false;
178 }
179 state_map2.erase(it->first);
180 }
181 return state_map2.empty();
182 }
183
130 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) { 184 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) {
131 profile->InitExtensions(true); 185 profile->InitExtensions(true);
132 profile_extensions_.insert(make_pair(profile, ExtensionNameMap())); 186 profile_extensions_.insert(make_pair(profile, ExtensionNameMap()));
133 } 187 }
134 188
135 namespace { 189 namespace {
136 190
137 std::string NameToPublicKey(const std::string& name) { 191 std::string NameToPublicKey(const std::string& name) {
138 std::string public_key; 192 std::string public_key;
139 std::string pem; 193 std::string pem;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (extension->id() != expected_id) { 286 if (extension->id() != expected_id) {
233 EXPECT_EQ(expected_id, extension->id()); 287 EXPECT_EQ(expected_id, extension->id());
234 return NULL; 288 return NULL;
235 } 289 }
236 VLOG(2) << "created extension with name = " 290 VLOG(2) << "created extension with name = "
237 << name << ", id = " << expected_id; 291 << name << ", id = " << expected_id;
238 (it->second)[name] = extension; 292 (it->second)[name] = extension;
239 id_to_name_[expected_id] = name; 293 id_to_name_[expected_id] = name;
240 return extension; 294 return extension;
241 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698