Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
@testable import Client
6
import Foundation
7
import Shared
8
import Storage
9
10
import XCTest
11
12
class TestBookmarks: ProfileTest {
13
func testBookmarks() {
14
withTestProfile { profile -> Void in
15
for i in 0...10 {
16
let bookmark = ShareItem(url: "http://www.example.com/\(i)", title: "Example \(i)", favicon: nil)
17
_ = profile.places.createBookmark(parentGUID: BookmarkRoots.MobileFolderGUID, url: bookmark.url, title: bookmark.title).value
18
}
19
20
let expectation = self.expectation(description: "asynchronous request")
21
profile.places.getBookmarksTree(rootGUID: BookmarkRoots.MobileFolderGUID, recursive: false) >>== { folder in
22
guard let mobileFolder = folder as? BookmarkFolder else {
23
XCTFail("Should not have failed to get mock bookmarks.")
24
expectation.fulfill()
25
return
26
}
27
28
// 11 bookmarks plus our two suggested sites.
29
XCTAssertEqual(mobileFolder.children!.count, 11, "We create 11 stub bookmarks in the Mobile Bookmarks folder.")
30
let bookmark = mobileFolder.children![0]
31
XCTAssertTrue(bookmark is BookmarkItem)
32
XCTAssertTrue((bookmark as! BookmarkItem).url.hasPrefix("http://www.example.com/"), "Example URL found.")
33
expectation.fulfill()
34
}
35
36
self.waitForExpectations(timeout: 15.0, handler:nil)
37
38
// This'll do.
39
_ = profile.places.forceClose()
40
try? profile.files.remove("mock_places.db")
41
}
42
}
43
}