diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-03-03 19:42:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-03 19:42:25 +0100 |
commit | d252c5b2320859c58900b68a7f5ac82199aa1e83 (patch) | |
tree | bee56152ced9b7485267debb8d50fca952d9c447 /devtools/server/tests/browser | |
parent | c3039dadd95f5487e84311a9719604fa901aacd7 (diff) | |
parent | 8114b67b64e17482e46c2eaa77dd6a6156130dba (diff) | |
download | UXP-d252c5b2320859c58900b68a7f5ac82199aa1e83.tar UXP-d252c5b2320859c58900b68a7f5ac82199aa1e83.tar.gz UXP-d252c5b2320859c58900b68a7f5ac82199aa1e83.tar.lz UXP-d252c5b2320859c58900b68a7f5ac82199aa1e83.tar.xz UXP-d252c5b2320859c58900b68a7f5ac82199aa1e83.zip |
Merge pull request #36 from janekptacijarabaci/devtools_import-from-moebius_2
Port across devtools enhancements - 2
Diffstat (limited to 'devtools/server/tests/browser')
7 files changed, 220 insertions, 93 deletions
diff --git a/devtools/server/tests/browser/browser.ini b/devtools/server/tests/browser/browser.ini index c05933230..b7929e2b0 100644 --- a/devtools/server/tests/browser/browser.ini +++ b/devtools/server/tests/browser/browser.ini @@ -11,6 +11,7 @@ support-files = doc_perf.html navigate-first.html navigate-second.html + storage-cookies-same-name.html storage-dynamic-windows.html storage-listings.html storage-unsecured-iframe.html @@ -80,6 +81,7 @@ skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still di #[browser_perf-front-profiler-01.js] bug 1077464 #[browser_perf-front-profiler-05.js] bug 1077464 #[browser_perf-front-profiler-06.js] +[browser_storage_cookies-duplicate-names.js] [browser_storage_dynamic_windows.js] [browser_storage_listings.js] [browser_storage_updates.js] diff --git a/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js b/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js new file mode 100644 index 000000000..c1cf0aa72 --- /dev/null +++ b/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js @@ -0,0 +1,105 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that the storage panel is able to display multiple cookies with the same +// name (and different paths). + +const {StorageFront} = require("devtools/shared/fronts/storage"); +Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/server/tests/browser/storage-helpers.js", this); + +const TESTDATA = { + "test1.example.org": [ + { + name: "name", + value: "value1", + expires: 0, + path: "/", + host: "test1.example.org", + isDomain: false, + isSecure: false, + }, + { + name: "name", + value: "value2", + expires: 0, + path: "/path2/", + host: "test1.example.org", + isDomain: false, + isSecure: false, + }, + { + name: "name", + value: "value3", + expires: 0, + path: "/path3/", + host: "test1.example.org", + isDomain: false, + isSecure: false, + } + ] +}; + +add_task(function* () { + yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-cookies-same-name.html"); + + initDebuggerServer(); + let client = new DebuggerClient(DebuggerServer.connectPipe()); + let form = yield connectDebuggerClient(client); + let front = StorageFront(client, form); + let data = yield front.listStores(); + + ok(data.cookies, "Cookies storage actor is present"); + + yield testCookies(data.cookies); + yield clearStorage(); + + // Forcing GC/CC to get rid of docshells and windows created by this test. + forceCollections(); + yield client.close(); + forceCollections(); + DebuggerServer.destroy(); + forceCollections(); +}); + +function testCookies(cookiesActor) { + let numHosts = Object.keys(cookiesActor.hosts).length; + is(numHosts, 1, "Correct number of host entries for cookies"); + return testCookiesObjects(0, cookiesActor.hosts, cookiesActor); +} + +var testCookiesObjects = Task.async(function* (index, hosts, cookiesActor) { + let host = Object.keys(hosts)[index]; + let matchItems = data => { + is(data.total, TESTDATA[host].length, + "Number of cookies in host " + host + " matches"); + for (let item of data.data) { + let found = false; + for (let toMatch of TESTDATA[host]) { + if (item.name === toMatch.name && + item.host === toMatch.host && + item.path === toMatch.path) { + found = true; + ok(true, "Found cookie " + item.name + " in response"); + is(item.value.str, toMatch.value, "The value matches."); + is(item.expires, toMatch.expires, "The expiry time matches."); + is(item.path, toMatch.path, "The path matches."); + is(item.host, toMatch.host, "The host matches."); + is(item.isSecure, toMatch.isSecure, "The isSecure value matches."); + is(item.isDomain, toMatch.isDomain, "The isDomain value matches."); + break; + } + } + ok(found, "cookie " + item.name + " should exist in response"); + } + }; + + ok(!!TESTDATA[host], "Host is present in the list : " + host); + matchItems(yield cookiesActor.getStoreObjects(host)); + if (index == Object.keys(hosts).length - 1) { + return; + } + yield testCookiesObjects(++index, hosts, cookiesActor); +}); diff --git a/devtools/server/tests/browser/browser_storage_dynamic_windows.js b/devtools/server/tests/browser/browser_storage_dynamic_windows.js index 440c91222..91b4155d9 100644 --- a/devtools/server/tests/browser/browser_storage_dynamic_windows.js +++ b/devtools/server/tests/browser/browser_storage_dynamic_windows.js @@ -66,6 +66,7 @@ function markOutMatched(toBeEmptied, data, deleted) { info("Testing for " + storageType); for (let host in data[storageType]) { ok(toBeEmptied[storageType][host], "Host " + host + " found"); + if (!deleted) { for (let item of data[storageType][host]) { let index = toBeEmptied[storageType][host].indexOf(item); @@ -87,50 +88,6 @@ function markOutMatched(toBeEmptied, data, deleted) { } } -// function testReload(front) { -// info("Testing if reload works properly"); - -// let shouldBeEmptyFirst = Cu.cloneInto(beforeReload, {}); -// let shouldBeEmptyLast = Cu.cloneInto(beforeReload, {}); -// return new Promise(resolve => { - -// let onStoresUpdate = data => { -// info("in stores update of testReload"); -// // This might be second time stores update is happening, in which case, -// // data.deleted will be null. -// // OR.. This might be the first time on a super slow machine where both -// // data.deleted and data.added is missing in the first update. -// if (data.deleted) { -// markOutMatched(shouldBeEmptyFirst, data.deleted, true); -// } - -// if (!Object.keys(shouldBeEmptyFirst).length) { -// info("shouldBeEmptyFirst is empty now"); -// } - -// // stores-update call might not have data.added for the first time on -// // slow machines, in which case, data.added will be null -// if (data.added) { -// markOutMatched(shouldBeEmptyLast, data.added); -// } - -// if (!Object.keys(shouldBeEmptyLast).length) { -// info("Everything to be received is received."); -// endTestReloaded(); -// } -// }; - -// let endTestReloaded = () => { -// front.off("stores-update", onStoresUpdate); -// resolve(); -// }; - -// front.on("stores-update", onStoresUpdate); - -// content.location.reload(); -// }); -// } - function testAddIframe(front) { info("Testing if new iframe addition works properly"); return new Promise(resolve => { @@ -142,7 +99,10 @@ function testAddIframe(front) { "https://sectest1.example.org": ["iframe-s-ss1"] }, cookies: { - "sectest1.example.org": ["sc1"] + "sectest1.example.org": [ + getCookieId("sc1", "sectest1.example.org", + "/browser/devtools/server/tests/browser/") + ] }, indexedDB: { // empty because indexed db creation happens after the page load, so at @@ -150,7 +110,7 @@ function testAddIframe(front) { "https://sectest1.example.org": [] }, Cache: { - "https://sectest1.example.org":[] + "https://sectest1.example.org": [] } }; diff --git a/devtools/server/tests/browser/browser_storage_listings.js b/devtools/server/tests/browser/browser_storage_listings.js index 4ff3c3fc1..e47a320b8 100644 --- a/devtools/server/tests/browser/browser_storage_listings.js +++ b/devtools/server/tests/browser/browser_storage_listings.js @@ -20,15 +20,6 @@ const storeMap = { isSecure: false, }, { - name: "cs2", - value: "sessionCookie", - path: "/", - host: ".example.org", - expires: 0, - isDomain: true, - isSecure: false, - }, - { name: "c3", value: "foobar-2", expires: 2000000001000, @@ -130,24 +121,24 @@ const storeMap = { const IDBValues = { listStoresResponse: { "http://test1.example.org": [ - ["idb1", "obj1"], ["idb1", "obj2"], ["idb2", "obj3"] + ["idb1 (default)", "obj1"], ["idb1 (default)", "obj2"], ["idb2 (default)", "obj3"] ], "http://sectest1.example.org": [ ], "https://sectest1.example.org": [ - ["idb-s1", "obj-s1"], ["idb-s2", "obj-s2"] + ["idb-s1 (default)", "obj-s1"], ["idb-s2 (default)", "obj-s2"] ] }, - dbDetails : { + dbDetails: { "http://test1.example.org": [ { - db: "idb1", + db: "idb1 (default)", origin: "http://test1.example.org", version: 1, objectStores: 2 }, { - db: "idb2", + db: "idb2 (default)", origin: "http://test1.example.org", version: 1, objectStores: 1 @@ -157,13 +148,13 @@ const IDBValues = { ], "https://sectest1.example.org": [ { - db: "idb-s1", + db: "idb-s1 (default)", origin: "https://sectest1.example.org", version: 1, objectStores: 1 }, { - db: "idb-s2", + db: "idb-s2 (default)", origin: "https://sectest1.example.org", version: 1, objectStores: 1 @@ -172,7 +163,7 @@ const IDBValues = { }, objectStoreDetails: { "http://test1.example.org": { - idb1: [ + "idb1 (default)": [ { objectStore: "obj1", keyPath: "id", @@ -199,7 +190,7 @@ const IDBValues = { indexes: [] } ], - idb2: [ + "idb2 (default)": [ { objectStore: "obj3", keyPath: "id3", @@ -217,7 +208,7 @@ const IDBValues = { }, "http://sectest1.example.org" : {}, "https://sectest1.example.org": { - "idb-s1": [ + "idb-s1 (default)": [ { objectStore: "obj-s1", keyPath: "id", @@ -225,7 +216,7 @@ const IDBValues = { indexes: [] }, ], - "idb-s2": [ + "idb-s2 (default)": [ { objectStore: "obj-s2", keyPath: "id3", @@ -245,7 +236,7 @@ const IDBValues = { }, entries: { "http://test1.example.org": { - "idb1#obj1": [ + "idb1 (default)#obj1": [ { name: 1, value: { @@ -271,7 +262,7 @@ const IDBValues = { } } ], - "idb1#obj2": [ + "idb1 (default)#obj2": [ { name: 1, value: { @@ -282,11 +273,11 @@ const IDBValues = { } } ], - "idb2#obj3": [] + "idb2 (default)#obj3": [] }, "http://sectest1.example.org" : {}, "https://sectest1.example.org": { - "idb-s1#obj-s1": [ + "idb-s1 (default)#obj-s1": [ { name: 6, value: { @@ -304,7 +295,7 @@ const IDBValues = { } } ], - "idb-s2#obj-s2": [ + "idb-s2 (default)#obj-s2": [ { name: 13, value: { @@ -337,7 +328,8 @@ function* testStores(data) { } function testCookies(cookiesActor) { - is(Object.keys(cookiesActor.hosts).length, 2, "Correct number of host entries for cookies"); + is(Object.keys(cookiesActor.hosts).length, 2, + "Correct number of host entries for cookies"); return testCookiesObjects(0, cookiesActor.hosts, cookiesActor); } @@ -346,9 +338,9 @@ var testCookiesObjects = Task.async(function* (index, hosts, cookiesActor) { let matchItems = data => { let cookiesLength = 0; for (let secureCookie of storeMap.cookies[host]) { - if (secureCookie.isSecure) { - ++cookiesLength; - } + if (secureCookie.isSecure) { + ++cookiesLength; + } } // Any secure cookies did not get stored in the database. is(data.total, storeMap.cookies[host].length - cookiesLength, @@ -478,17 +470,17 @@ var testIndexedDBs = Task.async(function* (index, hosts, indexedDBActor) { for (let item of data.data) { let found = false; for (let toMatch of IDBValues.dbDetails[host]) { - if (item.db == toMatch.db) { + if (item.uniqueKey == toMatch.db) { found = true; - ok(true, "Found indexed db " + item.db + " in response"); + ok(true, "Found indexed db " + item.uniqueKey + " in response"); is(item.origin, toMatch.origin, "The origin matches."); is(item.version, toMatch.version, "The version matches."); is(item.objectStores, toMatch.objectStores, - "The numebr of object stores matches."); + "The number of object stores matches."); break; } } - ok(found, "indexed db " + item.name + " should exist in response"); + ok(found, "indexed db " + item.uniqueKey + " should exist in response"); } }; diff --git a/devtools/server/tests/browser/browser_storage_updates.js b/devtools/server/tests/browser/browser_storage_updates.js index 28b2e509f..01a35cefc 100644 --- a/devtools/server/tests/browser/browser_storage_updates.js +++ b/devtools/server/tests/browser/browser_storage_updates.js @@ -27,7 +27,12 @@ const TESTS = [ expected: { added: { cookies: { - "test1.example.org": ["c1", "c2"] + "test1.example.org": [ + getCookieId("c1", "test1.example.org", + "/browser/devtools/server/tests/browser/"), + getCookieId("c2", "test1.example.org", + "/browser/devtools/server/tests/browser/") + ] }, localStorage: { "http://test1.example.org": ["l1"] @@ -48,7 +53,10 @@ const TESTS = [ expected: { changed: { cookies: { - "test1.example.org": ["c1"] + "test1.example.org": [ + getCookieId("c1", "test1.example.org", + "/browser/devtools/server/tests/browser/"), + ] } }, added: { @@ -74,7 +82,10 @@ const TESTS = [ expected: { deleted: { cookies: { - "test1.example.org": ["c2"] + "test1.example.org": [ + getCookieId("c2", "test1.example.org", + "/browser/devtools/server/tests/browser/"), + ] }, localStorage: { "http://test1.example.org": ["l1"] @@ -112,7 +123,10 @@ const TESTS = [ expected: { added: { cookies: { - "test1.example.org": ["c3"] + "test1.example.org": [ + getCookieId("c3", "test1.example.org", + "/browser/devtools/server/tests/browser/"), + ] }, sessionStorage: { "http://test1.example.org": ["s1", "s2"] @@ -125,7 +139,10 @@ const TESTS = [ }, deleted: { cookies: { - "test1.example.org": ["c1"] + "test1.example.org": [ + getCookieId("c1", "test1.example.org", + "/browser/devtools/server/tests/browser/"), + ] }, localStorage: { "http://test1.example.org": ["l2"] @@ -158,7 +175,10 @@ const TESTS = [ expected: { deleted: { cookies: { - "test1.example.org": ["c3"] + "test1.example.org": [ + getCookieId("c3", "test1.example.org", + "/browser/devtools/server/tests/browser/"), + ] } } } diff --git a/devtools/server/tests/browser/head.js b/devtools/server/tests/browser/head.js index 1e7f09d95..5cf98c2b0 100644 --- a/devtools/server/tests/browser/head.js +++ b/devtools/server/tests/browser/head.js @@ -2,6 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +/* eslint no-unused-vars: [2, {"vars": "local"}] */ + var Cc = Components.classes; var Ci = Components.interfaces; var Cu = Components.utils; @@ -19,6 +23,11 @@ const MAIN_DOMAIN = "http://test1.example.org/" + PATH; const ALT_DOMAIN = "http://sectest1.example.org/" + PATH; const ALT_DOMAIN_SECURED = "https://sectest1.example.org:443/" + PATH; +// GUID to be used as a separator in compound keys. This must match the same +// constant in devtools/server/actors/storage.js, +// devtools/client/storage/ui.js and devtools/client/storage/test/head.js +const SEPARATOR_GUID = "{9d414cc5-8319-0a04-0586-c0a6ae01670a}"; + // All tests are asynchronous. waitForExplicitFinish(); @@ -94,7 +103,6 @@ function once(target, eventName, useCapture = false) { info("Waiting for event: '" + eventName + "' on " + target + "."); return new Promise(resolve => { - for (let [add, remove] of [ ["addEventListener", "removeEventListener"], ["addListener", "removeListener"], @@ -137,6 +145,8 @@ function getMockTabActor(win) { } registerCleanupFunction(function tearDown() { + Services.cookies.removeAll(); + while (gBrowser.tabs.length > 1) { gBrowser.removeCurrentTab(); } @@ -148,8 +158,11 @@ function idleWait(time) { function busyWait(time) { let start = Date.now(); + // eslint-disable-next-line let stack; - while (Date.now() - start < time) { stack = Components.stack; } + while (Date.now() - start < time) { + stack = Components.stack; + } } /** @@ -172,11 +185,12 @@ function waitUntil(predicate, interval = 10) { } function waitForMarkerType(front, types, predicate, - unpackFun = (name, data) => data.markers, - eventName = "timeline-data") -{ + unpackFun = (name, data) => data.markers, + eventName = "timeline-data") { types = [].concat(types); - predicate = predicate || function () { return true; }; + predicate = predicate || function () { + return true; + }; let filteredMarkers = []; let { promise, resolve } = defer(); @@ -190,9 +204,11 @@ function waitForMarkerType(front, types, predicate, let markers = unpackFun(name, data); info("Got markers: " + JSON.stringify(markers, null, 2)); - filteredMarkers = filteredMarkers.concat(markers.filter(m => types.indexOf(m.name) !== -1)); + filteredMarkers = filteredMarkers.concat( + markers.filter(m => types.indexOf(m.name) !== -1)); - if (types.every(t => filteredMarkers.some(m => m.name === t)) && predicate(filteredMarkers)) { + if (types.every(t => filteredMarkers.some(m => m.name === t)) && + predicate(filteredMarkers)) { front.off(eventName, handler); resolve(filteredMarkers); } @@ -201,3 +217,7 @@ function waitForMarkerType(front, types, predicate, return promise; } + +function getCookieId(name, domain, path) { + return `${name}${SEPARATOR_GUID}${domain}${SEPARATOR_GUID}${path}`; +} diff --git a/devtools/server/tests/browser/storage-cookies-same-name.html b/devtools/server/tests/browser/storage-cookies-same-name.html new file mode 100644 index 000000000..e3e092ec3 --- /dev/null +++ b/devtools/server/tests/browser/storage-cookies-same-name.html @@ -0,0 +1,28 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Storage inspector cookies with duplicate names</title> +</head> +<body onload="createCookies()"> +<script type="application/javascript;version=1.7"> +"use strict"; +function createCookies() { + document.cookie = "name=value1;path=/;"; + document.cookie = "name=value2;path=/path2/;"; + document.cookie = "name=value3;path=/path3/;"; +} + +window.removeCookie = function (name) { + document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; +}; + +window.clearCookies = function () { + let cookies = document.cookie; + for (let cookie of cookies.split(";")) { + removeCookie(cookie.split("=")[0]); + } +}; +</script> +</body> +</html> |