toolkit/components/places/tests/unit/test_317472.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_317472.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +const charset = "UTF-8";
    1.11 +const CHARSET_ANNO = "URIProperties/characterSet";
    1.12 +
    1.13 +const TEST_URI = uri("http://foo.com");
    1.14 +const TEST_BOOKMARKED_URI = uri("http://bar.com");
    1.15 +
    1.16 +function run_test()
    1.17 +{
    1.18 +  run_next_test();
    1.19 +}
    1.20 +
    1.21 +add_task(function test_execute()
    1.22 +{
    1.23 +  // add pages to history
    1.24 +  yield promiseAddVisits(TEST_URI);
    1.25 +  yield promiseAddVisits(TEST_BOOKMARKED_URI);
    1.26 +
    1.27 +  // create bookmarks on TEST_BOOKMARKED_URI
    1.28 +  var bm1 = PlacesUtils.bookmarks.insertBookmark(
    1.29 +              PlacesUtils.unfiledBookmarksFolderId,
    1.30 +              TEST_BOOKMARKED_URI, PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.31 +              TEST_BOOKMARKED_URI.spec);
    1.32 +  var bm2 = PlacesUtils.bookmarks.insertBookmark(
    1.33 +              PlacesUtils.toolbarFolderId,
    1.34 +              TEST_BOOKMARKED_URI, PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.35 +              TEST_BOOKMARKED_URI.spec);
    1.36 +
    1.37 +  // set charset on not-bookmarked page
    1.38 +  yield PlacesUtils.setCharsetForURI(TEST_URI, charset);
    1.39 +  // set charset on bookmarked page
    1.40 +  yield PlacesUtils.setCharsetForURI(TEST_BOOKMARKED_URI, charset);
    1.41 +
    1.42 +  // check that we have created a page annotation
    1.43 +  do_check_eq(PlacesUtils.annotations.getPageAnnotation(TEST_URI, CHARSET_ANNO), charset);
    1.44 +
    1.45 +  // get charset from not-bookmarked page
    1.46 +  do_check_eq((yield PlacesUtils.getCharsetForURI(TEST_URI)), charset);
    1.47 +
    1.48 +  // get charset from bookmarked page
    1.49 +  do_check_eq((yield PlacesUtils.getCharsetForURI(TEST_BOOKMARKED_URI)), charset);
    1.50 +
    1.51 +  yield promiseClearHistory();
    1.52 +
    1.53 +  // ensure that charset has gone for not-bookmarked page
    1.54 +  do_check_neq((yield PlacesUtils.getCharsetForURI(TEST_URI)), charset);
    1.55 +
    1.56 +  // check that page annotation has been removed
    1.57 +  try {
    1.58 +    PlacesUtils.annotations.getPageAnnotation(TEST_URI, CHARSET_ANNO);
    1.59 +    do_throw("Charset page annotation has not been removed correctly");
    1.60 +  } catch (e) {}
    1.61 +
    1.62 +  // ensure that charset still exists for bookmarked page
    1.63 +  do_check_eq((yield PlacesUtils.getCharsetForURI(TEST_BOOKMARKED_URI)), charset);
    1.64 +
    1.65 +  // remove charset from bookmark and check that has gone
    1.66 +  yield PlacesUtils.setCharsetForURI(TEST_BOOKMARKED_URI, "");
    1.67 +  do_check_neq((yield PlacesUtils.getCharsetForURI(TEST_BOOKMARKED_URI)), charset);
    1.68 +});

mercurial