]> khamidou — GitHub mirrors - electron.git/commitdiff
Add spec for sanbox attribute of iframe.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 14:04:41 +0000 (22:04 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 14:04:41 +0000 (22:04 +0800)
spec/chromium-spec.coffee
spec/fixtures/pages/change-parent.html [new file with mode: 0644]

index d23294210c2fba7c908c9e91cc776eda861da598..91461a3e00a23ec4800fb781092f1227931b1762 100644 (file)
@@ -1,6 +1,9 @@
 assert = require 'assert'
+path = require 'path'
 
 describe 'chromium feature', ->
+  fixtures = path.resolve __dirname, 'fixtures'
+
   describe 'heap snapshot', ->
     it 'does not crash', ->
       process.atomBinding('v8_util').takeHeapSnapshot()
@@ -21,3 +24,18 @@ describe 'chromium feature', ->
       b = window.open 'about:blank', 'test', 'show=no'
       assert.equal b.constructor.name, 'BrowserWindow'
       b.destroy()
+
+  describe 'iframe with sandbox attribute', ->
+    it 'can not modify parent', (done) ->
+      page = path.join fixtures, 'pages', 'change-parent.html'
+      global.changedByIframe = false
+
+      iframe = $('<iframe sandbox="allow-scripts">')
+      iframe.hide()
+      iframe.attr 'src', "file://#{page}"
+      iframe.appendTo 'body'
+      isChanged = ->
+        iframe.remove()
+        assert.equal global.changedByIframe, false
+        done()
+      setTimeout isChanged, 30
diff --git a/spec/fixtures/pages/change-parent.html b/spec/fixtures/pages/change-parent.html
new file mode 100644 (file)
index 0000000..6a60f6c
--- /dev/null
@@ -0,0 +1,8 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  console.log('ready2')
+  window.parent.changedByIframe = true;
+</script>
+</body>
+</html>