Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: chrome/browser/extensions/execute_script_apitest.cc

Issue 2847313002: Update some host_resolver()->AddRules in chrome/browser. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/string_number_conversions.h" 5 #include "base/strings/string_number_conversions.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "net/dns/mock_host_resolver.h" 8 #include "net/dns/mock_host_resolver.h"
9 9
10 class ExecuteScriptApiTest : public ExtensionApiTest { 10 class ExecuteScriptApiTest : public ExtensionApiTest {
11 protected: 11 protected:
12 void SetupDelayedHostResolver() { 12 void SetUpOnMainThread() override {
13 ExtensionApiTest::SetUpOnMainThread();
13 // We need a.com to be a little bit slow to trigger a race condition. 14 // We need a.com to be a little bit slow to trigger a race condition.
14 host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500); 15 host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500);
15 host_resolver()->AddRule("b.com", "127.0.0.1"); 16 host_resolver()->AddRule("*", "127.0.0.1");
16 host_resolver()->AddRule("c.com", "127.0.0.1"); 17 ASSERT_TRUE(StartEmbeddedTestServer());
17 } 18 }
18 }; 19 };
19 20
20 // If failing, mark disabled and update http://crbug.com/92105. 21 // If failing, mark disabled and update http://crbug.com/92105.
21 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptBasic) { 22 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptBasic) {
22 SetupDelayedHostResolver();
23 ASSERT_TRUE(StartEmbeddedTestServer());
24 ASSERT_TRUE(RunExtensionTest("executescript/basic")) << message_; 23 ASSERT_TRUE(RunExtensionTest("executescript/basic")) << message_;
25 } 24 }
26 25
27 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptBadEncoding) { 26 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptBadEncoding) {
28 SetupDelayedHostResolver();
29 ASSERT_TRUE(StartEmbeddedTestServer());
30 // data/extensions/api_test/../bad = data/extensions/bad 27 // data/extensions/api_test/../bad = data/extensions/bad
31 ASSERT_TRUE(RunExtensionTest("../bad")) << message_; 28 ASSERT_TRUE(RunExtensionTest("../bad")) << message_;
32 } 29 }
33 30
34 // If failing, mark disabled and update http://crbug.com/92105. 31 // If failing, mark disabled and update http://crbug.com/92105.
35 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptInFrame) { 32 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptInFrame) {
36 SetupDelayedHostResolver();
37 ASSERT_TRUE(StartEmbeddedTestServer());
38 ASSERT_TRUE(RunExtensionTest("executescript/in_frame")) << message_; 33 ASSERT_TRUE(RunExtensionTest("executescript/in_frame")) << message_;
39 } 34 }
40 35
41 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptByFrameId) { 36 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptByFrameId) {
42 SetupDelayedHostResolver();
43 ASSERT_TRUE(StartEmbeddedTestServer());
44 ASSERT_TRUE(RunExtensionTest("executescript/frame_id")) << message_; 37 ASSERT_TRUE(RunExtensionTest("executescript/frame_id")) << message_;
45 } 38 }
46 39
47 // Fails often on Windows. 40 // Fails often on Windows.
48 // http://crbug.com/174715 41 // http://crbug.com/174715
49 #if defined(OS_WIN) 42 #if defined(OS_WIN)
50 #define MAYBE_ExecuteScriptPermissions DISABLED_ExecuteScriptPermissions 43 #define MAYBE_ExecuteScriptPermissions DISABLED_ExecuteScriptPermissions
51 #else 44 #else
52 #define MAYBE_ExecuteScriptPermissions ExecuteScriptPermissions 45 #define MAYBE_ExecuteScriptPermissions ExecuteScriptPermissions
53 #endif // defined(OS_WIN) 46 #endif // defined(OS_WIN)
54 47
55 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, MAYBE_ExecuteScriptPermissions) { 48 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, MAYBE_ExecuteScriptPermissions) {
56 SetupDelayedHostResolver();
57 ASSERT_TRUE(StartEmbeddedTestServer());
58 ASSERT_TRUE(RunExtensionTest("executescript/permissions")) << message_; 49 ASSERT_TRUE(RunExtensionTest("executescript/permissions")) << message_;
59 } 50 }
60 51
61 // If failing, mark disabled and update http://crbug.com/84760. 52 // If failing, mark disabled and update http://crbug.com/84760.
62 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFileAfterClose) { 53 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFileAfterClose) {
63 host_resolver()->AddRule("b.com", "127.0.0.1");
64 ASSERT_TRUE(StartEmbeddedTestServer());
65 ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_; 54 ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_;
66 } 55 }
67 56
68 // If crashing, mark disabled and update http://crbug.com/67774. 57 // If crashing, mark disabled and update http://crbug.com/67774.
69 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFragmentNavigation) { 58 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFragmentNavigation) {
70 ASSERT_TRUE(StartEmbeddedTestServer());
71 const char extension_name[] = "executescript/fragment"; 59 const char extension_name[] = "executescript/fragment";
72 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; 60 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
73 } 61 }
74 62
75 // Fails often on Windows dbg bots. http://crbug.com/177163 63 // Fails often on Windows dbg bots. http://crbug.com/177163
76 #if defined(OS_WIN) 64 #if defined(OS_WIN)
77 #define MAYBE_NavigationRaceExecuteScript DISABLED_NavigationRaceExecuteScript 65 #define MAYBE_NavigationRaceExecuteScript DISABLED_NavigationRaceExecuteScript
78 #else 66 #else
79 #define MAYBE_NavigationRaceExecuteScript NavigationRaceExecuteScript 67 #define MAYBE_NavigationRaceExecuteScript NavigationRaceExecuteScript
80 #endif // defined(OS_WIN) 68 #endif // defined(OS_WIN)
81 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, 69 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,
82 MAYBE_NavigationRaceExecuteScript) { 70 MAYBE_NavigationRaceExecuteScript) {
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", 71 ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race",
87 "execute_script.html")) << message_; 72 "execute_script.html")) << message_;
88 } 73 }
89 74
90 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, NavigationRaceJavaScriptURL) { 75 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, NavigationRaceJavaScriptURL) {
91 host_resolver()->AddRule("a.com", "127.0.0.1");
92 host_resolver()->AddRule("b.com", "127.0.0.1");
93 ASSERT_TRUE(StartEmbeddedTestServer());
94 ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race", 76 ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race",
95 "javascript_url.html")) << message_; 77 "javascript_url.html")) << message_;
96 } 78 }
97 79
98 // If failing, mark disabled and update http://crbug.com/92105. 80 // If failing, mark disabled and update http://crbug.com/92105.
99 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFrameAfterLoad) { 81 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFrameAfterLoad) {
100 SetupDelayedHostResolver();
101 ASSERT_TRUE(StartEmbeddedTestServer());
102 ASSERT_TRUE(RunExtensionTest("executescript/frame_after_load")) << message_; 82 ASSERT_TRUE(RunExtensionTest("executescript/frame_after_load")) << message_;
103 } 83 }
104 84
105 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, FrameWithHttp204) { 85 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, FrameWithHttp204) {
106 host_resolver()->AddRule("b.com", "127.0.0.1");
107 host_resolver()->AddRule("c.com", "127.0.0.1");
108 ASSERT_TRUE(StartEmbeddedTestServer());
109 ASSERT_TRUE(RunExtensionTest("executescript/http204")) << message_; 86 ASSERT_TRUE(RunExtensionTest("executescript/http204")) << message_;
110 } 87 }
111 88
112 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptRunAt) { 89 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptRunAt) {
113 SetupDelayedHostResolver();
114 ASSERT_TRUE(StartEmbeddedTestServer());
115 ASSERT_TRUE(RunExtensionTest("executescript/run_at")) << message_; 90 ASSERT_TRUE(RunExtensionTest("executescript/run_at")) << message_;
116 } 91 }
117 92
118 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptCallback) { 93 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptCallback) {
119 SetupDelayedHostResolver();
120 ASSERT_TRUE(StartEmbeddedTestServer());
121 ASSERT_TRUE(RunExtensionTest("executescript/callback")) << message_; 94 ASSERT_TRUE(RunExtensionTest("executescript/callback")) << message_;
122 } 95 }
123 96
124 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, UserGesture) { 97 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, UserGesture) {
125 SetupDelayedHostResolver();
126 ASSERT_TRUE(StartEmbeddedTestServer());
127 ASSERT_TRUE(RunExtensionTest("executescript/user_gesture")) << message_; 98 ASSERT_TRUE(RunExtensionTest("executescript/user_gesture")) << message_;
128 } 99 }
129 100
130 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, InjectIntoSubframesOnLoad) { 101 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, InjectIntoSubframesOnLoad) {
131 SetupDelayedHostResolver();
132 ASSERT_TRUE(StartEmbeddedTestServer());
133 ASSERT_TRUE(RunExtensionTest("executescript/subframes_on_load")) << message_; 102 ASSERT_TRUE(RunExtensionTest("executescript/subframes_on_load")) << message_;
134 } 103 }
135 104
136 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, RemovedFrames) { 105 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, RemovedFrames) {
137 SetupDelayedHostResolver();
138 ASSERT_TRUE(StartEmbeddedTestServer());
139 ASSERT_TRUE(RunExtensionTest("executescript/removed_frames")) << message_; 106 ASSERT_TRUE(RunExtensionTest("executescript/removed_frames")) << message_;
140 } 107 }
141 108
142 // If tests time out because it takes too long to run them, then this value can 109 // If tests time out because it takes too long to run them, then this value can
143 // be increased to split the DestructiveScriptTest tests in approximately equal 110 // be increased to split the DestructiveScriptTest tests in approximately equal
144 // parts. Each part takes approximately the same time to run. 111 // parts. Each part takes approximately the same time to run.
145 const int kDestructiveScriptTestBucketCount = 1; 112 const int kDestructiveScriptTestBucketCount = 1;
146 113
147 class DestructiveScriptTest : public ExecuteScriptApiTest, 114 class DestructiveScriptTest : public ExecuteScriptApiTest,
148 public testing::WithParamInterface<int> { 115 public testing::WithParamInterface<int> {
149 protected: 116 protected:
150 // The test extension selects the sub test based on the host name. 117 // The test extension selects the sub test based on the host name.
151 bool RunSubtest(const std::string& test_host) { 118 bool RunSubtest(const std::string& test_host) {
152 host_resolver()->AddRule(test_host, "127.0.0.1");
153 return RunExtensionSubtest( 119 return RunExtensionSubtest(
154 "executescript/destructive", 120 "executescript/destructive",
155 "test.html?" + test_host + 121 "test.html?" + test_host +
156 "#bucketcount=" + base::IntToString(kDestructiveScriptTestBucketCount) + 122 "#bucketcount=" + base::IntToString(kDestructiveScriptTestBucketCount) +
157 "&bucketindex=" + base::IntToString(GetParam())); 123 "&bucketindex=" + base::IntToString(GetParam()));
158 } 124 }
159 }; 125 };
160 126
161 // Removes the frame as soon as the content script is executed. 127 // Removes the frame as soon as the content script is executed.
162 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, SynchronousRemoval) { 128 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, SynchronousRemoval) {
163 ASSERT_TRUE(StartEmbeddedTestServer());
164 ASSERT_TRUE(RunSubtest("synchronous")) << message_; 129 ASSERT_TRUE(RunSubtest("synchronous")) << message_;
165 } 130 }
166 131
167 // Removes the frame at the frame's first scheduled microtask. 132 // Removes the frame at the frame's first scheduled microtask.
168 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MicrotaskRemoval) { 133 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MicrotaskRemoval) {
169 ASSERT_TRUE(StartEmbeddedTestServer());
170 ASSERT_TRUE(RunSubtest("microtask")) << message_; 134 ASSERT_TRUE(RunSubtest("microtask")) << message_;
171 } 135 }
172 136
173 // Removes the frame at the frame's first scheduled macrotask. 137 // Removes the frame at the frame's first scheduled macrotask.
174 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MacrotaskRemoval) { 138 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MacrotaskRemoval) {
175 ASSERT_TRUE(StartEmbeddedTestServer());
176 ASSERT_TRUE(RunSubtest("macrotask")) << message_; 139 ASSERT_TRUE(RunSubtest("macrotask")) << message_;
177 } 140 }
178 141
179 // Removes the frame at the first DOMNodeInserted event. 142 // Removes the frame at the first DOMNodeInserted event.
180 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted1) { 143 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted1) {
181 ASSERT_TRUE(StartEmbeddedTestServer());
182 ASSERT_TRUE(RunSubtest("domnodeinserted1")) << message_; 144 ASSERT_TRUE(RunSubtest("domnodeinserted1")) << message_;
183 } 145 }
184 146
185 // Removes the frame at the second DOMNodeInserted event. 147 // Removes the frame at the second DOMNodeInserted event.
186 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted2) { 148 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted2) {
187 ASSERT_TRUE(StartEmbeddedTestServer());
188 ASSERT_TRUE(RunSubtest("domnodeinserted2")) << message_; 149 ASSERT_TRUE(RunSubtest("domnodeinserted2")) << message_;
189 } 150 }
190 151
191 // Removes the frame at the third DOMNodeInserted event. 152 // Removes the frame at the third DOMNodeInserted event.
192 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted3) { 153 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted3) {
193 ASSERT_TRUE(StartEmbeddedTestServer());
194 ASSERT_TRUE(RunSubtest("domnodeinserted3")) << message_; 154 ASSERT_TRUE(RunSubtest("domnodeinserted3")) << message_;
195 } 155 }
196 156
197 // Removes the frame at the first DOMSubtreeModified event. 157 // Removes the frame at the first DOMSubtreeModified event.
198 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified1) { 158 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified1) {
199 ASSERT_TRUE(StartEmbeddedTestServer());
200 ASSERT_TRUE(RunSubtest("domsubtreemodified1")) << message_; 159 ASSERT_TRUE(RunSubtest("domsubtreemodified1")) << message_;
201 } 160 }
202 161
203 // Removes the frame at the second DOMSubtreeModified event. 162 // Removes the frame at the second DOMSubtreeModified event.
204 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified2) { 163 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified2) {
205 ASSERT_TRUE(StartEmbeddedTestServer());
206 ASSERT_TRUE(RunSubtest("domsubtreemodified2")) << message_; 164 ASSERT_TRUE(RunSubtest("domsubtreemodified2")) << message_;
207 } 165 }
208 166
209 // Removes the frame at the third DOMSubtreeModified event. 167 // Removes the frame at the third DOMSubtreeModified event.
210 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified3) { 168 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified3) {
211 ASSERT_TRUE(StartEmbeddedTestServer());
212 ASSERT_TRUE(RunSubtest("domsubtreemodified3")) << message_; 169 ASSERT_TRUE(RunSubtest("domsubtreemodified3")) << message_;
213 } 170 }
214 171
215 INSTANTIATE_TEST_CASE_P(ExecuteScriptApiTest, 172 INSTANTIATE_TEST_CASE_P(ExecuteScriptApiTest,
216 DestructiveScriptTest, 173 DestructiveScriptTest,
217 ::testing::Range(0, kDestructiveScriptTestBucketCount)); 174 ::testing::Range(0, kDestructiveScriptTestBucketCount));
OLDNEW
« no previous file with comments | « chrome/browser/extensions/cross_origin_xhr_apitest.cc ('k') | chrome/browser/extensions/extension_dom_clipboard_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698