1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/logging.h"
6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/common/media_galleries/itunes_library.h"
7a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/utility/media_galleries/itunes_library_parser.h"
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define SIMPLE_HEADER()         \
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "<plist>"                   \
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "  <dict>"                  \
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    <key>Tracks</key>"     \
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    <dict>"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define SIMPLE_TRACK(key, id, path, artist, album)                     \
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "<key>" #key "</key>"                                              \
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "<dict>"                                                           \
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "  <key>Track ID</key><integer>" #id "</integer>"                  \
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "  <key>Location</key><string>file://localhost/" path "</string>"  \
21ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    "  <key>Artist</key><string>" artist "</string>"                   \
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "  <key>Album</key><string>" album "</string>"                     \
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "</dict>"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define SIMPLE_FOOTER()  \
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    </dict>"        \
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "  </dict>"          \
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "</plist>"
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace itunes {
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace {
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid CompareTrack(const parser::Track& a, const parser::Track& b) {
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(a.id, b.id);
36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(a.location.value(), b.location.value());
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid CompareAlbum(const parser::Album& a, const parser::Album& b) {
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(a.size(), b.size());
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Album::const_iterator a_it;
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Album::const_iterator b_it;
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (a_it = a.begin(), b_it = b.begin();
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       a_it != a.end() && b_it != b.end();
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       ++a_it, ++b_it) {
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    CompareTrack(*a_it, *b_it);
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid CompareAlbums(const parser::Albums& a, const parser::Albums& b) {
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(a.size(), b.size());
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Albums::const_iterator a_it;
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Albums::const_iterator b_it;
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (a_it = a.begin(), b_it = b.begin();
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       a_it != a.end() && b_it != b.end();
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       ++a_it, ++b_it) {
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(a_it->first, b_it->first);
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    CompareAlbum(a_it->second, b_it->second);
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid CompareLibrary(const parser::Library& a, const parser::Library& b) {
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(a.size(), b.size());
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Library::const_iterator a_it;
68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Library::const_iterator b_it;
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (a_it = a.begin(), b_it = b.begin();
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       a_it != a.end() && b_it != b.end();
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       ++a_it, ++b_it) {
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(a_it->first, b_it->first);
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    CompareAlbums(a_it->second, b_it->second);
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ITunesLibraryParserTest : public testing::Test {
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ITunesLibraryParserTest() {}
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void TestParser(bool expected_result, const std::string& xml) {
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ITunesLibraryParser parser;
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(expected_result, parser.Parse(xml));
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if (!expected_result)
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      return;
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    CompareLibrary(expected_library_, parser.library());
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void AddExpectedTrack(uint32 id, const std::string& location,
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                        const std::string& artist, const std::string& album) {
93424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    // On Mac this pretends that C: is a directory.
94424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#if defined(OS_MACOSX)
95424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    std::string os_location = "/" + location;
96424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#else
97424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    const std::string& os_location = location;
98424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#endif
99424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    parser::Track track(id, base::FilePath::FromUTF8Unsafe(os_location));
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    expected_library_[artist][album].insert(track);
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser::Library expected_library_;
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ITunesLibraryParserTest);
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(ITunesLibraryParserTest, EmptyLibrary) {
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestParser(false, "");
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(ITunesLibraryParserTest, MinimalXML) {
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(1, "C:/dir/Song With Space.mp3", "Artist A", "Album A");
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestParser(
116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      true,
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_HEADER()
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(1, 1, "C:/dir/Song%20With%20Space.mp3", "Artist A",
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                   "Album A")
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_FOOTER());
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(ITunesLibraryParserTest, MultipleSongs) {
124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(1, "C:/dir/SongA1.mp3", "Artist A", "Album A");
125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(2, "C:/dir/SongA2.mp3", "Artist A", "Album A");
126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(3, "C:/dir/SongA3.mp3", "Artist A", "Album A");
127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(4, "C:/dir/SongB1.mp3", "Artist A", "Album B");
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(5, "C:/dir/SongB2.mp3", "Artist A", "Album B");
129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(6, "C:/dir2/SongB1.mp3", "Artist B", "Album B");
130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(7, "C:/dir2/SongB2.mp3", "Artist B", "Album B");
131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestParser(
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      true,
133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_HEADER()
134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(1, 1, "C:/dir/SongA1.mp3", "Artist A", "Album A")
135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(2, 2, "C:/dir/SongA2.mp3", "Artist A", "Album A")
136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(3, 3, "C:/dir/SongA3.mp3", "Artist A", "Album A")
137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(4, 4, "C:/dir/SongB1.mp3", "Artist A", "Album B")
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(5, 5, "C:/dir/SongB2.mp3", "Artist A", "Album B")
139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(6, 6, "C:/dir2/SongB1.mp3", "Artist B", "Album B")
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(7, 7, "C:/dir2/SongB2.mp3", "Artist B", "Album B")
141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_FOOTER());
142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
144868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(ITunesLibraryParserTest, MismatchedId) {
145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestParser(
146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      false,
147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_HEADER()
148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(1, 2, "C:/dir/SongA1.mp3", "Artist A", "Album A")
149868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_FOOTER());
150868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(1, "C:/dir/SongA1.mp3", "Artist A", "Album A");
152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestParser(
153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      true,
154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_HEADER()
155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(1, 1, "C:/dir/SongA1.mp3", "Artist A", "Album A")
156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(2, 3, "C:/dir/SongA2.mp3", "Artist A", "Album A")
157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_FOOTER());
158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(ITunesLibraryParserTest, OtherDictionaryEntries) {
161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AddExpectedTrack(1, "C:/dir/SongA1.mp3", "Artist A", "Album A");
162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestParser(
163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      true,
164868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "<plist>"
165868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "  <dict>"
166868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "    <key>Other section</key>"
167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "    <dict>"
168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // In Other section, not Tracks.
169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(10, 10, "C:/dir/SongB2.mp3", "Artist B", "Album B")
170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "    </dict>"
171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "    <key>Tracks</key>"
172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "    <dict>"
173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "      <key>1</key>"
174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "      <dict>"
175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // In the body of a track dictionary before the interesting entries.
176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(20, 20, "C:/dir/SongB2.mp3", "Artist B", "Album B")
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // Entries in a different order.
178ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "        <key>Artist</key><string>Artist A</string>"
179868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "        <key>Location</key>"
180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "          <string>file://localhost/C:/dir/SongA1.mp3</string>"
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "        <key>Album</key><string>Album A</string>"
182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "        <key>Track ID</key><integer>1</integer>"
183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // In the body of a track dictionary after the interesting entries.
184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_TRACK(30, 30, "C:/dir/SongB3.mp3", "Artist B", "Album B")
185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "      </dict>"
186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "      <key>40</key>"
187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "      <dict>"
188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // Missing album name.
189ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "        <key>Artist</key><string>Artist B</string>"
190868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "        <key>Location</key>"
191868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "          <string>file://localhost/C:/dir/SongB4.mp3</string>"
192868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "        <key>Track ID</key><integer>1</integer>"
193868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "      </dict>"
194868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      SIMPLE_FOOTER());
195868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
197ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochTEST_F(ITunesLibraryParserTest, MissingEntry) {
198ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(1, "C:/dir/SongA1.mp3", "Artist A", "Album A");
199ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(3, "C:/dir/SongA3.mp3", "Artist A", "Album A");
200ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  TestParser(
201ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      true,
202ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_HEADER()
203ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_TRACK(1, 1, "C:/dir/SongA1.mp3", "Artist A", "Album A")
204ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>2</key><dict>"
205ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>2</integer>"
206ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album</key><string>Album A</string>"
207ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Foo</key><string>Bar</string>"
208ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "   "  // A whitespace node is important for the test.
209ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
210ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_TRACK(3, 3, "C:/dir/SongA3.mp3", "Artist A", "Album A")
211ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_FOOTER());
212ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
213ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
214ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochTEST_F(ITunesLibraryParserTest, UnknownAlbumOrArtist) {
215ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(1, "C:/dir/SongA1.mp3", "Artist A", "Unknown Album");
216ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(2, "C:/dir/SongA2.mp3", "Unknown Artist", "Album A");
217ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(3, "C:/dir/SongA3.mp3", "Unknown Artist", "Unknown Album");
218ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  TestParser(
219ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      true,
220ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_HEADER()
221ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>1</key><dict>"
222ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>1</integer>"
223ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA1.mp3</string>"
224ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Artist</key><string>Artist A</string>"
225ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
226ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>2</key><dict>"
227ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>2</integer>"
228ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA2.mp3</string>"
229ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album</key><string>Album A</string>"
230ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
231ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>3</key><dict>"
232ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>3</integer>"
233ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA3.mp3</string>"
234ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
235ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_FOOTER());
236ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
237ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
238ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochTEST_F(ITunesLibraryParserTest, AlbumArtist) {
239ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(1, "C:/dir/SongA1.mp3", "Artist A", "Unknown Album");
240ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(2, "C:/dir/SongA2.mp3", "Artist A", "Unknown Album");
241ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(3, "C:/dir/SongA3.mp3", "Artist A", "Unknown Album");
242ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  AddExpectedTrack(4, "C:/dir/SongA4.mp3", "Artist A", "Album");
243ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  TestParser(
244ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      true,
245ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_HEADER()
246ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>1</key><dict>"
247ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>1</integer>"
248ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA1.mp3</string>"
249ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album Artist</key><string>Artist A</string>"
250ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
251ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>2</key><dict>"
252ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>2</integer>"
253ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA2.mp3</string>"
254ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Artist</key><string>Artist B</string>"
255ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album Artist</key><string>Artist A</string>"
256ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
257ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>3</key><dict>"
258ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>3</integer>"
259ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA3.mp3</string>"
260ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album Artist</key><string>Artist A</string>"
261ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Artist</key><string>Artist B</string>"
262ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
263ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "<key>4</key><dict>"
264ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Track ID</key><integer>4</integer>"
265ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Location</key><string>file://localhost/C:/dir/SongA4.mp3</string>"
266ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album</key><string>Album</string>"
267ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Artist</key><string>Artist B</string>"
268ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "  <key>Album Artist</key><string>Artist A</string>"
269ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      "</dict>"
270ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SIMPLE_FOOTER());
271ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
272ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
273424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(ITunesLibraryParserTest, MacPath) {
274424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  AddExpectedTrack(1, "dir/Song With Space.mp3", "Artist A", "Album A");
275424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  TestParser(
276424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      true,
277424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      SIMPLE_HEADER()
278424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      // This path is concatenated with "http://localhost/", so no leading
279424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      // slash should be used.
280424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      SIMPLE_TRACK(1, 1, "dir/Song%20With%20Space.mp3", "Artist A", "Album A")
281424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      SIMPLE_FOOTER());
282424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
283424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace itunes
287