def testTwoTabs(self): """Test content when we have 2 tabs.""" self.NavigateToURL(self._DataDirURL('title1.html')) self.AppendTab(pyauto.GURL(self._DataDirURL('title2.html')), 0) test_utils.StringContentCheck(self, self.GetTabContents(0, 0), ['page has no title'], ['Awesomeness']) test_utils.StringContentCheck(self, self.GetTabContents(1, 0), ['Awesomeness'], ['page has no title'])
def testThreeWindows(self): """Test content when we have 3 windows.""" self.NavigateToURL(self._DataDirURL('title1.html')) for (window_index, url) in ((1, 'title2.html'), (2, 'title3.html')): self.OpenNewBrowserWindow(True) self.GetBrowserWindow(window_index).BringToFront() self.NavigateToURL(self._DataDirURL(url), window_index, 0) test_utils.StringContentCheck(self, self.GetTabContents(0, 0), ['page has no title'], ['Awesomeness']) test_utils.StringContentCheck(self, self.GetTabContents(0, 1), ['Awesomeness'], ['page has no title']) test_utils.StringContentCheck(self, self.GetTabContents(0, 2), ['Title Of More Awesomeness'], ['page has no title'])
def testAboutVersion(self): """Confirm about:version contains some expected content.""" self.NavigateToURL('about:version') test_utils.StringContentCheck( self, self.GetTabContents(), ['WebKit', 'os_version', 'js_version'], ['odmomfodfm disfnodugdzuoufgbn ifdnf fif'])
def _VerifyAboutDNS(self): """Confirm about:dns contains expected content related to DNS info. Also confirms that prefetching DNS records propogate.""" # Navigate to a page to activate DNS prefetching. self.NavigateToURL('http://www.google.com') self.TabGoBack() test_utils.StringContentCheck( self, self.GetTabContents(), ['Host name', 'How long ago', 'Motivation'], [])
def testSpecialURLTabs(self): """Test special tabs created by URLs like chrome://downloads, chrome://settings/extensionSettings, chrome://history etc. Also ensures they specify content-security-policy and not inline scripts for those pages that are expected to do so. Patches which break this test by including new inline javascript are security vulnerabilities and should be reverted.""" tabs = self._GetPlatformSpecialURLTabs() for url, properties in tabs.iteritems(): logging.debug('Testing URL %s.' % url) self.NavigateToURL(url) expected_title = 'title' in properties and properties[ 'title'] or url actual_title = self.GetActiveTabTitle() self.assertTrue( self.WaitUntil(lambda: self.GetActiveTabTitle(), expect_retval=expected_title), msg='Title did not match for %s. Expected: %s. Got %s' % (url, expected_title, self.GetActiveTabTitle())) include_list = [] exclude_list = [] no_csp = 'CSP' in properties and not properties['CSP'] if no_csp: exclude_list.extend(['Content-Security-Policy']) else: exclude_list.extend([ '<script>', 'onclick=', 'onload=', 'onchange=', 'onsubmit=', 'javascript:' ]) if 'includes' in properties: include_list.extend(properties['includes']) if 'excludes' in properties: exclude_list.extend(properties['exlcudes']) test_utils.StringContentCheck(self, self.GetTabContents(), include_list, exclude_list) result = self.ExecuteJavascript(""" var r = 'blocked'; var f = 'executed'; var s = document.createElement('script'); s.textContent = 'r = f'; document.body.appendChild(s); window.domAutomationController.send(r); """) logging.debug('has csp %s, result %s.' % (not no_csp, result)) if no_csp: self.assertEqual(result, 'executed', msg='Got %s for %s' % (result, url)) else: self.assertEqual(result, 'blocked', msg='Got %s for %s' % (result, url)) # Restart browser so that every URL gets a fresh instance. self.RestartBrowser(clear_profile=True)
def _FileContentCheck(self, filename, have_list, nothave_list): """String check in local file. For each local filename, tell the browser to load it as a file URL from the DataDir. Ask the browser for the loaded html. Confirm all strings in have_list are found in it. Confirm all strings in nothave_list are NOT found in it. Assumes only one window/tab is open. """ self.NavigateToURL(self._DataDirURL(filename)) test_utils.StringContentCheck(self, self.GetTabContents(), have_list, nothave_list)
def _VerifyAppCacheInternals(self): """Confirm about:appcache-internals contains expected content for Caches. Also confirms that the about page populates Application Caches.""" # Navigate to html page to activate DNS prefetching. self.NavigateToURL('http://futtta.be/html5/offline.php') # Wait for page to load and display sucess or fail message. self.WaitUntil(lambda: self.GetDOMValue( 'document.getElementById("status").innerHTML'), expect_retval='cached') self.TabGoBack() test_utils.StringContentCheck( self, self.GetTabContents(), ['Manifest', 'http://futtta.be/html5/manifest.php'], [])
def _VerifyAppCacheInternals(self): """Confirm about:appcache-internals contains expected content for Caches. Also confirms that the about page populates Application Caches.""" # Navigate to html page to activate DNS prefetching. self.NavigateToURL('http://static.webvm.net/appcache-test/simple.html') # Wait for page to load and display sucess or fail message. self.WaitUntil(lambda: self.GetDOMValue( 'document.getElementById("result").innerHTML'), expect_retval='SUCCESS') self.GetBrowserWindow(0).GetTab(0).GoBack() test_utils.StringContentCheck(self, self.GetTabContents(), [ 'Manifest', 'http://static.webvm.net/appcache-test/resources/simple.manifest' ], [])
def testSpecialURLTabs(self): """Test special tabs created by URLs like chrome://downloads, chrome://settings/extensionSettings, chrome://history etc. Also ensures they specify content-security-policy and not inline scripts for those pages that are expected to do so.""" tabs = self._GetPlatformSpecialURLTabs() for url, properties in tabs.iteritems(): logging.debug('Testing URL %s.' % url) self.NavigateToURL(url) expected_title = 'title' in properties and properties['title'] or url actual_title = self.GetActiveTabTitle() logging.debug(' %s title was %s (%s)' % (url, actual_title, expected_title == actual_title)) self.assertEqual(expected_title, actual_title) include_list = [] exclude_list = [] no_csp = 'CSP' in properties and not properties['CSP'] if no_csp: exclude_list.extend(['X-WebKit-CSP']) else: exclude_list.extend(['<script>', 'onclick=', 'onload=', 'onchange=', 'onsubmit=', 'javascript:']) if 'includes' in properties: include_list.extend(properties['includes']) if 'excludes' in properties: exclude_list.extend(properties['exlcudes']) test_utils.StringContentCheck(self, self.GetTabContents(), include_list, exclude_list) result = self.ExecuteJavascript(""" var r = 'blocked'; var f = 'executed'; var s = document.createElement('script'); s.textContent = 'r = f'; document.body.appendChild(s); window.domAutomationController.send(r); """) logging.debug('has csp %s, result %s.' % (not no_csp, result)) if no_csp: self.assertEqual(result, 'executed', msg='Got %s for %s' % (result, url)) else: self.assertEqual(result, 'blocked');