@@ -9,6 +9,96 @@ exports["test main"] = function(assert) {
9
9
// if (require("sdk/system/runtime").OS == 'Linux') {
10
10
// }
11
11
12
+
13
+ function mpsites_upload_jquery ( ) {
14
+ return {
15
+ on : function ( x , cb ) {
16
+ if ( x === 'drop' ) {
17
+ cb ( {
18
+ originalEvent : {
19
+ dataTransfer : { files :[ { name :'test.mpsites' } ] }
20
+ } ,
21
+ preventDefault : function ( ) { } ,
22
+ stopPropagation : function ( ) { }
23
+ } ) ;
24
+ }
25
+ } ,
26
+ append : function ( ) { }
27
+ } ;
28
+ }
29
+ mpsites_upload_jquery . each = function ( ar , cb ) {
30
+ for ( var x in ar ) {
31
+ if ( ! ar . hasOwnProperty ( x ) ) continue ;
32
+ cb . apply ( ar [ x ] , [ x , ar [ x ] ] ) ;
33
+ }
34
+ } ;
35
+
36
+ exports [ "test mpsites upload invalid" ] = function ( assert ) {
37
+ var self = require ( "sdk/self" ) ;
38
+ const { sandbox, evaluate, load } = require ( "sdk/loader/sandbox" ) ;
39
+ var got_alert_not_mpsites = false ;
40
+ var scope = sandbox ( ) ;
41
+ scope . window = {
42
+ 'addEventListener' : function ( ) { }
43
+ } ;
44
+ scope . document = { } ;
45
+ scope . console = console ;
46
+ scope . confirm = function ( m ) { return true ; } ;
47
+ scope . alert = function ( m ) { if ( / N o t a m p s i t e s .f i l e / . test ( m ) ) got_alert_not_mpsites = true ; } ;
48
+ scope . $ = mpsites_upload_jquery ;
49
+ scope . FileReader = function ( ) { this . onload = function ( ) { console . error ( 'test failed, onload should be set!' ) ; } ; } ;
50
+ scope . FileReader . prototype . readAsText = function ( ) {
51
+ this . onload ( { target :{ result :"invalid..not.a.mpsites.file" } } ) ;
52
+ } ;
53
+ load ( scope , self . data . url ( 'config.js' ) ) ;
54
+
55
+ assert . ok ( got_alert_not_mpsites ) ;
56
+ } ;
57
+
58
+ exports [ "test mpsites upload valid" ] = function ( assert ) {
59
+ var self = require ( "sdk/self" ) ;
60
+ const { sandbox, evaluate, load } = require ( "sdk/loader/sandbox" ) ;
61
+
62
+ var file = [ '# Master Password site export' ,
63
+ '# Export of site names and stored passwords (unless device-private) encrypted with the master key.' ,
64
+ '# ' , '##' , '# Format: 1' , '# Date: 2015-09-30T10:15:25Z' , '# User Name: test' , '# Full Name: test' ,
65
+ '# Avatar: 0' ,
66
+ '# Version: 2.2' , '# Algorithm: 3' , '# Default Type: 17' , '# Passwords: PROTECTED' ,
67
+ '##' , '#' ,
68
+ '# Last Times Password Login\t Site\tSite' ,
69
+ '# used used type name\t name\tpassword' ,
70
+ '2015-09-30T10:14:31Z 0 16:1:6 \t asite\t' ,
71
+ '2015-09-30T10:14:39Z 0 18:1:4 \t åsite\t'
72
+ ] . join ( '\n' ) ;
73
+
74
+ var version_mismatch_received = false ;
75
+ var event_received ;
76
+ var scope = sandbox ( ) ;
77
+ scope . window = {
78
+ 'addEventListener' : function ( ) { }
79
+ } ;
80
+ scope . document = {
81
+ createEvent :function ( ) { return { initCustomEvent :function ( ) { this . sites = arguments [ 3 ] ; } } ; } ,
82
+ documentElement :{ dispatchEvent : function ( e ) { event_received = e ; } }
83
+ } ;
84
+ scope . console = console ;
85
+ scope . confirm = function ( m ) { return true ; } ;
86
+ scope . alert = function ( m ) { if ( / V e r s i o n m i s m a t c h / . test ( m ) ) version_mismatch_received = true ; } ;
87
+ scope . $ = mpsites_upload_jquery ;
88
+ scope . FileReader = function ( ) { this . onload = function ( ) { console . error ( 'test failed, onload should be set!' ) ; } ; } ;
89
+ scope . FileReader . prototype . readAsText = function ( ) {
90
+ this . onload ( { target :{ result :file } } ) ;
91
+ } ;
92
+ load ( scope , self . data . url ( 'config.js' ) ) ;
93
+ assert . ok ( version_mismatch_received ) ;
94
+ assert . ok ( 'asite' in event_received . sites ) ;
95
+ assert . ok ( 'åsite' in event_received . sites ) ;
96
+ assert . equal ( event_received . sites . asite . asite . generation , 6 ) ;
97
+ assert . equal ( event_received . sites . asite . asite . type , 'x' ) ;
98
+ assert . equal ( event_received . sites [ 'åsite' ] [ 'åsite' ] . generation , 4 ) ;
99
+ assert . equal ( event_received . sites [ 'åsite' ] [ 'åsite' ] . type , 'm' ) ;
100
+ } ;
101
+
12
102
exports [ "test main handlers" ] = function ( assert , async_test_done ) {
13
103
var self = require ( "sdk/self" ) ;
14
104
const { sandbox, evaluate, load } = require ( "sdk/loader/sandbox" ) ;
0 commit comments