Commit 6cbb9199 authored by phulce's avatar phulce Committed by Commit bot

[DevTools] Fix Cookie Sort

Adjust CookiesTable comparator to get the correct property for string comparisons.

BUG=671251

Review-Url: https://codereview.chromium.org/2550213002
Cr-Commit-Position: refs/heads/master@{#437605}
parent f4224baa
Tests inspector cookies table
params: name desc
cookieF,cookieE,cookieD,cookieC,cookieB,cookieA
params: value asc
cookieA,cookieB,cookieC,cookieF,cookieE,cookieD
params: path desc
cookieA,cookieE,cookieB,cookieD,cookieC,cookieF
params: domain asc
cookieB,cookieD,cookieC,cookieA,cookieF,cookieE
params: null asc
cookieA,cookieB,cookieC,cookieD,cookieE,cookieF
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script type="text/javascript">
var test = function () {
function dumpResults(cookies) {
InspectorTest.addResult(cookies.map(x => x.name()).join(','));
}
function createCookie(data) {
const cookie = new SDK.Cookie(null, data.name, data.value);
for (let key in data) {
if (key === 'name' || key === 'value')
continue;
cookie.addAttribute(key, data[key]);
}
return cookie;
}
function createSortAndDumpCookies(cookieData, column, isAsc) {
const table = new Components.CookiesTable(true);
const cookies = cookieData.map(createCookie);
table._dataGrid = {isSortOrderAscending: () => isAsc, sortColumnId: () => column};
table._sortCookies(cookies);
InspectorTest.addResult(`params: ${column} ${isAsc ? 'asc' : 'desc'}`);
dumpResults(cookies);
}
function run() {
const cookieData = [
{name: 'cookieA', value: '11', path: '/zzz', domain: 'example.com'},
{name: 'cookieB', value: '2', path: '/abc', domain: '.example.com'},
{name: 'cookieC', value: 'foo', path: '/', domain: 'abc.example.com'},
{name: 'cookieD', value: '{other}', path: '/aa', domain: '.other.com'},
{name: 'cookieE', value: 'zz', path: '/gg', domain: 'z.example.com'},
{name: 'cookieF', value: 'null', path: '/', domain: 'example.com'},
];
createSortAndDumpCookies(cookieData, 'name', false);
createSortAndDumpCookies(cookieData, 'value', true);
createSortAndDumpCookies(cookieData, 'path', false);
createSortAndDumpCookies(cookieData, 'domain', true);
createSortAndDumpCookies(cookieData, null, true);
InspectorTest.completeTest();
}
self.runtime.loadModulePromise('components_lazy').then(run);
};
</script>
</head>
<body onload="runTest()">
<p>Tests inspector cookies table</p>
</body>
</html>
......@@ -210,14 +210,22 @@ Components.CookiesTable = class extends UI.VBox {
_sortCookies(cookies) {
var sortDirection = this._dataGrid.isSortOrderAscending() ? 1 : -1;
/**
* @param {!SDK.Cookie} cookie
* @param {string} property
* @return {string}
*/
function getValue(cookie, property) {
return typeof cookie[property] === 'function' ? String(cookie[property]()) : String(cookie.name());
}
/**
* @param {string} property
* @param {!SDK.Cookie} cookie1
* @param {!SDK.Cookie} cookie2
*/
function compareTo(property, cookie1, cookie2) {
return sortDirection *
(String(cookie1[property] || cookie1['name'])).compareTo(String(cookie2[property] || cookie2['name']));
return sortDirection * getValue(cookie1, property).compareTo(getValue(cookie2, property));
}
/**
......
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