| 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 "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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 ext_host->render_view_host(), L"", L"version()", &version_from_bg); | 52 ext_host->render_view_host(), L"", L"version()", &version_from_bg); |
| 53 EXPECT_TRUE(exec); | 53 EXPECT_TRUE(exec); |
| 54 if (!exec) | 54 if (!exec) |
| 55 return false; | 55 return false; |
| 56 | 56 |
| 57 if (version_from_bg != expected_version || | 57 if (version_from_bg != expected_version || |
| 58 extension->VersionString() != expected_version) | 58 extension->VersionString() != expected_version) |
| 59 return false; | 59 return false; |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 | |
| 63 // Helper method that installs a low permission extension then updates | |
| 64 // to the second version requiring increased permissions. Returns whether | |
| 65 // the operation was completed successfully. | |
| 66 bool InstallAndUpdateIncreasingPermissionsExtension() { | |
| 67 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 68 size_t size_before = service->extensions()->size(); | |
| 69 | |
| 70 // Install the initial version, which should happen just fine. | |
| 71 const Extension* extension = InstallExtension( | |
| 72 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); | |
| 73 if (!extension) | |
| 74 return false; | |
| 75 if (service->extensions()->size() != size_before + 1) | |
| 76 return false; | |
| 77 | |
| 78 // Upgrade to a version that wants more permissions. We should disable the | |
| 79 // extension and prompt the user to reenable. | |
| 80 if (UpdateExtension( | |
| 81 extension->id(), | |
| 82 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) | |
| 83 return false; | |
| 84 EXPECT_EQ(size_before, service->extensions()->size()); | |
| 85 if (service->disabled_extensions()->size() != 1u) | |
| 86 return false; | |
| 87 return true; | |
| 88 } | |
| 89 }; | 62 }; |
| 90 | 63 |
| 91 #if defined(OS_LINUX) | 64 #if defined(OS_LINUX) |
| 92 // Times out sometimes on Linux. http://crbug.com/89727 | 65 // Times out sometimes on Linux. http://crbug.com/89727 |
| 93 #define MAYBE_InstallSameVersion DISABLED_InstallSameVersion | 66 #define MAYBE_InstallSameVersion DISABLED_InstallSameVersion |
| 94 #else | 67 #else |
| 95 #define MAYBE_InstallSameVersion InstallSameVersion | 68 #define MAYBE_InstallSameVersion InstallSameVersion |
| 96 #endif | 69 #endif |
| 97 | 70 |
| 98 // Tests that installing the same version overwrites. | 71 // Tests that installing the same version overwrites. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ASSERT_FALSE(InstallExtension(test_data_dir_.AppendASCII("good.crx"), 0)); | 114 ASSERT_FALSE(InstallExtension(test_data_dir_.AppendASCII("good.crx"), 0)); |
| 142 ASSERT_TRUE(service->GetExtensionById(id, true)); | 115 ASSERT_TRUE(service->GetExtensionById(id, true)); |
| 143 UninstallExtension(id); | 116 UninstallExtension(id); |
| 144 | 117 |
| 145 // And the install should succeed when the permissions are accepted. | 118 // And the install should succeed when the permissions are accepted. |
| 146 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm( | 119 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm( |
| 147 test_data_dir_.AppendASCII("good.crx"), 1, browser()->profile())); | 120 test_data_dir_.AppendASCII("good.crx"), 1, browser()->profile())); |
| 148 UninstallExtension(id); | 121 UninstallExtension(id); |
| 149 } | 122 } |
| 150 | 123 |
| 151 // Tests the process of updating an extension to one that requires higher | |
| 152 // permissions. | |
| 153 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissions) { | |
| 154 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 155 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); | |
| 156 const size_t size_before = service->extensions()->size(); | |
| 157 | |
| 158 // Now try reenabling it. | |
| 159 const std::string id = (*service->disabled_extensions()->begin())->id(); | |
| 160 service->EnableExtension(id); | |
| 161 EXPECT_EQ(size_before + 1, service->extensions()->size()); | |
| 162 EXPECT_EQ(0u, service->disabled_extensions()->size()); | |
| 163 } | |
| 164 | |
| 165 // Tests uninstalling an extension that was disabled due to higher permissions. | |
| 166 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissionsAndUninstall) { | |
| 167 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); | |
| 168 | |
| 169 // Make sure the "disable extension" infobar is present. | |
| 170 ASSERT_EQ(0, browser()->active_index()); | |
| 171 InfoBarTabHelper* infobar_helper = browser()->GetTabContentsWrapperAt(0)-> | |
| 172 infobar_tab_helper(); | |
| 173 ASSERT_EQ(1U, infobar_helper->infobar_count()); | |
| 174 | |
| 175 // Uninstall, and check that the infobar went away. | |
| 176 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 177 std::string id = (*service->disabled_extensions()->begin())->id(); | |
| 178 UninstallExtension(id); | |
| 179 ASSERT_EQ(0U, infobar_helper->infobar_count()); | |
| 180 | |
| 181 // Now select a new tab, and switch back to the first tab which had the | |
| 182 // infobar. We should not crash. | |
| 183 ASSERT_EQ(1, browser()->tab_count()); | |
| 184 ASSERT_EQ(0, browser()->active_index()); | |
| 185 browser()->NewTab(); | |
| 186 ASSERT_EQ(2, browser()->tab_count()); | |
| 187 ASSERT_EQ(1, browser()->active_index()); | |
| 188 browser()->ActivateTabAt(0, true); | |
| 189 } | |
| 190 | |
| 191 // Tests that we can uninstall a disabled extension. | |
| 192 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UninstallDisabled) { | |
| 193 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 194 ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); | |
| 195 const size_t size_before = service->extensions()->size(); | |
| 196 | |
| 197 // Now try uninstalling it. | |
| 198 UninstallExtension((*service->disabled_extensions()->begin())->id()); | |
| 199 EXPECT_EQ(size_before, service->extensions()->size()); | |
| 200 EXPECT_EQ(0u, service->disabled_extensions()->size()); | |
| 201 } | |
| 202 | |
| 203 // Tests that disabling and re-enabling an extension works. | 124 // Tests that disabling and re-enabling an extension works. |
| 204 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, DisableEnable) { | 125 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, DisableEnable) { |
| 205 ExtensionProcessManager* manager = browser()->profile()-> | 126 ExtensionProcessManager* manager = browser()->profile()-> |
| 206 GetExtensionProcessManager(); | 127 GetExtensionProcessManager(); |
| 207 ExtensionService* service = browser()->profile()->GetExtensionService(); | 128 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 208 const size_t size_before = service->extensions()->size(); | 129 const size_t size_before = service->extensions()->size(); |
| 209 | 130 |
| 210 // Load an extension, expect the background page to be available. | 131 // Load an extension, expect the background page to be available. |
| 211 std::string extension_id = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; | 132 std::string extension_id = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
| 212 ASSERT_TRUE(LoadExtension( | 133 ASSERT_TRUE(LoadExtension( |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); | 520 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); |
| 600 } | 521 } |
| 601 ASSERT_TRUE(WaitForExtensionInstall()); | 522 ASSERT_TRUE(WaitForExtensionInstall()); |
| 602 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 523 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 603 extension = service->GetExtensionById(kExtensionId, false); | 524 extension = service->GetExtensionById(kExtensionId, false); |
| 604 ASSERT_TRUE(extension); | 525 ASSERT_TRUE(extension); |
| 605 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 526 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 606 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 527 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 607 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 528 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
| 608 } | 529 } |
| OLD | NEW |