Bug 1584243: Wait until the link has the visited state. r=pbro

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daisuke Akatsuka 2019-10-15 07:43:33 +00:00
Родитель 8aa1c9d942
Коммит 1eb378edbd
4 изменённых файлов: 57 добавлений и 46 удалений

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

@ -5,33 +5,19 @@
// Test css properties that are inactive in :visited rule.
const VISISTED_URI = URL_ROOT + "doc_variables_1.html";
const TEST_URI = `
<style type='text/css'>
a:visited, #visited-and-other-matched-selector {
background-color: transparent;
border-color: lime;
color: rgba(0, 255, 0, 0.8);
font-size: 100px;
margin-left: 50px;
}
</style>
<a href="${VISISTED_URI}" id="visited-only">link1</a>
<a href="${VISISTED_URI}" id="visited-and-other-matched-selector">link2</a>
`;
const TEST_URI = URL_ROOT + "doc_visited.html";
const TEST_DATA = [
{
selector: "#visited-only",
selector: "#visited",
inactiveDeclarations: [
{
declaration: { "font-size": "100px" },
ruleIndex: 1,
ruleIndex: 2,
},
{
declaration: { "margin-left": "50px" },
ruleIndex: 1,
ruleIndex: 2,
},
],
activeDeclarations: [
@ -41,7 +27,7 @@ const TEST_DATA = [
"border-color": "lime",
color: "rgba(0, 255, 0, 0.8)",
},
ruleIndex: 1,
ruleIndex: 2,
},
],
},
@ -63,16 +49,12 @@ const TEST_DATA = [
];
add_task(async () => {
info("Open a particular url to make a visited link");
const tab = await addTab(VISISTED_URI);
info("Open a url which has visited links");
const tab = await addTab(TEST_URI);
info("Open tested page in the same tab");
tab.linkedBrowser.loadURI(
"data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI),
{
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
}
);
info("Wait until the visited links are available");
const selectors = TEST_DATA.map(t => t.selector);
await waitUntilVisitedState(tab, selectors);
info("Open the inspector");
const { inspector, view } = await openRuleView();

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

@ -12,24 +12,7 @@ add_task(async () => {
const tab = await addTab(TEST_URI);
info("Wait until the visited link is available");
await asyncWaitUntil(async () => {
const isVisitedLinkAvailable = await ContentTask.spawn(
tab.linkedBrowser,
{},
() => {
const NS_EVENT_STATE_VISITED = 1 << 24;
const target = content.wrappedJSObject.document.getElementById(
"visited"
);
return (
target &&
InspectorUtils.getContentState(target) & NS_EVENT_STATE_VISITED
);
}
);
return isVisitedLinkAvailable;
});
await waitUntilVisitedState(tab, ["#visited"]);
info("Open the inspector");
const { inspector, view } = await openRuleView();

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

@ -3,6 +3,13 @@
<head>
<meta charset="UTF-8">
<style type='text/css'>
a:visited, #visited-and-other-matched-selector {
background-color: transparent;
border-color: lime;
color: rgba(0, 255, 0, 0.8);
font-size: 100px;
margin-left: 50px;
}
a:visited { color: lime; }
a:link { color: blue; }
a { color: pink; }
@ -11,5 +18,8 @@
<body>
<a href="./doc_visited.html" id="visited">visited link</a>
<a href="#" id="unvisited">unvisited link</a>
<a href="./doc_visited.html" id="visited-and-other-matched-selector">
visited and other matched selector
</a>
</body>
</html>

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

@ -715,3 +715,39 @@ function openContextMenuAndGetAllItems(inspector, options) {
const menu = inspector.markup.contextMenu._openMenu(options);
return buildContextMenuItems(menu);
}
/**
* Wait until the elements the given selectors indicate come to have the visited state.
*
* @param {Tab} tab
* The tab where the elements on.
* @param {Array} selectors
* The selectors for the elements.
*/
async function waitUntilVisitedState(tab, selectors) {
await asyncWaitUntil(async () => {
const hasVisitedState = await ContentTask.spawn(
tab.linkedBrowser,
selectors,
args => {
const NS_EVENT_STATE_VISITED = 1 << 24;
for (const selector of args) {
const target = content.wrappedJSObject.document.querySelector(
selector
);
if (
!(
target &&
InspectorUtils.getContentState(target) & NS_EVENT_STATE_VISITED
)
) {
return false;
}
}
return true;
}
);
return hasVisitedState;
});
}