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

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: Fixed failing tests ToolbarActionsBarBubbleViewsTest.TestClickLearnMoreLink and TestBubbleLayoutAct… Created 4 years, 2 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
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 Extension::NO_FLAGS); 119 Extension::NO_FLAGS);
120 } 120 }
121 121
122 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX( 122 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRX(
123 const base::FilePath& dir_path, 123 const base::FilePath& dir_path,
124 InstallState install_state) { 124 InstallState install_state) {
125 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, 125 return PackAndInstallCRX(dir_path, base::FilePath(), install_state,
126 Extension::NO_FLAGS); 126 Extension::NO_FLAGS);
127 } 127 }
128 128
129 const Extension* ExtensionServiceTestWithInstall::PackAndInstallCRXWithLocation(
130 const base::FilePath& dir_path,
131 Manifest::Location install_location,
132 InstallState install_state) {
133 base::FilePath crx_path;
Devlin 2016/09/26 20:13:09 With functions like these, it's best to house the
catmullings 2016/10/06 18:24:19 Wrt "add a new version of PackAndInstallCRX that i
Devlin 2016/10/10 15:27:28 Not quite. With these types of functions, where t
catmullings 2016/10/12 18:58:58 Done.
134 base::ScopedTempDir temp_dir;
135 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
136 crx_path = temp_dir.GetPath().AppendASCII("temp.crx");
137
138 PackCRX(dir_path, base::FilePath(), crx_path);
139
140 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
141 installer->set_install_source(install_location);
142
143 content::WindowedNotificationObserver observer(
144 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
145 content::NotificationService::AllSources());
146 installer->InstallCrx(crx_path);
147 observer.Wait();
148
149 return VerifyCrxInstall(crx_path, install_state);
150 }
151
129 // Attempts to install an extension. Use INSTALL_FAILED if the installation 152 // Attempts to install an extension. Use INSTALL_FAILED if the installation
130 // is expected to fail. 153 // is expected to fail.
131 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is 154 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is
132 // non-empty, expects that the existing extension's title was 155 // non-empty, expects that the existing extension's title was
133 // |expected_old_name|. 156 // |expected_old_name|.
134 const Extension* ExtensionServiceTestWithInstall::InstallCRX( 157 const Extension* ExtensionServiceTestWithInstall::InstallCRX(
135 const base::FilePath& path, 158 const base::FilePath& path,
136 InstallState install_state, 159 InstallState install_state,
137 int creation_flags, 160 int creation_flags,
138 const std::string& expected_old_name) { 161 const std::string& expected_old_name) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 const std::string& id, 346 const std::string& id,
324 bool use_helper, 347 bool use_helper,
325 Extension::State expected_state) { 348 Extension::State expected_state) {
326 // Verify that the extension is installed. 349 // Verify that the extension is installed.
327 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); 350 base::FilePath extension_path = extensions_install_dir().AppendASCII(id);
328 EXPECT_TRUE(base::PathExists(extension_path)); 351 EXPECT_TRUE(base::PathExists(extension_path));
329 size_t pref_key_count = GetPrefKeyCount(); 352 size_t pref_key_count = GetPrefKeyCount();
330 EXPECT_GT(pref_key_count, 0u); 353 EXPECT_GT(pref_key_count, 0u);
331 ValidateIntegerPref(id, "state", expected_state); 354 ValidateIntegerPref(id, "state", expected_state);
332 355
356 // We make a copy of the extension's id since the extension can be deleted
357 // once it's uninstalled.
358 std::string extension_id = id;
333 // Uninstall it. 359 // Uninstall it.
334 if (use_helper) { 360 if (use_helper) {
335 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( 361 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(
336 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING)); 362 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING));
337 } else { 363 } else {
338 EXPECT_TRUE(service()->UninstallExtension( 364 EXPECT_TRUE(service()->UninstallExtension(
339 id, extensions::UNINSTALL_REASON_FOR_TESTING, 365 id, extensions::UNINSTALL_REASON_FOR_TESTING,
340 base::Bind(&base::DoNothing), nullptr)); 366 base::Bind(&base::DoNothing), nullptr));
341 } 367 }
342 --expected_extensions_count_; 368 --expected_extensions_count_;
343 369
344 // We should get an unload notification. 370 // We should get an unload notification.
345 EXPECT_FALSE(unloaded_id_.empty()); 371 EXPECT_FALSE(unloaded_id_.empty());
346 EXPECT_EQ(id, unloaded_id_); 372 EXPECT_EQ(extension_id, unloaded_id_);
347 373
348 // Verify uninstalled state. 374 // Verify uninstalled state.
349 size_t new_pref_key_count = GetPrefKeyCount(); 375 size_t new_pref_key_count = GetPrefKeyCount();
350 if (new_pref_key_count == pref_key_count) { 376 if (new_pref_key_count == pref_key_count) {
351 ValidateIntegerPref(id, "state", 377 ValidateIntegerPref(id, "state",
352 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 378 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
353 } else { 379 } else {
354 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); 380 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
355 } 381 }
356 382
357 // The extension should not be in the service anymore. 383 // The extension should not be in the service anymore.
358 EXPECT_FALSE(service()->GetInstalledExtension(id)); 384 EXPECT_FALSE(service()->GetInstalledExtension(extension_id));
359 base::RunLoop().RunUntilIdle(); 385 base::RunLoop().RunUntilIdle();
360 386
361 // The directory should be gone. 387 // The directory should be gone.
362 EXPECT_FALSE(base::PathExists(extension_path)); 388 EXPECT_FALSE(base::PathExists(extension_path));
363 } 389 }
364 390
365 void ExtensionServiceTestWithInstall::TerminateExtension( 391 void ExtensionServiceTestWithInstall::TerminateExtension(
366 const std::string& id) { 392 const std::string& id) {
367 const Extension* extension = service()->GetInstalledExtension(id); 393 const Extension* extension = service()->GetInstalledExtension(id);
368 if (!extension) { 394 if (!extension) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 content::WindowedNotificationObserver observer( 449 content::WindowedNotificationObserver observer(
424 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 450 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
425 content::Source<extensions::CrxInstaller>(installer.get())); 451 content::Source<extensions::CrxInstaller>(installer.get()));
426 452
427 installer->InstallCrx(crx_path); 453 installer->InstallCrx(crx_path);
428 454
429 observer.Wait(); 455 observer.Wait();
430 } 456 }
431 457
432 } // namespace extensions 458 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698