Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32009 from hfiguiere/bug1201705-playlist-tab-test…
Browse files Browse the repository at this point in the history
…-part2

Bug 1201705 - Playlist tab tests part2 r=justindarc
  • Loading branch information
hfiguiere committed Sep 25, 2015
2 parents 285486b + bde58f8 commit 1b00201
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions dev_apps/music-nga/test/marionette/playlist_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,35 @@ marionette('Music player playlist', function() {
});

// XXX fixme we can't set the playcount properly it seems....
test.skip('Most played playlist sort order. moztrap:3676,3677', function() {
test('Most played playlist sort order. moztrap:3676,3677', function() {

function incrementPlayCount(filePath, value) {

var result = client.executeAsyncScript(function(filePath, value) {

var w = window.wrappedJSObject;

w.Database.getFileInfo(filePath).
then(function(song) {
var p = [];
for (var i = 0; i < value; i++) {
p.push(w.Database.incrementPlayCount(song));
}
Promise.all(p).
then(function() {
marionetteScriptFinished(null);
}).
catch(function (r) {
marionetteScriptFinished('increment-fail ' + r);
});
}).catch(function (r) {
marionetteScriptFinished('get-file-info-fail ' + r);
});

}, [filePath, value]);
assert.ok(!result);
}

try {
music.launch();
music.waitForFirstTile();
Expand All @@ -328,77 +356,53 @@ marionette('Music player playlist', function() {

music.selectAlbum('We crash computers');

music.waitForSongs(function(songs) {
return songs.length >= 6;
});

var songs = music.songs;
assert.equal(songs.length, 6);

console.log(songs);

var playCounts = {
'XOXO': 5,
'Crash': 4,

'Break': 3,
'Windows BSOD': 2,

'Yield to Thread': 1,
'Yield to thread': 1,
'Abort': 0
};

client.switchToFrame(music.activeViewFrame);
music.switchToMe();
// we set the playcount.
client.executeScript(function(songs, playCounts) {
function incrementPlayCount(filename, value) {
var w = window.wrappedJSObject;
var p = [];
for (var i = 0; i < value; i++) {
p.push(w.view.client.method('getSong', filename)
.then(function (song) {
return Database.incrementPlayCount(song);
}));
}
return Promise.all(p);
songs.forEach(function (e) {
var c = playCounts[e.title];
if (c) {
incrementPlayCount(e.filePath, c);
}

var p = [];
songs.forEach(function (e) {
var c = playCounts[e.title];
if (c) {
p.push(incrementPlayCount(e.filePath, c));
}
});

return Promise.all(p);
}, [songs, playCounts]);

music.switchToMe();
});

music.switchToPlaylistsView();

// Most played
music.selectPlaylist('Most played');
music.waitForPlaylistDetailView();

music.waitForSongs(function(songs) {
return songs.length >= 6;
});
songs = music.songs;
console.log(songs);

//assert.equal(PlaylistHelper.songIndex(songs[0]), '1');
assert.equal(songs[0].title, 'XOXO');

//assert.equal(PlaylistHelper.songIndex(songs[1]), '2');
assert.equal(songs[1].title, 'Crash');

// Trick to go back to the playlistview.
// Alternative is to tap the back button.
music.switchToAlbumsView();
music.switchToPlaylistsView();

music.tapHeaderActionButton();
music.waitForPlaylistsView();

// Least played
music.selectPlaylist('Least played');
music.waitForPlaylistDetailView();

music.waitForSongs(function(songs) {
return songs.length >= 6;
Expand Down

0 comments on commit 1b00201

Please sign in to comment.