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 """Update tests for themes.""" 6 import os 7 import sys 8 9 _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) 10 sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, os.path.pardir, 11 os.path.pardir, 'build', 'util', 'lib')) 12 13 from common import util 14 15 import chrome_options 16 import install_test 17 18 19 class ThemeUpdater(install_test.InstallTest): 20 """Theme update tests.""" 21 _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) 22 _EXTENSIONS_DIR = os.path.join(_DIRECTORY, os.path.pardir, 'data', 23 'extensions') 24 camo_theme = os.path.join(_EXTENSIONS_DIR, 'theme.crx') 25 camo_img = ('chrome://theme/IDR_THEME_NTP_BACKGROUND?' 26 'iamefpfkojoapidjnbafmgkgncegbkad') 27 28 def setUp(self): 29 super(ThemeUpdater, self).setUp() 30 self._user_data_dir = util.MakeTempDir() 31 32 def _CheckThemeApplied(self): 33 """Loads the New Tab Page and asserts that the theme is applied.""" 34 self._driver.get('chrome://newtab') 35 html = self._driver.find_element_by_xpath('html') 36 html_background = html.value_of_css_property('background-image') 37 self.assertTrue(self.camo_img in html_background, 38 msg='Did not find expected theme background-image') 39 40 def _StartChromeProfile(self, incognito=False): 41 """Start Chrome with a temp profile. 42 43 Args: 44 incognito: Boolean flag for starting Chrome in incognito. 45 """ 46 options = chrome_options.ChromeOptions() 47 options.SetUserDataDir(self._user_data_dir) 48 if incognito: 49 options.AddSwitch('incognito') 50 self.StartChrome(options.GetCapabilities()) 51 52 def _StartChromeProfileExtension(self, extension): 53 """Start Chrome with a temp profile and with specified extension. 54 55 Args: 56 extension: Paths to extension to be installed. 57 """ 58 options = chrome_options.ChromeOptions() 59 options.AddExtension(extension) 60 options.SetUserDataDir(self._user_data_dir) 61 self.StartChrome(options.GetCapabilities()) 62 63 def testInstallTheme(self): 64 """Install a theme and check it is still applied after update.""" 65 self.Install(self.GetUpdateBuilds()[0]) 66 self._StartChromeProfileExtension(self.camo_theme) 67 self._CheckThemeApplied() 68 69 # Update and relaunch without extension. 70 self.Install(self.GetUpdateBuilds()[1]) 71 self._StartChromeProfile() 72 self._CheckThemeApplied() 73 74 def testInstallThemeIncognito(self): 75 """Install a theme and check it still applies to incognito after update.""" 76 self.Install(self.GetUpdateBuilds()[0]) 77 self._StartChromeProfileExtension(self.camo_theme) 78 self._CheckThemeApplied() 79 80 # Relaunch without extension in incognito. 81 self._driver.quit() 82 self._StartChromeProfile(incognito=True) 83 self._CheckThemeApplied() 84 85 # Update and relaunch without extension in incognito. 86 self.Install(self.GetUpdateBuilds()[1]) 87 self._StartChromeProfile(incognito=True) 88 self._CheckThemeApplied() 89