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

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: Add more runScriptsAtDocumentElementAvailable + comments 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
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 const int kNumberOfDestructiveScriptTests = 12;
143
144 class DestructiveScriptTest : public ExecuteScriptApiTest,
145 public testing::WithParamInterface<int> {
146 protected:
147 // The test extension selects the sub test based on the host name.
148 bool RunSubtest(const std::string& test_host) {
149 host_resolver()->AddRule(test_host, "127.0.0.1");
150 return RunExtensionSubtest(
151 "executescript/destructive",
152 "test.html?" + test_host +
153 "#instance=" + base::IntToString(GetParam()) +
154 "&count=" + base::IntToString(kNumberOfDestructiveScriptTests));
155 }
156 };
157
158 // Removes the frame as soon as the content script is executed.
159 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, SynchronousRemoval) {
160 ASSERT_TRUE(StartEmbeddedTestServer());
161 ASSERT_TRUE(RunSubtest("synchronous")) << message_;
162 }
163
164 // Removes the frame at the frame's first scheduled microtask.
165 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MicrotaskRemoval) {
166 ASSERT_TRUE(StartEmbeddedTestServer());
167 ASSERT_TRUE(RunSubtest("microtask")) << message_;
168 }
169
170 // Removes the frame at the frame's first scheduled macrotask.
171 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, MacrotaskRemoval) {
172 ASSERT_TRUE(StartEmbeddedTestServer());
173 ASSERT_TRUE(RunSubtest("macrotask")) << message_;
174 }
175
176 // Removes the frame at the first DOMNodeInserted event.
177 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted1) {
178 ASSERT_TRUE(StartEmbeddedTestServer());
179 ASSERT_TRUE(RunSubtest("domnodeinserted1")) << message_;
180 }
181
182 // Removes the frame at the second DOMNodeInserted event.
183 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted2) {
184 ASSERT_TRUE(StartEmbeddedTestServer());
185 ASSERT_TRUE(RunSubtest("domnodeinserted2")) << message_;
186 }
187
188 // Removes the frame at the third DOMNodeInserted event.
189 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMNodeInserted3) {
190 ASSERT_TRUE(StartEmbeddedTestServer());
191 ASSERT_TRUE(RunSubtest("domnodeinserted3")) << message_;
192 }
193
194 // Removes the frame at the first DOMSubtreeModified event.
195 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified1) {
196 ASSERT_TRUE(StartEmbeddedTestServer());
197 ASSERT_TRUE(RunSubtest("domsubtreemodified1")) << message_;
198 }
199
200 // Removes the frame at the second DOMSubtreeModified event.
201 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified2) {
202 ASSERT_TRUE(StartEmbeddedTestServer());
203 ASSERT_TRUE(RunSubtest("domsubtreemodified2")) << message_;
204 }
205
206 // Removes the frame at the third DOMSubtreeModified event.
207 IN_PROC_BROWSER_TEST_P(DestructiveScriptTest, DOMSubtreeModified3) {
208 ASSERT_TRUE(StartEmbeddedTestServer());
209 ASSERT_TRUE(RunSubtest("domsubtreemodified3")) << message_;
210 }
211
212 INSTANTIATE_TEST_CASE_P(ExecuteScriptApiTest, DestructiveScriptTest,
213 ::testing::Range(0, kNumberOfDestructiveScriptTests));
Devlin 2016/03/15 00:53:31 This effectively adds 108 more browser tests. Tha
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698