| <html> | |
| <script> | |
| function success_() { | |
| domAutomationController.send(true); | |
| } | |
| function failure_() { | |
| domAutomationController.send(false); | |
| } | |
| function isHttps_() { | |
| return location.protocol === 'https:'; | |
| } | |
| function setCookie() { | |
| const samesite_none_secure = '; SameSite=None; Secure'; | |
| document.cookie = 'foo=bar; Max-Age=1000' + (isHttps_() ? samesite_none_secure : ''); | |
| success_(); | |
| } | |
| function hasCookie() { | |
| domAutomationController.send(document.cookie == 'foo=bar'); | |
| } | |
| function setSessionCookie() { | |
| const samesite_none_secure = '; SameSite=None; Secure'; | |
| document.cookie = 'bar=session' + (isHttps_() ? samesite_none_secure : ''); | |
| success_(); | |
| } | |
| function hasSessionCookie() { | |
| domAutomationController.send(document.cookie == 'bar=session'); | |
| } | |
| function setLocalStorage() { | |
| localStorage.setItem('foo', 'bar'); | |
| success_(); | |
| } | |
| function hasLocalStorage() { | |
| try { | |
| domAutomationController.send(localStorage.getItem('foo') == 'bar'); | |
| } catch (e) { | |
| failure_(); | |
| } | |
| } | |
| function setSessionStorage() { | |
| sessionStorage.setItem('foo', 'bar'); | |
| success_(); | |
| } | |
| function hasSessionStorage() { | |
| try { | |
| domAutomationController.send(sessionStorage.getItem('foo') == 'bar'); | |
| } catch (e) { | |
| failure_(); | |
| } | |
| } | |
| function setServiceWorker() { | |
| navigator.serviceWorker.register('empty_worker.js').then(function() { | |
| navigator.serviceWorker.ready.then(success_); | |
| }).catch(failure_); | |
| } | |
| function hasServiceWorker() { | |
| navigator.serviceWorker.getRegistrations().then(function (registrations) { | |
| domAutomationController.send(registrations.length > 0); | |
| }).catch(failure_); | |
| } | |
| function setCacheStorage() { | |
| caches.open("cache").then(function (cache) { | |
| cache.put("/foo", new Response("bar")).then(success_); | |
| }).catch(failure_); | |
| } | |
| function hasCacheStorage() { | |
| caches.open("cache").then(function (cache) { | |
| cache.keys().then(function (keys) { | |
| domAutomationController.send(keys.length > 0); | |
| }); | |
| }).catch(failure_); | |
| } | |
| function openFile_(name, options, callback, error) { | |
| window.webkitRequestFileSystem(TEMPORARY, 1024, function (fs) { | |
| fs.root.getFile(name, options, callback, error); | |
| }, error); | |
| } | |
| function setFileSystem() { | |
| openFile_('foo.txt', { create: true, exclusive: true }, success_, failure_); | |
| } | |
| function hasFileSystem() { | |
| openFile_('foo.txt', { create: false }, success_, failure_); | |
| } | |
| function setWebSql() { | |
| var db = openDatabase('testdb', '1.0', 'a test db', 1024); | |
| db.transaction(function (tx) { | |
| tx.executeSql('CREATE TABLE IF NOT EXISTS foo (text)'); | |
| tx.executeSql('INSERT INTO foo (text) VALUES ("bar")'); | |
| }, failure_, success_); | |
| } | |
| function hasWebSql() { | |
| try { | |
| var db = openDatabase('testdb', '1.0', 'a test db', 1024); | |
| } catch (e) { | |
| return failure_(); | |
| } | |
| var num_results; | |
| db.transaction(function (tx) { | |
| tx.executeSql('CREATE TABLE IF NOT EXISTS foo (text)'); | |
| tx.executeSql('SELECT * FROM foo', [], function (tx, results) { | |
| num_results = results.rows.length; | |
| }); | |
| }, null, function() { domAutomationController.send(num_results > 0); }); | |
| } | |
| function setIndexedDb() { | |
| var open = indexedDB.open('db', 2); | |
| open.onupgradeneeded = function() { | |
| open.result.createObjectStore('store'); | |
| } | |
| open.onsuccess = function() { | |
| open.result.close(); | |
| success_(); | |
| } | |
| open.onerror = failure_; | |
| } | |
| function hasIndexedDb() { | |
| var open = indexedDB.open('db'); | |
| open.onsuccess = function() { | |
| var hasStore = open.result.objectStoreNames.contains('store'); | |
| open.result.close(); | |
| domAutomationController.send(hasStore); | |
| } | |
| open.onerror = failure_; | |
| } | |
| function setHistory() { | |
| history.pushState({}, "foo"); | |
| success_(); | |
| } | |
| function hasHistory() { | |
| domAutomationController.send(history.length > 1); | |
| } | |
| let sharedWorker; // Global variable to keep worker alive. | |
| function connectSharedWorker() { | |
| return new Promise((resolve, reject) => { | |
| sharedWorker = new SharedWorker("shared_worker.js"); | |
| sharedWorker.onerror = reject; | |
| sharedWorker.port.onmessage = resolve; | |
| sharedWorker.port.start(); | |
| }); | |
| } | |
| function setSharedWorker() { | |
| connectSharedWorker().then(() => { | |
| sharedWorker.port.postMessage({ "value": "foo" }); | |
| success_(); | |
| }).catch(failure_); | |
| } | |
| async function hasSharedWorker() { | |
| connectSharedWorker().then(() => { | |
| sharedWorker.port.onmessage = e => { | |
| domAutomationController.send(e.data.value === "foo"); | |
| }; | |
| sharedWorker.port.postMessage({}); | |
| }).catch(failure_); | |
| } | |
| let lock; | |
| function setWebLock() { | |
| navigator.locks.request("foo", l => { | |
| lock = new Promise((res, rej) => { }); | |
| // Now lock will be held while |lock| exists. | |
| success_(); | |
| return lock; | |
| }).catch(failure_); | |
| } | |
| function hasWebLock() { | |
| navigator.locks.query().then(locks => { | |
| if (locks.held.length) | |
| domAutomationController.send(locks.held[0].name === "foo"); | |
| else | |
| failure_(); | |
| }).catch(failure_); | |
| } | |
| </script> | |
| <body> | |
| This page is used to test creation and deletion of various site data types. | |
| The functions are called from BrowsingDataRemoverBrowserTest::HasDataForType | |
| and BrowsingDataRemoverBrowserTest::SetDataForType. | |
| </body> | |
| </html> |