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

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

Issue 1642283002: Deal with frame removal by content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last nits Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 6 #include "build/build_config.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "net/dns/mock_host_resolver.h" 8 #include "net/dns/mock_host_resolver.h"
8 9
9 class ExecuteScriptApiTest : public ExtensionApiTest { 10 class ExecuteScriptApiTest : public ExtensionApiTest {
10 protected: 11 protected:
11 void SetupDelayedHostResolver() { 12 void SetupDelayedHostResolver() {
12 // We need a.com to be a little bit slow to trigger a race condition. 13 // We need a.com to be a little bit slow to trigger a race condition.
13 host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500); 14 host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500);
14 host_resolver()->AddRule("b.com", "127.0.0.1"); 15 host_resolver()->AddRule("b.com", "127.0.0.1");
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 SetupDelayedHostResolver(); 131 SetupDelayedHostResolver();
131 ASSERT_TRUE(StartEmbeddedTestServer()); 132 ASSERT_TRUE(StartEmbeddedTestServer());
132 ASSERT_TRUE(RunExtensionTest("executescript/subframes_on_load")) << message_; 133 ASSERT_TRUE(RunExtensionTest("executescript/subframes_on_load")) << message_;
133 } 134 }
134 135
135 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, RemovedFrames) { 136 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, RemovedFrames) {
136 SetupDelayedHostResolver(); 137 SetupDelayedHostResolver();
137 ASSERT_TRUE(StartEmbeddedTestServer()); 138 ASSERT_TRUE(StartEmbeddedTestServer());
138 ASSERT_TRUE(RunExtensionTest("executescript/removed_frames")) << message_; 139 ASSERT_TRUE(RunExtensionTest("executescript/removed_frames")) << message_;
139 } 140 }
141
142 // 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
144 // parts. Each part takes approximately the same time to run.
145 const int kDestructiveScriptTestBucketCount = 1;
146
147 class DestructiveScriptTest : public ExecuteScriptApiTest,
148 public testing::WithParamInterface<int> {
149 protected:
150 // The test extension selects the sub test based on the host name.
151 bool RunSubtest(const std::string& test_host) {
152 host_resolver()->AddRule(test_host, "127.0.0.1");
153 return RunExtensionSubtest(
154 "executescript/destructive",
155 "test.html?" + test_host +
156 "#bucketcount=" + base::IntToString(kDestructiveScriptTestBucketCount) +
157 "&bucketindex=" + base::IntToString(GetParam()));
158 }
159 };
160
161 // Removes the frame as soon as the content script is executed.
162 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, SynchronousRemoval) {
163 ASSERT_TRUE(StartEmbeddedTestServer());
164 ASSERT_TRUE(RunSubtest("synchronous")) << message_;
165 }
166
167 // Removes the frame at the frame's first scheduled microtask.
168 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MicrotaskRemoval) {
169 ASSERT_TRUE(StartEmbeddedTestServer());
170 ASSERT_TRUE(RunSubtest("microtask")) << message_;
171 }
172
173 // Removes the frame at the frame's first scheduled macrotask.
174 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MacrotaskRemoval) {
175 ASSERT_TRUE(StartEmbeddedTestServer());
176 ASSERT_TRUE(RunSubtest("macrotask")) << message_;
177 }
178
179 // Removes the frame at the first DOMNodeInserted event.
180 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted1) {
181 ASSERT_TRUE(StartEmbeddedTestServer());
182 ASSERT_TRUE(RunSubtest("domnodeinserted1")) << message_;
183 }
184
185 // Removes the frame at the second DOMNodeInserted event.
186 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted2) {
187 ASSERT_TRUE(StartEmbeddedTestServer());
188 ASSERT_TRUE(RunSubtest("domnodeinserted2")) << message_;
189 }
190
191 // Removes the frame at the third DOMNodeInserted event.
192 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted3) {
193 ASSERT_TRUE(StartEmbeddedTestServer());
194 ASSERT_TRUE(RunSubtest("domnodeinserted3")) << message_;
195 }
196
197 // Removes the frame at the first DOMSubtreeModified event.
198 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified1) {
199 ASSERT_TRUE(StartEmbeddedTestServer());
200 ASSERT_TRUE(RunSubtest("domsubtreemodified1")) << message_;
201 }
202
203 // Removes the frame at the second DOMSubtreeModified event.
204 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified2) {
205 ASSERT_TRUE(StartEmbeddedTestServer());
206 ASSERT_TRUE(RunSubtest("domsubtreemodified2")) << message_;
207 }
208
209 // Removes the frame at the third DOMSubtreeModified event.
210 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified3) {
211 ASSERT_TRUE(StartEmbeddedTestServer());
212 ASSERT_TRUE(RunSubtest("domsubtreemodified3")) << message_;
213 }
214
215 INSTANTIATE_TEST_CASE_P(ExecuteScriptApiTest,
216 DestructiveScriptTest,
217 ::testing::Range(0, kDestructiveScriptTestBucketCount));
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698