b2g/components/test/mochitest/test_filepicker_path.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=949944
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Permission Prompt Test</title>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 </head>
michael@0 12 <body onload="processTestCase()">
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949944"> [B2G][Helix][Browser][Wallpaper] use new File([blob], filename) to return a blob with filename when picking</a>
michael@0 14 <script type="application/javascript">
michael@0 15
michael@0 16 'use strict';
michael@0 17
michael@0 18 var testCases = [
michael@0 19 // case 1: returns blob with name
michael@0 20 { pickedResult: { success: true,
michael@0 21 result: {
michael@0 22 type: 'text/plain',
michael@0 23 blob: new Blob(['1234567890'],
michael@0 24 { type: 'text/plain' }),
michael@0 25 name: 'test1.txt'
michael@0 26 }
michael@0 27 },
michael@0 28 fileName: 'test1.txt' },
michael@0 29 // case 2: returns blob without name
michael@0 30 { pickedResult: { success: true,
michael@0 31 result: {
michael@0 32 type: 'text/plain',
michael@0 33 blob: new Blob(['1234567890'],
michael@0 34 { type: 'text/plain' })
michael@0 35 }
michael@0 36 },
michael@0 37 fileName: 'blob.txt' },
michael@0 38 // case 3: returns blob with full path name
michael@0 39 { pickedResult: { success: true,
michael@0 40 result: {
michael@0 41 type: 'text/plain',
michael@0 42 blob: new Blob(['1234567890'],
michael@0 43 { type: 'text/plain' }),
michael@0 44 name: '/full/path/test3.txt'
michael@0 45 }
michael@0 46 },
michael@0 47 fileName: 'test3.txt' },
michael@0 48 // case 4: returns blob relative path name
michael@0 49 { pickedResult: { success: true,
michael@0 50 result: {
michael@0 51 type: 'text/plain',
michael@0 52 blob: new Blob(['1234567890'],
michael@0 53 { type: 'text/plain' }),
michael@0 54 name: 'relative/path/test4.txt'
michael@0 55 }
michael@0 56 },
michael@0 57 fileName: 'test4.txt' },
michael@0 58 // case 5: returns file with name
michael@0 59 { pickedResult: { success: true,
michael@0 60 result: {
michael@0 61 type: 'text/plain',
michael@0 62 blob: new File(['1234567890'],
michael@0 63 'useless-name.txt',
michael@0 64 { type: 'text/plain' }),
michael@0 65 name: 'test5.txt'
michael@0 66 }
michael@0 67 },
michael@0 68 fileName: 'test5.txt'},
michael@0 69 // case 6: returns file without name. This case may fail because we
michael@0 70 // need to make sure the DOMFile can be sent through
michael@0 71 // sendAsyncMessage API.
michael@0 72 { pickedResult: { success: true,
michael@0 73 result: {
michael@0 74 type: 'text/plain',
michael@0 75 blob: new File(['1234567890'],
michael@0 76 'test6.txt',
michael@0 77 { type: 'text/plain' })
michael@0 78 }
michael@0 79 },
michael@0 80 todo: true,
michael@0 81 fileName: 'test6.txt'}
michael@0 82 ];
michael@0 83
michael@0 84 var chromeJS = SimpleTest.getTestFileURL('filepicker_path_handler_chrome.js');
michael@0 85 var chromeScript = SpecialPowers.loadChromeScript(chromeJS);
michael@0 86 var activeTestCase;
michael@0 87
michael@0 88 chromeScript.addMessageListener('pick-result-updated', handleMessage);
michael@0 89 chromeScript.addMessageListener('file-picked-posted', handleMessage);
michael@0 90
michael@0 91 // handle messages returned from chromeScript
michael@0 92 function handleMessage(data) {
michael@0 93 var fileInput = document.getElementById('fileInput');
michael@0 94 switch (data.type) {
michael@0 95 case 'pick-result-updated':
michael@0 96 fileInput.click();
michael@0 97 break;
michael@0 98 case 'file-picked-posted':
michael@0 99 if (activeTestCase.todo) {
michael@0 100 todo_is(fileInput.value, activeTestCase.fileName,
michael@0 101 'DOMFile should be able to send through message.');
michael@0 102 } else {
michael@0 103 is(fileInput.value, activeTestCase.fileName);
michael@0 104 }
michael@0 105 processTestCase();
michael@0 106 break;
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 function processTestCase() {
michael@0 111 if (!testCases.length) {
michael@0 112 SimpleTest.finish();
michael@0 113 return;
michael@0 114 }
michael@0 115 activeTestCase = testCases.shift();
michael@0 116 var expectedResult = activeTestCase.pickedResult;
michael@0 117 if (navigator.userAgent.indexOf('Windows') > -1 &&
michael@0 118 expectedResult.result.name) {
michael@0 119 // If we run at a window box, we need to translate the path from '/' to '\\'
michael@0 120 var name = expectedResult.result.name;
michael@0 121 name = name.replace('/', '\\');
michael@0 122 // If the name is an absolute path, we need to prepend drive letter.
michael@0 123 if (name.startsWith('\\')) {
michael@0 124 name = 'C:' + name;
michael@0 125 }
michael@0 126 // update the expected name.
michael@0 127 expectedResult.result.name = name
michael@0 128 }
michael@0 129 chromeScript.sendAsyncMessage('update-pick-result', expectedResult);
michael@0 130 }
michael@0 131
michael@0 132 </script>
michael@0 133 <input type="file" id="fileInput">
michael@0 134 </body>
michael@0 135 </html>

mercurial