| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 base64 | 5 import base64 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| 11 import webtest | 11 import webtest |
| 12 | 12 |
| 13 from crash import crash_pipeline | 13 from crash import crash_pipeline |
| 14 from crash.findit import Findit |
| 14 from crash.test.crash_testcase import CrashTestCase | 15 from crash.test.crash_testcase import CrashTestCase |
| 15 from handlers.crash import crash_handler | 16 from handlers.crash import crash_handler |
| 16 | 17 |
| 17 | 18 |
| 18 class CrashHandlerTest(CrashTestCase): | 19 class CrashHandlerTest(CrashTestCase): |
| 19 app_module = webapp2.WSGIApplication([ | 20 app_module = webapp2.WSGIApplication([ |
| 20 ('/_ah/push-handlers/crash/fracas', crash_handler.CrashHandler), | 21 ('/_ah/push-handlers/crash/fracas', crash_handler.CrashHandler), |
| 21 ], debug=True) | 22 ], debug=True) |
| 22 | 23 |
| 23 def _MockScheduleNewAnalysisForCrash(self, requested_crashes): | 24 def testAnalysisScheduled(self): |
| 24 def Mocked_ScheduleNewAnalysisForCrash(*crash_data, **_): | 25 # We need to mock out the method on Findit itself (rather than using a |
| 26 # subclass), since this method only gets called on objects we |
| 27 # ourselves don't construct. |
| 28 requested_crashes = [] |
| 29 def _MockScheduleNewAnalysis(_self, crash_data, **_): |
| 25 requested_crashes.append(crash_data) | 30 requested_crashes.append(crash_data) |
| 26 self.mock(crash_pipeline, 'ScheduleNewAnalysisForCrash', | 31 self.mock(Findit, 'ScheduleNewAnalysis', _MockScheduleNewAnalysis) |
| 27 Mocked_ScheduleNewAnalysisForCrash) | |
| 28 | 32 |
| 29 def testAnalysisScheduled(self): | |
| 30 requested_crashes = [] | |
| 31 self._MockScheduleNewAnalysisForCrash(requested_crashes) | |
| 32 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 33 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 33 | 34 |
| 34 client_id = 'fracas' | |
| 35 channel = 'supported_channel' | 35 channel = 'supported_channel' |
| 36 platform = 'supported_platform' | 36 platform = 'supported_platform' |
| 37 signature = 'signature/here' | 37 signature = 'signature/here' |
| 38 stack_trace = 'frame1\nframe2\nframe3' | |
| 39 chrome_version = '50.2500.0.0' | 38 chrome_version = '50.2500.0.0' |
| 40 historic_metadata = [{'chrome_version': '50.2500.0.0', 'cpm': 0.6}] | 39 crash_data = { |
| 41 | 40 'client_id': 'fracas', |
| 42 crash_identifiers = { | 41 'platform': platform, |
| 42 'signature': signature, |
| 43 'stack_trace': 'frame1\nframe2\nframe3', |
| 43 'chrome_version': chrome_version, | 44 'chrome_version': chrome_version, |
| 44 'signature': signature, | 45 'crash_identifiers': { |
| 45 'channel': channel, | 46 'chrome_version': chrome_version, |
| 46 'platform': platform, | 47 'signature': signature, |
| 47 'process_type': 'renderer' | 48 'channel': channel, |
| 49 'platform': platform, |
| 50 'process_type': 'renderer', |
| 51 }, |
| 52 'customized_data': { |
| 53 'channel': channel, |
| 54 'historical_metadata': |
| 55 [{'chrome_version': chrome_version, 'cpm': 0.6}], |
| 56 }, |
| 48 } | 57 } |
| 49 | 58 |
| 50 request_json_data = { | 59 request_json_data = { |
| 51 'message': { | 60 'message': { |
| 52 'data': base64.b64encode(json.dumps({ | 61 'data': base64.b64encode(json.dumps(crash_data)), |
| 53 'customized_data': { | |
| 54 'channel': 'supported_channel', | |
| 55 'historical_metadata': [ | |
| 56 { | |
| 57 'chrome_version': '50.2500.0.0', | |
| 58 'cpm': 0.6 | |
| 59 }, | |
| 60 ] | |
| 61 }, | |
| 62 'chrome_version': '50.2500.0.0', | |
| 63 'signature': 'signature/here', | |
| 64 'client_id': 'fracas', | |
| 65 'platform': 'supported_platform', | |
| 66 'crash_identifiers': { | |
| 67 'chrome_version': '50.2500.0.0', | |
| 68 'signature': 'signature/here', | |
| 69 'channel': 'supported_channel', | |
| 70 'platform': 'supported_platform', | |
| 71 'process_type': 'renderer' | |
| 72 }, | |
| 73 'stack_trace': 'frame1\nframe2\nframe3' | |
| 74 })), | |
| 75 'message_id': 'id', | 62 'message_id': 'id', |
| 76 }, | 63 }, |
| 77 'subscription': 'subscription', | 64 'subscription': 'subscription', |
| 78 } | 65 } |
| 79 | 66 |
| 80 self.test_app.post_json('/_ah/push-handlers/crash/fracas', | 67 self.test_app.post_json('/_ah/push-handlers/crash/fracas', |
| 81 request_json_data) | 68 request_json_data) |
| 82 | 69 |
| 83 self.assertEqual(1, len(requested_crashes)) | 70 self.assertEqual(1, len(requested_crashes)) |
| 84 self.assertEqual( | 71 self.assertEqual(crash_data, requested_crashes[0]) |
| 85 (crash_identifiers, chrome_version, signature, client_id, | |
| 86 platform, stack_trace, {'channel': channel, | |
| 87 'historical_metadata': historic_metadata}), | |
| 88 requested_crashes[0]) | |
| OLD | NEW |