This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
manage_test.js
210 lines (175 loc) · 7.34 KB
/
manage_test.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* jshint node: true*/
/* global marionette, setup, suite, test*/
'use strict';
var assert = require('assert');
var Ringtones = require('./lib/ringtones');
var Settings = require('../../../settings/test/marionette/app/app');
var Music = require('../../../music/test/marionette/lib/music');
function assert_sorted(array, message) {
if (array.length === 0) {
return;
}
var prevElt = array[0];
for (var i = 1; i < array.length; i++) {
assert(prevElt.localeCompare(array[i]) < 0, message);
prevElt = array[i];
}
}
marionette('Ringtone management', function() {
var client = marionette.client({
prefs: {
'device.storage.enabled': true,
'device.storage.testing': true,
'device.storage.prompt.testing': true
}
});
var app, settingsApp;
var soundPanel;
setup(function() {
settingsApp = new Settings(client);
app = new Ringtones(client);
client.fileManager.removeAllFiles();
client.fileManager.add([
{ type: 'music', filePath: 'test_media/samples/Music/b2g.ogg' }
]);
settingsApp.launch();
soundPanel = settingsApp.soundPanel;
});
suite('Manage ringtones', function() {
test('Load list of sounds', function() {
app.inManager(soundPanel, function(container) {
var soundLists = container.soundLists;
assert.equal(soundLists.length, 2,
'Should have found 2 sound lists');
assert.equal(soundLists[0].header.getAttribute('data-l10n-id'),
'list-title-ringtone');
assert.equal(soundLists[1].header.getAttribute('data-l10n-id'),
'list-title-custom');
assert.notEqual(soundLists[0].sounds.length, 0,
'Built-in ringtone list should not be empty');
assert.equal(soundLists[1].sounds.length, 0,
'Custom ringtone list should be empty');
assert.equal(soundLists[0].displayed(), true,
'Built-in ringtone list should be displayed');
assert.equal(soundLists[1].displayed(), false,
'Custom ringtone list should be hidden');
var names = soundLists[0].sounds.map(function(element) {
return element.name.toLocaleLowerCase();
});
assert_sorted(names, 'Tones should be sorted by name');
});
});
test('Load custom sound', function() {
// Inject a custom ringtone, then close and reopen the app to show it.
app.inManager(soundPanel, function(container) {
var tone = container.addCustomRingtone({
name: 'My ringtone', subtitle: 'Bob\'s Ringtones'
});
assert.equal(tone.name, 'My ringtone');
assert.equal(tone.subtitle, 'Bob\'s Ringtones');
container.backButton.tap();
});
app.inManager(soundPanel, function(container) {
var customSounds = container.soundLists[1];
assert.equal(customSounds.sounds.length, 1,
'Custom ringtone list should have one item');
assert.equal(customSounds.displayed(), true,
'Custom ringtone list should be displayed');
var myTone = customSounds.sounds[0];
assert.equal(myTone.name, 'My ringtone');
assert.equal(myTone.subtitle, 'Bob\'s Ringtones');
});
});
test('Open action menu for built-in ringtone', function() {
app.inManager(soundPanel, function(container) {
var actionsMenu = container.soundLists[0].sounds[0].openActions();
assert.equal(actionsMenu.shareButton.displayed(), true,
'Share button should be displayed');
assert.equal(actionsMenu.deleteButton.displayed(), false,
'Delete button should be hidden');
});
});
test('Open action menu for custom ringtone', function() {
// Inject a custom ringtone, then close and reopen the app to show it.
app.inManager(soundPanel, function(container) {
container.addCustomRingtone({
name: 'My ringtone', subtitle: 'Bob\'s Ringtones'
});
container.backButton.tap();
});
app.inManager(soundPanel, function(container) {
var customSounds = container.soundLists[1];
assert.equal(customSounds.sounds.length, 1,
'Custom ringtone list should have one item');
assert.equal(customSounds.displayed(), true,
'Custom ringtone list should be displayed');
var actionsMenu = customSounds.sounds[0].openActions();
assert.equal(actionsMenu.shareButton.displayed(), true,
'Share button should be displayed');
assert.equal(actionsMenu.deleteButton.displayed(), true,
'Delete button should be displayed');
});
});
test('Share ringtone', function() {
app.inManager(soundPanel, function(container) {
// Make sure we get at least as far as being able to share to the SMS
// app. XXX: Later, this could be more detailed and actually check that
// the right data was sent...
var actionsMenu = container.soundLists[0].sounds[0].openActions();
actionsMenu.shareButton.tap();
// Make sure we can't share with ourselves, since that's weird.
assert.equal(actionsMenu.shareWith('Ringtones'), null,
'Ringtones app shouldn\'t be in Share menu');
// Share with the messages app.
actionsMenu.shareWith('Messages').tap();
});
});
test('Delete ringtone', function() {
// Inject a custom ringtone, then close and reopen the app to show it.
app.inManager(soundPanel, function(container) {
container.addCustomRingtone({
name: 'My ringtone', subtitle: 'Bob\'s Ringtones'
});
container.backButton.tap();
});
app.inManager(soundPanel, function(container) {
var customSounds = container.soundLists[1];
var numTones = customSounds.sounds.length;
var actionsMenu = customSounds.sounds[0].openActions();
actionsMenu.deleteButton.tap();
var dialog = actionsMenu.waitForDialog();
dialog.cancelButton.tap();
assert.equal(customSounds.sounds.length, numTones,
'Tone should not have been deleted');
actionsMenu = customSounds.sounds[0].openActions();
actionsMenu.deleteButton.tap();
dialog = actionsMenu.waitForDialog();
dialog.confirmButton.tap();
assert.equal(customSounds.sounds.length, numTones - 1,
'Tone should have been deleted');
});
});
test('Create new ringtone', function() {
var musicApp = new Music(client);
app.inManager(soundPanel, function(container) {
container.addButton.tap();
musicApp.switchToMe();
musicApp.playFirstSong();
musicApp.finishPick();
container.waitForNewRingtoneWindow(function(win) {
win.waitForSongInfo('Boot To Gecko (B2G)', 'Minute With');
win.saveButton.tap();
});
var customSounds = container.soundLists[1];
client.waitFor(function() {
return customSounds.sounds.length === 1;
});
assert.equal(customSounds.displayed(), true,
'Custom ringtone list should be displayed');
var myTone = customSounds.sounds[0];
assert.equal(myTone.name, 'Boot To Gecko (B2G)');
assert.equal(myTone.subtitle, 'Minute With');
});
});
});
});