NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_bindings_apitest.cc
blob38512e951b55b986039a496cb3d8a1f638b3db37
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Contains holistic tests of the bindings infrastructure
7 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "extensions/browser/extension_system.h"
15 #include "extensions/browser/process_manager.h"
17 namespace extensions {
18 namespace {
20 class ExtensionBindingsApiTest : public ExtensionApiTest {};
22 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
23 UnavailableBindingsNeverRegistered) {
24 // Test will request the 'storage' permission.
25 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
26 ASSERT_TRUE(RunExtensionTest(
27 "bindings/unavailable_bindings_never_registered")) << message_;
30 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
31 ExceptionInHandlerShouldNotCrash) {
32 ASSERT_TRUE(RunExtensionSubtest(
33 "bindings/exception_in_handler_should_not_crash",
34 "page.html")) << message_;
37 // Tests that an error raised during an async function still fires
38 // the callback, but sets chrome.runtime.lastError.
39 // FIXME should be in ExtensionBindingsApiTest.
40 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) {
41 ASSERT_TRUE(LoadExtension(
42 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error")));
44 // Get the ExtensionHost that is hosting our background page.
45 extensions::ProcessManager* manager =
46 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
47 extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1);
49 bool result = false;
50 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
51 host->render_view_host(), "testLastError()", &result));
52 EXPECT_TRUE(result);
55 // Regression test that we don't delete our own bindings with about:blank
56 // iframes.
57 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) {
58 ResultCatcher catcher;
59 ExtensionTestMessageListener listener("load", true);
61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings")
62 .AppendASCII("about_blank_iframe")));
64 ASSERT_TRUE(listener.WaitUntilSatisfied());
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());
72 ASSERT_TRUE(catcher.GetNextResult()) << message_;
75 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
76 InternalAPIsNotOnChromeObject) {
77 ASSERT_TRUE(RunExtensionSubtest(
78 "bindings/internal_apis_not_on_chrome_object",
79 "page.html")) << message_;
82 // Tests that we don't override events when bindings are re-injected.
83 // Regression test for http://crbug.com/269149.
84 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, EventOverriding) {
85 ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_;
88 } // namespace
89 } // namespace extensions