blob: 660c0ce460d7c9b0fe129228ec2ee84a0392c9c7 [file] [log] [blame]
[email protected]fad73672012-06-15 23:26:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c80b8ee2011-12-03 04:26:522// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Contains holistic tests of the bindings infrastructure
6
[email protected]7eef3942013-08-14 02:53:497#include "chrome/browser/extensions/api/permissions/permissions_api.h"
[email protected]c80b8ee2011-12-03 04:26:528#include "chrome/browser/extensions/extension_apitest.h"
[email protected]fad73672012-06-15 23:26:069#include "chrome/browser/ui/browser.h"
[email protected]7d478cb2012-07-24 17:19:4210#include "content/public/test/browser_test_utils.h"
[email protected]22401dc2014-03-21 01:38:5711#include "extensions/browser/extension_host.h"
[email protected]98b6d942013-11-10 00:34:0712#include "extensions/browser/process_manager.h"
lfg910f2f92014-09-19 05:31:0913#include "extensions/test/extension_test_message_listener.h"
yoze8dc2f12014-09-09 23:16:3214#include "extensions/test/result_catcher.h"
[email protected]fad73672012-06-15 23:26:0615
[email protected]adafe5b2013-08-09 10:35:0416namespace extensions {
17namespace {
18
19class ExtensionBindingsApiTest : public ExtensionApiTest {};
20
21IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
[email protected]7eef3942013-08-14 02:53:4922 UnavailableBindingsNeverRegistered) {
23 // Test will request the 'storage' permission.
24 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
25 ASSERT_TRUE(RunExtensionTest(
26 "bindings/unavailable_bindings_never_registered")) << message_;
27}
28
29IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
[email protected]adafe5b2013-08-09 10:35:0430 ExceptionInHandlerShouldNotCrash) {
[email protected]c80b8ee2011-12-03 04:26:5231 ASSERT_TRUE(RunExtensionSubtest(
32 "bindings/exception_in_handler_should_not_crash",
33 "page.html")) << message_;
34}
[email protected]fad73672012-06-15 23:26:0635
36// Tests that an error raised during an async function still fires
[email protected]754ea8b72013-01-08 15:10:3137// the callback, but sets chrome.runtime.lastError.
[email protected]fc034482013-08-09 20:25:1438// FIXME should be in ExtensionBindingsApiTest.
[email protected]fad73672012-06-15 23:26:0639IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) {
40 ASSERT_TRUE(LoadExtension(
41 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error")));
42
43 // Get the ExtensionHost that is hosting our background page.
[email protected]98b6d942013-11-10 00:34:0744 extensions::ProcessManager* manager =
reillyg0ea3fa902014-10-28 15:30:2345 extensions::ProcessManager::Get(browser()->profile());
[email protected]3a1dc572012-07-31 22:25:1346 extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1);
[email protected]fad73672012-06-15 23:26:0647
48 bool result = false;
[email protected]b6987e02013-01-04 18:30:4349 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
50 host->render_view_host(), "testLastError()", &result));
[email protected]fad73672012-06-15 23:26:0651 EXPECT_TRUE(result);
52}
[email protected]52eafbd2013-04-03 04:43:1953
[email protected]adafe5b2013-08-09 10:35:0454// Regression test that we don't delete our own bindings with about:blank
55// iframes.
56IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) {
57 ResultCatcher catcher;
58 ExtensionTestMessageListener listener("load", true);
59
60 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings")
61 .AppendASCII("about_blank_iframe")));
62
63 ASSERT_TRUE(listener.WaitUntilSatisfied());
64
65 const Extension* extension = LoadExtension(
66 test_data_dir_.AppendASCII("bindings")
67 .AppendASCII("internal_apis_not_on_chrome_object"));
68 ASSERT_TRUE(extension);
69 listener.Reply(extension->id());
70
71 ASSERT_TRUE(catcher.GetNextResult()) << message_;
72}
73
74IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
75 InternalAPIsNotOnChromeObject) {
[email protected]52eafbd2013-04-03 04:43:1976 ASSERT_TRUE(RunExtensionSubtest(
77 "bindings/internal_apis_not_on_chrome_object",
78 "page.html")) << message_;
79}
[email protected]adafe5b2013-08-09 10:35:0480
[email protected]fc034482013-08-09 20:25:1481// Tests that we don't override events when bindings are re-injected.
82// Regression test for http://crbug.com/269149.
rpaquay96bf3b7d2014-11-26 00:19:0883// Regression test for http://crbug.com/436593.
[email protected]fc034482013-08-09 20:25:1484IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, EventOverriding) {
85 ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_;
86}
87
[email protected]adafe5b2013-08-09 10:35:0488} // namespace
89} // namespace extensions