services/sync/tests/unit/test_tab_store.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 Cu.import("resource://services-sync/engines/tabs.js");
michael@0 5 Cu.import("resource://services-sync/service.js");
michael@0 6 Cu.import("resource://services-sync/util.js");
michael@0 7 Cu.import("resource://testing-common/services-common/utils.js");
michael@0 8
michael@0 9 function getMockStore() {
michael@0 10 let engine = new TabEngine(Service);
michael@0 11 let store = engine._store;
michael@0 12 store.getTabState = mockGetTabState;
michael@0 13 store.shouldSkipWindow = mockShouldSkipWindow;
michael@0 14 return store;
michael@0 15 }
michael@0 16
michael@0 17 function test_create() {
michael@0 18 let store = new TabEngine(Service)._store;
michael@0 19
michael@0 20 _("Create a first record");
michael@0 21 let rec = {id: "id1",
michael@0 22 clientName: "clientName1",
michael@0 23 cleartext: "cleartext1",
michael@0 24 modified: 1000};
michael@0 25 store.applyIncoming(rec);
michael@0 26 do_check_eq(store._remoteClients["id1"], "cleartext1");
michael@0 27 do_check_eq(Svc.Prefs.get("notifyTabState"), 1);
michael@0 28
michael@0 29 _("Create a second record");
michael@0 30 let rec = {id: "id2",
michael@0 31 clientName: "clientName2",
michael@0 32 cleartext: "cleartext2",
michael@0 33 modified: 2000};
michael@0 34 store.applyIncoming(rec);
michael@0 35 do_check_eq(store._remoteClients["id2"], "cleartext2");
michael@0 36 do_check_eq(Svc.Prefs.get("notifyTabState"), 0);
michael@0 37
michael@0 38 _("Create a third record");
michael@0 39 let rec = {id: "id3",
michael@0 40 clientName: "clientName3",
michael@0 41 cleartext: "cleartext3",
michael@0 42 modified: 3000};
michael@0 43 store.applyIncoming(rec);
michael@0 44 do_check_eq(store._remoteClients["id3"], "cleartext3");
michael@0 45 do_check_eq(Svc.Prefs.get("notifyTabState"), 0);
michael@0 46
michael@0 47 // reset the notifyTabState
michael@0 48 Svc.Prefs.reset("notifyTabState");
michael@0 49 }
michael@0 50
michael@0 51 function test_getAllTabs() {
michael@0 52 let store = getMockStore();
michael@0 53 let tabs;
michael@0 54
michael@0 55 store.getWindowEnumerator = mockGetWindowEnumerator.bind(this, "http://foo.com", 1, 1);
michael@0 56
michael@0 57 _("Get all tabs.");
michael@0 58 tabs = store.getAllTabs();
michael@0 59 _("Tabs: " + JSON.stringify(tabs));
michael@0 60 do_check_eq(tabs.length, 1);
michael@0 61 do_check_eq(tabs[0].title, "title");
michael@0 62 do_check_eq(tabs[0].urlHistory.length, 1);
michael@0 63 do_check_eq(tabs[0].urlHistory[0], ["http://foo.com"]);
michael@0 64 do_check_eq(tabs[0].icon, "image");
michael@0 65 do_check_eq(tabs[0].lastUsed, 1);
michael@0 66
michael@0 67 _("Get all tabs, and check that filtering works.");
michael@0 68 store.getWindowEnumerator = mockGetWindowEnumerator.bind(this, "about:foo", 1, 1);
michael@0 69 tabs = store.getAllTabs(true);
michael@0 70 _("Filtered: " + JSON.stringify(tabs));
michael@0 71 do_check_eq(tabs.length, 0);
michael@0 72 }
michael@0 73
michael@0 74 function test_createRecord() {
michael@0 75 let store = getMockStore();
michael@0 76 let record;
michael@0 77
michael@0 78 store.getTabState = mockGetTabState;
michael@0 79 store.shouldSkipWindow = mockShouldSkipWindow;
michael@0 80 store.getWindowEnumerator = mockGetWindowEnumerator.bind(this, "http://foo.com", 1, 1);
michael@0 81
michael@0 82 let tabs = store.getAllTabs();
michael@0 83 let tabsize = JSON.stringify(tabs[0]).length;
michael@0 84 let numtabs = Math.ceil(20000./77.);
michael@0 85
michael@0 86 store.getWindowEnumerator = mockGetWindowEnumerator.bind(this, "http://foo.com", 1, 1);
michael@0 87 record = store.createRecord("fake-guid");
michael@0 88 do_check_true(record instanceof TabSetRecord);
michael@0 89 do_check_eq(record.tabs.length, 1);
michael@0 90
michael@0 91 _("create a big record");
michael@0 92 store.getWindowEnumerator = mockGetWindowEnumerator.bind(this, "http://foo.com", 1, numtabs);
michael@0 93 record = store.createRecord("fake-guid");
michael@0 94 do_check_true(record instanceof TabSetRecord);
michael@0 95 do_check_eq(record.tabs.length, 256);
michael@0 96 }
michael@0 97
michael@0 98 function run_test() {
michael@0 99 test_create();
michael@0 100 test_getAllTabs();
michael@0 101 test_createRecord();
michael@0 102 }

mercurial