diff --git a/game/end_to_end_tests/test_localstorage.py b/game/end_to_end_tests/test_localstorage.py deleted file mode 100644 index c3b9ad528..000000000 --- a/game/end_to_end_tests/test_localstorage.py +++ /dev/null @@ -1,54 +0,0 @@ -from django.urls.base import reverse -from .base_game_test import BaseGameTest -from selenium.webdriver.common.by import By - - -class LocalStorage: - def __init__(self, driver): - self.driver = driver - - def items(self): - items = self.driver.execute_script( - "var ls = window.localStorage, items = {}; " - "for (var i = 0, k; i < ls.length; ++i) " - " items[k = ls.key(i)] = ls.getItem(k); " - "return items; " - ) - return items - - def clear(self): - self.driver.execute_script("window.localStorage.clear();") - - -class TestLocalStorage(BaseGameTest): - def level_in_localstorage(self, level_number): - items = LocalStorage(self.selenium).items() - return (f"blocklyWorkspaceXml-{level_number}" in items) and ( - f"pythonWorkspace-{level_number}" in items - ) - - def test_localstorage_if_logged_in(self): - self.login_once() - self._complete_level(1) - self.assertTrue(self.level_in_localstorage(1)) - - def test_nothing_in_localstorage_if_not_logged_in(self): - page = self.go_to_homepage() - page.teacher_logout() - - level1 = self.go_to_level(1) - - ls = LocalStorage(self.selenium) - ls.clear() - - solution = self.read_solution("once_forwards") - script = f""" - const xml = `{solution}`; - Blockly.Xml.clearWorkspaceAndLoadFromXml(Blockly.Xml.textToDom(xml), Blockly.mainWorkspace); - """ - self.selenium.execute_script(script) - self.selenium.find_element_by_id("fast_tab").click() - - level1.wait_for_element_to_be_clickable((By.CSS_SELECTOR, "#next_level_button")) - level1.next_level() - self.assertFalse(self.level_in_localstorage(1)) diff --git a/game/static/game/js/blocklyControl.js b/game/static/game/js/blocklyControl.js index aece7a737..0757cba91 100644 --- a/game/static/game/js/blocklyControl.js +++ b/game/static/game/js/blocklyControl.js @@ -64,22 +64,6 @@ ocargo.BlocklyControl.prototype.reset = function() { this.clearIncorrectBlock(); }; - -ocargo.BlocklyControl.prototype.teardown = function() { - if (localStorage && !ANONYMOUS && USER_LOGGED_IN) { - var text = this.serialize(); - try { - if (NIGHT_MODE) { - localStorage.setItem('blocklyNightModeWorkspaceXml-' + LEVEL_ID, text); - } else { - localStorage.setItem('blocklyWorkspaceXml-' + LEVEL_ID, text); - } - } catch (e) { - // No point in even logging, as page is unloading - } - } -}; - ocargo.BlocklyControl.prototype.deserialize = function(text) { try { var oldXml = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace); @@ -163,15 +147,9 @@ ocargo.BlocklyControl.prototype.loadPreviousAttempt = function() { e.innerHTML = text; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; } - // Use the user's last attempt if available, else use whatever's in local storage + // Use the user's last attempt if available if (WORKSPACE) { this.deserialize(decodeHTML(WORKSPACE)); - } else { - if (NIGHT_MODE) { - this.deserialize(localStorage.getItem('blocklyNightModeWorkspaceXml-' + LEVEL_ID)); - } else { - this.deserialize(localStorage.getItem('blocklyWorkspaceXml-' + LEVEL_ID)); - } } this.redrawBlockly(); diff --git a/game/static/game/js/level_editor.js b/game/static/game/js/level_editor.js index fd1e14ae1..eca679dea 100644 --- a/game/static/game/js/level_editor.js +++ b/game/static/game/js/level_editor.js @@ -98,9 +98,6 @@ ocargo.LevelEditor = function(levelId) { $('#play_night_tab').show() } - // So that we store the current state when the page unloads - window.addEventListener('unload', storeStateInLocalStorage); - // Setup max_fuel setupMaxFuel(); @@ -117,9 +114,6 @@ ocargo.LevelEditor = function(levelId) { setupTrashcan(); - // If there's any previous state in local storage retrieve it - retrieveStateFromLocalStorage(); - // Draw everything drawAll(); @@ -247,7 +241,6 @@ ocargo.LevelEditor = function(levelId) { $('#clear').click(function() { clear(); - localStorage.removeItem('levelEditorState'); drawAll(); }); @@ -2597,37 +2590,6 @@ ocargo.LevelEditor = function(levelId) { ownedLevels.save(level, levelId, callback); } - function storeStateInLocalStorage() { - if (localStorage) { - var state = extractState(); - - // Append additional non-level orientated editor state - state.id = saveState.id; - state.savedState = saveState.savedState; - state.owned = saveState.owned; - - localStorage.levelEditorState = JSON.stringify(state); - } - } - - function retrieveStateFromLocalStorage() { - if (localStorage) { - if (localStorage.levelEditorState) { - var state = JSON.parse(localStorage.levelEditorState); - - if (state) { - restoreState(state); - } - - // Restore additional non-level orientated editor state - saveState.id = state.id; - saveState.savedState = state.savedState; - saveState.owned = state.owned; - } - - } - } - function isLevelValid() { // Check to see if a road has been created if (nodes === undefined || nodes.length == 0) { diff --git a/game/static/game/js/pythonControl.js b/game/static/game/js/pythonControl.js index 875e397ad..2f5beb31f 100644 --- a/game/static/game/js/pythonControl.js +++ b/game/static/game/js/pythonControl.js @@ -81,28 +81,10 @@ ocargo.PythonControl = function () { if (PYTHON_WORKSPACE) { this.setCode(PYTHON_WORKSPACE); } else { - try { - this.setCode( - localStorage.getItem('pythonWorkspace-' + LEVEL_ID)); - } catch (e) { - this.reset(); - } + this.reset(); } }; - this.teardown = function () { - if (localStorage && !ANONYMOUS && USER_LOGGED_IN) { - var text = this.getCode(); - try { - localStorage.setItem('pythonWorkspace-' + LEVEL_ID, text); - - } catch (e) { - // No point in even logging, as page is unloading - } - } - }; - - /*********************/ /** Private methods **/ /*********************/ diff --git a/game/static/game/js/saving.js b/game/static/game/js/saving.js index 58e95de8c..b3116cb04 100644 --- a/game/static/game/js/saving.js +++ b/game/static/game/js/saving.js @@ -1,25 +1,6 @@ var ocargo = ocargo || {}; -ocargo.Saving = function () { - this.getListOfWorkspacesFromLocalStorage = function () { - var query = /blocklySavedWorkspaceXml-([0-9]+)$/; - var i, results = []; - for (i in localStorage) { - if (localStorage.hasOwnProperty(i)) { - var matches = query.exec(i); - if (matches) { - var json = JSON.parse(localStorage.getItem(i)); - results.push({ - id: matches[1], - name: json.name, - workspace: json.workspace - }); - } - } - } - return results; - }; -}; +ocargo.Saving = function () {}; function csrfSafeMethod(method) { // these HTTP methods do not require CSRF protection @@ -44,10 +25,6 @@ ocargo.Saving.prototype.retrieveListOfWorkspaces = function (callback) { } }); } - else if (localStorage) { - var results = this.getListOfWorkspacesFromLocalStorage(); - callback(null, results); - } else { callback("Not logged in and no local storage available"); } @@ -67,13 +44,6 @@ ocargo.Saving.prototype.retrieveWorkspace = function (id, callback) { } }); } - //setTimeout is used here in order to ensure that these lines of code are executed after the correct tab is selected - else if (localStorage) { - setTimeout(function () { - var json = JSON.parse(localStorage.getItem('blocklySavedWorkspaceXml-' + id)); - callback(null, json); - }, 0) - } else { callback("Not logged in and no local storage available"); } @@ -98,10 +68,6 @@ ocargo.Saving.prototype.deleteWorkspace = function (id, callback) { callback(xhr.status + ": " + errmsg + " " + err + " " + xhr.responseText); } }); - } else if (localStorage) { - localStorage.removeItem('blocklySavedWorkspaceXml-' + id); - var results = this.getListOfWorkspacesFromLocalStorage(); - callback(null, results); } else { callback("Not logged in and no local storage available"); } @@ -128,17 +94,6 @@ ocargo.Saving.prototype.saveWorkspace = function (workspace, id, callback) { } }); } - else if (localStorage) { - if (!id) { - // Need to generate a unique integer, for our purposes this should do - id = new Date().getTime(); - } - - localStorage.setItem('blocklySavedWorkspaceXml-' + id, JSON.stringify(workspace)); - - var results = this.getListOfWorkspacesFromLocalStorage(); - callback(null, results); - } else { callback("Not logged in and no local storage available"); }