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

Side by Side Diff: chrome/browser/extensions/extension_service_test_with_install.cc

Issue 2206693002: Improve settings override bubble to indicate policy installed extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/extension_service_test_with_install.h" 5 #include "chrome/browser/extensions/extension_service_test_with_install.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/crx_installer.h" 9 #include "chrome/browser/extensions/crx_installer.h"
10 #include "chrome/browser/extensions/extension_creator.h" 10 #include "chrome/browser/extensions/extension_creator.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 pem_output_path, 94 pem_output_path,
95 ExtensionCreator::kOverwriteCRX)); 95 ExtensionCreator::kOverwriteCRX));
96 96
97 ASSERT_TRUE(base::PathExists(crx_path)); 97 ASSERT_TRUE(base::PathExists(crx_path));
98 } 98 }
99 99
100 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( 100 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX(
101 const base::FilePath& dir_path, 101 const base::FilePath& dir_path,
102 const base::FilePath& pem_path, 102 const base::FilePath& pem_path,
103 InstallState install_state, 103 InstallState install_state,
104 int creation_flags) { 104 int creation_flags,
105 Manifest::Location install_location) {
105 base::FilePath crx_path; 106 base::FilePath crx_path;
106 base::ScopedTempDir temp_dir; 107 base::ScopedTempDir temp_dir;
107 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); 108 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
108 crx_path = temp_dir.GetPath().AppendASCII("temp.crx"); 109 crx_path = temp_dir.GetPath().AppendASCII("temp.crx");
110 PackCRX(dir_path, pem_path, crx_path);
109 111
110 PackCRX(dir_path, pem_path, crx_path); 112 return InstallCRX(crx_path, install_location, install_state, creation_flags);
111 return InstallCRX(crx_path, install_state, creation_flags);
112 } 113 }
113 114
114 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( 115 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX(
115 const base::FilePath& dir_path, 116 const base::FilePath& dir_path,
116 const base::FilePath& pem_path, 117 const base::FilePath& pem_path,
117 InstallState install_state) { 118 InstallState install_state) {
118 return PackAndInstallCRX(dir_path, pem_path, install_state, 119 return PackAndInstallCRX(dir_path, pem_path, install_state,
119 Extension::NO_FLAGS); 120 Extension::NO_FLAGS, Manifest::Location::INTERNAL);
120 } 121 }
121 122
122 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( 123 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX(
123 const base::FilePath& dir_path, 124 const base::FilePath& dir_path,
124 InstallState install_state) { 125 InstallState install_state) {
125 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, 126 return PackAndInstallCRX(dir_path, base::FilePath(), install_state,
126 Extension::NO_FLAGS); 127 Extension::NO_FLAGS, Manifest::Location::INTERNAL);
128 }
129
130 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX(
131 const base::FilePath& dir_path,
132 Manifest::Location install_location,
133 InstallState install_state) {
134 return PackAndInstallCRX(dir_path, base::FilePath(), install_state,
135 Extension::NO_FLAGS, install_location);
127 } 136 }
128 137
129 // Attempts to install an extension. Use INSTALL_FAILED if the installation 138 // Attempts to install an extension. Use INSTALL_FAILED if the installation
130 // is expected to fail. 139 // is expected to fail.
131 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is 140 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is
132 // non-empty, expects that the existing extension's title was 141 // non-empty, expects that the existing extension's title was
133 // |expected_old_name|. 142 // |expected_old_name|.
134 const Extension* ExtensionServiceTestWithInstall::InstallCRX( 143 const Extension* ExtensionServiceTestWithInstall::InstallCRX(
135 const base::FilePath& path, 144 const base::FilePath& path,
136 InstallState install_state, 145 InstallState install_state,
137 int creation_flags, 146 int creation_flags,
138 const std::string& expected_old_name) { 147 const std::string& expected_old_name) {
139 InstallCRXInternal(path, creation_flags); 148 InstallCRXInternal(path, Manifest::Location::INTERNAL, install_state,
140 return VerifyCrxInstall(path, install_state, expected_old_name); 149 creation_flags);
150 return VerifyCrxInstall(path, install_state);
151 }
152
153 const Extension* ExtensionServiceTestWithInstall::InstallCRX(
154 const base::FilePath& path,
155 Manifest::Location install_location,
156 InstallState install_state,
157 int creation_flags) {
158 InstallCRXInternal(path, install_location, install_state, creation_flags);
159 return VerifyCrxInstall(path, install_state);
141 } 160 }
142 161
143 // Attempts to install an extension. Use INSTALL_FAILED if the installation 162 // Attempts to install an extension. Use INSTALL_FAILED if the installation
144 // is expected to fail. 163 // is expected to fail.
145 const Extension* ExtensionServiceTestWithInstall::InstallCRX( 164 const Extension* ExtensionServiceTestWithInstall::InstallCRX(
146 const base::FilePath& path, 165 const base::FilePath& path,
147 InstallState install_state, 166 InstallState install_state,
148 int creation_flags) { 167 int creation_flags) {
149 return InstallCRX(path, install_state, creation_flags, std::string()); 168 return InstallCRX(path, install_state, creation_flags, std::string());
150 } 169 }
151 170
152 // Attempts to install an extension. Use INSTALL_FAILED if the installation 171 // Attempts to install an extension. Use INSTALL_FAILED if the installation
153 // is expected to fail. 172 // is expected to fail.
154 const Extension* ExtensionServiceTestWithInstall::InstallCRX( 173 const Extension* ExtensionServiceTestWithInstall::InstallCRX(
155 const base::FilePath& path, 174 const base::FilePath& path,
156 InstallState install_state) { 175 InstallState install_state) {
157 return InstallCRX(path, install_state, Extension::NO_FLAGS); 176 return InstallCRX(path, install_state, Extension::NO_FLAGS);
158 } 177 }
159 178
160 const Extension* ExtensionServiceTestWithInstall::InstallCRXFromWebStore( 179 const Extension* ExtensionServiceTestWithInstall::InstallCRXFromWebStore(
161 const base::FilePath& path, 180 const base::FilePath& path,
162 InstallState install_state) { 181 InstallState install_state) {
163 InstallCRXInternal(path, Extension::FROM_WEBSTORE); 182 InstallCRXInternal(path, Manifest::Location::INTERNAL, install_state,
183 Extension::FROM_WEBSTORE);
164 return VerifyCrxInstall(path, install_state); 184 return VerifyCrxInstall(path, install_state);
165 } 185 }
166 186
167 const Extension* ExtensionServiceTestWithInstall::InstallCRXWithLocation(
168 const base::FilePath& crx_path,
169 Manifest::Location install_location,
170 InstallState install_state) {
171 EXPECT_TRUE(base::PathExists(crx_path))
172 << "Path does not exist: "<< crx_path.value().c_str();
173 // no client (silent install)
174 scoped_refptr<CrxInstaller> installer(
175 CrxInstaller::CreateSilent(service()));
176 installer->set_install_source(install_location);
177
178 content::WindowedNotificationObserver observer(
179 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
180 content::NotificationService::AllSources());
181 installer->InstallCrx(crx_path);
182 observer.Wait();
183
184 return VerifyCrxInstall(crx_path, install_state);
185 }
186
187 const Extension* ExtensionServiceTestWithInstall::VerifyCrxInstall( 187 const Extension* ExtensionServiceTestWithInstall::VerifyCrxInstall(
188 const base::FilePath& path, 188 const base::FilePath& path,
189 InstallState install_state) { 189 InstallState install_state) {
190 return VerifyCrxInstall(path, install_state, std::string()); 190 return VerifyCrxInstall(path, install_state, std::string());
191 } 191 }
192 192
193 const Extension* ExtensionServiceTestWithInstall::VerifyCrxInstall( 193 const Extension* ExtensionServiceTestWithInstall::VerifyCrxInstall(
194 const base::FilePath& path, 194 const base::FilePath& path,
195 InstallState install_state, 195 InstallState install_state,
196 const std::string& expected_old_name) { 196 const std::string& expected_old_name) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 const std::string& id, 323 const std::string& id,
324 bool use_helper, 324 bool use_helper,
325 Extension::State expected_state) { 325 Extension::State expected_state) {
326 // Verify that the extension is installed. 326 // Verify that the extension is installed.
327 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); 327 base::FilePath extension_path = extensions_install_dir().AppendASCII(id);
328 EXPECT_TRUE(base::PathExists(extension_path)); 328 EXPECT_TRUE(base::PathExists(extension_path));
329 size_t pref_key_count = GetPrefKeyCount(); 329 size_t pref_key_count = GetPrefKeyCount();
330 EXPECT_GT(pref_key_count, 0u); 330 EXPECT_GT(pref_key_count, 0u);
331 ValidateIntegerPref(id, "state", expected_state); 331 ValidateIntegerPref(id, "state", expected_state);
332 332
333 // We make a copy of the extension's id since the extension can be deleted
334 // once it's uninstalled.
335 std::string extension_id = id;
333 // Uninstall it. 336 // Uninstall it.
334 if (use_helper) { 337 if (use_helper) {
335 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( 338 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(
336 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING)); 339 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING));
337 } else { 340 } else {
338 EXPECT_TRUE(service()->UninstallExtension( 341 EXPECT_TRUE(service()->UninstallExtension(
339 id, extensions::UNINSTALL_REASON_FOR_TESTING, 342 id, extensions::UNINSTALL_REASON_FOR_TESTING,
340 base::Bind(&base::DoNothing), nullptr)); 343 base::Bind(&base::DoNothing), nullptr));
341 } 344 }
342 --expected_extensions_count_; 345 --expected_extensions_count_;
343 346
344 // We should get an unload notification. 347 // We should get an unload notification.
345 EXPECT_FALSE(unloaded_id_.empty()); 348 EXPECT_FALSE(unloaded_id_.empty());
346 EXPECT_EQ(id, unloaded_id_); 349 EXPECT_EQ(extension_id, unloaded_id_);
347 350
348 // Verify uninstalled state. 351 // Verify uninstalled state.
349 size_t new_pref_key_count = GetPrefKeyCount(); 352 size_t new_pref_key_count = GetPrefKeyCount();
350 if (new_pref_key_count == pref_key_count) { 353 if (new_pref_key_count == pref_key_count) {
351 ValidateIntegerPref(id, "state", 354 ValidateIntegerPref(id, "state",
352 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 355 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
353 } else { 356 } else {
354 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); 357 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
355 } 358 }
356 359
357 // The extension should not be in the service anymore. 360 // The extension should not be in the service anymore.
358 EXPECT_FALSE(service()->GetInstalledExtension(id)); 361 EXPECT_FALSE(service()->GetInstalledExtension(extension_id));
359 base::RunLoop().RunUntilIdle(); 362 base::RunLoop().RunUntilIdle();
360 363
361 // The directory should be gone. 364 // The directory should be gone.
362 EXPECT_FALSE(base::PathExists(extension_path)); 365 EXPECT_FALSE(base::PathExists(extension_path));
363 } 366 }
364 367
365 void ExtensionServiceTestWithInstall::TerminateExtension( 368 void ExtensionServiceTestWithInstall::TerminateExtension(
366 const std::string& id) { 369 const std::string& id) {
367 const Extension* extension = service()->GetInstalledExtension(id); 370 const Extension* extension = service()->GetInstalledExtension(id);
368 if (!extension) { 371 if (!extension) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 installed_ = extension; 407 installed_ = extension;
405 was_update_ = is_update; 408 was_update_ = is_update;
406 old_name_ = old_name; 409 old_name_ = old_name;
407 } 410 }
408 411
409 // Create a CrxInstaller and install the CRX file. 412 // Create a CrxInstaller and install the CRX file.
410 // Instead of calling this method yourself, use InstallCRX(), which does extra 413 // Instead of calling this method yourself, use InstallCRX(), which does extra
411 // error checking. 414 // error checking.
412 void ExtensionServiceTestWithInstall::InstallCRXInternal( 415 void ExtensionServiceTestWithInstall::InstallCRXInternal(
413 const base::FilePath& crx_path, 416 const base::FilePath& crx_path,
417 Manifest::Location install_location,
418 InstallState install_state,
414 int creation_flags) { 419 int creation_flags) {
415 ASSERT_TRUE(base::PathExists(crx_path)) 420 EXPECT_TRUE(base::PathExists(crx_path)) << "Path does not exist: "
416 << "Path does not exist: "<< crx_path.value().c_str(); 421 << crx_path.value().c_str();
422 // no client (silent install)
417 scoped_refptr<CrxInstaller> installer( 423 scoped_refptr<CrxInstaller> installer(
418 CrxInstaller::CreateSilent(service())); 424 CrxInstaller::CreateSilent(service()));
425 installer->set_install_source(install_location);
419 installer->set_creation_flags(creation_flags); 426 installer->set_creation_flags(creation_flags);
420 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) 427 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT))
421 installer->set_allow_silent_install(true); 428 installer->set_allow_silent_install(true);
422 429
423 content::WindowedNotificationObserver observer( 430 content::WindowedNotificationObserver observer(
424 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 431 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
425 content::Source<extensions::CrxInstaller>(installer.get())); 432 content::Source<extensions::CrxInstaller>(installer.get()));
426 433
427 installer->InstallCrx(crx_path); 434 installer->InstallCrx(crx_path);
428
429 observer.Wait(); 435 observer.Wait();
430 } 436 }
431 437
432 } // namespace extensions 438 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698