def testFilePathAbsolute(self):
     apage = page.Page('file:///somedir/otherdir/file.html',
                       None,
                       base_dir='basedir')
     self.assertPathEqual(apage.file_path, '/somedir/otherdir/file.html')
 def testFilePathUrlQueryString(self):
     apage = page.Page('file://somedir/file.html?key=val',
                       None,
                       base_dir='basedir')
     self.assertPathEqual(apage.file_path_url,
                          'basedir/somedir/file.html?key=val')
    def testDisplayUrlForSingleDirectory(self):
        ps = page_set.PageSet(file_path=os.path.dirname(__file__))
        ps.AddUserStory(page.Page('file://../../otherdir/foo', ps,
                                  ps.base_dir))

        self.assertEquals(ps[0].display_name, 'foo')
 def testPagesHaveDifferentIds(self):
     p0 = page.Page("http://example.com")
     p1 = page.Page("http://example.com")
     self.assertNotEqual(p0.id, p1.id)
示例#5
0
 def testGpuExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page6.html', ps)
     self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA)
     self.assertExpectationEquals('fail', page, gpu=VENDOR_INTEL)
     self.assertExpectationEquals('pass', page, gpu=VENDOR_AMD)
示例#6
0
 def testFilePathQueryString(self):
   apage = page.Page('file://somedir/otherdir/file.html?key=val',
                     None, base_dir='basedir', name='test')
   self.assertPathEqual(apage.file_path, 'basedir/somedir/otherdir/file.html')
示例#7
0
 def __init__(self, test):
     super(TestPageTestResults, self).__init__()
     self.test = test
     page = page_module.Page("http://www.google.com", {})
     self.WillRunPage(page)
示例#8
0
 def testConditionlessExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page3.html', ps)
     self.assertExpectationEquals('fail', page, StubPlatform('win'))
     self.assertExpectationEquals('fail', page, StubPlatform('mac', 'lion'))
     self.assertExpectationEquals('fail', page, StubPlatform('linux'))
 def testUserDefinedExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page15.html', ps)
     self.assertExpectationEquals('fail', page, gpu=VENDOR_AMD)
     page = page_module.Page('http://test.com/page16.html', ps)
     self.assertExpectationEquals('pass', page, gpu=VENDOR_AMD)
示例#10
0
def GetSingleEventMetrics(events, interactions):
    results = page_test_results.PageTestResults()
    results.WillRunPage(page.Page('file://blank.html'))
    SingleEventTestMetric()._AddResultsInternal(events, interactions, results)
    return dict((value.name, value.values)
                for value in results.current_page_run.values)
 def testNoExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page0.html', ps)
     self.assertExpectationEquals('pass', page, StubPlatform('win'))
 def setUp(self):
     self.metric = smoothness.SmoothnessMetric()
     self.page = page_module.Page('file://blank.html')
     self.good_timestamps = [[10, 20], [30, 40, 50]]
     self.not_enough_frames_timestamps = [[10], [20, 30, 40]]
 def testOSExpectations(self):
   ps = page_set.PageSet()
   page = page_module.Page('http://test.com/page1.html', ps)
   self.assertExpectationEquals('fail', StubPlatform('win'), page)
   self.assertExpectationEquals('fail', StubPlatform('mac'), page)
   self.assertExpectationEquals('pass', StubPlatform('linux'), page)
 def testFilePathUrlTrailingSeparator(self):
     apage = page.Page('file://somedir/otherdir/', None, base_dir='basedir')
     self.assertPathEqual(apage.file_path_url, 'basedir/somedir/otherdir/')
     self.assertTrue(
         apage.file_path_url.endswith(os.sep)
         or (os.altsep and apage.file_path_url.endswith(os.altsep)))
示例#15
0
 def AddPageWithDefaultRunNavigate(self, page_url):
     """ Add a simple page with url equals to page_url that contains only default
 RunNavigateSteps.
 """
     self.AddPage(page_module.Page(page_url, self, self.base_dir))
示例#16
0
 def testOSVersionExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page2.html', ps)
     self.assertExpectationEquals('fail', page,
                                  StubPlatform('win', 'vista'))
     self.assertExpectationEquals('pass', page, StubPlatform('win', 'win7'))
示例#17
0
    def __init__(self, file_path='', attributes=None):
        self.file_path = file_path

        # These attributes can be set dynamically by the page set.
        self.description = ''
        self.archive_data_file = ''
        self.credentials_path = None
        self.user_agent_type = None
        self.make_javascript_deterministic = True
        self.navigate_steps = {'action': 'navigate'}

        if attributes:
            for k, v in attributes.iteritems():
                setattr(self, k, v)

        # Create a PageSetArchiveInfo object.
        if self.archive_data_file:
            self.wpr_archive_info = page_set_archive_info.PageSetArchiveInfo.FromFile(
                os.path.join(self._base_dir, self.archive_data_file))
        else:
            self.wpr_archive_info = None

        # Create a Page object for every page.
        self.pages = []
        if attributes and 'pages' in attributes:
            for page_attributes in attributes['pages']:
                url = page_attributes.pop('url')

                page = page_module.Page(url,
                                        self,
                                        attributes=page_attributes,
                                        base_dir=self._base_dir)
                self.pages.append(page)

        # Prepend _base_dir to our serving dirs.
        # Always use realpath to ensure no duplicates in set.
        self.serving_dirs = set()
        if attributes and 'serving_dirs' in attributes:
            if not isinstance(attributes['serving_dirs'], list):
                raise ValueError('serving_dirs must be a list.')
            for serving_dir in attributes['serving_dirs']:
                self.serving_dirs.add(
                    os.path.realpath(os.path.join(self._base_dir,
                                                  serving_dir)))

        # Attempt to download the credentials file.
        if self.credentials_path:
            cloud_storage.GetIfChanged(
                cloud_storage.INTERNAL_BUCKET,
                os.path.join(self._base_dir, self.credentials_path))

        # Scan every serving directory for .sha1 files
        # and download them from Cloud Storage. Assume all data is public.
        all_serving_dirs = self.serving_dirs.copy()
        # Add individual page dirs to all serving dirs.
        for page in self:
            if page.is_file:
                all_serving_dirs.add(page.serving_dir)
        # Scan all serving dirs.
        for serving_dir in all_serving_dirs:
            if serving_dir == '/':
                raise ValueError('Trying to serve "/" from HTTP server.')
            for dirpath, _, filenames in os.walk(serving_dir):
                for filename in filenames:
                    path, extension = os.path.splitext(
                        os.path.join(dirpath, filename))
                    if extension != '.sha1':
                        continue
                    cloud_storage.GetIfChanged(cloud_storage.PUBLIC_BUCKET,
                                               path)
示例#18
0
 def testWildcardExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page4.html', ps)
     page_js = page_module.Page('http://test.com/page4.html', ps)
     self.assertExpectationEquals('fail', page, StubPlatform('win'))
     self.assertExpectationEquals('fail', page_js, StubPlatform('win'))
示例#19
0
    def testUpdateAndCheckArchives(self):
        usr_stub = system_stub.Override(story_runner, ['cloud_storage'])
        wpr_stub = system_stub.Override(archive_info, ['cloud_storage'])
        archive_data_dir = os.path.join(util.GetTelemetryDir(), 'telemetry',
                                        'internal', 'testing', 'archive_files')
        try:
            story_set = story_module.StorySet()
            story_set.AddStory(
                page_module.Page('http://www.testurl.com', story_set,
                                 story_set.base_dir))
            # Page set missing archive_data_file.
            self.assertRaises(story_runner.ArchiveError,
                              story_runner._UpdateAndCheckArchives,
                              story_set.archive_data_file,
                              story_set.wpr_archive_info, story_set.stories)

            story_set = story_module.StorySet(
                archive_data_file='missing_archive_data_file.json')
            story_set.AddStory(
                page_module.Page('http://www.testurl.com', story_set,
                                 story_set.base_dir))
            # Page set missing json file specified in archive_data_file.
            self.assertRaises(story_runner.ArchiveError,
                              story_runner._UpdateAndCheckArchives,
                              story_set.archive_data_file,
                              story_set.wpr_archive_info, story_set.stories)

            story_set = story_module.StorySet(
                archive_data_file=os.path.join(archive_data_dir, 'test.json'),
                cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET)
            story_set.AddStory(
                page_module.Page('http://www.testurl.com', story_set,
                                 story_set.base_dir))
            # Page set with valid archive_data_file.
            self.assertTrue(
                story_runner._UpdateAndCheckArchives(
                    story_set.archive_data_file, story_set.wpr_archive_info,
                    story_set.stories))
            story_set.AddStory(
                page_module.Page('http://www.google.com', story_set,
                                 story_set.base_dir))
            # Page set with an archive_data_file which exists but is missing a page.
            self.assertRaises(story_runner.ArchiveError,
                              story_runner._UpdateAndCheckArchives,
                              story_set.archive_data_file,
                              story_set.wpr_archive_info, story_set.stories)

            story_set = story_module.StorySet(
                archive_data_file=os.path.join(archive_data_dir,
                                               'test_missing_wpr_file.json'),
                cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET)
            story_set.AddStory(
                page_module.Page('http://www.testurl.com', story_set,
                                 story_set.base_dir))
            story_set.AddStory(
                page_module.Page('http://www.google.com', story_set,
                                 story_set.base_dir))
            # Page set with an archive_data_file which exists and contains all pages
            # but fails to find a wpr file.
            self.assertRaises(story_runner.ArchiveError,
                              story_runner._UpdateAndCheckArchives,
                              story_set.archive_data_file,
                              story_set.wpr_archive_info, story_set.stories)
        finally:
            usr_stub.Restore()
            wpr_stub.Restore()
示例#20
0
 def testPageNameExpectations(self):
     ps = page_set.PageSet()
     page = page_module.Page('http://test.com/page11.html', ps)
     page.name = "Pages.page_11"
     self.assertExpectationEquals('fail', page)
示例#21
0
 def testFilePathRelative(self):
   apage = page.Page('file://somedir/otherdir/file.html',
                     None, base_dir='basedir', name='test')
   self.assertPathEqual(apage.file_path, 'basedir/somedir/otherdir/file.html')