summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qmltests/data/filesystemapi.html
blob: ab1a33e4d601f79b42f9bbc8c5e24c36b4fb8980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Failed to Upload </title>
</script>
</head>

<body>
<button>Request File Picker</button>
<script>
 async function handleDirectoryEntry( dirHandle, out ) {
     for await (const entry of dirHandle.values()) {
         if (entry.kind === "file"){
             const file = await entry.getFile();
             out[ file.name ] = file;
         }
         if (entry.kind === "directory") {
             const newHandle = await dirHandle.getDirectoryHandle( entry.name, { create: false } );
             const newOut = out[ entry.name ] = {};
             await handleDirectoryEntry( newHandle, newOut );
         }
     }
 }
    const button = document.querySelector('button');
    button.addEventListener('click', async function() {
    switch(window.dialogType) {
        case "savePicker":
           const saveFileHandle = await window.showSaveFilePicker();
           const writable = await saveFileHandle.createWritable();
           await writable.write(new Blob(['TEST_CONTENT']));
           await writable.close();
           console.log("TEST:DONE")
           break;
       case "filePicker":
            let [openFileHandle] = await window.showOpenFilePicker();
            const options = {};
            options.mode = 'readwrite'
            await openFileHandle.requestPermission(options)
            const file = await openFileHandle.getFile();
            const contents = await file.text();
            console.log("TEST:" + contents)
            console.log("TEST:DONE")
            break;
       case "directoryPicker":
            console.log("start")
            const dirHandle = await window.showDirectoryPicker();
            for await (const entry of dirHandle.values()) {
                if (entry.kind === "file"){
                    continue
                }
                if (entry.kind === "directory") {
                    console.log("TEST:" + entry.name)
                }
            }
            console.log("TEST:DONE")
            break;
       default:
    }
    });
    window.onload = function() {
    window.dialogType = window.location.href.split('=')[1];
    document.querySelector('button').focus()
    }
</script>
</body>
</html>