OLD | NEW |
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_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.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/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/extensions/pending_extension_info.h" | 13 #include "chrome/browser/extensions/pending_extension_info.h" |
14 #include "chrome/browser/extensions/pending_extension_manager.h" | 14 #include "chrome/browser/extensions/pending_extension_manager.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
17 #include "chrome/browser/sync/test/integration/sync_test.h" | 17 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 18 #include "components/crx_file/id_util.h" |
18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
20 #include "extensions/browser/install_flag.h" | 21 #include "extensions/browser/install_flag.h" |
21 #include "extensions/browser/uninstall_reason.h" | 22 #include "extensions/browser/uninstall_reason.h" |
22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
23 #include "extensions/common/extension_set.h" | 24 #include "extensions/common/extension_set.h" |
24 #include "extensions/common/id_util.h" | |
25 #include "extensions/common/manifest_constants.h" | 25 #include "extensions/common/manifest_constants.h" |
26 #include "sync/api/string_ordinal.h" | 26 #include "sync/api/string_ordinal.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 using extensions::Extension; | 29 using extensions::Extension; |
30 using extensions::ExtensionRegistry; | 30 using extensions::ExtensionRegistry; |
31 using extensions::Manifest; | 31 using extensions::Manifest; |
32 | 32 |
33 SyncExtensionHelper::ExtensionState::ExtensionState() | 33 SyncExtensionHelper::ExtensionState::ExtensionState() |
34 : enabled_state(ENABLED), incognito_enabled(false) {} | 34 : enabled_state(ENABLED), incognito_enabled(false) {} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ->OnExtensionInstalled(extension.get(), | 76 ->OnExtensionInstalled(extension.get(), |
77 syncer::StringOrdinal(), | 77 syncer::StringOrdinal(), |
78 extensions::kInstallFlagInstallImmediately); | 78 extensions::kInstallFlagInstallImmediately); |
79 return extension->id(); | 79 return extension->id(); |
80 } | 80 } |
81 | 81 |
82 void SyncExtensionHelper::UninstallExtension( | 82 void SyncExtensionHelper::UninstallExtension( |
83 Profile* profile, const std::string& name) { | 83 Profile* profile, const std::string& name) { |
84 ExtensionService::UninstallExtensionHelper( | 84 ExtensionService::UninstallExtensionHelper( |
85 extensions::ExtensionSystem::Get(profile)->extension_service(), | 85 extensions::ExtensionSystem::Get(profile)->extension_service(), |
86 extensions::id_util::GenerateId(name), | 86 crx_file::id_util::GenerateId(name), |
87 extensions::UNINSTALL_REASON_SYNC); | 87 extensions::UNINSTALL_REASON_SYNC); |
88 } | 88 } |
89 | 89 |
90 std::vector<std::string> SyncExtensionHelper::GetInstalledExtensionNames( | 90 std::vector<std::string> SyncExtensionHelper::GetInstalledExtensionNames( |
91 Profile* profile) const { | 91 Profile* profile) const { |
92 std::vector<std::string> names; | 92 std::vector<std::string> names; |
93 | 93 |
94 scoped_ptr<const extensions::ExtensionSet> extensions( | 94 scoped_ptr<const extensions::ExtensionSet> extensions( |
95 extensions::ExtensionRegistry::Get(profile) | 95 extensions::ExtensionRegistry::Get(profile) |
96 ->GenerateInstalledExtensionsSet()); | 96 ->GenerateInstalledExtensionsSet()); |
97 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 97 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
98 it != extensions->end(); ++it) { | 98 it != extensions->end(); ++it) { |
99 names.push_back((*it)->name()); | 99 names.push_back((*it)->name()); |
100 } | 100 } |
101 | 101 |
102 return names; | 102 return names; |
103 } | 103 } |
104 | 104 |
105 void SyncExtensionHelper::EnableExtension(Profile* profile, | 105 void SyncExtensionHelper::EnableExtension(Profile* profile, |
106 const std::string& name) { | 106 const std::string& name) { |
107 extensions::ExtensionSystem::Get(profile) | 107 extensions::ExtensionSystem::Get(profile) |
108 ->extension_service() | 108 ->extension_service() |
109 ->EnableExtension(extensions::id_util::GenerateId(name)); | 109 ->EnableExtension(crx_file::id_util::GenerateId(name)); |
110 } | 110 } |
111 | 111 |
112 void SyncExtensionHelper::DisableExtension(Profile* profile, | 112 void SyncExtensionHelper::DisableExtension(Profile* profile, |
113 const std::string& name) { | 113 const std::string& name) { |
114 extensions::ExtensionSystem::Get(profile) | 114 extensions::ExtensionSystem::Get(profile) |
115 ->extension_service() | 115 ->extension_service() |
116 ->DisableExtension(extensions::id_util::GenerateId(name), | 116 ->DisableExtension(crx_file::id_util::GenerateId(name), |
117 Extension::DISABLE_USER_ACTION); | 117 Extension::DISABLE_USER_ACTION); |
118 } | 118 } |
119 | 119 |
120 bool SyncExtensionHelper::IsExtensionEnabled( | 120 bool SyncExtensionHelper::IsExtensionEnabled( |
121 Profile* profile, const std::string& name) const { | 121 Profile* profile, const std::string& name) const { |
122 return extensions::ExtensionSystem::Get(profile) | 122 return extensions::ExtensionSystem::Get(profile) |
123 ->extension_service() | 123 ->extension_service() |
124 ->IsExtensionEnabled(extensions::id_util::GenerateId(name)); | 124 ->IsExtensionEnabled(crx_file::id_util::GenerateId(name)); |
125 } | 125 } |
126 | 126 |
127 void SyncExtensionHelper::IncognitoEnableExtension( | 127 void SyncExtensionHelper::IncognitoEnableExtension( |
128 Profile* profile, const std::string& name) { | 128 Profile* profile, const std::string& name) { |
129 extensions::util::SetIsIncognitoEnabled( | 129 extensions::util::SetIsIncognitoEnabled( |
130 extensions::id_util::GenerateId(name), profile, true); | 130 crx_file::id_util::GenerateId(name), profile, true); |
131 } | 131 } |
132 | 132 |
133 void SyncExtensionHelper::IncognitoDisableExtension( | 133 void SyncExtensionHelper::IncognitoDisableExtension( |
134 Profile* profile, const std::string& name) { | 134 Profile* profile, const std::string& name) { |
135 extensions::util::SetIsIncognitoEnabled( | 135 extensions::util::SetIsIncognitoEnabled( |
136 extensions::id_util::GenerateId(name), profile, false); | 136 crx_file::id_util::GenerateId(name), profile, false); |
137 } | 137 } |
138 | 138 |
139 bool SyncExtensionHelper::IsIncognitoEnabled( | 139 bool SyncExtensionHelper::IsIncognitoEnabled( |
140 Profile* profile, const std::string& name) const { | 140 Profile* profile, const std::string& name) const { |
141 return extensions::util::IsIncognitoEnabled( | 141 return extensions::util::IsIncognitoEnabled( |
142 extensions::id_util::GenerateId(name), profile); | 142 crx_file::id_util::GenerateId(name), profile); |
143 } | 143 } |
144 | 144 |
145 | 145 |
146 bool SyncExtensionHelper::IsExtensionPendingInstallForSync( | 146 bool SyncExtensionHelper::IsExtensionPendingInstallForSync( |
147 Profile* profile, const std::string& id) const { | 147 Profile* profile, const std::string& id) const { |
148 const extensions::PendingExtensionManager* pending_extension_manager = | 148 const extensions::PendingExtensionManager* pending_extension_manager = |
149 extensions::ExtensionSystem::Get(profile) | 149 extensions::ExtensionSystem::Get(profile) |
150 ->extension_service() | 150 ->extension_service() |
151 ->pending_extension_manager(); | 151 ->pending_extension_manager(); |
152 const extensions::PendingExtensionInfo* info = | 152 const extensions::PendingExtensionInfo* info = |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 scoped_refptr<Extension> extension = | 377 scoped_refptr<Extension> extension = |
378 CreateExtension(extensions::ExtensionSystem::Get(profile) | 378 CreateExtension(extensions::ExtensionSystem::Get(profile) |
379 ->extension_service() | 379 ->extension_service() |
380 ->install_directory(), | 380 ->install_directory(), |
381 name, | 381 name, |
382 type); | 382 type); |
383 if (!extension.get()) { | 383 if (!extension.get()) { |
384 ADD_FAILURE(); | 384 ADD_FAILURE(); |
385 return NULL; | 385 return NULL; |
386 } | 386 } |
387 const std::string& expected_id = extensions::id_util::GenerateId(name); | 387 const std::string& expected_id = crx_file::id_util::GenerateId(name); |
388 if (extension->id() != expected_id) { | 388 if (extension->id() != expected_id) { |
389 EXPECT_EQ(expected_id, extension->id()); | 389 EXPECT_EQ(expected_id, extension->id()); |
390 return NULL; | 390 return NULL; |
391 } | 391 } |
392 DVLOG(2) << "created extension with name = " | 392 DVLOG(2) << "created extension with name = " |
393 << name << ", id = " << expected_id; | 393 << name << ", id = " << expected_id; |
394 (it->second)[name] = extension; | 394 (it->second)[name] = extension; |
395 id_to_name_[expected_id] = name; | 395 id_to_name_[expected_id] = name; |
396 id_to_type_[expected_id] = type; | 396 id_to_type_[expected_id] = type; |
397 return extension; | 397 return extension; |
398 } | 398 } |
OLD | NEW |