(docUrl)
| 1825 | }); |
| 1826 | |
| 1827 | function attach(docUrl) { |
| 1828 | const hostElement = win.document.createElement('div'); |
| 1829 | win.document.body.appendChild(hostElement); |
| 1830 | const importDoc = win.document.implementation.createHTMLDocument(''); |
| 1831 | const shadowRoot = createShadowRoot(hostElement); |
| 1832 | const ampdoc = new AmpDocShadow(win, docUrl, shadowRoot); |
| 1833 | |
| 1834 | ampdocServiceMock |
| 1835 | .expects('installShadowDoc') |
| 1836 | .withArgs( |
| 1837 | docUrl, |
| 1838 | env.sandbox.match((arg) => arg == getShadowRoot(hostElement)) |
| 1839 | ) |
| 1840 | .returns(ampdoc) |
| 1841 | .atLeast(0); |
| 1842 | ampdocServiceMock |
| 1843 | .expects('getAmpDoc') |
| 1844 | .withExactArgs( |
| 1845 | env.sandbox.match((arg) => arg == getShadowRoot(hostElement)) |
| 1846 | ) |
| 1847 | .returns(ampdoc) |
| 1848 | .atLeast(0); |
| 1849 | |
| 1850 | const amp = win.AMP.attachShadowDoc(hostElement, importDoc, docUrl); |
| 1851 | const viewer = getServiceForDoc(ampdoc, 'viewer'); |
| 1852 | const broadcastReceived = env.sandbox.spy(); |
| 1853 | viewer.onBroadcast(broadcastReceived); |
| 1854 | const onMessage = env.sandbox.stub(); |
| 1855 | amp.onMessage(function (eventType, data) { |
| 1856 | if (eventType == 'ignore') { |
| 1857 | return Promise.resolve(); |
| 1858 | } |
| 1859 | return onMessage(eventType, data); |
| 1860 | }); |
| 1861 | return { |
| 1862 | hostElement, |
| 1863 | amp, |
| 1864 | ampdoc, |
| 1865 | viewer, |
| 1866 | broadcastReceived, |
| 1867 | onMessage, |
| 1868 | }; |
| 1869 | } |
| 1870 | |
| 1871 | it('should broadcast to all but sender', () => { |
| 1872 | doc1.viewer.broadcast({test: 1}); |
no test coverage detected