| 1 |
import { isEmbedded } from '@shared/lib/embedded-guard'; |
| 2 |
|
| 3 |
describe('isEmbedded', () => { |
| 4 |
it('reports not-embedded on a top-level window (self === top)', () => { |
| 5 |
const win = {}; |
| 6 |
win.self = win; |
| 7 |
win.top = win; |
| 8 |
expect(isEmbedded(win)).toBe(false); |
| 9 |
}); |
| 10 |
|
| 11 |
it('reports embedded when framed (self !== top)', () => { |
| 12 |
const win = { self: {}, top: {} }; |
| 13 |
expect(isEmbedded(win)).toBe(true); |
| 14 |
}); |
| 15 |
|
| 16 |
it('treats a cross-origin parent (top access throws) as embedded', () => { |
| 17 |
const win = { self: {} }; |
| 18 |
Object.defineProperty(win, 'top', { |
| 19 |
get() { |
| 20 |
throw new Error('SecurityError: cross-origin frame'); |
| 21 |
}, |
| 22 |
}); |
| 23 |
expect(isEmbedded(win)).toBe(true); |
| 24 |
}); |
| 25 |
|
| 26 |
it('defaults to the real (top-level) window → not embedded', () => { |
| 27 |
expect(isEmbedded()).toBe(false); |
| 28 |
}); |
| 29 |
}); |
| 30 |
|