]> khamidou — GitHub mirrors - electron.git/commitdiff
add spec and docs
authorRobo <hop2deep@gmail.com>
Thu, 27 Aug 2015 01:27:03 +0000 (06:57 +0530)
committerRobo <hop2deep@gmail.com>
Thu, 3 Sep 2015 15:19:29 +0000 (20:49 +0530)
docs/api/web-view-tag.md
spec/fixtures/pages/partition/one.html [new file with mode: 0644]
spec/fixtures/pages/partition/two.html [new file with mode: 0644]
spec/webview-spec.coffee

index 6b64a0269c5251348328856daf8b1e66269b3393..ec8529655272e612c0da8d6e89cb73d6896f66fc 100644 (file)
@@ -131,6 +131,23 @@ page is loaded, use the `setUserAgent` method to change the user agent.
 
 If "on", the guest page will have web security disabled.
 
+### partition
+
+```html
+<webview src="https://github.com" partition="persist:github"></webview>
+<webview src="http://electron.atom.io" partition="electron"></webview>
+```
+
+Sets the storage partition used by the `webview`. If the storage partition ID starts with `persist:`,
+the `webview` will use a persistent storage partition available to all `webview` in the app with
+the same storage partition ID. If the ID is unset or if there is no `persist:` prefix, the `webview` will
+use an in-memory storage partition. By assigning the same partition ID, multiple `webview`
+can share the same storage partition.
+
+This value can only be modified before the first navigation, since the storage partition of an active
+renderer process cannot change. Subsequent attempts to modify the value will fail with a
+DOM exception.
+
 ## Methods
 
 The `webview` tag has the following methods:
diff --git a/spec/fixtures/pages/partition/one.html b/spec/fixtures/pages/partition/one.html
new file mode 100644 (file)
index 0000000..765f721
--- /dev/null
@@ -0,0 +1,5 @@
+<script>
+window.localStorage.setItem('test', 'one');
+const item = window.localStorage.getItem('test');
+console.log([item, window.localStorage.length].join(' '));
+</script>
diff --git a/spec/fixtures/pages/partition/two.html b/spec/fixtures/pages/partition/two.html
new file mode 100644 (file)
index 0000000..ad22c34
--- /dev/null
@@ -0,0 +1,4 @@
+<script>
+const item = window.localStorage.getItem('test');
+console.log([item, window.localStorage.length].join(' '));
+</script>
index 6eb391ac94832f78b7e208b25bb3d3c68f3f6715..ae8cd5d45579cc61e2ebb07a71cbdc40fef6a976 100644 (file)
@@ -154,6 +154,33 @@ describe '<webview> tag', ->
       webview.src = "data:text/html;base64,#{encoded}"
       document.body.appendChild webview
 
+  describe 'partition attribute', ->
+    isolatedWebview = null
+    beforeEach ->
+      isolatedWebview = new WebView
+
+    afterEach ->
+      document.body.removeChild isolatedWebview
+
+    it 'isolates storage for different id', (done) ->
+      listener = (e) ->
+        document.body.appendChild isolatedWebview
+        webview.removeEventListener 'did-finish-load', listener
+      listener2 = (e) ->
+        assert.equal e.message, "one 1"
+        webview.removeEventListener 'console-message', listener2
+      listener3 = (e) ->
+        assert.equal e.message, " 0"
+        isolatedWebview.removeEventListener 'console-message', listener3
+        done()
+      webview.addEventListener 'did-finish-load', listener
+      webview.addEventListener 'console-message', listener2
+      webview.src = "file://#{fixtures}/pages/partition/one.html"
+      isolatedWebview.addEventListener 'console-message', listener3
+      isolatedWebview.setAttribute 'partition', 'test'
+      isolatedWebview.src = "file://#{fixtures}/pages/partition/two.html"
+      document.body.appendChild webview
+
   describe 'new-window event', ->
     it 'emits when window.open is called', (done) ->
       webview.addEventListener 'new-window', (e) ->