Browse Source

fix: refactoring regression in LocationProxy (#19494)

Milan Burda 5 years ago
parent
commit
922a4d9ba6
2 changed files with 19 additions and 3 deletions
  1. 3 3
      lib/renderer/window-setup.ts
  2. 16 0
      spec/chromium-spec.js

+ 3 - 3
lib/renderer/window-setup.ts

@@ -69,19 +69,19 @@ class LocationProxy {
    */
   private static ProxyProperty<T> (target: LocationProxy, propertyKey: LocationProperties) {
     Object.defineProperty(target, propertyKey, {
-      get: function (): T | string {
+      get: function (this: LocationProxy): T | string {
         const guestURL = this.getGuestURL()
         const value = guestURL ? guestURL[propertyKey] : ''
         return value === undefined ? '' : value
       },
-      set: function (newVal: T) {
+      set: function (this: LocationProxy, newVal: T) {
         const guestURL = this.getGuestURL()
         if (guestURL) {
           // TypeScript doesn't want us to assign to read-only variables.
           // It's right, that's bad, but we're doing it anway.
           (guestURL as any)[propertyKey] = newVal
 
-          return this.ipcRenderer.sendSync(
+          return ipcRendererInternal.sendSync(
             'ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC',
             this.guestId, 'loadURL', guestURL.toString())
         }

+ 16 - 0
spec/chromium-spec.js

@@ -520,6 +520,22 @@ describe('chromium feature', () => {
       b = window.open('about:blank')
     })
 
+    it('defines a window.location.href setter', (done) => {
+      let b = null
+      app.once('browser-window-created', (event, { webContents }) => {
+        webContents.once('did-finish-load', () => {
+          // When it loads, redirect
+          b.location.href = `file://${fixtures}/pages/base-page.html`
+          webContents.once('did-finish-load', () => {
+            // After our second redirect, cleanup and callback
+            b.close()
+            done()
+          })
+        })
+      })
+      b = window.open('about:blank')
+    })
+
     it('open a blank page when no URL is specified', async () => {
       const browserWindowCreated = emittedOnce(app, 'browser-window-created')
       const w = window.open()