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" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 const char kTargetJs[] = | 194 const char kTargetJs[] = |
195 "var is_valid = !!(chrome.tabs && chrome.tabs.create);"; | 195 "var is_valid = !!(chrome.tabs && chrome.tabs.create);"; |
196 | 196 |
197 devtools_dir.WriteManifestWithSingleQuotes(kDevtoolsManifest); | 197 devtools_dir.WriteManifestWithSingleQuotes(kDevtoolsManifest); |
198 devtools_dir.WriteFile(FILE_PATH_LITERAL("devtools.js"), kDevtoolsJs); | 198 devtools_dir.WriteFile(FILE_PATH_LITERAL("devtools.js"), kDevtoolsJs); |
199 devtools_dir.WriteFile(FILE_PATH_LITERAL("devtools.html"), | 199 devtools_dir.WriteFile(FILE_PATH_LITERAL("devtools.html"), |
200 "<script src='devtools.js'></script>"); | 200 "<script src='devtools.js'></script>"); |
201 | 201 |
202 inspect_dir.WriteManifestWithSingleQuotes(kTargetManifest); | 202 inspect_dir.WriteManifestWithSingleQuotes(kTargetManifest); |
203 inspect_dir.WriteFile(FILE_PATH_LITERAL("background.js"), kTargetJs); | 203 inspect_dir.WriteFile(FILE_PATH_LITERAL("background.js"), kTargetJs); |
204 const Extension* devtools_ext = LoadExtension(devtools_dir.unpacked_path()); | 204 const Extension* devtools_ext = LoadExtension(devtools_dir.UnpackedPath()); |
205 ASSERT_TRUE(devtools_ext); | 205 ASSERT_TRUE(devtools_ext); |
206 | 206 |
207 const Extension* inspect_ext = LoadExtension(inspect_dir.unpacked_path()); | 207 const Extension* inspect_ext = LoadExtension(inspect_dir.UnpackedPath()); |
208 ASSERT_TRUE(inspect_ext); | 208 ASSERT_TRUE(inspect_ext); |
209 const std::string inspect_ext_id = inspect_ext->id(); | 209 const std::string inspect_ext_id = inspect_ext->id(); |
210 | 210 |
211 // Open the devtools and wait until the devtools_page is ready. | 211 // Open the devtools and wait until the devtools_page is ready. |
212 ExtensionTestMessageListener devtools_ready("devtools_page_ready", false); | 212 ExtensionTestMessageListener devtools_ready("devtools_page_ready", false); |
213 devtools_util::InspectBackgroundPage(inspect_ext, profile()); | 213 devtools_util::InspectBackgroundPage(inspect_ext, profile()); |
214 ASSERT_TRUE(devtools_ready.WaitUntilSatisfied()); | 214 ASSERT_TRUE(devtools_ready.WaitUntilSatisfied()); |
215 | 215 |
216 // Reload the extension. The devtools window will stay open, but temporarily | 216 // Reload the extension. The devtools window will stay open, but temporarily |
217 // be detached. As soon as the background is attached again, the devtools | 217 // be detached. As soon as the background is attached again, the devtools |
218 // continues with spamming eval requests. | 218 // continues with spamming eval requests. |
219 ReloadExtension(inspect_ext_id); | 219 ReloadExtension(inspect_ext_id); |
220 WaitForExtensionViewsToLoad(); | 220 WaitForExtensionViewsToLoad(); |
221 | 221 |
222 content::WebContents* bg_contents = | 222 content::WebContents* bg_contents = |
223 ProcessManager::Get(profile()) | 223 ProcessManager::Get(profile()) |
224 ->GetBackgroundHostForExtension(inspect_ext_id) | 224 ->GetBackgroundHostForExtension(inspect_ext_id) |
225 ->host_contents(); | 225 ->host_contents(); |
226 ASSERT_TRUE(bg_contents); | 226 ASSERT_TRUE(bg_contents); |
227 | 227 |
228 // Now check whether the extension runtime is valid (see kTargetJs). | 228 // Now check whether the extension runtime is valid (see kTargetJs). |
229 bool is_valid = false; | 229 bool is_valid = false; |
230 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 230 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
231 bg_contents, "domAutomationController.send(is_valid);", &is_valid)); | 231 bg_contents, "domAutomationController.send(is_valid);", &is_valid)); |
232 EXPECT_TRUE(is_valid); | 232 EXPECT_TRUE(is_valid); |
233 } | 233 } |
234 | 234 |
235 } // namespace | 235 } // namespace |
236 } // namespace extensions | 236 } // namespace extensions |
OLD | NEW |