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

Side by Side Diff: extensions/browser/api/runtime/runtime_apitest.cc

Issue 2908513002: Include terminated extensions while retrieving extension version. (Closed)
Patch Set: fix browsertest Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/apps/app_browsertest_util.h" 5 #include "chrome/browser/apps/app_browsertest_util.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h" 7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/extensions/test_extension_dir.h" 8 #include "chrome/browser/extensions/test_extension_dir.h"
9 #include "chrome/test/base/ui_test_utils.h" 9 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/public/test/browser_test_utils.h"
10 #include "extensions/browser/api/runtime/runtime_api.h" 11 #include "extensions/browser/api/runtime/runtime_api.h"
11 #include "extensions/browser/extension_dialog_auto_confirm.h" 12 #include "extensions/browser/extension_dialog_auto_confirm.h"
12 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/scoped_ignore_content_verifier_for_test.h"
13 #include "extensions/browser/test_extension_registry_observer.h" 15 #include "extensions/browser/test_extension_registry_observer.h"
14 #include "extensions/test/result_catcher.h" 16 #include "extensions/test/result_catcher.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 17 #include "net/test/embedded_test_server/embedded_test_server.h"
16 18
17 // Tests the privileged components of chrome.runtime. 19 // Tests the privileged components of chrome.runtime.
18 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimePrivileged) { 20 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimePrivileged) {
19 ASSERT_TRUE(RunExtensionTest("runtime/privileged")) << message_; 21 ASSERT_TRUE(RunExtensionTest("runtime/privileged")) << message_;
20 } 22 }
21 23
22 // Tests the unprivileged components of chrome.runtime. 24 // Tests the unprivileged components of chrome.runtime.
(...skipping 14 matching lines...) Expand all
37 extensions::ScopedTestDialogAutoConfirm auto_confirm( 39 extensions::ScopedTestDialogAutoConfirm auto_confirm(
38 extensions::ScopedTestDialogAutoConfirm::ACCEPT); 40 extensions::ScopedTestDialogAutoConfirm::ACCEPT);
39 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("runtime") 41 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("runtime")
40 .AppendASCII("uninstall_url") 42 .AppendASCII("uninstall_url")
41 .AppendASCII("sets_uninstall_url"))); 43 .AppendASCII("sets_uninstall_url")));
42 ASSERT_TRUE(RunExtensionTest("runtime/uninstall_url")) << message_; 44 ASSERT_TRUE(RunExtensionTest("runtime/uninstall_url")) << message_;
43 } 45 }
44 46
45 namespace extensions { 47 namespace extensions {
46 48
49 namespace {
50
51 class RuntimeAPIUpdateTest : public ExtensionApiTest {
52 public:
53 RuntimeAPIUpdateTest() {}
54
55 protected:
56 void SetUpOnMainThread() override {
57 ExtensionApiTest::SetUpOnMainThread();
58 EXPECT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
59 }
60
61 struct ExtensionCRXData {
62 std::string unpacked_relative_path;
63 base::FilePath crx_path;
64 explicit ExtensionCRXData(const std::string& unpacked_relative_path)
65 : unpacked_relative_path(unpacked_relative_path) {}
66 };
67
68 void SetUpCRX(const std::string& root_dir,
69 const std::string& pem_filename,
70 std::vector<ExtensionCRXData>* crx_data_list) {
71 const base::FilePath test_dir = test_data_dir_.AppendASCII(root_dir);
72 const base::FilePath pem_path = test_dir.AppendASCII(pem_filename);
73 for (ExtensionCRXData& crx_data : *crx_data_list) {
74 crx_data.crx_path = PackExtensionWithOptions(
75 test_dir.AppendASCII(crx_data.unpacked_relative_path),
76 scoped_temp_dir_.GetPath().AppendASCII(
77 crx_data.unpacked_relative_path + ".crx"),
78 pem_path, base::FilePath());
79 }
80 }
81
82 bool CrashEnabledExtension(const std::string& extension_id) {
83 ExtensionHost* background_host =
84 ProcessManager::Get(browser()->profile())
85 ->GetBackgroundHostForExtension(extension_id);
86 if (!background_host)
87 return false;
88 content::CrashTab(background_host->host_contents());
89 return true;
90 }
91
92 private:
93 base::ScopedTempDir scoped_temp_dir_;
94 ScopedIgnoreContentVerifierForTest ignore_content_verification_;
95
96 DISALLOW_COPY_AND_ASSIGN(RuntimeAPIUpdateTest);
97 };
98
99 } // namespace
100
47 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeOpenOptionsPage) { 101 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeOpenOptionsPage) {
48 ASSERT_TRUE(RunExtensionTest("runtime/open_options_page")); 102 ASSERT_TRUE(RunExtensionTest("runtime/open_options_page"));
49 } 103 }
50 104
51 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeOpenOptionsPageError) { 105 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeOpenOptionsPageError) {
52 ASSERT_TRUE(RunExtensionTest("runtime/open_options_page_error")); 106 ASSERT_TRUE(RunExtensionTest("runtime/open_options_page_error"));
53 } 107 }
54 108
55 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeGetPlatformInfo) { 109 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeGetPlatformInfo) {
56 std::unique_ptr<base::Value> result( 110 std::unique_ptr<base::Value> result(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // We need to let other registry observers handle the notification to 174 // We need to let other registry observers handle the notification to
121 // finish initialization 175 // finish initialization
122 base::RunLoop().RunUntilIdle(); 176 base::RunLoop().RunUntilIdle();
123 WaitForExtensionViewsToLoad(); 177 WaitForExtensionViewsToLoad();
124 } 178 }
125 } 179 }
126 ASSERT_TRUE( 180 ASSERT_TRUE(
127 registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)); 181 registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED));
128 } 182 }
129 183
184 // Tests that updating a terminated extension sends runtime.onInstalled event
185 // with correct previousVersion.
186 // Regression test for https://crbug.com/724563.
187 IN_PROC_BROWSER_TEST_F(RuntimeAPIUpdateTest,
188 TerminatedExtensionUpdateHasCorrectPreviousVersion) {
189 std::vector<ExtensionCRXData> data;
190 data.emplace_back("v1");
191 data.emplace_back("v2");
192 SetUpCRX("runtime/update_terminated_extension", "pem.pem", &data);
193
194 ExtensionId extension_id;
195 {
196 // Install version 1 of the extension.
197 ResultCatcher catcher;
198 const int expected_change = 1;
199 const Extension* extension_v1 =
200 InstallExtension(data[0].crx_path, expected_change);
201 extension_id = extension_v1->id();
202 ASSERT_TRUE(extension_v1);
203 EXPECT_TRUE(catcher.GetNextResult());
204 }
205 ASSERT_TRUE(CrashEnabledExtension(extension_id));
206 {
207 // Update to version 2, expect runtime.onInstalled with
208 // previousVersion = '1'.
209 ResultCatcher catcher;
210 const int expected_change = 1;
211 const Extension* extension_v2 =
212 UpdateExtension(extension_id, data[1].crx_path, expected_change);
213 ASSERT_TRUE(extension_v2);
214 EXPECT_TRUE(catcher.GetNextResult());
215 }
216 }
217
130 } // namespace extensions 218 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698