1 # Copyright (c) 2012 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.
8 from telemetry.page import page
9 from telemetry.page import page_set
12 class TestPage(unittest.TestCase):
13 def assertPathEqual(self, path1, path2):
14 self.assertEqual(os.path.normpath(path1), os.path.normpath(path2))
16 def testFilePathRelative(self):
17 apage = page.Page('file://somedir/otherdir/file.html',
18 None, base_dir='basedir')
19 self.assertPathEqual(apage.file_path, 'basedir/somedir/otherdir/file.html')
21 def testFilePathAbsolute(self):
22 apage = page.Page('file:///somedir/otherdir/file.html',
23 None, base_dir='basedir')
24 self.assertPathEqual(apage.file_path, '/somedir/otherdir/file.html')
26 def testFilePathQueryString(self):
27 apage = page.Page('file://somedir/otherdir/file.html?key=val',
28 None, base_dir='basedir')
29 self.assertPathEqual(apage.file_path, 'basedir/somedir/otherdir/file.html')
31 def testFilePathUrlQueryString(self):
32 apage = page.Page('file://somedir/file.html?key=val',
33 None, base_dir='basedir')
34 self.assertPathEqual(apage.file_path_url,
35 'basedir/somedir/file.html?key=val')
37 def testFilePathUrlTrailingSeparator(self):
38 apage = page.Page('file://somedir/otherdir/',
39 None, base_dir='basedir')
40 self.assertPathEqual(apage.file_path_url, 'basedir/somedir/otherdir/')
41 self.assertTrue(apage.file_path_url.endswith(os.sep) or
42 (os.altsep and apage.file_path_url.endswith(os.altsep)))
45 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
46 ps.AddPageWithDefaultRunNavigate('http://www.foo.com/')
47 ps.AddPageWithDefaultRunNavigate('http://www.bar.com/')
49 pages = [ps.pages[0], ps.pages[1]]
51 self.assertEquals([ps.pages[1], ps.pages[0]],
54 def testGetUrlBaseDirAndFileForUrlBaseDir(self):
55 ps = page_set.PageSet(file_path='basedir/', serving_dirs=['../somedir/'])
56 ps.AddPageWithDefaultRunNavigate('file://../otherdir/file.html')
57 self.assertPathEqual(ps[0].file_path, 'otherdir/file.html')
59 def testDisplayUrlForHttp(self):
60 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
61 ps.AddPageWithDefaultRunNavigate('http://www.foo.com/')
62 ps.AddPageWithDefaultRunNavigate('http://www.bar.com/')
64 self.assertEquals(ps[0].display_name, 'http://www.foo.com/')
65 self.assertEquals(ps[1].display_name, 'http://www.bar.com/')
67 def testDisplayUrlForHttps(self):
68 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
69 ps.AddPageWithDefaultRunNavigate('http://www.foo.com/')
70 ps.AddPageWithDefaultRunNavigate('https://www.bar.com/')
72 self.assertEquals(ps[0].display_name, 'http://www.foo.com/')
73 self.assertEquals(ps[1].display_name, 'https://www.bar.com/')
75 def testDisplayUrlForFile(self):
76 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
77 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo.html')
78 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/bar.html')
80 self.assertEquals(ps[0].display_name, 'foo.html')
81 self.assertEquals(ps[1].display_name, 'bar.html')
83 def testDisplayUrlForFilesDifferingBySuffix(self):
84 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
85 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo.html')
86 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo1.html')
88 self.assertEquals(ps[0].display_name, 'foo.html')
89 self.assertEquals(ps[1].display_name, 'foo1.html')
91 def testDisplayUrlForFileOfDifferentPaths(self):
92 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
93 ps.AddPageWithDefaultRunNavigate('file://../../somedir/foo.html')
94 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/bar.html')
96 self.assertEquals(ps[0].display_name, 'somedir/foo.html')
97 self.assertEquals(ps[1].display_name, 'otherdir/bar.html')
99 def testDisplayUrlForFileDirectories(self):
100 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
101 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo')
102 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/bar')
104 self.assertEquals(ps[0].display_name, 'foo')
105 self.assertEquals(ps[1].display_name, 'bar')
107 def testDisplayUrlForSingleFile(self):
108 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
109 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo.html')
111 self.assertEquals(ps[0].display_name, 'foo.html')
113 def testDisplayUrlForSingleDirectory(self):
114 ps = page_set.PageSet(file_path=os.path.dirname(__file__))
115 ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo')
117 self.assertEquals(ps[0].display_name, 'foo')