blob: 5f1bb82c7dab869d52020d0225f58c97cbdbb39a [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"
10#include "chrome/test/base/ui_test_utils.h"
[email protected]7d478cb2012-07-24 17:19:4211#include "content/public/test/browser_test_utils.h"
[email protected]22401dc2014-03-21 01:38:5712#include "extensions/browser/extension_host.h"
[email protected]59b0e602014-01-30 00:41:2413#include "extensions/browser/extension_system.h"
[email protected]98b6d942013-11-10 00:34:0714#include "extensions/browser/process_manager.h"
lfg910f2f92014-09-19 05:31:0915#include "extensions/test/extension_test_message_listener.h"
yoze8dc2f12014-09-09 23:16:3216#include "extensions/test/result_catcher.h"
[email protected]fad73672012-06-15 23:26:0617
[email protected]adafe5b2013-08-09 10:35:0418namespace extensions {
19namespace {
20
21class ExtensionBindingsApiTest : public ExtensionApiTest {};
22
23IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
[email protected]7eef3942013-08-14 02:53:4924 UnavailableBindingsNeverRegistered) {
25 // Test will request the 'storage' permission.
26 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
27 ASSERT_TRUE(RunExtensionTest(
28 "bindings/unavailable_bindings_never_registered")) << message_;
29}
30
31IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
[email protected]adafe5b2013-08-09 10:35:0432 ExceptionInHandlerShouldNotCrash) {
[email protected]c80b8ee2011-12-03 04:26:5233 ASSERT_TRUE(RunExtensionSubtest(
34 "bindings/exception_in_handler_should_not_crash",
35 "page.html")) << message_;
36}
[email protected]fad73672012-06-15 23:26:0637
38// Tests that an error raised during an async function still fires
[email protected]754ea8b72013-01-08 15:10:3139// the callback, but sets chrome.runtime.lastError.
[email protected]fc034482013-08-09 20:25:1440// FIXME should be in ExtensionBindingsApiTest.
[email protected]fad73672012-06-15 23:26:0641IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) {
42 ASSERT_TRUE(LoadExtension(
43 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error")));
44
45 // Get the ExtensionHost that is hosting our background page.
[email protected]98b6d942013-11-10 00:34:0746 extensions::ProcessManager* manager =
[email protected]be93bba02012-10-24 16:44:0347 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
[email protected]3a1dc572012-07-31 22:25:1348 extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1);
[email protected]fad73672012-06-15 23:26:0649
50 bool result = false;
[email protected]b6987e02013-01-04 18:30:4351 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
52 host->render_view_host(), "testLastError()", &result));
[email protected]fad73672012-06-15 23:26:0653 EXPECT_TRUE(result);
54}
[email protected]52eafbd2013-04-03 04:43:1955
[email protected]adafe5b2013-08-09 10:35:0456// Regression test that we don't delete our own bindings with about:blank
57// iframes.
58IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) {
59 ResultCatcher catcher;
60 ExtensionTestMessageListener listener("load", true);
61
62 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings")
63 .AppendASCII("about_blank_iframe")));
64
65 ASSERT_TRUE(listener.WaitUntilSatisfied());
66
67 const Extension* extension = LoadExtension(
68 test_data_dir_.AppendASCII("bindings")
69 .AppendASCII("internal_apis_not_on_chrome_object"));
70 ASSERT_TRUE(extension);
71 listener.Reply(extension->id());
72
73 ASSERT_TRUE(catcher.GetNextResult()) << message_;
74}
75
76IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
77 InternalAPIsNotOnChromeObject) {
[email protected]52eafbd2013-04-03 04:43:1978 ASSERT_TRUE(RunExtensionSubtest(
79 "bindings/internal_apis_not_on_chrome_object",
80 "page.html")) << message_;
81}
[email protected]adafe5b2013-08-09 10:35:0482
[email protected]fc034482013-08-09 20:25:1483// Tests that we don't override events when bindings are re-injected.
84// Regression test for http://crbug.com/269149.
85IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, EventOverriding) {
86 ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_;
87}
88
[email protected]adafe5b2013-08-09 10:35:0489} // namespace
90} // namespace extensions