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 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "net/dns/mock_host_resolver.h"
8 class ExecuteScriptApiTest
: public ExtensionApiTest
{
10 void SetupDelayedHostResolver() {
11 // We need a.com to be a little bit slow to trigger a race condition.
12 host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500);
13 host_resolver()->AddRule("b.com", "127.0.0.1");
14 host_resolver()->AddRule("c.com", "127.0.0.1");
18 // If failing, mark disabled and update http://crbug.com/92105.
19 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptBasic
) {
20 SetupDelayedHostResolver();
21 ASSERT_TRUE(StartEmbeddedTestServer());
22 ASSERT_TRUE(RunExtensionTest("executescript/basic")) << message_
;
25 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptBadEncoding
) {
26 SetupDelayedHostResolver();
27 ASSERT_TRUE(StartEmbeddedTestServer());
28 // data/extensions/api_test/../bad = data/extensions/bad
29 ASSERT_TRUE(RunExtensionTest("../bad")) << message_
;
32 // If failing, mark disabled and update http://crbug.com/92105.
33 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptInFrame
) {
34 SetupDelayedHostResolver();
35 ASSERT_TRUE(StartEmbeddedTestServer());
36 ASSERT_TRUE(RunExtensionTest("executescript/in_frame")) << message_
;
39 // Fails often on Windows.
40 // http://crbug.com/174715
42 #define MAYBE_ExecuteScriptPermissions DISABLED_ExecuteScriptPermissions
44 #define MAYBE_ExecuteScriptPermissions ExecuteScriptPermissions
45 #endif // defined(OS_WIN)
47 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, MAYBE_ExecuteScriptPermissions
) {
48 SetupDelayedHostResolver();
49 ASSERT_TRUE(StartEmbeddedTestServer());
50 ASSERT_TRUE(RunExtensionTest("executescript/permissions")) << message_
;
53 // If failing, mark disabled and update http://crbug.com/84760.
54 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptFileAfterClose
) {
55 host_resolver()->AddRule("b.com", "127.0.0.1");
56 ASSERT_TRUE(StartEmbeddedTestServer());
57 ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_
;
60 // If crashing, mark disabled and update http://crbug.com/67774.
61 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptFragmentNavigation
) {
62 ASSERT_TRUE(StartEmbeddedTestServer());
63 const char extension_name
[] = "executescript/fragment";
64 ASSERT_TRUE(RunExtensionTest(extension_name
)) << message_
;
67 // Fails often on Windows dbg bots. http://crbug.com/177163
69 #define MAYBE_NavigationRaceExecuteScript DISABLED_NavigationRaceExecuteScript
71 #define MAYBE_NavigationRaceExecuteScript NavigationRaceExecuteScript
72 #endif // defined(OS_WIN)
73 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
,
74 MAYBE_NavigationRaceExecuteScript
) {
75 host_resolver()->AddRule("a.com", "127.0.0.1");
76 host_resolver()->AddRule("b.com", "127.0.0.1");
77 ASSERT_TRUE(StartEmbeddedTestServer());
78 ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race",
79 "execute_script.html")) << message_
;
82 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, NavigationRaceJavaScriptURL
) {
83 host_resolver()->AddRule("a.com", "127.0.0.1");
84 host_resolver()->AddRule("b.com", "127.0.0.1");
85 ASSERT_TRUE(StartEmbeddedTestServer());
86 ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race",
87 "javascript_url.html")) << message_
;
90 // If failing, mark disabled and update http://crbug.com/92105.
91 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptFrameAfterLoad
) {
92 SetupDelayedHostResolver();
93 ASSERT_TRUE(StartEmbeddedTestServer());
94 ASSERT_TRUE(RunExtensionTest("executescript/frame_after_load")) << message_
;
97 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptRunAt
) {
98 SetupDelayedHostResolver();
99 ASSERT_TRUE(StartEmbeddedTestServer());
100 ASSERT_TRUE(RunExtensionTest("executescript/run_at")) << message_
;
103 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, ExecuteScriptCallback
) {
104 SetupDelayedHostResolver();
105 ASSERT_TRUE(StartEmbeddedTestServer());
106 ASSERT_TRUE(RunExtensionTest("executescript/callback")) << message_
;
109 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, UserGesture
) {
110 SetupDelayedHostResolver();
111 ASSERT_TRUE(StartEmbeddedTestServer());
112 ASSERT_TRUE(RunExtensionTest("executescript/user_gesture")) << message_
;
115 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest
, InjectIntoSubframesOnLoad
) {
116 SetupDelayedHostResolver();
117 ASSERT_TRUE(StartEmbeddedTestServer());
118 ASSERT_TRUE(RunExtensionTest("executescript/subframes_on_load")) << message_
;