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