Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: tools/android/loading/content_classification_lens_unittest.py

Issue 1645953002: Conditional import of adblocker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use new filters for ad filtering Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import copy 5 import copy
6 import unittest 6 import unittest
7 7
8 from content_classification_lens import (ContentClassificationLens, 8 from content_classification_lens import (ContentClassificationLens,
9 _RulesMatcher) 9 _RulesMatcher)
10 from request_track import (Request, TimingFromDict) 10 from request_track import (Request, TimingFromDict)
11 import test_utils 11 import test_utils
12 12
13 13
14 class ContentClassificationLensTestCase(unittest.TestCase): 14 class ContentClassificationLensTestCase(unittest.TestCase):
15 _REQUEST = Request.FromJsonDict({'url': 'http://bla.com', 15 _REQUEST = Request.FromJsonDict({'url': 'http://bla.com',
16 'request_id': '1234.1', 16 'request_id': '1234.1',
17 'frame_id': '123.1', 17 'frame_id': '123.1',
18 'initiator': {'type': 'other'}, 18 'initiator': {'type': 'other'},
19 'timestamp': 2, 19 'timestamp': 2,
20 'timing': TimingFromDict({})}) 20 'timing': TimingFromDict({})})
21 _MAIN_FRAME_ID = '123.1' 21 _MAIN_FRAME_ID = '123.1'
22 _PAGE_EVENTS = [{'method': 'Page.frameStartedLoading', 22 _PAGE_EVENTS = [{'method': 'Page.frameStartedLoading',
23 'frame_id': _MAIN_FRAME_ID}, 23 'frame_id': _MAIN_FRAME_ID},
24 {'method': 'Page.frameAttached', 24 {'method': 'Page.frameAttached',
25 'frame_id': '123.13', 'parent_frame_id': _MAIN_FRAME_ID}] 25 'frame_id': '123.13', 'parent_frame_id': _MAIN_FRAME_ID}]
26 _RULES = ['bla.com'] 26 _RULES = ['bla.com']
27 27
28 def testNoRules(self):
29 trace = test_utils.LoadingTraceFromEvents(
30 [self._REQUEST], self._PAGE_EVENTS)
31 lens = ContentClassificationLens(trace, [], [])
32 self.assertFalse(lens.IsAdRequest(self._REQUEST))
33 self.assertFalse(lens.IsTrackingRequest(self._REQUEST))
34
28 def testAdRequest(self): 35 def testAdRequest(self):
29 trace = test_utils.LoadingTraceFromEvents( 36 trace = test_utils.LoadingTraceFromEvents(
30 [self._REQUEST], self._PAGE_EVENTS) 37 [self._REQUEST], self._PAGE_EVENTS)
31 lens = ContentClassificationLens(trace, self._RULES, []) 38 lens = ContentClassificationLens(trace, self._RULES, [])
32 self.assertTrue(lens.IsAdRequest(self._REQUEST)) 39 self.assertTrue(lens.IsAdRequest(self._REQUEST))
33 self.assertFalse(lens.IsTrackingRequest(self._REQUEST)) 40 self.assertFalse(lens.IsTrackingRequest(self._REQUEST))
34 41
35 def testTrackingRequest(self): 42 def testTrackingRequest(self):
36 trace = test_utils.LoadingTraceFromEvents( 43 trace = test_utils.LoadingTraceFromEvents(
37 [self._REQUEST], self._PAGE_EVENTS) 44 [self._REQUEST], self._PAGE_EVENTS)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 def testScriptRule(self): 83 def testScriptRule(self):
77 matcher = _RulesMatcher([self._SCRIPT_RULE], False) 84 matcher = _RulesMatcher([self._SCRIPT_RULE], False)
78 request = copy.deepcopy(self._SCRIPT_REQUEST) 85 request = copy.deepcopy(self._SCRIPT_REQUEST)
79 request.resource_type = 'Stylesheet' 86 request.resource_type = 'Stylesheet'
80 self.assertFalse(matcher.Matches(request)) 87 self.assertFalse(matcher.Matches(request))
81 self.assertTrue(matcher.Matches(self._SCRIPT_REQUEST)) 88 self.assertTrue(matcher.Matches(self._SCRIPT_REQUEST))
82 89
83 90
84 if __name__ == '__main__': 91 if __name__ == '__main__':
85 unittest.main() 92 unittest.main()
OLDNEW
« no previous file with comments | « tools/android/loading/content_classification_lens.py ('k') | tools/android/loading/loading_model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698