blob: 7df99a14ebfa15b477f737902ecf227227da0f67 [file] [log] [blame]
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +02001<!doctype html>
2<html lang="en">
3
4 <head>
5 <meta charset="utf-8">
6
7 <title>reveal.js - Test Iframe Backgrounds</title>
8
9 <link rel="stylesheet" href="../dist/reveal.css">
10 <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
11 <script src="../node_modules/qunit/qunit/qunit.js"></script>
12 </head>
13
14 <body style="overflow: auto;">
15
16 <div id="qunit"></div>
17 <div id="qunit-fixture"></div>
18
19 <div class="reveal" style="display: none;">
20
21 <div class="slides">
22
23 <section data-background-iframe="https://revealjs.com">1</section>
24 <section data-background-iframe="https://revealjs.com">2</section>
25 <section data-background-iframe="https://revealjs.com" data-preload>3</section>
26 <section data-background-iframe="https://revealjs.com">4</section>
27 <section data-background-iframe="https://revealjs.com">5</section>
28 <section data-background-iframe="https://revealjs.com">6</section>
29
30 </div>
31
32 </div>
33
34 <script src="../dist/reveal.js"></script>
35 <script>
36
Marc Kupietz09b75752023-10-07 09:32:19 +020037 QUnit.config.testTimeout = 30000;
38
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020039 Reveal.initialize({ viewDistance: 3 }).then( () => {
40
41 function getIframe( index ) {
42 return document.querySelectorAll( '.slide-background' )[index].querySelector( 'iframe' );
43 }
44
45 QUnit.module( 'Iframe' );
46
47 QUnit.test( 'Using default settings', function( assert ) {
48
49 Reveal.slide(0);
50 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );
51
52 Reveal.slide(1);
53 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
54
55 Reveal.slide(0);
56 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' );
57
58 });
59
60 QUnit.test( 'Using data-preload', function( assert ) {
61
62 Reveal.slide(1);
63 assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
64 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
65
66 Reveal.slide(0);
67 assert.strictEqual( getIframe(3).hasAttribute( 'src' ), false, 'unloads outside of viewDistance' );
68
69 });
70
71 QUnit.test( 'Using preloadIframes: true', function( assert ) {
72
73 Reveal.configure({ preloadIframes: true });
74
75 Reveal.slide(1);
76 assert.strictEqual( getIframe(0).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
77 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
78 assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
79
80 });
81
82 QUnit.test( 'Using preloadIframes: false', function( assert ) {
83
84 Reveal.configure({ preloadIframes: false });
85
86 Reveal.slide(0);
87 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
88 assert.strictEqual( getIframe(2).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
89
90 Reveal.slide(1);
91 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
92
93
94 });
95
96 } );
97 </script>
98
99 </body>
100</html>