• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3# found in the LICENSE file.
4
5import os
6import tempfile
7import unittest
8
9from telemetry.internal.backends import browser_backend
10from telemetry.testing import options_for_unittests
11import mock
12
13
14class BrowserBackendLogsUploadingUnittest(unittest.TestCase):
15  def testUploadingToCLoudStorage(self):
16    temp_file = tempfile.NamedTemporaryFile(delete=False)
17    temp_file_name = temp_file.name
18    try:
19      temp_file.write('This is a\ntest log file.\n')
20      temp_file.close()
21
22      # pylint: disable=abstract-method
23      class FakeBrowserBackend(browser_backend.BrowserBackend):
24        @property
25        def supports_uploading_logs(self):
26          return True
27
28        @property
29        def log_file_path(self):
30          return temp_file_name
31
32      options = options_for_unittests.GetCopy()
33      options.browser_options.logging_verbosity = (
34          options.browser_options.VERBOSE_LOGGING)
35      options.browser_options.logs_cloud_bucket = 'ABC'
36      options.browser_options.logs_cloud_remote_path = 'def'
37
38      b = FakeBrowserBackend(None, False, options.browser_options, None)
39      self.assertEquals(b.GetLogFileContents(), 'This is a\ntest log file.\n')
40      with mock.patch('py_utils.cloud_storage.Insert') as mock_insert:
41        b.UploadLogsToCloudStorage()
42        mock_insert.assert_called_with(
43            bucket='ABC', remote_path='def', local_path=temp_file_name)
44    finally:
45      os.remove(temp_file_name)
46