toolkit/components/search/tests/xpcshell/test_serialize_file.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.

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 /*
michael@0 5 * test_serialize_file: Add test engines
michael@0 6 *
michael@0 7 * Ensure that :
michael@0 8 * - File is created.
michael@0 9 * - File size is bigger than 0.
michael@0 10 * - lazySerializeTask updates the file.
michael@0 11 */
michael@0 12
michael@0 13 const Ci = Components.interfaces;
michael@0 14 const Cu = Components.utils;
michael@0 15
michael@0 16 Cu.import("resource://testing-common/httpd.js");
michael@0 17 Cu.import("resource://gre/modules/NetUtil.jsm");
michael@0 18
michael@0 19 add_test(function test_batchTask() {
michael@0 20 let observer = function(aSubject, aTopic, aData) {
michael@0 21 if (aTopic == "browser-search-engine-modified" && aData == "engine-loaded") {
michael@0 22 let engine1 = Services.search.getEngineByName("Test search engine");
michael@0 23 let engine2 = Services.search.getEngineByName("Sherlock test search engine");
michael@0 24 if (engine1 && engine2) {
michael@0 25 Services.obs.removeObserver(observer, aTopic);
michael@0 26 // Test that files are written correctly.
michael@0 27 let engineFile1 = engine1.wrappedJSObject._file;
michael@0 28 let engineFile2 = engine2.wrappedJSObject._file;
michael@0 29 do_check_true(engineFile1.exists());
michael@0 30 do_check_true(engineFile2.exists());
michael@0 31 do_check_neq(engineFile1.fileSize, 0);
michael@0 32 do_check_neq(engineFile2.fileSize, 0);
michael@0 33 run_next_test();
michael@0 34 }
michael@0 35 }
michael@0 36 }
michael@0 37
michael@0 38 Services.obs.addObserver(observer, "browser-search-engine-modified", false);
michael@0 39 Services.search.addEngine("http://localhost:4444/data/engine.xml",
michael@0 40 Ci.nsISearchEngine.DATA_XML, null, false);
michael@0 41 Services.search.addEngine("http://localhost:4444/data/engine.src",
michael@0 42 Ci.nsISearchEngine.DATA_TEXT,
michael@0 43 "http://localhost:4444/data/ico-size-16x16-png.ico",
michael@0 44 false);
michael@0 45 });
michael@0 46
michael@0 47 add_test(function test_addParam() {
michael@0 48 let engine = Services.search.getEngineByName("Test search engine");
michael@0 49 engine.addParam("param-name", "param-value", null);
michael@0 50
michael@0 51 function readAsyncFile(aFile, aCallback) {
michael@0 52 NetUtil.asyncFetch(aFile, function(inputStream, status) {
michael@0 53 do_check_true(Components.isSuccessCode(status));
michael@0 54
michael@0 55 let data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
michael@0 56 aCallback(data);
michael@0 57 });
michael@0 58 }
michael@0 59
michael@0 60 let observer = function(aSubject, aTopic, aData) {
michael@0 61 // The sherlock engine file may still be updated because the icon takes
michael@0 62 // time be loaded, therefore, the engine name is checked here.
michael@0 63 aSubject.QueryInterface(Ci.nsIFile);
michael@0 64 if (aTopic == "browser-search-service" &&
michael@0 65 aData == "write-engine-to-disk-complete" &&
michael@0 66 aSubject.leafName == "test-search-engine.xml") {
michael@0 67 Services.obs.removeObserver(observer, aTopic);
michael@0 68
michael@0 69 let engineFile = engine.wrappedJSObject._file;
michael@0 70
michael@0 71 readAsyncFile(engineFile, function(engineData) {
michael@0 72 do_check_true(engineData.indexOf("param-name") > 0);
michael@0 73 run_next_test();
michael@0 74 });
michael@0 75 }
michael@0 76 }
michael@0 77 Services.obs.addObserver(observer, "browser-search-service", false);
michael@0 78 });
michael@0 79
michael@0 80 function run_test() {
michael@0 81 updateAppInfo();
michael@0 82
michael@0 83 let httpServer = new HttpServer();
michael@0 84 httpServer.start(4444);
michael@0 85 httpServer.registerDirectory("/", do_get_cwd());
michael@0 86
michael@0 87 do_register_cleanup(function cleanup() {
michael@0 88 httpServer.stop(function() {});
michael@0 89 });
michael@0 90
michael@0 91 run_next_test();
michael@0 92 }

mercurial