Commit 092e6016 authored by Andrey Lushnikov's avatar Andrey Lushnikov Committed by Commit Bot

DevTools(Protocol): expose BrowserContextId in TargetInfo

This patch exposes BrowserContextId as a part of TargetInfo.
This helps to attribute pages to the browser contexts they
belong to.

BUG=836272
R=dgozman

Change-Id: I93d54756c98124a077bd979c207c0c7cd7e38971
Reviewed-on: https://chromium-review.googlesource.com/1026391Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553268}
parent 6560e0ed
......@@ -10,6 +10,7 @@
#include "content/browser/devtools/devtools_manager.h"
#include "content/browser/devtools/devtools_session.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/navigation_throttle.h"
......@@ -32,6 +33,8 @@ std::unique_ptr<Target::TargetInfo> CreateInfo(DevToolsAgentHost* host) {
.Build();
if (!host->GetOpenerId().empty())
target_info->SetOpenerId(host->GetOpenerId());
if (host->GetBrowserContext())
target_info->SetBrowserContextId(host->GetBrowserContext()->UniqueId());
return target_info;
}
......
Tests that targets created with window.open share the same browser context.
Opened a second window
SUCCESS: All 3 pages belong to the same browser context.
(async function(testRunner) {
const {page, session, dp} = await testRunner.startBlank(
`Tests that targets created with window.open share the same browser context.`);
await dp.Target.setDiscoverTargets({discover: true});
session.evaluate(`
window.myWindow = window.open('../resources/inspector-protocol-page.html'); undefined;
`);
testRunner.log('Opened a second window');
await dp.Target.onceTargetCreated();
const pageTargets = (await dp.Target.getTargets()).result.targetInfos.filter(target => target.type === 'page');
const browserContextId = pageTargets[0].browserContextId;
if (!browserContextId) {
testRunner.log('Found a page target without a browserContextId!');
testRunner.log(pageTargets);
testRunner.completeTest();
return;
}
for (const pageTarget of pageTargets) {
if (pageTarget.browserContextId !== browserContextId) {
testRunner.log('Targets have different browserContextIds!');
testRunner.log(pageTargets);
testRunner.completeTest();
return;
}
}
testRunner.log('SUCCESS: All ' + pageTargets.length + ' pages belong to the same browser context.');
testRunner.completeTest();
})
......@@ -5471,6 +5471,7 @@ domain Target
boolean attached
# Opener target Id
optional TargetID openerId
experimental optional BrowserContextID browserContextId
experimental type RemoteLocation extends object
properties
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment