|
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 const charset = "UTF-8"; |
|
8 const CHARSET_ANNO = "URIProperties/characterSet"; |
|
9 |
|
10 const TEST_URI = uri("http://foo.com"); |
|
11 const TEST_BOOKMARKED_URI = uri("http://bar.com"); |
|
12 |
|
13 function run_test() |
|
14 { |
|
15 run_next_test(); |
|
16 } |
|
17 |
|
18 add_task(function test_execute() |
|
19 { |
|
20 // add pages to history |
|
21 yield promiseAddVisits(TEST_URI); |
|
22 yield promiseAddVisits(TEST_BOOKMARKED_URI); |
|
23 |
|
24 // create bookmarks on TEST_BOOKMARKED_URI |
|
25 var bm1 = PlacesUtils.bookmarks.insertBookmark( |
|
26 PlacesUtils.unfiledBookmarksFolderId, |
|
27 TEST_BOOKMARKED_URI, PlacesUtils.bookmarks.DEFAULT_INDEX, |
|
28 TEST_BOOKMARKED_URI.spec); |
|
29 var bm2 = PlacesUtils.bookmarks.insertBookmark( |
|
30 PlacesUtils.toolbarFolderId, |
|
31 TEST_BOOKMARKED_URI, PlacesUtils.bookmarks.DEFAULT_INDEX, |
|
32 TEST_BOOKMARKED_URI.spec); |
|
33 |
|
34 // set charset on not-bookmarked page |
|
35 yield PlacesUtils.setCharsetForURI(TEST_URI, charset); |
|
36 // set charset on bookmarked page |
|
37 yield PlacesUtils.setCharsetForURI(TEST_BOOKMARKED_URI, charset); |
|
38 |
|
39 // check that we have created a page annotation |
|
40 do_check_eq(PlacesUtils.annotations.getPageAnnotation(TEST_URI, CHARSET_ANNO), charset); |
|
41 |
|
42 // get charset from not-bookmarked page |
|
43 do_check_eq((yield PlacesUtils.getCharsetForURI(TEST_URI)), charset); |
|
44 |
|
45 // get charset from bookmarked page |
|
46 do_check_eq((yield PlacesUtils.getCharsetForURI(TEST_BOOKMARKED_URI)), charset); |
|
47 |
|
48 yield promiseClearHistory(); |
|
49 |
|
50 // ensure that charset has gone for not-bookmarked page |
|
51 do_check_neq((yield PlacesUtils.getCharsetForURI(TEST_URI)), charset); |
|
52 |
|
53 // check that page annotation has been removed |
|
54 try { |
|
55 PlacesUtils.annotations.getPageAnnotation(TEST_URI, CHARSET_ANNO); |
|
56 do_throw("Charset page annotation has not been removed correctly"); |
|
57 } catch (e) {} |
|
58 |
|
59 // ensure that charset still exists for bookmarked page |
|
60 do_check_eq((yield PlacesUtils.getCharsetForURI(TEST_BOOKMARKED_URI)), charset); |
|
61 |
|
62 // remove charset from bookmark and check that has gone |
|
63 yield PlacesUtils.setCharsetForURI(TEST_BOOKMARKED_URI, ""); |
|
64 do_check_neq((yield PlacesUtils.getCharsetForURI(TEST_BOOKMARKED_URI)), charset); |
|
65 }); |