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

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: Review changes 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::LiveSyncExtensionHelper() {} 19 LiveSyncExtensionHelper::LiveSyncExtensionHelper() {}
20 20
21 LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {} 21 LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {}
22 22
23 bool LiveSyncExtensionHelper::ExtensionState::operator==(
24 const LiveSyncExtensionHelper::ExtensionState &other) const {
25 return ((enabled_state == other.enabled_state) &&
26 (incognito_enabled == other.incognito_enabled));
27 }
28
23 // static 29 // static
24 std::string LiveSyncExtensionHelper::NameToId(const std::string& name) { 30 std::string LiveSyncExtensionHelper::NameToId(const std::string& name) {
25 std::string id; 31 std::string id;
26 EXPECT_TRUE(Extension::GenerateId(name, &id)); 32 EXPECT_TRUE(Extension::GenerateId(name, &id));
27 return id; 33 return id;
28 } 34 }
29 35
30 void LiveSyncExtensionHelper::Setup(LiveSyncTest* test) { 36 void LiveSyncExtensionHelper::Setup(LiveSyncTest* test) {
31 for (int i = 0; i < test->num_clients(); ++i) { 37 for (int i = 0; i < test->num_clients(); ++i) {
32 SetupProfile(test->GetProfile(i)); 38 SetupProfile(test->GetProfile(i));
33 } 39 }
34 SetupProfile(test->verifier()); 40 SetupProfile(test->verifier());
35 } 41 }
36 42
37 void LiveSyncExtensionHelper::InstallExtension( 43 void LiveSyncExtensionHelper::InstallExtension(
38 Profile* profile, const std::string& name, Extension::Type type) { 44 Profile* profile, const std::string& name, Extension::Type type) {
39 scoped_refptr<Extension> extension = GetExtension(profile, name, type); 45 scoped_refptr<Extension> extension = GetExtension(profile, name, type);
40 ASSERT_TRUE(extension.get()) << "Could not get extension " << name 46 ASSERT_TRUE(extension.get()) << "Could not get extension " << name
41 << " (profile = " << profile << ")"; 47 << " (profile = " << profile << ")";
42 profile->GetExtensionService()->OnExtensionInstalled(extension); 48 profile->GetExtensionService()->OnExtensionInstalled(extension);
43 } 49 }
44 50
45 void LiveSyncExtensionHelper::UninstallExtension( 51 void LiveSyncExtensionHelper::UninstallExtension(
46 Profile* profile, const std::string& name) { 52 Profile* profile, const std::string& name) {
47 ExtensionService::UninstallExtensionHelper(profile->GetExtensionService(), 53 ExtensionService::UninstallExtensionHelper(profile->GetExtensionService(),
48 NameToId(name)); 54 NameToId(name));
49 } 55 }
50 56
57 void LiveSyncExtensionHelper::EnableExtension(Profile* profile,
58 const std::string& name) {
59 profile->GetExtensionService()->EnableExtension(NameToId(name));
60 }
61
62 void LiveSyncExtensionHelper::DisableExtension(Profile* profile,
63 const std::string& name) {
64 profile->GetExtensionService()->DisableExtension(NameToId(name));
65 }
66
67 void LiveSyncExtensionHelper::IncognitoEnableExtension(
68 Profile* profile, const std::string& name) {
69 profile->GetExtensionService()->SetIsIncognitoEnabled(NameToId(name), true);
70 }
71
72 void LiveSyncExtensionHelper::IncognitoDisableExtension(
73 Profile* profile, const std::string& name) {
74 profile->GetExtensionService()->SetIsIncognitoEnabled(NameToId(name), false);
75 }
76
51 bool LiveSyncExtensionHelper::IsExtensionPendingInstallForSync( 77 bool LiveSyncExtensionHelper::IsExtensionPendingInstallForSync(
52 Profile* profile, const std::string& id) const { 78 Profile* profile, const std::string& id) const {
53 const PendingExtensionManager* pending_extension_manager = 79 const PendingExtensionManager* pending_extension_manager =
54 profile->GetExtensionService()->pending_extension_manager(); 80 profile->GetExtensionService()->pending_extension_manager();
55 PendingExtensionInfo info; 81 PendingExtensionInfo info;
56 if (!pending_extension_manager->GetById(id, &info)) { 82 if (!pending_extension_manager->GetById(id, &info)) {
57 return false; 83 return false;
58 } 84 }
59 return info.is_from_sync(); 85 return info.is_from_sync();
60 } 86 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 Profile* profile) const { 119 Profile* profile) const {
94 const std::string& profile_debug_name = profile->GetDebugName(); 120 const std::string& profile_debug_name = profile->GetDebugName();
95 121
96 ExtensionStateMap extension_state_map; 122 ExtensionStateMap extension_state_map;
97 123
98 ExtensionService* extension_service = profile->GetExtensionService(); 124 ExtensionService* extension_service = profile->GetExtensionService();
99 125
100 const ExtensionList* extensions = extension_service->extensions(); 126 const ExtensionList* extensions = extension_service->extensions();
101 for (ExtensionList::const_iterator it = extensions->begin(); 127 for (ExtensionList::const_iterator it = extensions->begin();
102 it != extensions->end(); ++it) { 128 it != extensions->end(); ++it) {
103 extension_state_map[(*it)->id()] = ENABLED; 129 extension_state_map[(*it)->id()].enabled_state = ExtensionState::ENABLED;
130 if (extension_service->IsIncognitoEnabled((*it)->id())) {
akalin 2011/06/09 20:35:37 lotta duplicated code. Perhaps decomp into a sepa
braffert 2011/06/09 23:09:35 I'm not sure if this is a good idea as such a func
131 extension_state_map[(*it)->id()].incognito_enabled = true;
akalin 2011/06/09 20:35:37 simpler to do extension_state_map[...].incognito_
braffert 2011/06/09 23:09:35 Done.
132 VLOG(2) << "incognito enabled...";
133 } else {
134 extension_state_map[(*it)->id()].incognito_enabled = false;
135 VLOG(2) << "incognito disabled...";
136 }
104 VLOG(2) << "Extension " << (*it)->id() << " in profile " 137 VLOG(2) << "Extension " << (*it)->id() << " in profile "
105 << profile_debug_name << " is enabled"; 138 << profile_debug_name << " is enabled";
106 } 139 }
107 140
108 const ExtensionList* disabled_extensions = 141 const ExtensionList* disabled_extensions =
109 extension_service->disabled_extensions(); 142 extension_service->disabled_extensions();
110 for (ExtensionList::const_iterator it = disabled_extensions->begin(); 143 for (ExtensionList::const_iterator it = disabled_extensions->begin();
111 it != disabled_extensions->end(); ++it) { 144 it != disabled_extensions->end(); ++it) {
112 extension_state_map[(*it)->id()] = DISABLED; 145 extension_state_map[(*it)->id()].enabled_state = ExtensionState::DISABLED;
146 if (extension_service->IsIncognitoEnabled((*it)->id())) {
147 extension_state_map[(*it)->id()].incognito_enabled = true;
148 VLOG(2) << "incognito enabled...";
149 } else {
150 extension_state_map[(*it)->id()].incognito_enabled = false;
151 VLOG(2) << "incognito disabled...";
152 }
113 VLOG(2) << "Extension " << (*it)->id() << " in profile " 153 VLOG(2) << "Extension " << (*it)->id() << " in profile "
114 << profile_debug_name << " is disabled"; 154 << profile_debug_name << " is disabled";
115 } 155 }
116 156
117 const PendingExtensionManager* pending_extension_manager = 157 const PendingExtensionManager* pending_extension_manager =
118 extension_service->pending_extension_manager(); 158 extension_service->pending_extension_manager();
119 PendingExtensionManager::const_iterator it; 159 PendingExtensionManager::const_iterator it;
120 for (it = pending_extension_manager->begin(); 160 for (it = pending_extension_manager->begin();
121 it != pending_extension_manager->end(); ++it) { 161 it != pending_extension_manager->end(); ++it) {
122 extension_state_map[it->first] = PENDING; 162 extension_state_map[it->first].enabled_state = ExtensionState::PENDING;
163 if (extension_service->IsIncognitoEnabled(it->first)) {
164 extension_state_map[it->first].incognito_enabled = true;
165 VLOG(2) << "incognito enabled...";
166 } else {
167 extension_state_map[it->first].incognito_enabled = false;
168 VLOG(2) << "incognito disabled...";
169 }
123 VLOG(2) << "Extension " << it->first << " in profile " 170 VLOG(2) << "Extension " << it->first << " in profile "
124 << profile_debug_name << " is pending"; 171 << profile_debug_name << " is pending";
125 } 172 }
126 173
127 return extension_state_map; 174 return extension_state_map;
128 } 175 }
129 176
130 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) { 177 void LiveSyncExtensionHelper::SetupProfile(Profile* profile) {
131 profile->InitExtensions(true); 178 profile->InitExtensions(true);
132 profile_extensions_.insert(make_pair(profile, ExtensionNameMap())); 179 profile_extensions_.insert(make_pair(profile, ExtensionNameMap()));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (extension->id() != expected_id) { 279 if (extension->id() != expected_id) {
233 EXPECT_EQ(expected_id, extension->id()); 280 EXPECT_EQ(expected_id, extension->id());
234 return NULL; 281 return NULL;
235 } 282 }
236 VLOG(2) << "created extension with name = " 283 VLOG(2) << "created extension with name = "
237 << name << ", id = " << expected_id; 284 << name << ", id = " << expected_id;
238 (it->second)[name] = extension; 285 (it->second)[name] = extension;
239 id_to_name_[expected_id] = name; 286 id_to_name_[expected_id] = name;
240 return extension; 287 return extension;
241 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698