Skip to content

Commit

Permalink
splash.indexeddb_enabled attribute; enable IndexedDB by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Jan 30, 2018
1 parent 669e02d commit e568015
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changes
=======

3.1 (TBA)

* IndexedDB is enabled by default; to turn it off set
:ref:`splash-indexeddb-enabled` attribute to ``false``.
* Documentation and testing improvements.


3.0 (2017-07-06)
----------------

Expand Down Expand Up @@ -55,6 +62,7 @@ Other changes and bug fixes:
with Lua ``assert``, so now a string with an error message is returned
instead. It was always documented that a string is returned by splash:runjs
as a second value when error happens.
<<<<<<< HEAD
* Fixed :ref:`splash-element-png` and :ref:`splash-element-jpeg` for elements
outside curent viewport;
* DOM attributes and methods are documented as accessible on
Expand Down
13 changes: 13 additions & 0 deletions docs/scripting-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ It is also possible to omit coordinates which you don't want to change.
For example, ``splash.scroll_position = {y=200}`` sets y to 200 and keeps
previous x value.

.. _splash-indexeddb-enabled:

splash.indexeddb_enabled
------------------------

Enable or disable IndexedDB_.

**Signature:** ``splash.indexeddb_enabled = true/false``

IndexedDB is enabled by default. Use ``splash.indexeddb_enabled = false``
to disable it.

.. _IndexedDB: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API

Methods
~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions splash/browser_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def set_private_mode_enabled(self, val):
get_plugins_enabled = webpage_option_getter(QWebSettings.PluginsEnabled)
set_plugins_enabled = webpage_option_setter(QWebSettings.PluginsEnabled, bool)

get_indexeddb_enabled = webpage_option_getter(QWebSettings.OfflineStorageDatabaseEnabled)
set_indexeddb_enabled = webpage_option_setter(QWebSettings.OfflineStorageDatabaseEnabled)

def _set_default_webpage_options(self, web_page):
"""
Expand All @@ -207,6 +209,7 @@ def _set_default_webpage_options(self, web_page):

self.set_plugins_enabled(defaults.PLUGINS_ENABLED)
self.set_response_body_enabled(defaults.RESPONSE_BODY_ENABLED)
self.set_indexeddb_enabled(defaults.INDEXEDDB_ENABLED)

def _setup_webpage_events(self):
main_frame = self.web_page.mainFrame()
Expand Down
3 changes: 3 additions & 0 deletions splash/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@

# response content
RESPONSE_BODY_ENABLED = False

# IndexedDB
INDEXEDDB_ENABLED = True
10 changes: 10 additions & 0 deletions splash/qtrender_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,16 @@ def get_plugins_enabled(self):
def set_plugins_enabled(self, enabled):
self.tab.set_plugins_enabled(bool(enabled))

@lua_property("indexeddb_enabled")
@command()
def get_indexeddb_enabled(self):
return self.tab.get_indexeddb_enabled()

@get_indexeddb_enabled.lua_setter
@command()
def set_indexeddb_enabled(self, value):
self.tab.set_indexeddb_enabled(bool(value))

@lua_property('resource_timeout')
@command()
def get_resource_timeout(self):
Expand Down
51 changes: 51 additions & 0 deletions splash/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3574,6 +3574,57 @@ def test_localstorage_nopage(self):
self.assertEqual(resp.text, "value")


class IndexedDBTest(BaseLuaRenderTest):
DETECT_INDEXEDDB_JS = """
function main(splash) {
if (!window.indexedDB) {
splash.resume("no indexed DB");
return;
}
var request = window.indexedDB.open("MyTestDatabase", 3);
request.onerror = function(event) {
splash.resume("can't open IndexedDB database");
};
request.onsuccess = function(event) {
splash.resume("ok");
};
}
"""
def test_indexeddb_available(self):
resp = self.request_lua("""
function main(splash)
assert(splash:go(splash.args.url))
return assert(splash:wait_for_resume(splash.args.js))
end
""", {'url': self.mockurl('jsrender'), 'js': self.DETECT_INDEXEDDB_JS})
self.assertStatusCode(resp, 200)
self.assertEqual(resp.json(), {'value': 'ok'})

def test_indexeddb_enable_disable(self):
resp = self.request_lua("""
treat = require('treat')
function main(splash)
splash.indexeddb_enabled = false
assert(splash:go(splash.args.url))
local res1 = assert(splash:wait_for_resume(splash.args.js))
local val1 = splash.indexeddb_enabled
splash.indexeddb_enabled = true
assert(splash:go(splash.args.url))
local res2 = assert(splash:wait_for_resume(splash.args.js))
local val2 = splash.indexeddb_enabled
return treat.as_array({res1, val1, res2, val2})
end
""", {'url': self.mockurl('jsrender'), 'js': self.DETECT_INDEXEDDB_JS})
self.assertStatusCode(resp, 200)
res1, val1, res2, val2 = resp.json()
assert res1 == {'value': 'no indexed DB'}
assert val1 is False

assert res2 == {'value': 'ok'}
assert val2 is True


class EnableDisablePrivateModeTest(BaseLuaRenderTest):
LOCAL_STORAGE_WORKS_JS = """
(function () {
Expand Down

0 comments on commit e568015

Please sign in to comment.