From e3279be9bc339673145850e07d864e0adb722d39 Mon Sep 17 00:00:00 2001 From: Eric Lemoine Date: Mon, 20 Sep 2010 18:53:13 +0200 Subject: [PATCH] Bug 591816 - Add tests for TabEngine [r=mconnor] --- services/sync/tests/unit/test_tab_engine.js | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 services/sync/tests/unit/test_tab_engine.js diff --git a/services/sync/tests/unit/test_tab_engine.js b/services/sync/tests/unit/test_tab_engine.js new file mode 100644 index 000000000000..fe71129dfcbe --- /dev/null +++ b/services/sync/tests/unit/test_tab_engine.js @@ -0,0 +1,47 @@ +Cu.import("resource://services-sync/engines/tabs.js"); +Cu.import("resource://services-sync/util.js"); + +function fakeSessionSvc() { + let tabs = []; + for(let i = 0; i < arguments.length; i++) { + tabs.push({ + index: 1, + entries: [{ + url: arguments[i], + title: "title" + }], + attributes: { + image: "image" + }, + extData: { + weaveLastUsed: 1 + } + }); + } + let obj = {windows: [{tabs: tabs}]}; + + // delete the getter, or the previously created fake Session + delete Svc.Session; + Svc.Session = { + getBrowserState: function() JSON.stringify(obj) + }; +} + +function run_test() { + + _("test locallyOpenTabMatchesURL"); + let engine = new TabEngine(); + + // 3 tabs + fakeSessionSvc("http://bar.com", "http://foo.com", "http://foobar.com"); + + let matches; + + _(" test matching works (true)"); + matches = engine.locallyOpenTabMatchesURL("http://foo.com"); + do_check_true(matches); + + _(" test matching works (false)"); + matches = engine.locallyOpenTabMatchesURL("http://barfoo.com"); + do_check_false(matches); +}