blob: fb5c114947e8ed0b41113bbec199ea74a10cd4bd [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/extensions/extension_host.h"
[email protected]be93bba02012-10-24 16:44:0310#include "chrome/browser/extensions/extension_system.h"
[email protected]adafe5b2013-08-09 10:35:0411#include "chrome/browser/extensions/extension_test_message_listener.h"
[email protected]fad73672012-06-15 23:26:0612#include "chrome/browser/ui/browser.h"
13#include "chrome/test/base/ui_test_utils.h"
[email protected]7d478cb2012-07-24 17:19:4214#include "content/public/test/browser_test_utils.h"
[email protected]98b6d942013-11-10 00:34:0715#include "extensions/browser/process_manager.h"
[email protected]fad73672012-06-15 23:26:0616
[email protected]adafe5b2013-08-09 10:35:0417namespace extensions {
18namespace {
19
20class ExtensionBindingsApiTest : public ExtensionApiTest {};
21
22IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
[email protected]7eef3942013-08-14 02:53:4923 UnavailableBindingsNeverRegistered) {
24 // Test will request the 'storage' permission.
25 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
26 ASSERT_TRUE(RunExtensionTest(
27 "bindings/unavailable_bindings_never_registered")) << message_;
28}
29
30IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
[email protected]adafe5b2013-08-09 10:35:0431 ExceptionInHandlerShouldNotCrash) {
[email protected]c80b8ee2011-12-03 04:26:5232 ASSERT_TRUE(RunExtensionSubtest(
33 "bindings/exception_in_handler_should_not_crash",
34 "page.html")) << message_;
35}
[email protected]fad73672012-06-15 23:26:0636
37// Tests that an error raised during an async function still fires
[email protected]754ea8b72013-01-08 15:10:3138// the callback, but sets chrome.runtime.lastError.
[email protected]fc034482013-08-09 20:25:1439// FIXME should be in ExtensionBindingsApiTest.
[email protected]fad73672012-06-15 23:26:0640IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) {
41 ASSERT_TRUE(LoadExtension(
42 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error")));
43
44 // Get the ExtensionHost that is hosting our background page.
[email protected]98b6d942013-11-10 00:34:0745 extensions::ProcessManager* manager =
[email protected]be93bba02012-10-24 16:44:0346 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
[email protected]3a1dc572012-07-31 22:25:1347 extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1);
[email protected]fad73672012-06-15 23:26:0648
49 bool result = false;
[email protected]b6987e02013-01-04 18:30:4350 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
51 host->render_view_host(), "testLastError()", &result));
[email protected]fad73672012-06-15 23:26:0652 EXPECT_TRUE(result);
53}
[email protected]52eafbd2013-04-03 04:43:1954
[email protected]adafe5b2013-08-09 10:35:0455// Regression test that we don't delete our own bindings with about:blank
56// iframes.
57IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) {
58 ResultCatcher catcher;
59 ExtensionTestMessageListener listener("load", true);
60
61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings")
62 .AppendASCII("about_blank_iframe")));
63
64 ASSERT_TRUE(listener.WaitUntilSatisfied());
65
66 const Extension* extension = LoadExtension(
67 test_data_dir_.AppendASCII("bindings")
68 .AppendASCII("internal_apis_not_on_chrome_object"));
69 ASSERT_TRUE(extension);
70 listener.Reply(extension->id());
71
72 ASSERT_TRUE(catcher.GetNextResult()) << message_;
73}
74
75IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
76 InternalAPIsNotOnChromeObject) {
[email protected]52eafbd2013-04-03 04:43:1977 ASSERT_TRUE(RunExtensionSubtest(
78 "bindings/internal_apis_not_on_chrome_object",
79 "page.html")) << message_;
80}
[email protected]adafe5b2013-08-09 10:35:0481
[email protected]fc034482013-08-09 20:25:1482// Tests that we don't override events when bindings are re-injected.
83// Regression test for http://crbug.com/269149.
84IN_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