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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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/. */
     7 const bmsvc = PlacesUtils.bookmarks;
     8 const testFolderId = PlacesUtils.bookmarksMenuFolderId;
    10 // main
    11 function run_test() {
    12   var testURI = uri("http://foo.com");
    14   /*
    15   1. Create a bookmark for a URI, with a keyword and post data.
    16   2. Create a bookmark for the same URI, with a different keyword and different post data.
    17   3. Confirm that our method for getting a URI+postdata retains bookmark affinity.
    18   */
    19   var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
    20   bmsvc.setKeywordForBookmark(bm1, "foo");
    21   PlacesUtils.setPostDataForBookmark(bm1, "pdata1");
    22   var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
    23   bmsvc.setKeywordForBookmark(bm2, "bar");
    24   PlacesUtils.setPostDataForBookmark(bm2, "pdata2");
    26   // check kw, pd for bookmark 1
    27   var url, postdata;
    28   [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo");
    29   do_check_eq(testURI.spec, url);
    30   do_check_eq(postdata, "pdata1");
    32   // check kw, pd for bookmark 2
    33   [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("bar");
    34   do_check_eq(testURI.spec, url);
    35   do_check_eq(postdata, "pdata2");
    37   // cleanup
    38   bmsvc.removeItem(bm1);
    39   bmsvc.removeItem(bm2);
    41   /*
    42   1. Create two bookmarks with the same URI and keyword.
    43   2. Confirm that the most recently created one is returned for that keyword.
    44   */
    45   var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
    46   bmsvc.setKeywordForBookmark(bm1, "foo");
    47   PlacesUtils.setPostDataForBookmark(bm1, "pdata1");
    48   var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
    49   bmsvc.setKeywordForBookmark(bm2, "foo");
    50   PlacesUtils.setPostDataForBookmark(bm2, "pdata2");
    52   var bm1da = bmsvc.getItemDateAdded(bm1);
    53   var bm1lm = bmsvc.getItemLastModified(bm1);
    54   LOG("bm1 dateAdded: " + bm1da + ", lastModified: " + bm1lm);
    55   var bm2da = bmsvc.getItemDateAdded(bm2);
    56   var bm2lm = bmsvc.getItemLastModified(bm2);
    57   LOG("bm2 dateAdded: " + bm2da + ", lastModified: " + bm2lm);
    58   do_check_true(bm1da <= bm2da);
    59   do_check_true(bm1lm <= bm2lm);
    61   [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo");
    62   do_check_eq(testURI.spec, url);
    63   do_check_eq(postdata, "pdata2");
    65   // cleanup
    66   bmsvc.removeItem(bm1);
    67   bmsvc.removeItem(bm2);
    69   /*
    70   1. Create two bookmarks with the same URI and keyword.
    71   2. Modify the first-created bookmark.
    72   3. Confirm that the most recently modified one is returned for that keyword.
    73   */
    74   var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
    75   bmsvc.setKeywordForBookmark(bm1, "foo");
    76   PlacesUtils.setPostDataForBookmark(bm1, "pdata1");
    77   var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
    78   bmsvc.setKeywordForBookmark(bm2, "foo");
    79   PlacesUtils.setPostDataForBookmark(bm2, "pdata2");
    81   // modify the older bookmark
    82   bmsvc.setItemTitle(bm1, "change");
    84   var bm1da = bmsvc.getItemDateAdded(bm1);
    85   var bm1lm = bmsvc.getItemLastModified(bm1);
    86   LOG("bm1 dateAdded: " + bm1da + ", lastModified: " + bm1lm);
    87   var bm2da = bmsvc.getItemDateAdded(bm2);
    88   var bm2lm = bmsvc.getItemLastModified(bm2);
    89   LOG("bm2 dateAdded: " + bm2da + ", lastModified: " + bm2lm);
    90   do_check_true(bm1da <= bm2da);
    91   // the last modified for bm1 should be at least as big as bm2
    92   // but could be equal if the test runs faster than our PRNow()
    93   // granularity
    94   do_check_true(bm1lm >= bm2lm);
    96   // we need to ensure that bm1 last modified date is greater
    97   // that the modified date of bm2, otherwise in case of a "tie"
    98   // bm2 will win, as it has a bigger item id
    99   if (bm1lm == bm2lm) 
   100     bmsvc.setItemLastModified(bm1, bm2lm + 1);
   102   [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo");
   103   do_check_eq(testURI.spec, url);
   104   do_check_eq(postdata, "pdata1");
   106   // cleanup
   107   bmsvc.removeItem(bm1);
   108   bmsvc.removeItem(bm2);
   110   /*
   111   Test that id breaks ties:
   112   1. Create two bookmarks with the same URI and keyword, dateAdded and lastModified.
   113   2. Confirm that the most recently created one is returned for that keyword.
   114   */
   115   var testDate = Date.now() * 1000;
   116   var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
   117   bmsvc.setKeywordForBookmark(bm1, "foo");
   118   PlacesUtils.setPostDataForBookmark(bm1, "pdata1");
   119   bmsvc.setItemDateAdded(bm1, testDate);
   120   bmsvc.setItemLastModified(bm1, testDate);
   122   var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah");
   123   bmsvc.setKeywordForBookmark(bm2, "foo");
   124   PlacesUtils.setPostDataForBookmark(bm2, "pdata2");
   125   bmsvc.setItemDateAdded(bm2, testDate);
   126   bmsvc.setItemLastModified(bm2, testDate);
   128   var bm1da = bmsvc.getItemDateAdded(bm1, testDate);
   129   var bm1lm = bmsvc.getItemLastModified(bm1);
   130   LOG("bm1 dateAdded: " + bm1da + ", lastModified: " + bm1lm);
   131   var bm2da = bmsvc.getItemDateAdded(bm2);
   132   var bm2lm = bmsvc.getItemLastModified(bm2);
   133   LOG("bm2 dateAdded: " + bm2da + ", lastModified: " + bm2lm);
   135   do_check_eq(bm1da, bm2da);
   136   do_check_eq(bm1lm, bm2lm);
   139   var ids = bmsvc.getBookmarkIdsForURI(testURI);
   140   do_check_eq(ids[0], bm2);
   141   do_check_eq(ids[1], bm1);
   143   [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo");
   144   do_check_eq(testURI.spec, url);
   145   do_check_eq(postdata, "pdata2");
   147   // cleanup
   148   bmsvc.removeItem(bm1);
   149   bmsvc.removeItem(bm2);
   150 }

mercurial