Browse Source

spec: "preload" attribute of <webview>

Cheng Zhao 10 years ago
parent
commit
395b0c4224
3 changed files with 19 additions and 0 deletions
  1. 1 0
      spec/fixtures/module/preload.js
  2. 7 0
      spec/fixtures/pages/e.html
  3. 11 0
      spec/webview-spec.coffee

+ 1 - 0
spec/fixtures/module/preload.js

@@ -0,0 +1 @@
+console.log([typeof require, typeof module, typeof process].join(' '));

+ 7 - 0
spec/fixtures/pages/e.html

@@ -0,0 +1,7 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  console.log('Window script is loaded before preload script');
+</script>
+</body>
+</html>

+ 11 - 0
spec/webview-spec.coffee

@@ -47,6 +47,17 @@ describe '<webview> tag', ->
       webview.src = "file://#{fixtures}/pages/d.html"
       document.body.appendChild webview
 
+  describe 'preload attribute', ->
+    it 'loads the script before other scripts in window', (done) ->
+      listener = (e) ->
+        assert.equal e.message, 'function object object'
+        webview.removeEventListener 'console-message', listener
+        done()
+      webview.addEventListener 'console-message', listener
+      webview.setAttribute 'preload', "#{fixtures}/module/preload.js"
+      webview.src = "file://#{fixtures}/pages/e.html"
+      document.body.appendChild webview
+
   describe 'new-window event', ->
     it 'emits when window.open is called', (done) ->
       webview.addEventListener 'new-window', (e) ->