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