Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function getCacheService() |
michael@0 | 2 | { |
michael@0 | 3 | var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; |
michael@0 | 4 | var service = nsCacheService.getService(Components.interfaces.nsICacheService); |
michael@0 | 5 | return service; |
michael@0 | 6 | } |
michael@0 | 7 | |
michael@0 | 8 | function createCacheSession(clientID, storagePolicy, streamable) |
michael@0 | 9 | { |
michael@0 | 10 | var service = getCacheService(); |
michael@0 | 11 | var nsICache = Components.interfaces.nsICache; |
michael@0 | 12 | var session = service.createSession(clientID, storagePolicy, streamable); |
michael@0 | 13 | return session; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | function openCacheEntry(clientID, url) |
michael@0 | 17 | { |
michael@0 | 18 | var nsICache = Components.interfaces.nsICache; |
michael@0 | 19 | var session = createCacheSession(clientID, nsICache.STORE_ANYWHERE, false); |
michael@0 | 20 | var entry = session.openCacheEntry(url, nsICache.ACCESS_READ_WRITE); |
michael@0 | 21 | return entry; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function wrapString(str) |
michael@0 | 25 | { |
michael@0 | 26 | var nsISupportsCString = Components.interfaces.nsISupportsCString; |
michael@0 | 27 | var factory = Components.classes["@mozilla.org/supports-cstring;1"]; |
michael@0 | 28 | var wrapper = factory.createInstance(nsISupportsCString); |
michael@0 | 29 | wrapper.data = str; |
michael@0 | 30 | return wrapper; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function test() |
michael@0 | 34 | { |
michael@0 | 35 | var data = wrapString("javascript"); |
michael@0 | 36 | var entry = openCacheEntry("javascript", "theme:button"); |
michael@0 | 37 | entry.cacheElement = data; |
michael@0 | 38 | entry.markValid(); |
michael@0 | 39 | entry.close(); |
michael@0 | 40 | |
michael@0 | 41 | var newEntry = openCacheEntry("javascript", "theme:button"); |
michael@0 | 42 | if (newEntry.cacheElement === data) |
michael@0 | 43 | print("object cache works."); |
michael@0 | 44 | else |
michael@0 | 45 | print("object cache failed."); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | test(); |