| 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 #include "chrome/browser/extensions/browsertest_util.h" | 5 #include "chrome/browser/extensions/browsertest_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/extensions/test_extension_dir.h" | 9 #include "chrome/browser/extensions/test_extension_dir.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 ExecuteScriptInBackground) { | 24 ExecuteScriptInBackground) { |
| 25 TestExtensionDir ext_dir; | 25 TestExtensionDir ext_dir; |
| 26 ext_dir.WriteManifest( | 26 ext_dir.WriteManifest( |
| 27 "{\n" | 27 "{\n" |
| 28 " \"name\": \"ExecuteScript extension\",\n" | 28 " \"name\": \"ExecuteScript extension\",\n" |
| 29 " \"version\": \"0.1\",\n" | 29 " \"version\": \"0.1\",\n" |
| 30 " \"manifest_version\": 2,\n" | 30 " \"manifest_version\": 2,\n" |
| 31 " \"background\": {\"scripts\": [\"background.js\"]}\n" | 31 " \"background\": {\"scripts\": [\"background.js\"]}\n" |
| 32 "}\n"); | 32 "}\n"); |
| 33 ext_dir.WriteFile(FILE_PATH_LITERAL("background.js"), ""); | 33 ext_dir.WriteFile(FILE_PATH_LITERAL("background.js"), ""); |
| 34 const Extension* extension = LoadExtension(ext_dir.unpacked_path()); | 34 const Extension* extension = LoadExtension(ext_dir.UnpackedPath()); |
| 35 ASSERT_TRUE(extension); | 35 ASSERT_TRUE(extension); |
| 36 EXPECT_EQ(extension->id(), | 36 EXPECT_EQ(extension->id(), |
| 37 browsertest_util::ExecuteScriptInBackgroundPage( | 37 browsertest_util::ExecuteScriptInBackgroundPage( |
| 38 profile(), | 38 profile(), |
| 39 extension->id(), | 39 extension->id(), |
| 40 "window.domAutomationController.send(chrome.runtime.id);")); | 40 "window.domAutomationController.send(chrome.runtime.id);")); |
| 41 | 41 |
| 42 // This test checks that executing a script doesn't block the browser process. | 42 // This test checks that executing a script doesn't block the browser process. |
| 43 EXPECT_EQ(base::IntToString(browser()->tab_strip_model()->count()), | 43 EXPECT_EQ(base::IntToString(browser()->tab_strip_model()->count()), |
| 44 browsertest_util::ExecuteScriptInBackgroundPage( | 44 browsertest_util::ExecuteScriptInBackgroundPage( |
| 45 profile(), | 45 profile(), |
| 46 extension->id(), | 46 extension->id(), |
| 47 "chrome.tabs.query({}, function(result) {\n" | 47 "chrome.tabs.query({}, function(result) {\n" |
| 48 " window.domAutomationController.send('' + result.length);\n" | 48 " window.domAutomationController.send('' + result.length);\n" |
| 49 "});")); | 49 "});")); |
| 50 | 50 |
| 51 // An argument that isn't a string should cause a failure, not a hang. | 51 // An argument that isn't a string should cause a failure, not a hang. |
| 52 EXPECT_NONFATAL_FAILURE(browsertest_util::ExecuteScriptInBackgroundPage( | 52 EXPECT_NONFATAL_FAILURE(browsertest_util::ExecuteScriptInBackgroundPage( |
| 53 profile(), | 53 profile(), |
| 54 extension->id(), | 54 extension->id(), |
| 55 "window.domAutomationController.send(3);"), | 55 "window.domAutomationController.send(3);"), |
| 56 "send(3)"); | 56 "send(3)"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 } // namespace extensions | 60 } // namespace extensions |
| OLD | NEW |