Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/stats.js

Issue 6444238522810368: Fixed unit tests (Closed)
Patch Set: Created Dec. 18, 2013, 12:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | qunit/index.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 24 matching lines...) Expand all
35 { 35 {
36 if (!tab) 36 if (!tab)
37 return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0); 37 return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0);
38 38
39 let frameData = getFrameData(tab, 0); 39 let frameData = getFrameData(tab, 0);
40 return (frameData && key in frameData ? frameData[key] : 0); 40 return (frameData && key in frameData ? frameData[key] : 0);
41 }; 41 };
42 42
43 FilterNotifier.addListener(function(action, item, newValue, oldValue, tab) 43 FilterNotifier.addListener(function(action, item, newValue, oldValue, tab)
44 { 44 {
45 if (action != "filter.hitCount") 45 if (action != "filter.hitCount" || !tab)
46 return; 46 return;
47 47
48 let blocked = item instanceof BlockingFilter; 48 let blocked = item instanceof BlockingFilter;
49 49
50 // Increment counts 50 // Increment counts
51 if (blocked) 51 if (blocked)
52 { 52 {
53 if ("blocked" in Prefs.stats_total) 53 if ("blocked" in Prefs.stats_total)
54 Prefs.stats_total.blocked++; 54 Prefs.stats_total.blocked++;
55 else 55 else
56 Prefs.stats_total.blocked = 1; 56 Prefs.stats_total.blocked = 1;
57 Prefs.stats_total = Prefs.stats_total; 57 Prefs.stats_total = Prefs.stats_total;
58 58
59 let frameData = getFrameData(tab, 0); 59 let frameData = getFrameData(tab, 0);
60 if (frameData) 60 if (frameData)
61 { 61 {
62 if ("blocked" in frameData) 62 if ("blocked" in frameData)
63 frameData.blocked++; 63 frameData.blocked++;
64 else 64 else
65 frameData.blocked = 1; 65 frameData.blocked = 1;
66 } 66 }
67 67
68 // Update number in icon 68 // Update number in icon
69 if (Prefs.show_statsinicon) 69 if (Prefs.show_statsinicon)
70 { 70 {
71 tab.browserAction.setBadge({ 71 tab.browserAction.setBadge({
72 color: badgeColor, 72 color: badgeColor,
73 number: frameData.blocked 73 number: frameData.blocked
74 }); 74 });
75 } 75 }
76 } 76 }
77 }); 77 });
(...skipping 14 matching lines...) Expand all
92 func(tabs[i]); 92 func(tabs[i]);
93 }); 93 });
94 } 94 }
95 }); 95 });
96 } 96 }
97 97
98 Prefs.addListener(function(name) 98 Prefs.addListener(function(name)
99 { 99 {
100 if (name != "show_statsinicon") 100 if (name != "show_statsinicon")
101 return; 101 return;
102 102
103 forEachTab(function(tab) 103 forEachTab(function(tab)
104 { 104 {
105 let badge = null; 105 let badge = null;
106 if (Prefs.show_statsinicon) 106 if (Prefs.show_statsinicon)
107 { 107 {
108 let frameData = getFrameData(tab, 0); 108 let frameData = getFrameData(tab, 0);
109 if (frameData && "blocked" in frameData) 109 if (frameData && "blocked" in frameData)
110 { 110 {
111 badge = { 111 badge = {
112 color: badgeColor, 112 color: badgeColor,
113 number: frameData.blocked 113 number: frameData.blocked
114 }; 114 };
115 } 115 }
116 } 116 }
117 tab.browserAction.setBadge(badge); 117 tab.browserAction.setBadge(badge);
118 }); 118 });
119 }); 119 });
OLDNEW
« no previous file with comments | « no previous file | qunit/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld