diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-10 00:09:03 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-10 00:09:03 +0000 |
commit | 4d1929f16b8c00f304fdc291cd4672c61ae5f400 (patch) | |
tree | 08ba2870510d8d11c5bffc0764a0d5968fda2b9d | |
parent | b7ca76b51d7a8c3f28d068a70b7b607be814c63e (diff) | |
download | chromium_src-4d1929f16b8c00f304fdc291cd4672c61ae5f400.zip chromium_src-4d1929f16b8c00f304fdc291cd4672c61ae5f400.tar.gz chromium_src-4d1929f16b8c00f304fdc291cd4672c61ae5f400.tar.bz2 |
PyAuto: Automation hooks to get/set theme
Add automation hooks to:
- install a given theme
- fetch info about the current theme
- reset to default theme
Add a test exercising the above.
BUG=36215
TEST=python chrome/test/functional/themes.py
Review URL: http://codereview.chromium.org/2827048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52024 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 24 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 6 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 1 | ||||
-rw-r--r-- | chrome/test/functional/themes.py | 45 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 62 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.cc | 4 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.h | 3 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 6 |
8 files changed, 150 insertions, 1 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 586a212..e708147 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -2347,6 +2347,27 @@ void AutomationProvider::SaveTabContents(Browser* browser, Send(reply_message); } +// Sample json input: { "command": "GetThemeInfo" } +// Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. +void AutomationProvider::GetThemeInfo(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + Extension* theme = browser->profile()->GetTheme(); + if (theme) { + return_value->SetString(L"name", theme->name()); + return_value->Set(L"images", theme->GetThemeImages()->DeepCopy()); + return_value->Set(L"colors", theme->GetThemeColors()->DeepCopy()); + return_value->Set(L"tints", theme->GetThemeTints()->DeepCopy()); + } + + std::string json_return; + base::JSONWriter::Write(return_value.get(), false, &json_return); + AutomationMsg_SendJSONRequest::WriteReplyParams( + reply_message, json_return, true); + Send(reply_message); +} + // Sample json input: // { "command": "GetAutoFillProfile" } // Refer to GetAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample @@ -2677,6 +2698,9 @@ void AutomationProvider::SendJSONRequest(int handle, handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; + // SetTheme() implemented using InstallExtension(). + handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; + handler_map["GetAutoFillProfile"] = &AutomationProvider::GetAutoFillProfile; handler_map["FillAutoFillProfile"] = &AutomationProvider::FillAutoFillProfile; diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 5361695..d8e8d0b 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -441,6 +441,12 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, DictionaryValue* args, IPC::Message* reply_message); + // Get info about theme. + // Uses the JSON interface for input/output. + void GetThemeInfo(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + // Get the profiles that are currently saved to the DB. // Uses the JSON interface for input/output. void GetAutoFillProfile(Browser* browser, diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 85772d5..12d5adf 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -35,6 +35,7 @@ 'prefs', 'special_tabs', 'test_basic.SimpleTest.testCanOpenGoogle', + 'themes', ], 'win': [ diff --git a/chrome/test/functional/themes.py b/chrome/test/functional/themes.py new file mode 100644 index 0000000..855e85d --- /dev/null +++ b/chrome/test/functional/themes.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os + +import pyauto_functional # Must be imported before pyauto +import pyauto + + +class ThemesTest(pyauto.PyUITest): + """TestCase for Themes.""" + + def Debug(self): + """Test method for experimentation. + + This method will not run automatically. + """ + import pprint + pp = pprint.PrettyPrinter(indent=2) + while True: + raw_input('Hit <enter> to dump info.. ') + pp.pprint(self.GetThemeInfo()) + + def testSetTheme(self): + """Verify theme install.""" + self.assertFalse(self.GetThemeInfo()) # Verify there's no theme at startup + crx_file = os.path.join(self.DataDir(), 'extensions', 'theme.crx') + self.assertTrue(self.SetTheme(pyauto.FilePath(crx_file))) + theme = self.GetThemeInfo() + self.assertEqual('camo theme', theme['name']) + # TODO: verify "theme installed" infobar + + def testThemeReset(self): + """Verify theme reset.""" + crx_file = os.path.join(self.DataDir(), 'extensions', 'theme.crx') + self.assertTrue(self.SetTheme(pyauto.FilePath(crx_file))) + self.assertTrue(self.ResetToDefaultTheme()) + self.assertFalse(self.GetThemeInfo()) + + +if __name__ == '__main__': + pyauto_functional.Main() + diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index e2c64c5..4b94b3d 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -757,6 +757,68 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): finally: shutil.rmtree(tempdir) + def SetTheme(self, crx_file_path): + """Installs the given theme synchronously. + + A theme file is file with .crx suffix, like an extension. + This method call waits until theme is installed and will trigger the + "theme installed" infobar. + + Uses InstallExtension(). + + Returns: + True, on success. + """ + return self.InstallExtension(crx_file_path, True) + + def ClearTheme(self): + """Clear the theme. Resets to default. + + Has no effect when the theme is already the default one. + This is a blocking call. + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'ClearTheme', + } + ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) + if ret_dict.has_key('error'): + raise JSONInterfaceError(ret_dict['error']) + return ret_dict + + def GetThemeInfo(self): + """Get info about theme. + + This includes info about the theme name, its colors, images, etc. + + Returns: + a dictionary containing info about the theme. + empty dictionary if no theme has been applied (default theme). + SAMPLE: + { u'colors': { u'frame': [71, 105, 91], + u'ntp_link': [36, 70, 0], + u'ntp_section': [207, 221, 192], + u'ntp_text': [20, 40, 0], + u'toolbar': [207, 221, 192]}, + u'images': { u'theme_frame': u'images/theme_frame_camo.png', + u'theme_ntp_background': u'images/theme_ntp_background.png', + u'theme_toolbar': u'images/theme_toolbar_camo.png'}, + u'name': u'camo theme', + u'tints': {u'buttons': [0.33000000000000002, 0.5, 0.46999999999999997]}} + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'GetThemeInfo', + } + ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) + if ret_dict.has_key('error'): + raise JSONInterfaceError(ret_dict['error']) + return ret_dict + class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): """Base TestSuite for PyAuto UI tests.""" diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index 452727b..0ae5b55 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -294,3 +294,7 @@ std::string PyUITestBase::_SendJSONRequest(int window_index, } return response; } + +bool PyUITestBase::ResetToDefaultTheme() { + return automation()->ResetToDefaultTheme(); +} diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h index d293370..6c6fc35 100644 --- a/chrome/test/pyautolib/pyautolib.h +++ b/chrome/test/pyautolib/pyautolib.h @@ -147,6 +147,9 @@ class PyUITestBase : public UITestBase { // automation proxy additions. Returns response as JSON dict. std::string _SendJSONRequest(int window_index, std::string& request); + // Resets to the default theme. Returns true on success. + bool ResetToDefaultTheme(); + private: // Enables PostTask to main thread. // Should be shared across multiple instances of PyUITestBase so that this diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index 1b011a2..889f989 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -330,9 +330,13 @@ class PyUITestBase { // Meta-method %feature("docstring", "Send a sync JSON request to Chrome. " "Returns a JSON dict as a response. " - "Internal method.") + "Internal method.") _SendJSONRequest; std::string _SendJSONRequest(int window_index, std::string request); + %feature("docstring", "Resets to the default theme. " + "Returns true on success.") ResetToDefaultTheme; + bool ResetToDefaultTheme(); + }; |