OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/ref_counted.h" | 5 #include "base/ref_counted.h" |
6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
7 #include "chrome/browser/renderer_host/render_view_host.h" | 7 #include "chrome/browser/renderer_host/render_view_host.h" |
8 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 8 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
11 #include "chrome/browser/extensions/extensions_service.h" | 11 #include "chrome/browser/extensions/extensions_service.h" |
12 #include "chrome/browser/extensions/extension_updater.h" | 12 #include "chrome/browser/extensions/extension_updater.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/ui_test_utils.h" | 15 #include "chrome/test/ui_test_utils.h" |
16 | 16 |
17 class ExtensionManagementTest : public ExtensionBrowserTest { | 17 class ExtensionManagementTest : public ExtensionBrowserTest { |
18 protected: | 18 protected: |
19 // Helper method that returns whether the extension is at the given version. | 19 // Helper method that returns whether the extension is at the given version. |
20 // This calls version(), which must be defined in the extension's bg page, | 20 // This calls version(), which must be defined in the extension's bg page, |
21 // as well as asking the extension itself. | 21 // as well as asking the extension itself. |
| 22 // |
| 23 // Note that 'version' here means something different than the version field |
| 24 // in the extension's manifest. We use the version as reported by the |
| 25 // background page to test how overinstalling crx files with the same |
| 26 // manifest version works. |
22 bool IsExtensionAtVersion(Extension* extension, | 27 bool IsExtensionAtVersion(Extension* extension, |
23 const std::string& expected_version) { | 28 const std::string& expected_version) { |
24 // Test that the extension's version from the manifest and reported by the | 29 // Test that the extension's version from the manifest and reported by the |
25 // background page is correct. This is to ensure that the processes are in | 30 // background page is correct. This is to ensure that the processes are in |
26 // sync with the Extension. | 31 // sync with the Extension. |
27 ExtensionProcessManager* manager = browser()->profile()-> | 32 ExtensionProcessManager* manager = browser()->profile()-> |
28 GetExtensionProcessManager(); | 33 GetExtensionProcessManager(); |
29 ExtensionHost* ext_host = manager->GetBackgroundHostForExtension(extension); | 34 ExtensionHost* ext_host = manager->GetBackgroundHostForExtension(extension); |
30 EXPECT_TRUE(ext_host); | 35 EXPECT_TRUE(ext_host); |
31 if (!ext_host) | 36 if (!ext_host) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 service->extensions()->at(size_before)->id(), | 69 service->extensions()->at(size_before)->id(), |
65 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) | 70 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) |
66 return false; | 71 return false; |
67 EXPECT_EQ(size_before, service->extensions()->size()); | 72 EXPECT_EQ(size_before, service->extensions()->size()); |
68 if (service->disabled_extensions()->size() != 1u) | 73 if (service->disabled_extensions()->size() != 1u) |
69 return false; | 74 return false; |
70 return true; | 75 return true; |
71 } | 76 } |
72 }; | 77 }; |
73 | 78 |
74 // Tests that installing the same version does not overwrite. | 79 // Tests that installing the same version overwrites. |
75 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallSameVersion) { | 80 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallSameVersion) { |
76 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 81 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
77 const size_t size_before = service->extensions()->size(); | 82 const size_t size_before = service->extensions()->size(); |
78 ASSERT_TRUE(InstallExtension( | 83 ASSERT_TRUE(InstallExtension( |
79 test_data_dir_.AppendASCII("install/install.crx"), 1)); | 84 test_data_dir_.AppendASCII("install/install.crx"), 1)); |
| 85 FilePath old_path = service->extensions()->back()->path(); |
80 | 86 |
81 // Install an extension with the same version. The previous install should | 87 // Install an extension with the same version. The previous install should be |
82 // be kept. | 88 // overwritten. |
83 ASSERT_TRUE(InstallExtension( | 89 ASSERT_TRUE(InstallExtension( |
84 test_data_dir_.AppendASCII("install/install_same_version.crx"), 0)); | 90 test_data_dir_.AppendASCII("install/install_same_version.crx"), 0)); |
| 91 FilePath new_path = service->extensions()->back()->path(); |
85 | 92 |
86 EXPECT_TRUE(IsExtensionAtVersion(service->extensions()->at(size_before), | 93 EXPECT_FALSE(IsExtensionAtVersion(service->extensions()->at(size_before), |
87 "1.0")); | 94 "1.0")); |
| 95 EXPECT_NE(old_path.value(), new_path.value()); |
88 } | 96 } |
89 | 97 |
90 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallOlderVersion) { | 98 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallOlderVersion) { |
91 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 99 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
92 const size_t size_before = service->extensions()->size(); | 100 const size_t size_before = service->extensions()->size(); |
93 ASSERT_TRUE(InstallExtension( | 101 ASSERT_TRUE(InstallExtension( |
94 test_data_dir_.AppendASCII("install/install.crx"), 1)); | 102 test_data_dir_.AppendASCII("install/install.crx"), 1)); |
95 ASSERT_TRUE(InstallExtension( | 103 ASSERT_TRUE(InstallExtension( |
96 test_data_dir_.AppendASCII("install/install_older_version.crx"), 0)); | 104 test_data_dir_.AppendASCII("install/install_older_version.crx"), 0)); |
97 EXPECT_TRUE(IsExtensionAtVersion(service->extensions()->at(size_before), | 105 EXPECT_TRUE(IsExtensionAtVersion(service->extensions()->at(size_before), |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 service->updater()->CheckNow(); | 242 service->updater()->CheckNow(); |
235 ASSERT_TRUE(WaitForExtensionInstallError()); | 243 ASSERT_TRUE(WaitForExtensionInstallError()); |
236 | 244 |
237 // Make sure the extension state is the same as before. | 245 // Make sure the extension state is the same as before. |
238 extensions = service->extensions(); | 246 extensions = service->extensions(); |
239 ASSERT_EQ(size_before + 1, extensions->size()); | 247 ASSERT_EQ(size_before + 1, extensions->size()); |
240 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", | 248 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", |
241 extensions->at(size_before)->id()); | 249 extensions->at(size_before)->id()); |
242 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString()); | 250 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString()); |
243 } | 251 } |
OLD | NEW |