1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#
# This is a stub for chrome.strorage.sync for testing.
# It does what chrome.storage.sync should do (roughly), but does so synchronously.
# It also provides stubs for a number of other chrome APIs.
#
exports.window = {}
exports.localStorage = {}
exports.chrome =
runtime:
getManifest: () ->
version: "1.2.3"
onConnect:
addListener: () -> true
onMessage:
addListener: () -> true
onInstalled:
addListener: ->
extension:
getURL: (path) -> path
tabs:
onSelectionChanged:
addListener: () -> true
onUpdated:
addListener: () -> true
onAttached:
addListener: () -> true
onMoved:
addListener: () -> true
onRemoved:
addListener: () -> true
onActiveChanged:
addListener: () -> true
onActivated:
addListener: () -> true
onReplaced:
addListener: () -> true
query: () -> true
webNavigation:
onHistoryStateUpdated:
addListener: () ->
onReferenceFragmentUpdated:
addListener: () ->
windows:
onRemoved:
addListener: () -> true
getAll: () -> true
browserAction:
setBadgeBackgroundColor: ->
storage:
# chrome.storage.local
local:
get: ->
set: ->
remove: ->
# chrome.storage.onChanged
onChanged:
addListener: (func) -> @func = func
# Fake a callback from chrome.storage.sync.
call: (key, value) ->
chrome.runtime.lastError = undefined
key_value = {}
key_value[key] = { newValue: value }
@func(key_value,'sync') if @func
callEmpty: (key) ->
chrome.runtime.lastError = undefined
if @func
items = {}
items[key] = {}
@func(items,'sync')
session:
MAX_SESSION_RESULTS: 25
# chrome.storage.sync
sync:
store: {}
set: (items, callback) ->
chrome.runtime.lastError = undefined
for own key, value of items
@store[key] = value
callback() if callback
# Now, generate (supposedly asynchronous) notifications for listeners.
for own key, value of items
global.chrome.storage.onChanged.call(key,value)
get: (keys, callback) ->
chrome.runtime.lastError = undefined
if keys == null
keys = []
for own key, value of @store
keys.push key
items = {}
for key in keys
items[key] = @store[key]
# Now, generate (supposedly asynchronous) callback
callback items if callback
remove: (key, callback) ->
chrome.runtime.lastError = undefined
if key of @store
delete @store[key]
callback() if callback
# Now, generate (supposedly asynchronous) notification for listeners.
global.chrome.storage.onChanged.callEmpty(key)
|