Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / page_unittest.py
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.
4
5 import os
6 import unittest
7
8 from telemetry.page import page
9 from telemetry.page import page_set
10
11
12 class TestPage(unittest.TestCase):
13   def assertPathEqual(self, path1, path2):
14     self.assertEqual(os.path.normpath(path1), os.path.normpath(path2))
15
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')
20
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')
25
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')
30
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')
36
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)))
43
44   def testSort(self):
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/')
48
49     pages = [ps.pages[0], ps.pages[1]]
50     pages.sort()
51     self.assertEquals([ps.pages[1], ps.pages[0]],
52                       pages)
53
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')
58
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/')
63
64     self.assertEquals(ps[0].display_name, 'http://www.foo.com/')
65     self.assertEquals(ps[1].display_name, 'http://www.bar.com/')
66
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/')
71
72     self.assertEquals(ps[0].display_name, 'http://www.foo.com/')
73     self.assertEquals(ps[1].display_name, 'https://www.bar.com/')
74
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')
79
80     self.assertEquals(ps[0].display_name, 'foo.html')
81     self.assertEquals(ps[1].display_name, 'bar.html')
82
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')
87
88     self.assertEquals(ps[0].display_name, 'foo.html')
89     self.assertEquals(ps[1].display_name, 'foo1.html')
90
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')
95
96     self.assertEquals(ps[0].display_name, 'somedir/foo.html')
97     self.assertEquals(ps[1].display_name, 'otherdir/bar.html')
98
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')
103
104     self.assertEquals(ps[0].display_name, 'foo')
105     self.assertEquals(ps[1].display_name, 'bar')
106
107   def testDisplayUrlForSingleFile(self):
108     ps = page_set.PageSet(file_path=os.path.dirname(__file__))
109     ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo.html')
110
111     self.assertEquals(ps[0].display_name, 'foo.html')
112
113   def testDisplayUrlForSingleDirectory(self):
114     ps = page_set.PageSet(file_path=os.path.dirname(__file__))
115     ps.AddPageWithDefaultRunNavigate('file://../../otherdir/foo')
116
117     self.assertEquals(ps[0].display_name, 'foo')