Bug 1587907 - Move test content inside the BrowserTestUtils.withNewTab function callback r=gregtatum

In Bug 1587907 we got some contentPid not found errors. It seemed like we were
failing intermittently at getting content pid. After moving test content inside
the BrowserTestUtils.withNewTab callback, we won't get the same error anymore.
Also from my testing, it looks like it makes the test execution faster. We were
getting some intermittents before because of the timeouts, these will be fixed
if my testing is correct.

Differential Revision: https://phabricator.services.mozilla.com/D49951

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nazım Can Altınova 2019-10-21 16:43:31 +00:00
Родитель 78f01e1de1
Коммит 809db7ead1
2 изменённых файлов: 98 добавлений и 66 удалений

Просмотреть файл

@ -7,57 +7,73 @@ add_task(async function test_profile_multi_frame_page_info() {
return;
}
Assert.ok(!Services.profiler.IsActive());
// Clear all pages in case we have some pages registered before.
info("Clear the previous pages just in case we still some open tabs.");
await Services.profiler.ClearAllPages();
info(
"Start the profiler to test the page information with multi frame page."
);
startProfiler();
info("Open a tab with multi_frame.html in it.");
// multi_frame.html embeds single_frame.html inside an iframe.
const url = BASE_URL + "multi_frame.html";
let contentPid;
await BrowserTestUtils.withNewTab(url, async function(contentBrowser) {
contentPid = await ContentTask.spawn(contentBrowser, null, () => {
const contentPid = await ContentTask.spawn(contentBrowser, null, () => {
return Services.appinfo.processID;
});
info("Capture the profile data.");
const profile = await Services.profiler.getProfileDataAsync();
Services.profiler.StopProfiler();
let foundPage = 0;
// We need to find the correct content process for that tab.
let contentProcess = profile.processes.find(
p => p.threads[0].pid == contentPid
);
if (!contentProcess) {
throw new Error(
`Could not find the content process with given pid: ${contentPid}`
);
}
info(
"Check if the captured pages are the ones with correct values we created."
);
let parentPage;
for (const page of contentProcess.pages) {
// Parent page
if (page.url == url) {
Assert.equal(page.url, url);
Assert.equal(typeof page.browsingContextID, "number");
Assert.equal(typeof page.innerWindowID, "number");
// Top level document will have no embedder.
Assert.equal(page.embedderInnerWindowID, 0);
parentPage = page;
foundPage++;
break;
}
}
Assert.notEqual(typeof parentPage, "undefined");
for (const page of contentProcess.pages) {
// Child page (iframe)
if (page.url == BASE_URL + "single_frame.html") {
Assert.equal(page.url, BASE_URL + "single_frame.html");
Assert.equal(typeof page.browsingContextID, "number");
Assert.equal(typeof page.innerWindowID, "number");
Assert.equal(typeof page.embedderInnerWindowID, "number");
Assert.notEqual(typeof parentPage, "undefined");
Assert.equal(page.embedderInnerWindowID, parentPage.innerWindowID);
foundPage++;
break;
}
}
Assert.equal(foundPage, 2);
});
const profile = await Services.profiler.getProfileDataAsync();
Services.profiler.StopProfiler();
let foundPage = 0;
// We need to find the correct content process for that tab.
let contentProcess = profile.processes.find(
p => p.threads[0].pid == contentPid
);
let parentPage;
for (const page of contentProcess.pages) {
// Parent page
if (page.url == url) {
Assert.equal(page.url, url);
Assert.equal(typeof page.browsingContextID, "number");
Assert.equal(typeof page.innerWindowID, "number");
// Top level document will have no embedder.
Assert.equal(page.embedderInnerWindowID, 0);
parentPage = page;
foundPage++;
break;
}
}
Assert.notEqual(typeof parentPage, "undefined");
for (const page of contentProcess.pages) {
// Child page (iframe)
if (page.url == BASE_URL + "single_frame.html") {
Assert.equal(page.url, BASE_URL + "single_frame.html");
Assert.equal(typeof page.browsingContextID, "number");
Assert.equal(typeof page.innerWindowID, "number");
Assert.equal(typeof page.embedderInnerWindowID, "number");
Assert.notEqual(typeof parentPage, "undefined");
Assert.equal(page.embedderInnerWindowID, parentPage.innerWindowID);
foundPage++;
break;
}
}
Assert.equal(foundPage, 2);
});

Просмотреть файл

@ -7,36 +7,52 @@ add_task(async function test_profile_single_frame_page_info() {
return;
}
Assert.ok(!Services.profiler.IsActive());
// Clear all pages in case we have some pages registered before.
info("Clear the previous pages just in case we still some open tabs.");
await Services.profiler.ClearAllPages();
info(
"Start the profiler to test the page information with single frame page."
);
startProfiler();
info("Open a tab with single_frame.html in it.");
const url = BASE_URL + "single_frame.html";
let contentPid;
await BrowserTestUtils.withNewTab(url, async function(contentBrowser) {
contentPid = await ContentTask.spawn(contentBrowser, null, () => {
const contentPid = await ContentTask.spawn(contentBrowser, null, () => {
return Services.appinfo.processID;
});
});
const profile = await Services.profiler.getProfileDataAsync();
Services.profiler.StopProfiler();
info("Capture the profile data.");
const profile = await Services.profiler.getProfileDataAsync();
Services.profiler.StopProfiler();
let pageFound = false;
// We need to find the correct content process for that tab.
let contentProcess = profile.processes.find(
p => p.threads[0].pid == contentPid
);
for (const page of contentProcess.pages) {
if (page.url == url) {
Assert.equal(page.url, url);
Assert.equal(typeof page.browsingContextID, "number");
Assert.equal(typeof page.innerWindowID, "number");
// Top level document will have no embedder.
Assert.equal(page.embedderInnerWindowID, 0);
pageFound = true;
break;
let pageFound = false;
// We need to find the correct content process for that tab.
let contentProcess = profile.processes.find(
p => p.threads[0].pid == contentPid
);
if (!contentProcess) {
throw new Error(
`Could not find the content process with given pid: ${contentPid}`
);
}
}
Assert.equal(pageFound, true);
info(
"Check if the captured page is the one with correct values we created."
);
for (const page of contentProcess.pages) {
if (page.url == url) {
Assert.equal(page.url, url);
Assert.equal(typeof page.browsingContextID, "number");
Assert.equal(typeof page.innerWindowID, "number");
// Top level document will have no embedder.
Assert.equal(page.embedderInnerWindowID, 0);
pageFound = true;
break;
}
}
Assert.equal(pageFound, true);
});
});