| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 7 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 8 #include "chrome/browser/extensions/extension_function_test_utils.h" | 9 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 9 #include "chrome/browser/extensions/extension_service_test_base.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 12 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/test_browser_window.h" | 15 #include "chrome/test/base/test_browser_window.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/common/browser_side_navigation_policy.h" | 17 #include "content/public/common/browser_side_navigation_policy.h" |
| 17 #include "content/public/test/browser_side_navigation_test_utils.h" | 18 #include "content/public/test/browser_side_navigation_test_utils.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 EXPECT_EQ(kGoogle, web_contents->GetLastCommittedURL()); | 264 EXPECT_EQ(kGoogle, web_contents->GetLastCommittedURL()); |
| 264 EXPECT_EQ(kGoogle, web_contents->GetVisibleURL()); | 265 EXPECT_EQ(kGoogle, web_contents->GetVisibleURL()); |
| 265 | 266 |
| 266 // Clean up. | 267 // Clean up. |
| 267 response_helper.WaitForResponse(); | 268 response_helper.WaitForResponse(); |
| 268 while (!browser()->tab_strip_model()->empty()) | 269 while (!browser()->tab_strip_model()->empty()) |
| 269 browser()->tab_strip_model()->CloseWebContentsAt(0, 0); | 270 browser()->tab_strip_model()->CloseWebContentsAt(0, 0); |
| 270 base::RunLoop().RunUntilIdle(); | 271 base::RunLoop().RunUntilIdle(); |
| 271 } | 272 } |
| 272 | 273 |
| 274 // Tests that non-validation failure in tabs.executeScript results in error, and |
| 275 // not bad_message. |
| 276 // Regression test for https://crbug.com/642794. |
| 277 TEST_F(TabsApiUnitTest, ExecuteScriptNoTabIsNonFatalError) { |
| 278 // An extension with "tabs" permission. |
| 279 scoped_refptr<const Extension> extension = |
| 280 ExtensionBuilder() |
| 281 .SetManifest( |
| 282 DictionaryBuilder() |
| 283 .Set("name", "Extension with tabs permission") |
| 284 .Set("version", "1.0") |
| 285 .Set("manifest_version", 2) |
| 286 .Set("permissions", ListBuilder().Append("tabs").Build()) |
| 287 .Build()) |
| 288 .Build(); |
| 289 scoped_refptr<TabsExecuteScriptFunction> function( |
| 290 new TabsExecuteScriptFunction()); |
| 291 function->set_extension(extension); |
| 292 const char* kArgs = R"(["", {"code": ""}])"; |
| 293 std::string error = extension_function_test_utils::RunFunctionAndReturnError( |
| 294 function.get(), kArgs, |
| 295 browser(), // browser() doesn't have any tabs. |
| 296 extension_function_test_utils::NONE); |
| 297 EXPECT_EQ(tabs_constants::kNoTabInBrowserWindowError, error); |
| 298 } |
| 299 |
| 273 } // namespace extensions | 300 } // namespace extensions |
| OLD | NEW |