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.

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

mercurial