Browse Source

fix: default prop of location should be empty str

Cheng Zhao 6 years ago
parent
commit
ca7dec2082

+ 2 - 1
lib/renderer/window-setup.js

@@ -70,7 +70,8 @@ function LocationProxy (ipcRenderer, guestId) {
     return {
       get: function () {
         const guestURL = getGuestURL()
-        return guestURL ? guestURL[property] : ''
+        const value = guestURL ? guestURL[property] : ''
+        return value === undefined ? '' : value
       },
       set: function (newVal) {
         const guestURL = getGuestURL()

+ 1 - 1
spec/api-browser-window-spec.js

@@ -3480,7 +3480,7 @@ describe('BrowserWindow module', () => {
       iw.loadURL('about:blank')
       iw.webContents.executeJavaScript(`
         const opened = window.open()
-        openedLocation = opened.location
+        openedLocation = opened.location.href
         opened.close()
         window.postMessage({openedLocation}, '*')
       `)

+ 4 - 4
spec/chromium-spec.js

@@ -545,14 +545,14 @@ describe('chromium feature', () => {
         webContents.once('did-finish-load', () => {
           const { location } = b
           b.close()
-          assert.strictEqual(location, 'about:blank')
+          assert.strictEqual(location.href, 'about:blank')
 
           let c = null
           app.once('browser-window-created', (event, { webContents }) => {
             webContents.once('did-finish-load', () => {
               const { location } = c
               c.close()
-              assert.strictEqual(location, 'about:blank')
+              assert.strictEqual(location.href, 'about:blank')
               done()
             })
           })
@@ -645,7 +645,7 @@ describe('chromium feature', () => {
 
     it('does nothing when origin of current window does not match opener', (done) => {
       listener = (event) => {
-        assert.strictEqual(event.data, null)
+        assert.strictEqual(event.data, '')
         done()
       }
       window.addEventListener('message', listener)
@@ -694,7 +694,7 @@ describe('chromium feature', () => {
     it('does nothing when origin of webview src URL does not match opener', (done) => {
       webview = new WebView()
       webview.addEventListener('console-message', (e) => {
-        assert.strictEqual(e.message, 'null')
+        assert.strictEqual(e.message, '')
         done()
       })
       webview.setAttribute('allowpopups', 'on')

+ 1 - 1
spec/fixtures/pages/window-opener-location.html

@@ -1,7 +1,7 @@
 <html>
 <body>
 <script type="text/javascript" charset="utf-8">
-  window.opener.postMessage(window.opener.location, '*')
+  window.opener.postMessage(window.opener.location.href, '*')
 </script>
 </body>
 </html>