| OLD | NEW |
| 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 7 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Helper method that installs a low permission extension then updates | 63 // Helper method that installs a low permission extension then updates |
| 64 // to the second version requiring increased permissions. Returns whether | 64 // to the second version requiring increased permissions. Returns whether |
| 65 // the operation was completed successfully. | 65 // the operation was completed successfully. |
| 66 bool InstallAndUpdateIncreasingPermissionsExtension() { | 66 bool InstallAndUpdateIncreasingPermissionsExtension() { |
| 67 ExtensionService* service = browser()->profile()->GetExtensionService(); | 67 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 68 size_t size_before = service->extensions()->size(); | 68 size_t size_before = service->extensions()->size(); |
| 69 | 69 |
| 70 // Install the initial version, which should happen just fine. | 70 // Install the initial version, which should happen just fine. |
| 71 if (!InstallExtension( | 71 const Extension* extension = InstallExtension( |
| 72 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1)) | 72 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); |
| 73 if (!extension) |
| 74 return false; |
| 75 if (service->extensions()->size() != size_before + 1) |
| 73 return false; | 76 return false; |
| 74 | 77 |
| 75 // Upgrade to a version that wants more permissions. We should disable the | 78 // Upgrade to a version that wants more permissions. We should disable the |
| 76 // extension and prompt the user to reenable. | 79 // extension and prompt the user to reenable. |
| 77 if (service->extensions()->size() != size_before + 1) | 80 if (UpdateExtension( |
| 78 return false; | 81 extension->id(), |
| 79 if (!UpdateExtension( | 82 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) |
| 80 service->extensions()->at(size_before)->id(), | |
| 81 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) | |
| 82 return false; | 83 return false; |
| 83 EXPECT_EQ(size_before, service->extensions()->size()); | 84 EXPECT_EQ(size_before, service->extensions()->size()); |
| 84 if (service->disabled_extensions()->size() != 1u) | 85 if (service->disabled_extensions()->size() != 1u) |
| 85 return false; | 86 return false; |
| 86 return true; | 87 return true; |
| 87 } | 88 } |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 #if defined(OS_LINUX) | 91 #if defined(OS_LINUX) |
| 91 // Times out sometimes on Linux. http://crbug.com/89727 | 92 // Times out sometimes on Linux. http://crbug.com/89727 |
| 92 #define MAYBE_InstallSameVersion FLAKY_InstallSameVersion | 93 #define MAYBE_InstallSameVersion FLAKY_InstallSameVersion |
| 93 #else | 94 #else |
| 94 #define MAYBE_InstallSameVersion InstallSameVersion | 95 #define MAYBE_InstallSameVersion InstallSameVersion |
| 95 #endif | 96 #endif |
| 96 | 97 |
| 97 // Tests that installing the same version overwrites. | 98 // Tests that installing the same version overwrites. |
| 98 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_InstallSameVersion) { | 99 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_InstallSameVersion) { |
| 99 ExtensionService* service = browser()->profile()->GetExtensionService(); | 100 const Extension* extension = InstallExtension( |
| 100 const size_t size_before = service->extensions()->size(); | 101 test_data_dir_.AppendASCII("install/install.crx"), 1); |
| 101 ASSERT_TRUE(InstallExtension( | 102 ASSERT_TRUE(extension); |
| 102 test_data_dir_.AppendASCII("install/install.crx"), 1)); | 103 FilePath old_path = extension->path(); |
| 103 FilePath old_path = service->extensions()->back()->path(); | |
| 104 | 104 |
| 105 // Install an extension with the same version. The previous install should be | 105 // Install an extension with the same version. The previous install should be |
| 106 // overwritten. | 106 // overwritten. |
| 107 ASSERT_TRUE(InstallExtension( | 107 extension = InstallExtension( |
| 108 test_data_dir_.AppendASCII("install/install_same_version.crx"), 0)); | 108 test_data_dir_.AppendASCII("install/install_same_version.crx"), 0); |
| 109 FilePath new_path = service->extensions()->back()->path(); | 109 ASSERT_TRUE(extension); |
| 110 FilePath new_path = extension->path(); |
| 110 | 111 |
| 111 EXPECT_FALSE(IsExtensionAtVersion(service->extensions()->at(size_before), | 112 EXPECT_FALSE(IsExtensionAtVersion(extension, "1.0")); |
| 112 "1.0")); | |
| 113 EXPECT_NE(old_path.value(), new_path.value()); | 113 EXPECT_NE(old_path.value(), new_path.value()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallOlderVersion) { | 116 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallOlderVersion) { |
| 117 ExtensionService* service = browser()->profile()->GetExtensionService(); | 117 const Extension* extension = InstallExtension( |
| 118 const size_t size_before = service->extensions()->size(); | 118 test_data_dir_.AppendASCII("install/install.crx"), 1); |
| 119 ASSERT_TRUE(InstallExtension( | 119 ASSERT_TRUE(extension); |
| 120 test_data_dir_.AppendASCII("install/install.crx"), 1)); | 120 ASSERT_FALSE(InstallExtension( |
| 121 ASSERT_TRUE(InstallExtension( | |
| 122 test_data_dir_.AppendASCII("install/install_older_version.crx"), 0)); | 121 test_data_dir_.AppendASCII("install/install_older_version.crx"), 0)); |
| 123 EXPECT_TRUE(IsExtensionAtVersion(service->extensions()->at(size_before), | 122 EXPECT_TRUE(IsExtensionAtVersion(extension, "1.0")); |
| 124 "1.0")); | |
| 125 } | 123 } |
| 126 | 124 |
| 127 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallThenCancel) { | 125 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallThenCancel) { |
| 128 ExtensionService* service = browser()->profile()->GetExtensionService(); | 126 const Extension* extension = InstallExtension( |
| 129 const size_t size_before = service->extensions()->size(); | 127 test_data_dir_.AppendASCII("install/install.crx"), 1); |
| 130 ASSERT_TRUE(InstallExtension( | 128 ASSERT_TRUE(extension); |
| 131 test_data_dir_.AppendASCII("install/install.crx"), 1)); | |
| 132 | 129 |
| 133 // Cancel this install. | 130 // Cancel this install. |
| 134 StartInstallButCancel(test_data_dir_.AppendASCII("install/install_v2.crx")); | 131 ASSERT_FALSE(StartInstallButCancel( |
| 135 EXPECT_TRUE(IsExtensionAtVersion(service->extensions()->at(size_before), | 132 test_data_dir_.AppendASCII("install/install_v2.crx"))); |
| 136 "1.0")); | 133 EXPECT_TRUE(IsExtensionAtVersion(extension, "1.0")); |
| 137 } | 134 } |
| 138 | 135 |
| 139 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallRequiresConfirm) { | 136 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallRequiresConfirm) { |
| 140 // Installing the extension without an auto confirming UI should fail | 137 // Installing the extension without an auto confirming UI should result in |
| 141 // since good.crx has permissions that require approval. | 138 // it being disabled, since good.crx has permissions that require approval. |
| 142 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("good.crx"), 0)); | 139 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 143 UninstallExtension("ldnnhddmnhbkjipkidpdiheffobcpfmf"); | 140 std::string id = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 141 ASSERT_FALSE(InstallExtension(test_data_dir_.AppendASCII("good.crx"), 0)); |
| 142 ASSERT_TRUE(service->GetExtensionById(id, true)); |
| 143 UninstallExtension(id); |
| 144 | 144 |
| 145 // And the install should succeed when the permissions are accepted. | 145 // And the install should succeed when the permissions are accepted. |
| 146 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm( | 146 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm( |
| 147 test_data_dir_.AppendASCII("good.crx"), 1, browser()->profile())); | 147 test_data_dir_.AppendASCII("good.crx"), 1, browser()->profile())); |
| 148 UninstallExtension("ldnnhddmnhbkjipkidpdiheffobcpfmf"); | 148 UninstallExtension(id); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Tests the process of updating an extension to one that requires higher | 151 // Tests the process of updating an extension to one that requires higher |
| 152 // permissions. | 152 // permissions. |
| 153 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissions) { | 153 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissions) { |
| 154 ExtensionService* service = browser()->profile()->GetExtensionService(); | 154 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 155 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); | 155 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); |
| 156 const size_t size_before = service->extensions()->size(); | 156 const size_t size_before = service->extensions()->size(); |
| 157 | 157 |
| 158 // Now try reenabling it. | 158 // Now try reenabling it. |
| 159 service->EnableExtension(service->disabled_extensions()->at(0)->id()); | 159 const std::string id = (*service->disabled_extensions()->begin())->id(); |
| 160 service->EnableExtension(id); |
| 160 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 161 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 161 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 162 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 162 } | 163 } |
| 163 | 164 |
| 164 // Tests uninstalling an extension that was disabled due to higher permissions. | 165 // Tests uninstalling an extension that was disabled due to higher permissions. |
| 165 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissionsAndUninstall) { | 166 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissionsAndUninstall) { |
| 166 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); | 167 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); |
| 167 | 168 |
| 168 // Make sure the "disable extension" infobar is present. | 169 // Make sure the "disable extension" infobar is present. |
| 169 ASSERT_EQ(0, browser()->active_index()); | 170 ASSERT_EQ(0, browser()->active_index()); |
| 170 InfoBarTabHelper* infobar_helper = browser()->GetTabContentsWrapperAt(0)-> | 171 InfoBarTabHelper* infobar_helper = browser()->GetTabContentsWrapperAt(0)-> |
| 171 infobar_tab_helper(); | 172 infobar_tab_helper(); |
| 172 ASSERT_EQ(1U, infobar_helper->infobar_count()); | 173 ASSERT_EQ(1U, infobar_helper->infobar_count()); |
| 173 | 174 |
| 174 // Uninstall, and check that the infobar went away. | 175 // Uninstall, and check that the infobar went away. |
| 175 ExtensionService* service = browser()->profile()->GetExtensionService(); | 176 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 176 std::string id = service->disabled_extensions()->at(0)->id(); | 177 std::string id = (*service->disabled_extensions()->begin())->id(); |
| 177 UninstallExtension(id); | 178 UninstallExtension(id); |
| 178 ASSERT_EQ(0U, infobar_helper->infobar_count()); | 179 ASSERT_EQ(0U, infobar_helper->infobar_count()); |
| 179 | 180 |
| 180 // Now select a new tab, and switch back to the first tab which had the | 181 // Now select a new tab, and switch back to the first tab which had the |
| 181 // infobar. We should not crash. | 182 // infobar. We should not crash. |
| 182 ASSERT_EQ(1, browser()->tab_count()); | 183 ASSERT_EQ(1, browser()->tab_count()); |
| 183 ASSERT_EQ(0, browser()->active_index()); | 184 ASSERT_EQ(0, browser()->active_index()); |
| 184 browser()->NewTab(); | 185 browser()->NewTab(); |
| 185 ASSERT_EQ(2, browser()->tab_count()); | 186 ASSERT_EQ(2, browser()->tab_count()); |
| 186 ASSERT_EQ(1, browser()->active_index()); | 187 ASSERT_EQ(1, browser()->active_index()); |
| 187 browser()->ActivateTabAt(0, true); | 188 browser()->ActivateTabAt(0, true); |
| 188 } | 189 } |
| 189 | 190 |
| 190 // Tests that we can uninstall a disabled extension. | 191 // Tests that we can uninstall a disabled extension. |
| 191 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UninstallDisabled) { | 192 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UninstallDisabled) { |
| 192 ExtensionService* service = browser()->profile()->GetExtensionService(); | 193 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 193 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); | 194 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); |
| 194 const size_t size_before = service->extensions()->size(); | 195 const size_t size_before = service->extensions()->size(); |
| 195 | 196 |
| 196 // Now try uninstalling it. | 197 // Now try uninstalling it. |
| 197 UninstallExtension(service->disabled_extensions()->at(0)->id()); | 198 UninstallExtension((*service->disabled_extensions()->begin())->id()); |
| 198 EXPECT_EQ(size_before, service->extensions()->size()); | 199 EXPECT_EQ(size_before, service->extensions()->size()); |
| 199 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 200 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 200 } | 201 } |
| 201 | 202 |
| 202 // Tests that disabling and re-enabling an extension works. | 203 // Tests that disabling and re-enabling an extension works. |
| 203 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, DisableEnable) { | 204 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, DisableEnable) { |
| 204 ExtensionProcessManager* manager = browser()->profile()-> | 205 ExtensionProcessManager* manager = browser()->profile()-> |
| 205 GetExtensionProcessManager(); | 206 GetExtensionProcessManager(); |
| 206 ExtensionService* service = browser()->profile()->GetExtensionService(); | 207 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 207 const size_t size_before = service->extensions()->size(); | 208 const size_t size_before = service->extensions()->size(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 308 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 308 basedir.AppendASCII("manifest_v2.xml")); | 309 basedir.AppendASCII("manifest_v2.xml")); |
| 309 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 310 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 310 basedir.AppendASCII("v2.crx")); | 311 basedir.AppendASCII("v2.crx")); |
| 311 | 312 |
| 312 // Install version 1 of the extension. | 313 // Install version 1 of the extension. |
| 313 ExtensionTestMessageListener listener1("v1 installed", false); | 314 ExtensionTestMessageListener listener1("v1 installed", false); |
| 314 ExtensionService* service = browser()->profile()->GetExtensionService(); | 315 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 315 const size_t size_before = service->extensions()->size(); | 316 const size_t size_before = service->extensions()->size(); |
| 316 ASSERT_TRUE(service->disabled_extensions()->empty()); | 317 ASSERT_TRUE(service->disabled_extensions()->empty()); |
| 317 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v1.crx"), 1)); | 318 const Extension* extension = |
| 319 InstallExtension(basedir.AppendASCII("v1.crx"), 1); |
| 320 ASSERT_TRUE(extension); |
| 318 listener1.WaitUntilSatisfied(); | 321 listener1.WaitUntilSatisfied(); |
| 319 const ExtensionList* extensions = service->extensions(); | 322 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 320 ASSERT_EQ(size_before + 1, extensions->size()); | 323 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", extension->id()); |
| 321 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", | 324 ASSERT_EQ("1.0", extension->VersionString()); |
| 322 extensions->at(size_before)->id()); | |
| 323 ASSERT_EQ("1.0", extensions->at(size_before)->VersionString()); | |
| 324 | 325 |
| 325 // We don't want autoupdate blacklist checks. | 326 // We don't want autoupdate blacklist checks. |
| 326 service->updater()->set_blacklist_checks_enabled(false); | 327 service->updater()->set_blacklist_checks_enabled(false); |
| 327 | 328 |
| 328 // Run autoupdate and make sure version 2 of the extension was installed. | 329 // Run autoupdate and make sure version 2 of the extension was installed. |
| 329 ExtensionTestMessageListener listener2("v2 installed", false); | 330 ExtensionTestMessageListener listener2("v2 installed", false); |
| 330 service->updater()->CheckNow(); | 331 service->updater()->CheckNow(); |
| 331 ASSERT_TRUE(WaitForExtensionInstall()); | 332 ASSERT_TRUE(WaitForExtensionInstall()); |
| 332 listener2.WaitUntilSatisfied(); | 333 listener2.WaitUntilSatisfied(); |
| 333 extensions = service->extensions(); | 334 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 334 ASSERT_EQ(size_before + 1, extensions->size()); | 335 extension = service->GetExtensionById( |
| 335 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", | 336 "ogjcoiohnmldgjemafoockdghcjciccf", false); |
| 336 extensions->at(size_before)->id()); | 337 ASSERT_TRUE(extension); |
| 337 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString()); | 338 ASSERT_EQ("2.0", extension->VersionString()); |
| 338 ASSERT_TRUE(notification_listener.started()); | 339 ASSERT_TRUE(notification_listener.started()); |
| 339 ASSERT_TRUE(notification_listener.finished()); | 340 ASSERT_TRUE(notification_listener.finished()); |
| 340 ASSERT_TRUE(ContainsKey(notification_listener.updates(), | 341 ASSERT_TRUE(ContainsKey(notification_listener.updates(), |
| 341 "ogjcoiohnmldgjemafoockdghcjciccf")); | 342 "ogjcoiohnmldgjemafoockdghcjciccf")); |
| 342 notification_listener.Reset(); | 343 notification_listener.Reset(); |
| 343 | 344 |
| 344 // Now try doing an update to version 3, which has been incorrectly | 345 // Now try doing an update to version 3, which has been incorrectly |
| 345 // signed. This should fail. | 346 // signed. This should fail. |
| 346 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 347 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 347 basedir.AppendASCII("manifest_v3.xml")); | 348 basedir.AppendASCII("manifest_v3.xml")); |
| 348 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v3.crx", | 349 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v3.crx", |
| 349 basedir.AppendASCII("v3.crx")); | 350 basedir.AppendASCII("v3.crx")); |
| 350 | 351 |
| 351 service->updater()->CheckNow(); | 352 service->updater()->CheckNow(); |
| 352 ASSERT_TRUE(WaitForExtensionInstallError()); | 353 ASSERT_TRUE(WaitForExtensionInstallError()); |
| 353 ASSERT_TRUE(notification_listener.started()); | 354 ASSERT_TRUE(notification_listener.started()); |
| 354 ASSERT_TRUE(notification_listener.finished()); | 355 ASSERT_TRUE(notification_listener.finished()); |
| 355 ASSERT_TRUE(ContainsKey(notification_listener.updates(), | 356 ASSERT_TRUE(ContainsKey(notification_listener.updates(), |
| 356 "ogjcoiohnmldgjemafoockdghcjciccf")); | 357 "ogjcoiohnmldgjemafoockdghcjciccf")); |
| 357 | 358 |
| 358 // Make sure the extension state is the same as before. | 359 // Make sure the extension state is the same as before. |
| 359 extensions = service->extensions(); | 360 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 360 ASSERT_EQ(size_before + 1, extensions->size()); | 361 extension = service->GetExtensionById( |
| 361 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", | 362 "ogjcoiohnmldgjemafoockdghcjciccf", false); |
| 362 extensions->at(size_before)->id()); | 363 ASSERT_TRUE(extension); |
| 363 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString()); | 364 ASSERT_EQ("2.0", extension->VersionString()); |
| 364 } | 365 } |
| 365 | 366 |
| 366 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { | 367 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { |
| 367 ExtensionService* service = browser()->profile()->GetExtensionService(); | 368 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 368 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 369 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 369 // We don't want autoupdate blacklist checks. | 370 // We don't want autoupdate blacklist checks. |
| 370 service->updater()->set_blacklist_checks_enabled(false); | 371 service->updater()->set_blacklist_checks_enabled(false); |
| 371 | 372 |
| 372 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 373 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 373 | 374 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 // is race-prone, because instantating the ExtensionService starts a read | 392 // is race-prone, because instantating the ExtensionService starts a read |
| 392 // of external_extensions.json before this test function starts. | 393 // of external_extensions.json before this test function starts. |
| 393 | 394 |
| 394 pending_extension_manager->AddFromExternalUpdateUrl( | 395 pending_extension_manager->AddFromExternalUpdateUrl( |
| 395 kExtensionId, GURL("http://localhost/autoupdate/manifest"), | 396 kExtensionId, GURL("http://localhost/autoupdate/manifest"), |
| 396 Extension::EXTERNAL_PREF_DOWNLOAD); | 397 Extension::EXTERNAL_PREF_DOWNLOAD); |
| 397 | 398 |
| 398 // Run autoupdate and make sure version 2 of the extension was installed. | 399 // Run autoupdate and make sure version 2 of the extension was installed. |
| 399 service->updater()->CheckNow(); | 400 service->updater()->CheckNow(); |
| 400 ASSERT_TRUE(WaitForExtensionInstall()); | 401 ASSERT_TRUE(WaitForExtensionInstall()); |
| 401 const ExtensionList* extensions = service->extensions(); | 402 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 402 ASSERT_EQ(size_before + 1, extensions->size()); | 403 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 403 ASSERT_EQ(kExtensionId, extensions->at(size_before)->id()); | 404 ASSERT_TRUE(extension); |
| 404 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString()); | 405 ASSERT_EQ("2.0", extension->VersionString()); |
| 405 | 406 |
| 406 // Uninstalling the extension should set a pref that keeps the extension from | 407 // Uninstalling the extension should set a pref that keeps the extension from |
| 407 // being installed again the next time external_extensions.json is read. | 408 // being installed again the next time external_extensions.json is read. |
| 408 | 409 |
| 409 UninstallExtension(kExtensionId); | 410 UninstallExtension(kExtensionId); |
| 410 | 411 |
| 411 ExtensionPrefs* extension_prefs = service->extension_prefs(); | 412 ExtensionPrefs* extension_prefs = service->extension_prefs(); |
| 412 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) | 413 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) |
| 413 << "Uninstalling should set kill bit on externaly installed extension."; | 414 << "Uninstalling should set kill bit on externaly installed extension."; |
| 414 | 415 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 477 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 477 ListValue* forcelist = pref_update.Get(); | 478 ListValue* forcelist = pref_update.Get(); |
| 478 ASSERT_TRUE(forcelist->empty()); | 479 ASSERT_TRUE(forcelist->empty()); |
| 479 forcelist->Append(Value::CreateStringValue( | 480 forcelist->Append(Value::CreateStringValue( |
| 480 std::string(kExtensionId) + | 481 std::string(kExtensionId) + |
| 481 ";http://localhost/autoupdate/manifest")); | 482 ";http://localhost/autoupdate/manifest")); |
| 482 } | 483 } |
| 483 | 484 |
| 484 // Check if the extension got installed. | 485 // Check if the extension got installed. |
| 485 ASSERT_TRUE(WaitForExtensionInstall()); | 486 ASSERT_TRUE(WaitForExtensionInstall()); |
| 486 const ExtensionList* extensions = service->extensions(); | 487 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 487 ASSERT_EQ(size_before + 1, extensions->size()); | 488 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 488 ASSERT_EQ(kExtensionId, extensions->at(size_before)->id()); | 489 ASSERT_TRUE(extension); |
| 489 EXPECT_EQ("2.0", extensions->at(size_before)->VersionString()); | 490 ASSERT_EQ("2.0", extension->VersionString()); |
| 490 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, | 491 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 491 extensions->at(size_before)->location()); | |
| 492 | 492 |
| 493 // Try to disable and unstall the extension which should fail. | 493 // Try to disable and uninstall the extension which should fail. |
| 494 service->DisableExtension(kExtensionId); | 494 service->DisableExtension(kExtensionId); |
| 495 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 495 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 496 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 496 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 497 UninstallExtension(kExtensionId); | 497 UninstallExtension(kExtensionId); |
| 498 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 498 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 499 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 499 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 500 | 500 |
| 501 // Now try to disable it through the management api. | 501 // Now try to disable it through the management api, again failing. |
| 502 ExtensionTestMessageListener listener1("ready", false); | 502 ExtensionTestMessageListener listener1("ready", false); |
| 503 ASSERT_TRUE(LoadExtension( | 503 ASSERT_TRUE(LoadExtension( |
| 504 test_data_dir_.AppendASCII("management/uninstall_extension"))); | 504 test_data_dir_.AppendASCII("management/uninstall_extension"))); |
| 505 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | 505 ASSERT_TRUE(listener1.WaitUntilSatisfied()); |
| 506 EXPECT_EQ(size_before + 2, service->extensions()->size()); | 506 EXPECT_EQ(size_before + 2, service->extensions()->size()); |
| 507 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 507 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 508 | 508 |
| 509 // Check that emptying the list triggers uninstall. | 509 // Check that emptying the list triggers uninstall. |
| 510 { | 510 { |
| 511 prefs->ClearPref(prefs::kExtensionInstallForceList); | 511 prefs->ClearPref(prefs::kExtensionInstallForceList); |
| 512 } | 512 } |
| 513 EXPECT_EQ(size_before + 1, extensions->size()); | 513 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 514 ExtensionList::const_iterator i; | 514 EXPECT_FALSE(service->GetExtensionById(kExtensionId, true)); |
| 515 for (i = extensions->begin(); i != extensions->end(); ++i) | |
| 516 EXPECT_NE(kExtensionId, (*i)->id()); | |
| 517 } | 515 } |
| 518 | 516 |
| 519 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) { | 517 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) { |
| 520 ExtensionService* service = browser()->profile()->GetExtensionService(); | 518 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 521 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 519 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 522 service->updater()->set_blacklist_checks_enabled(false); | 520 service->updater()->set_blacklist_checks_enabled(false); |
| 523 const size_t size_before = service->extensions()->size(); | 521 const size_t size_before = service->extensions()->size(); |
| 524 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 522 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 525 ASSERT_TRUE(service->disabled_extensions()->empty()); | 523 ASSERT_TRUE(service->disabled_extensions()->empty()); |
| 526 | 524 |
| 527 // Note: This interceptor gets requests on the IO thread. | 525 // Note: This interceptor gets requests on the IO thread. |
| 528 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 526 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 529 content::URLFetcher::SetEnableInterceptionForTests(true); | 527 content::URLFetcher::SetEnableInterceptionForTests(true); |
| 530 | 528 |
| 531 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 529 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 532 basedir.AppendASCII("manifest_v2.xml")); | 530 basedir.AppendASCII("manifest_v2.xml")); |
| 533 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 531 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 534 basedir.AppendASCII("v2.crx")); | 532 basedir.AppendASCII("v2.crx")); |
| 535 | 533 |
| 536 // Check that the policy is initially empty. | 534 // Check that the policy is initially empty. |
| 537 PrefService* prefs = browser()->profile()->GetPrefs(); | 535 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 538 const ListValue* forcelist = | 536 const ListValue* forcelist = |
| 539 prefs->GetList(prefs::kExtensionInstallForceList); | 537 prefs->GetList(prefs::kExtensionInstallForceList); |
| 540 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 538 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 541 | 539 |
| 542 // User install of the extension. | 540 // User install of the extension. |
| 543 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 541 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 544 const ExtensionList* extensions = service->extensions(); | 542 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 545 ASSERT_EQ(size_before + 1, extensions->size()); | 543 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 546 const Extension* extension = extensions->at(size_before); | 544 ASSERT_TRUE(extension); |
| 547 ASSERT_EQ(kExtensionId, extension->id()); | |
| 548 EXPECT_EQ(Extension::INTERNAL, extension->location()); | 545 EXPECT_EQ(Extension::INTERNAL, extension->location()); |
| 549 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 546 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 550 | 547 |
| 551 // Setup the force install policy. It should override the location. | 548 // Setup the force install policy. It should override the location. |
| 552 { | 549 { |
| 553 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 550 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 554 ListValue* forcelist = pref_update.Get(); | 551 ListValue* forcelist = pref_update.Get(); |
| 555 ASSERT_TRUE(forcelist->empty()); | 552 ASSERT_TRUE(forcelist->empty()); |
| 556 forcelist->Append(Value::CreateStringValue( | 553 forcelist->Append(Value::CreateStringValue( |
| 557 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); | 554 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); |
| 558 } | 555 } |
| 559 ASSERT_TRUE(WaitForExtensionInstall()); | 556 ASSERT_TRUE(WaitForExtensionInstall()); |
| 560 extensions = service->extensions(); | 557 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 561 ASSERT_EQ(size_before + 1, extensions->size()); | 558 extension = service->GetExtensionById(kExtensionId, false); |
| 562 extension = extensions->at(size_before); | 559 ASSERT_TRUE(extension); |
| 563 ASSERT_EQ(kExtensionId, extension->id()); | |
| 564 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 560 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 565 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 561 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 566 | 562 |
| 567 // Remove the policy, and verify that the extension was uninstalled. | 563 // Remove the policy, and verify that the extension was uninstalled. |
| 568 // TODO(joaodasilva): it would be nicer if the extension was kept instead, | 564 // TODO(joaodasilva): it would be nicer if the extension was kept instead, |
| 569 // and reverted location to INTERNAL or whatever it was before the policy | 565 // and reverted location to INTERNAL or whatever it was before the policy |
| 570 // was applied. | 566 // was applied. |
| 571 { | 567 { |
| 572 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 568 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 573 ListValue* forcelist = pref_update.Get(); | 569 ListValue* forcelist = pref_update.Get(); |
| 574 ASSERT_TRUE(!forcelist->empty()); | 570 ASSERT_TRUE(!forcelist->empty()); |
| 575 forcelist->Clear(); | 571 forcelist->Clear(); |
| 576 } | 572 } |
| 577 extensions = service->extensions(); | 573 ASSERT_EQ(size_before, service->extensions()->size()); |
| 578 ASSERT_EQ(size_before, extensions->size()); | |
| 579 extension = service->GetExtensionById(kExtensionId, true); | 574 extension = service->GetExtensionById(kExtensionId, true); |
| 580 EXPECT_TRUE(extension == NULL); | 575 EXPECT_FALSE(extension); |
| 581 | 576 |
| 582 // User install again, but have it disabled too before setting the policy. | 577 // User install again, but have it disabled too before setting the policy. |
| 583 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 578 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 584 extensions = service->extensions(); | 579 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 585 ASSERT_EQ(size_before + 1, extensions->size()); | 580 extension = service->GetExtensionById(kExtensionId, false); |
| 586 extension = extensions->at(size_before); | 581 ASSERT_TRUE(extension); |
| 587 ASSERT_EQ(kExtensionId, extension->id()); | |
| 588 EXPECT_EQ(Extension::INTERNAL, extension->location()); | 582 EXPECT_EQ(Extension::INTERNAL, extension->location()); |
| 589 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 583 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 590 EXPECT_TRUE(service->disabled_extensions()->empty()); | 584 EXPECT_TRUE(service->disabled_extensions()->empty()); |
| 591 | 585 |
| 592 service->DisableExtension(kExtensionId); | 586 service->DisableExtension(kExtensionId); |
| 593 EXPECT_EQ(1u, service->disabled_extensions()->size()); | 587 EXPECT_EQ(1u, service->disabled_extensions()->size()); |
| 594 EXPECT_EQ(kExtensionId, service->disabled_extensions()->at(0)->id()); | 588 extension = service->GetExtensionById(kExtensionId, true); |
| 589 EXPECT_TRUE(extension); |
| 595 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); | 590 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); |
| 596 | 591 |
| 597 // Install the policy again. It should overwrite the extension's location, | 592 // Install the policy again. It should overwrite the extension's location, |
| 598 // and force enable it too. | 593 // and force enable it too. |
| 599 { | 594 { |
| 600 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 595 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 601 ListValue* forcelist = pref_update.Get(); | 596 ListValue* forcelist = pref_update.Get(); |
| 602 ASSERT_TRUE(forcelist->empty()); | 597 ASSERT_TRUE(forcelist->empty()); |
| 603 forcelist->Append(Value::CreateStringValue( | 598 forcelist->Append(Value::CreateStringValue( |
| 604 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); | 599 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); |
| 605 } | 600 } |
| 606 ASSERT_TRUE(WaitForExtensionInstall()); | 601 ASSERT_TRUE(WaitForExtensionInstall()); |
| 607 extensions = service->extensions(); | 602 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 608 ASSERT_EQ(size_before + 1, extensions->size()); | 603 extension = service->GetExtensionById(kExtensionId, false); |
| 609 extension = extensions->at(size_before); | 604 ASSERT_TRUE(extension); |
| 610 ASSERT_EQ(kExtensionId, extension->id()); | |
| 611 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 605 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 612 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 606 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 613 EXPECT_TRUE(service->disabled_extensions()->empty()); | 607 EXPECT_TRUE(service->disabled_extensions()->empty()); |
| 614 } | 608 } |
| OLD | NEW |