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

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2408133004: [DevTools] Implement Target.setDiscoverTargets method. (Closed)
Patch Set: rebased Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 web_contents->GetController().GetTransientEntry(); 1237 web_contents->GetController().GetTransientEntry();
1238 ASSERT_TRUE(transient_entry); 1238 ASSERT_TRUE(transient_entry);
1239 transient_entry->GetSSL().certificate = expired_cert(); 1239 transient_entry->GetSSL().certificate = expired_cert();
1240 ASSERT_TRUE(transient_entry->GetSSL().certificate); 1240 ASSERT_TRUE(transient_entry->GetSSL().certificate);
1241 1241
1242 std::unique_ptr<base::DictionaryValue> params2(new base::DictionaryValue()); 1242 std::unique_ptr<base::DictionaryValue> params2(new base::DictionaryValue());
1243 SendCommand("Security.showCertificateViewer", std::move(params2), true); 1243 SendCommand("Security.showCertificateViewer", std::move(params2), true);
1244 EXPECT_EQ(transient_entry->GetSSL().certificate, last_shown_certificate()); 1244 EXPECT_EQ(transient_entry->GetSSL().certificate, last_shown_certificate());
1245 } 1245 }
1246 1246
1247 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TargetDiscovery) {
1248 std::string temp;
1249 std::set<std::string> ids;
1250 std::unique_ptr<base::DictionaryValue> command_params;
1251 std::unique_ptr<base::DictionaryValue> params;
1252
1253 ASSERT_TRUE(embedded_test_server()->Start());
1254 GURL first_url = embedded_test_server()->GetURL("/devtools/navigation.html");
1255 NavigateToURLBlockUntilNavigationsComplete(shell(), first_url, 1);
1256
1257 GURL second_url = embedded_test_server()->GetURL("/devtools/navigation.html");
1258 Shell* second = CreateBrowser();
1259 NavigateToURLBlockUntilNavigationsComplete(second, second_url, 1);
1260
1261 Attach();
1262 command_params.reset(new base::DictionaryValue());
1263 command_params->SetBoolean("discover", true);
1264 SendCommand("Target.setDiscoverTargets", std::move(command_params), true);
1265 params = WaitForNotification("Target.targetCreated", true);
1266 EXPECT_TRUE(params->GetString("targetInfo.type", &temp));
1267 EXPECT_EQ("page", temp);
1268 EXPECT_TRUE(params->GetString("targetInfo.targetId", &temp));
1269 EXPECT_TRUE(ids.find(temp) == ids.end());
1270 ids.insert(temp);
1271 params = WaitForNotification("Target.targetCreated", true);
1272 EXPECT_TRUE(params->GetString("targetInfo.type", &temp));
1273 EXPECT_EQ("page", temp);
1274 EXPECT_TRUE(params->GetString("targetInfo.targetId", &temp));
1275 EXPECT_TRUE(ids.find(temp) == ids.end());
1276 ids.insert(temp);
1277 EXPECT_TRUE(notifications_.empty());
1278
1279 GURL third_url = embedded_test_server()->GetURL("/devtools/navigation.html");
1280 Shell* third = CreateBrowser();
1281 NavigateToURLBlockUntilNavigationsComplete(third, third_url, 1);
1282 params = WaitForNotification("Target.targetCreated", true);
1283 EXPECT_TRUE(params->GetString("targetInfo.type", &temp));
1284 EXPECT_EQ("page", temp);
1285 EXPECT_TRUE(params->GetString("targetInfo.targetId", &temp));
1286 EXPECT_TRUE(ids.find(temp) == ids.end());
1287 std::string attached_id = temp;
1288 ids.insert(temp);
1289 EXPECT_TRUE(notifications_.empty());
1290
1291 second->Close();
1292 second = nullptr;
1293 params = WaitForNotification("Target.targetDestroyed", true);
1294 EXPECT_TRUE(params->GetString("targetId", &temp));
1295 EXPECT_TRUE(ids.find(temp) != ids.end());
1296 ids.erase(temp);
1297 EXPECT_TRUE(notifications_.empty());
1298
1299 command_params.reset(new base::DictionaryValue());
1300 command_params->SetString("targetId", attached_id);
1301 SendCommand("Target.attachToTarget", std::move(command_params), true);
1302 params = WaitForNotification("Target.attachedToTarget", true);
1303 EXPECT_TRUE(params->GetString("targetInfo.targetId", &temp));
1304 EXPECT_EQ(attached_id, temp);
1305 EXPECT_TRUE(notifications_.empty());
1306
1307 command_params.reset(new base::DictionaryValue());
1308 command_params->SetBoolean("discover", false);
1309 SendCommand("Target.setDiscoverTargets", std::move(command_params), true);
1310 params = WaitForNotification("Target.targetDestroyed", true);
1311 EXPECT_TRUE(params->GetString("targetId", &temp));
1312 EXPECT_TRUE(ids.find(temp) != ids.end());
1313 ids.erase(temp);
1314 params = WaitForNotification("Target.targetDestroyed", true);
1315 EXPECT_TRUE(params->GetString("targetId", &temp));
1316 EXPECT_TRUE(ids.find(temp) != ids.end());
1317 ids.erase(temp);
1318 EXPECT_TRUE(notifications_.empty());
1319
1320 command_params.reset(new base::DictionaryValue());
1321 command_params->SetString("targetId", attached_id);
1322 SendCommand("Target.detachFromTarget", std::move(command_params), true);
1323 params = WaitForNotification("Target.detachedFromTarget", true);
1324 EXPECT_TRUE(params->GetString("targetId", &temp));
1325 EXPECT_EQ(attached_id, temp);
1326 EXPECT_TRUE(notifications_.empty());
1327 }
1328
1247 class SitePerProcessDevToolsProtocolTest : public DevToolsProtocolTest { 1329 class SitePerProcessDevToolsProtocolTest : public DevToolsProtocolTest {
1248 public: 1330 public:
1249 void SetUpCommandLine(base::CommandLine* command_line) override { 1331 void SetUpCommandLine(base::CommandLine* command_line) override {
1250 DevToolsProtocolTest::SetUpCommandLine(command_line); 1332 DevToolsProtocolTest::SetUpCommandLine(command_line);
1251 IsolateAllSitesForTesting(command_line); 1333 IsolateAllSitesForTesting(command_line);
1252 }; 1334 };
1253 1335
1254 void SetUpOnMainThread() override { 1336 void SetUpOnMainThread() override {
1255 DevToolsProtocolTest::SetUpOnMainThread(); 1337 DevToolsProtocolTest::SetUpOnMainThread();
1256 host_resolver()->AddRule("*", "127.0.0.1"); 1338 host_resolver()->AddRule("*", "127.0.0.1");
(...skipping 25 matching lines...) Expand all
1282 // Enable auto-attach. 1364 // Enable auto-attach.
1283 Attach(); 1365 Attach();
1284 command_params.reset(new base::DictionaryValue()); 1366 command_params.reset(new base::DictionaryValue());
1285 command_params->SetBoolean("autoAttach", true); 1367 command_params->SetBoolean("autoAttach", true);
1286 command_params->SetBoolean("waitForDebuggerOnStart", true); 1368 command_params->SetBoolean("waitForDebuggerOnStart", true);
1287 SendCommand("Target.setAutoAttach", std::move(command_params), true); 1369 SendCommand("Target.setAutoAttach", std::move(command_params), true);
1288 EXPECT_TRUE(notifications_.empty()); 1370 EXPECT_TRUE(notifications_.empty());
1289 command_params.reset(new base::DictionaryValue()); 1371 command_params.reset(new base::DictionaryValue());
1290 command_params->SetBoolean("value", true); 1372 command_params->SetBoolean("value", true);
1291 SendCommand("Target.setAttachToFrames", std::move(command_params), false); 1373 SendCommand("Target.setAttachToFrames", std::move(command_params), false);
1292 params = WaitForNotification("Target.targetCreated", true); 1374 params = WaitForNotification("Target.attachedToTarget", true);
1293 EXPECT_TRUE(params->GetString("targetInfo.targetId", &target_id)); 1375 EXPECT_TRUE(params->GetString("targetInfo.targetId", &target_id));
1294 EXPECT_TRUE(params->GetString("targetInfo.type", &temp)); 1376 EXPECT_TRUE(params->GetString("targetInfo.type", &temp));
1295 EXPECT_EQ("iframe", temp); 1377 EXPECT_EQ("iframe", temp);
1296 params = WaitForNotification("Target.attachedToTarget", true);
1297 EXPECT_TRUE(params->GetString("targetId", &temp));
1298 EXPECT_EQ(target_id, temp);
1299 1378
1300 // Load same-site page into iframe. 1379 // Load same-site page into iframe.
1301 FrameTreeNode* child = root->child_at(0); 1380 FrameTreeNode* child = root->child_at(0);
1302 GURL http_url(embedded_test_server()->GetURL("/title1.html")); 1381 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
1303 NavigateFrameToURL(child, http_url); 1382 NavigateFrameToURL(child, http_url);
1304 params = WaitForNotification("Target.detachedFromTarget", true); 1383 params = WaitForNotification("Target.detachedFromTarget", true);
1305 EXPECT_TRUE(params->GetString("targetId", &temp)); 1384 EXPECT_TRUE(params->GetString("targetId", &temp));
1306 EXPECT_EQ(target_id, temp); 1385 EXPECT_EQ(target_id, temp);
1307 params = WaitForNotification("Target.targetRemoved", true);
1308 EXPECT_TRUE(params->GetString("targetId", &temp));
1309 EXPECT_EQ(target_id, temp);
1310 1386
1311 // Navigate back to cross-site iframe. 1387 // Navigate back to cross-site iframe.
1312 NavigateFrameToURL(root->child_at(0), cross_site_url); 1388 NavigateFrameToURL(root->child_at(0), cross_site_url);
1313 params = WaitForNotification("Target.targetCreated", true); 1389 params = WaitForNotification("Target.attachedToTarget", true);
1314 EXPECT_TRUE(params->GetString("targetInfo.targetId", &target_id)); 1390 EXPECT_TRUE(params->GetString("targetInfo.targetId", &target_id));
1315 EXPECT_TRUE(params->GetString("targetInfo.type", &temp)); 1391 EXPECT_TRUE(params->GetString("targetInfo.type", &temp));
1316 EXPECT_EQ("iframe", temp); 1392 EXPECT_EQ("iframe", temp);
1317 params = WaitForNotification("Target.attachedToTarget", true);
1318 EXPECT_TRUE(params->GetString("targetId", &temp));
1319 EXPECT_EQ(target_id, temp);
1320 1393
1321 // Disable auto-attach. 1394 // Disable auto-attach.
1322 command_params.reset(new base::DictionaryValue()); 1395 command_params.reset(new base::DictionaryValue());
1323 command_params->SetBoolean("autoAttach", false); 1396 command_params->SetBoolean("autoAttach", false);
1324 command_params->SetBoolean("waitForDebuggerOnStart", false); 1397 command_params->SetBoolean("waitForDebuggerOnStart", false);
1325 SendCommand("Target.setAutoAttach", std::move(command_params), false); 1398 SendCommand("Target.setAutoAttach", std::move(command_params), false);
1326 params = WaitForNotification("Target.detachedFromTarget", true); 1399 params = WaitForNotification("Target.detachedFromTarget", true);
1327 EXPECT_TRUE(params->GetString("targetId", &temp)); 1400 EXPECT_TRUE(params->GetString("targetId", &temp));
1328 EXPECT_EQ(target_id, temp); 1401 EXPECT_EQ(target_id, temp);
1329 params = WaitForNotification("Target.targetRemoved", true);
1330 EXPECT_TRUE(params->GetString("targetId", &temp));
1331 EXPECT_EQ(target_id, temp);
1332 } 1402 }
1333 1403
1334 } // namespace content 1404 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/forwarding_agent_host.cc ('k') | content/browser/devtools/protocol/target_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698