Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / test_util / page_set_smoke_test.py
1 # Copyright 2014 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
5 import logging
6 import os
7 import unittest
8
9 from telemetry.core import discover
10 from telemetry.page import page_set as page_set_module
11 from telemetry.page import page_set_archive_info
12
13
14 class PageSetSmokeTest(unittest.TestCase):
15
16   def RunSmokeTest(self, page_sets_dir):
17     """
18     Run smoke test on all page sets in page_sets_dir. Subclass of
19     PageSetSmokeTest is supposed to call this in some test method to run smoke
20     test.
21     """
22     # Instantiate all page sets and verify that all URLs have an associated
23     # archive.
24     page_sets = discover.GetAllPageSetFilenames(page_sets_dir)
25     for path in page_sets:
26       page_set = page_set_module.PageSet.FromFile(path)
27
28       # TODO: Eventually these should be fatal.
29       if not page_set.archive_data_file:
30         logging.warning('Skipping %s: missing archive data file', path)
31         continue
32       if not os.path.exists(os.path.join(page_sets_dir,
33                                          page_set.archive_data_file)):
34         logging.warning('Skipping %s: archive data file not found', path)
35         continue
36
37       wpr_archive_info = page_set_archive_info.PageSetArchiveInfo.FromFile(
38         os.path.join(page_sets_dir, page_set.archive_data_file),
39         ignore_archive=True)
40
41       logging.info('Testing %s', path)
42       for page in page_set.pages:
43         if not page.url.startswith('http'):
44           continue
45         self.assertTrue(wpr_archive_info.WprFilePathForPage(page),
46                         msg='No archive found for %s in %s' % (
47                             page.url, page_set.archive_data_file))