Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/test/functional/content.py

Issue 2861019: Enable "get html from page" functionality for PyAuto.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7
8 import pyauto_functional # Must be imported before pyauto
9 import pyauto
10
11
12 class ContentTest(pyauto.PyUITest):
13 """TestCase for getting html content from the browser."""
14
15 def _DataDirURL(self, filename):
16 """Return a URL in the data dir for the given filename."""
17 return self.GetFileURLForPath(os.path.join(self.DataDir(), filename))
18
19 def _StringContentCheck(self, content_string, have_list, nothave_list):
20 """Look for the presence or absence of strings in content.
21
22 Confirm all strings in have_list are found in content_string.
23 Confirm all strings in nothave_list are NOT found in content_string.
24 """
25 for s in have_list:
26 self.assertTrue(s in content_string)
27 for s in nothave_list:
28 self.assertTrue(s not in content_string)
29
30 def _FileContentCheck(self, filename, have_list, nothave_list):
31 """String check in local file.
32
33 For each local filename, tell the browser to load it as a file
34 UEL from the DataDir. Ask the browser for the loaded html.
35 Confirm all strings in have_list are found in it. Confirm all
36 strings in nothave_list are NOT found in it. Assumes only one
37 window/tab is open.
38 """
39 self.NavigateToURL(self._DataDirURL(filename))
40 self._StringContentCheck(self.GetTabContents(), have_list, nothave_list)
41
42 def testLocalFileBasics(self):
43 """For a few local files, do some basic has / not has."""
44 self._FileContentCheck('title1.html',
45 ['<html>', '</html>', 'page has no title'],
46 ['Title Of Awesomeness', '<b>'])
47 self._FileContentCheck('title2.html',
48 ['<html>', '</html>', 'Title Of Awesomeness'],
49 ['plastic flower', '<b>'])
50 self._FileContentCheck('title3.html',
51 ['<html>', '</html>', 'Title Of More Awesomeness'],
52 ['dinfidnfid', 'Title Of Awesomeness', '<b>'])
53
54 def testTwoTabs(self):
55 """Test content when we have 2 tabs."""
56 self.NavigateToURL(self._DataDirURL('title1.html'))
57 self.AppendTab(pyauto.GURL(self._DataDirURL('title2.html')), 0)
58 self._StringContentCheck(self.GetTabContents(0, 0),
59 ['page has no title'],
60 ['Awesomeness'])
61 self._StringContentCheck(self.GetTabContents(1, 0),
62 ['Awesomeness'],
63 ['page has no title'])
64
65 def testThreeWindows(self):
66 """Test content when we have 3 windows."""
67 self.NavigateToURL(self._DataDirURL('title1.html'))
68 for (window_index, url) in ((1, 'title2.html'), (2, 'title3.html')):
69 self.OpenNewBrowserWindow(True)
70 self.GetBrowserWindow(window_index).BringToFront()
71 self.NavigateToURL(self._DataDirURL(url), window_index, 0)
72
73 self._StringContentCheck(self.GetTabContents(0, 0),
74 ['page has no title'],
75 ['Awesomeness'])
76 self._StringContentCheck(self.GetTabContents(0, 1),
77 ['Awesomeness'],
78 ['page has no title'])
79 self._StringContentCheck(self.GetTabContents(0, 2),
80 ['Title Of More Awesomeness'],
81 ['page has no title'])
82
83 def testAboutVersion(self):
84 """Confirm about:version contains some expected content."""
85 self.NavigateToURL('about:version')
86 self._StringContentCheck(self.GetTabContents(),
87 ['User Agent', 'Command Line'],
88 ['odmomfodfm disfnodugdzuoufgbn ifdnf fif'])
89
90
91 if __name__ == '__main__':
92 pyauto_functional.Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698