OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This file contains tests for extension loading, reloading, and | 5 // This file contains tests for extension loading, reloading, and |
6 // unloading behavior. | 6 // unloading behavior. |
7 | 7 |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/version.h" | 10 #include "base/version.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/browser/extensions/devtools_util.h" | 12 #include "chrome/browser/extensions/devtools_util.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/test_extension_dir.h" | 15 #include "chrome/browser/extensions/test_extension_dir.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/public/browser/devtools_agent_host.h" | 20 #include "content/public/browser/devtools_agent_host.h" |
21 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
22 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/process_manager.h" | 23 #include "extensions/browser/process_manager.h" |
24 #include "extensions/common/permissions/permissions_data.h" | |
24 #include "extensions/test/extension_test_message_listener.h" | 25 #include "extensions/test/extension_test_message_listener.h" |
25 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
30 #endif | 31 #endif |
31 | 32 |
32 namespace extensions { | 33 namespace extensions { |
33 namespace { | 34 namespace { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 AddTabAtIndex(browser()->tab_strip_model()->count(), | 95 AddTabAtIndex(browser()->tab_strip_model()->count(), |
95 GURL("http://www.google.com/"), | 96 GURL("http://www.google.com/"), |
96 ui::PAGE_TRANSITION_TYPED); | 97 ui::PAGE_TRANSITION_TYPED); |
97 | 98 |
98 // Check that the extension hasn't crashed. | 99 // Check that the extension hasn't crashed. |
99 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 100 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
100 EXPECT_EQ(0U, registry->terminated_extensions().size()); | 101 EXPECT_EQ(0U, registry->terminated_extensions().size()); |
101 EXPECT_TRUE(registry->enabled_extensions().Contains(new_tab_extension->id())); | 102 EXPECT_TRUE(registry->enabled_extensions().Contains(new_tab_extension->id())); |
102 } | 103 } |
103 | 104 |
105 IN_PROC_BROWSER_TEST_F(ExtensionLoadingTest, | |
106 UpgradeAddingNewTabPagePermissionNoPrompt) { | |
107 embedded_test_server()->ServeFilesFromDirectory( | |
108 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
109 ASSERT_TRUE(embedded_test_server()->Start()); | |
110 | |
111 TestExtensionDir extension_dir; | |
112 const char manifest_template[] = | |
113 "{" | |
114 " 'name': 'Overrides New Tab'," | |
115 " 'version': '%d'," | |
116 " 'description': 'Will override New Tab soon'," | |
117 " 'manifest_version': 2," | |
118 " %s" // Placeholder for future NTP url override block. | |
119 " 'background': {" | |
120 " 'persistent': false," | |
121 " 'scripts': ['event.js']" | |
122 " }" | |
123 "}"; | |
124 extension_dir.WriteManifestWithSingleQuotes( | |
125 base::StringPrintf(manifest_template, 1, "")); | |
126 extension_dir.WriteFile(FILE_PATH_LITERAL("event.js"), ""); | |
127 extension_dir.WriteFile(FILE_PATH_LITERAL("newtab.html"), | |
128 "<h1>Overridden New Tab Page</h1>"); | |
129 | |
130 const Extension* new_tab_extension = | |
131 InstallExtension(extension_dir.Pack(), 1 /*new install*/); | |
132 ASSERT_NE(nullptr, new_tab_extension); | |
Devlin
2017/07/05 15:45:02
optional: I think ASSERT_TRUE(new_tab_extension) i
robertshield
2017/07/18 19:46:20
Done.
| |
133 | |
134 EXPECT_FALSE(new_tab_extension->permissions_data()->HasAPIPermission( | |
135 APIPermission::kNewTabPageOverride)); | |
136 | |
137 // Navigate that tab to a non-extension URL to swap out the extension's | |
138 // renderer. | |
139 const GURL test_link_from_NTP = | |
Devlin
2017/07/05 15:45:02
nit: ignore capitals in variable names, so just |t
robertshield
2017/07/18 19:46:20
Done.
| |
140 embedded_test_server()->GetURL("/README.chromium"); | |
141 EXPECT_THAT(test_link_from_NTP.spec(), testing::EndsWith("/README.chromium")) | |
142 << "Check that the test server started."; | |
143 NavigateInRenderer(browser()->tab_strip_model()->GetActiveWebContents(), | |
144 test_link_from_NTP); | |
145 | |
146 // Increase the extension's version and add the NTP url override which will | |
147 // add the kNewTabPageOverride permission. | |
148 const char ntp_override_string[] = | |
149 " 'chrome_url_overrides': {" | |
150 " 'newtab': 'newtab.html'" | |
151 " },"; | |
152 extension_dir.WriteManifestWithSingleQuotes( | |
153 base::StringPrintf(manifest_template, 2, ntp_override_string)); | |
154 | |
155 // Upgrade the extension, ensure that the upgrade 'worked' in the sense that | |
156 // the extension is still present and not disabled and that it now has the | |
Devlin
2017/07/05 15:45:02
Is this desired? It means that if I don't want th
robertshield
2017/07/18 19:46:20
Yes, it's intended for migration. The intent is no
| |
157 // new API permission. | |
158 new_tab_extension = UpdateExtension( | |
159 new_tab_extension->id(), extension_dir.Pack(), 0 /*expected upgrade*/); | |
160 ASSERT_NE(nullptr, new_tab_extension); | |
161 | |
162 EXPECT_TRUE(new_tab_extension->permissions_data()->HasAPIPermission( | |
163 APIPermission::kNewTabPageOverride)); | |
164 EXPECT_THAT(new_tab_extension->version()->components(), | |
165 testing::ElementsAre(2)); | |
166 } | |
167 | |
104 // Tests the behavior described in http://crbug.com/532088. | 168 // Tests the behavior described in http://crbug.com/532088. |
105 IN_PROC_BROWSER_TEST_F(ExtensionLoadingTest, | 169 IN_PROC_BROWSER_TEST_F(ExtensionLoadingTest, |
106 KeepAliveWithDevToolsOpenOnReload) { | 170 KeepAliveWithDevToolsOpenOnReload) { |
107 embedded_test_server()->ServeFilesFromDirectory( | 171 embedded_test_server()->ServeFilesFromDirectory( |
108 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 172 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
109 ASSERT_TRUE(embedded_test_server()->Start()); | 173 ASSERT_TRUE(embedded_test_server()->Start()); |
110 | 174 |
111 TestExtensionDir extension_dir; | 175 TestExtensionDir extension_dir; |
112 const char manifest_contents[] = | 176 const char manifest_contents[] = |
113 "{" | 177 "{" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 294 |
231 // Now check whether the extension runtime is valid (see kTargetJs). | 295 // Now check whether the extension runtime is valid (see kTargetJs). |
232 bool is_valid = false; | 296 bool is_valid = false; |
233 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 297 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
234 bg_contents, "domAutomationController.send(is_valid);", &is_valid)); | 298 bg_contents, "domAutomationController.send(is_valid);", &is_valid)); |
235 EXPECT_TRUE(is_valid); | 299 EXPECT_TRUE(is_valid); |
236 } | 300 } |
237 | 301 |
238 } // namespace | 302 } // namespace |
239 } // namespace extensions | 303 } // namespace extensions |
OLD | NEW |