diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-03 20:09:52 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-03 20:09:52 +0000 |
commit | f815828e98b8449e52963f5b50e95d9cd6ed84c0 (patch) | |
tree | 2f1026fbbc63ab9ce2c75554b64293894f0f9bd2 | |
parent | cc9a9a88d5da672b09285ead7e604b6d7b77fd3d (diff) | |
download | chromium_src-f815828e98b8449e52963f5b50e95d9cd6ed84c0.zip chromium_src-f815828e98b8449e52963f5b50e95d9cd6ed84c0.tar.gz chromium_src-f815828e98b8449e52963f5b50e95d9cd6ed84c0.tar.bz2 |
New automation hooks to get/set the thumbnail/menu modes for NTP sections.
A few sample PyAuto tests are included that exerise these new hooks.
Contributed by dennisjeffrey@chromium.org.
BUG=64271
TEST=None
Review URL: http://codereview.chromium.org/6610021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76787 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 143 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 22 | ||||
-rw-r--r-- | chrome/browser/ui/webui/shown_sections_handler.cc | 2 | ||||
-rw-r--r-- | chrome/test/functional/ntp.py | 225 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 104 |
5 files changed, 495 insertions, 1 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 6c61b3e..d5a0d91 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -67,12 +67,14 @@ #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/browser/ui/webui/shown_sections_handler.h" #include "chrome/common/automation_messages.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" @@ -2238,6 +2240,15 @@ void TestingAutomationProvider::SendJSONRequest(int handle, browser_handler_map["SendKeyEventToActiveTab"] = &TestingAutomationProvider::SendKeyEventToActiveTab; + browser_handler_map["GetNTPThumbnailMode"] = + &TestingAutomationProvider::GetNTPThumbnailMode; + browser_handler_map["SetNTPThumbnailMode"] = + &TestingAutomationProvider::SetNTPThumbnailMode; + browser_handler_map["GetNTPMenuMode"] = + &TestingAutomationProvider::GetNTPMenuMode; + browser_handler_map["SetNTPMenuMode"] = + &TestingAutomationProvider::SetNTPMenuMode; + browser_handler_map["WebkitMouseMove"] = &TestingAutomationProvider::WebkitMouseMove; browser_handler_map["WebkitMouseClick"] = @@ -4626,6 +4637,138 @@ void TestingAutomationProvider::SendKeyEventToActiveTab( ForwardKeyboardEvent(event); } +// Sample JSON input: { "command": "GetNTPThumbnailMode" } +// For output, refer to GetNTPThumbnailMode() in +// chrome/test/pyautolib/pyauto.py. +void TestingAutomationProvider::GetNTPThumbnailMode( + Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + const int shown_sections = ShownSectionsHandler::GetShownSections( + browser->profile()->GetPrefs()); + + DictionaryValue* return_value = new DictionaryValue; + return_value->SetBoolean("apps", shown_sections & APPS ? true : false); + return_value->SetBoolean("most_visited", + shown_sections & THUMB ? true : false); + + AutomationJSONReply reply(this, reply_message); + reply.SendSuccess(return_value); +} + +// Sample JSON input: { "command": "SetNTPThumbnailMode", "section": "apps", +// "turn_on": true } +// Refer to SetNTPThumbnailMode() in chrome/test/pyautolib/pyauto.py for +// all possible input values. +// Sample JSON output: {} +void TestingAutomationProvider::SetNTPThumbnailMode( + Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + AutomationJSONReply reply(this, reply_message); + std::string section_name; + bool turn_on; + if (!args->GetString("section", §ion_name) || + !args->GetBoolean("turn_on", &turn_on)) { + reply.SendError("Invalid or missing args"); + return; + } + + PrefService* prefs = browser->profile()->GetPrefs(); + Section section; + if (section_name.compare("apps") == 0) { + section = APPS; + } else if (section_name.compare("most_visited") == 0) { + section = THUMB; + } else if (section_name.compare("recently_closed") == 0) { + reply.SendError("Thumbnail mode does not apply to the recently closed " + "section."); + return; + } else { + reply.SendError(StringPrintf("Unexpected section name: '%s'", + section_name.c_str())); + return; + } + + if (turn_on) { + ShownSectionsHandler::SetShownSection(prefs, section); + } else { + int shown_sections = ShownSectionsHandler::GetShownSections(prefs); + // Change the bit for the relevant section in the bitmask to 0. + shown_sections &= ~(0xFFFFFFFF & section); + prefs->SetInteger(prefs::kNTPShownSections, shown_sections); + } + + reply.SendSuccess(NULL); +} + +// Sample JSON input: { "command": "GetNTPMenuMode" } +// For output, refer to GetNTPMenuMode() in +// chrome/test/pyautolib/pyauto.py. +void TestingAutomationProvider::GetNTPMenuMode( + Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + const int shown_sections = ShownSectionsHandler::GetShownSections( + browser->profile()->GetPrefs()); + + DictionaryValue* return_value = new DictionaryValue; + return_value->SetBoolean("apps", shown_sections & MENU_APPS ? true : false); + return_value->SetBoolean("most_visited", + shown_sections & MENU_THUMB ? true : false); + return_value->SetBoolean("recently_closed", + shown_sections & MENU_RECENT ? true : false); + + AutomationJSONReply reply(this, reply_message); + reply.SendSuccess(return_value); +} + +// Sample JSON input: { "command": "SetNTPMenuMode", "section": "apps", +// "turn_on": false } +// Refer to SetNTPMenuMode() in chrome/test/pyautolib/pyauto.py for all possible +// input values. +// Sample JSON output: {} +void TestingAutomationProvider::SetNTPMenuMode( + Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + AutomationJSONReply reply(this, reply_message); + std::string section_name; + bool turn_on; + if (!args->GetString("section", §ion_name) || + !args->GetBoolean("turn_on", &turn_on)) { + reply.SendError("Invalid or missing args"); + return; + } + + PrefService* prefs = browser->profile()->GetPrefs(); + Section section; + if (section_name.compare("apps") == 0) { + section = MENU_APPS; + } else if (section_name.compare("most_visited") == 0) { + section = MENU_THUMB; + } else if (section_name.compare("recently_closed") == 0) { + section = MENU_RECENT; + } + else { + reply.SendError(StringPrintf("Unexpected section name: '%s'", + section_name.c_str())); + return; + } + + int shown_sections = ShownSectionsHandler::GetShownSections(prefs); + if (turn_on) { + // Change the bit for the relevant section in the bitmask to 1. + shown_sections |= section; + } else { + // Change the bit for the relevant section in the bitmask to 0. + shown_sections &= ~(0xFFFFFFFF & section); + } + prefs->SetInteger(prefs::kNTPShownSections, shown_sections); + + reply.SendSuccess(NULL); +} + void TestingAutomationProvider::WaitForAllTabsToStopLoading( DictionaryValue* args, IPC::Message* reply_message) { diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index 1295f83..7d7c95c8 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -772,6 +772,28 @@ class TestingAutomationProvider : public AutomationProvider, DictionaryValue* args, IPC::Message* reply_message); + // Determines whether each relevant section of the NTP is in thumbnail mode. + void GetNTPThumbnailMode(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + + // Puts or removes the specified section of the NTP into/from thumbnail mode. + // If the section is put into thumbnail mode, all other relevant sections are + // removed from thumbnail mode. + void SetNTPThumbnailMode(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + + // Determines whether each relevant section of the NTP is in menu mode. + void GetNTPMenuMode(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + + // Puts or removes the specified section of the NTP into/from menu mode. + void SetNTPMenuMode(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + // Waits for all tabs to stop loading. void WaitForAllTabsToStopLoading(DictionaryValue* args, IPC::Message* reply_message); diff --git a/chrome/browser/ui/webui/shown_sections_handler.cc b/chrome/browser/ui/webui/shown_sections_handler.cc index ff1d926b..de84d8b 100644 --- a/chrome/browser/ui/webui/shown_sections_handler.cc +++ b/chrome/browser/ui/webui/shown_sections_handler.cc @@ -105,7 +105,7 @@ void ShownSectionsHandler::HandleSetShownSections(const ListValue* args) { // static void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { #if defined(OS_CHROMEOS) - // Default to have expanded APPS and all other secions are minimized. + // Default to have expanded APPS and all other sections are minimized. pref_service->RegisterIntegerPref(prefs::kNTPShownSections, APPS | MENU_THUMB | MENU_RECENT); #else diff --git a/chrome/test/functional/ntp.py b/chrome/test/functional/ntp.py index dad980b..1ea8abe 100644 --- a/chrome/test/functional/ntp.py +++ b/chrome/test/functional/ntp.py @@ -380,6 +380,231 @@ class NTPTest(pyauto.PyUITest): ] self._VerifyAppInfo(app_info, expected_app_info) + def _VerifyThumbnailOrMenuMode(self, actual_info, expected_info): + """Verifies that the expected thumbnail/menu info matches the actual info. + + This function verifies that the expected info is contained within the + actual info. It's ok for the expected info to be a subset of the actual + info. Only the specified expected info will be verified. + + Args: + actual_info: A dictionary representing the actual thumbnail or menu mode + information for all relevant sections of the NTP. + expected_info: A dictionary representing the expected thumbnail or menu + mode information for the relevant sections of the NTP. + """ + for sec_name in expected_info: + # Ensure the expected section name is present in the actual info. + self.assertTrue(sec_name in actual_info, + msg='The actual info is missing information for section ' + '"%s".' % (sec_name)) + # Ensure the expected section value matches what's in the actual info. + self.assertTrue(expected_info[sec_name] == actual_info[sec_name], + msg='For section "%s", expected value %s, but instead ' + 'was %s.' % (sec_name, expected_info[sec_name], + actual_info[sec_name])) + + def testGetThumbnailModeInNewProfile(self): + """Ensures only the most visited thumbnails are present in a new profile.""" + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': False, + u'most_visited': True + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + def testSetThumbnailModeOn(self): + """Ensures that we can turn on thumbnail mode properly.""" + # Initially, only the Most Visited section should be in thumbnail mode. + # Turn on thumbnail mode for the Apps section and verify that only this + # section is in thumbnail mode (thumbnail mode for the Most Visited section + # should be turned off). + self.SetNTPThumbnailMode('apps', True) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': True, + u'most_visited': False + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + # Now turn on thumbnail mode for the Most Visited section, and verify that + # it gets turned on while the Apps section has thumbnail mode turned off. + self.SetNTPThumbnailMode('most_visited', True) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': False, + u'most_visited': True + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + # Now turn on thumbnail mode for both sections and verify that only the last + # one has thumbnail mode turned on. + self.SetNTPThumbnailMode('most_visited', True) + self.SetNTPThumbnailMode('apps', True) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': True, + u'most_visited': False + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + def testSetThumbnailModeOff(self): + """Ensures that we can turn off thumbnail mode properly.""" + # Initially, only the Most Visited section should be in thumbnail mode. + # Verify this. + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': False, + u'most_visited': True + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + # Turn off thumbnail mode for the Most Visited section and verify. + self.SetNTPThumbnailMode('most_visited', False) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': False, + u'most_visited': False + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + # Turn off thumbnail mode for the Most Visited section and verify that it + # remains off. + self.SetNTPThumbnailMode('most_visited', False) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': False, + u'most_visited': False + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + + def testGetMenuModeInNewProfile(self): + """Ensures that all NTP sections are not in menu mode in a fresh profile.""" + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': False, + u'most_visited': False, + u'recently_closed': False + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + def testSetMenuModeOn(self): + """Ensures that we can turn on menu mode properly.""" + # Initially, all NTP sections have menu mode turned off. + # Turn on menu mode for the Apps section and verify that it's turned on. + self.SetNTPMenuMode('apps', True) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': True, + u'most_visited': False, + u'recently_closed': False + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + # Turn on menu mode for the remaining sections and verify that they're all + # on. + self.SetNTPMenuMode('most_visited', True) + self.SetNTPMenuMode('recently_closed', True) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': True, + u'most_visited': True, + u'recently_closed': True + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + def testSetMenuModeOff(self): + # Turn on menu mode for all sections, then turn it off for only the Apps + # section, then verify. + self.SetNTPMenuMode('apps', True) + self.SetNTPMenuMode('most_visited', True) + self.SetNTPMenuMode('recently_closed', True) + self.SetNTPMenuMode('apps', False) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': False, + u'most_visited': True, + u'recently_closed': True + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + # Turn off menu mode for the remaining sections and verify. + self.SetNTPMenuMode('most_visited', False) + self.SetNTPMenuMode('recently_closed', False) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': False, + u'most_visited': False, + u'recently_closed': False + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + # Turn off menu mode for the Apps section again, and verify that it + # remains off. + self.SetNTPMenuMode('apps', False) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': False, + u'most_visited': False, + u'recently_closed': False + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + def testSetThumbnailModeDoesNotAffectMenuModeAndViceVersa(self): + """Verifies that setting thumbnail/menu mode does not affect the other.""" + # Set thumbnail mode for the Apps section, set and unset menu mode for a + # few sections, and verify that all sections are in thumbnail/menu mode as + # expected. + self.SetNTPThumbnailMode('apps', True) + self.SetNTPMenuMode('apps', True) + self.SetNTPMenuMode('recently_closed', True) + self.SetNTPMenuMode('apps', False) + self.SetNTPMenuMode('most_visited', True) + self.SetNTPMenuMode('recently_closed', False) + self.SetNTPMenuMode('apps', True) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': True, + u'most_visited': False + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': True, + u'most_visited': True, + u'recently_closed': False + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + + # Turn off menu mode for all sections. + self.SetNTPMenuMode('apps', False) + self.SetNTPMenuMode('most_visited', False) + self.SetNTPMenuMode('recently_closed', False) + + # Set menu mode for the Most Visited and Recently Closed sections, set and + # unset thumbnail mode for a few sections, and verify all is as expected. + self.SetNTPMenuMode('most_visited', True) + self.SetNTPMenuMode('recently_closed', True) + self.SetNTPThumbnailMode('apps', True) + self.SetNTPThumbnailMode('most_visited', True) + self.SetNTPThumbnailMode('apps', False) + self.SetNTPThumbnailMode('most_visited', False) + self.SetNTPThumbnailMode('apps', True) + self.SetNTPThumbnailMode('most_visited', True) + menu_info = self.GetNTPMenuMode() + expected_menu_info = { + u'apps': False, + u'most_visited': True, + u'recently_closed': True + } + self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) + thumb_info = self.GetNTPThumbnailMode() + expected_thumb_info = { + u'apps': False, + u'most_visited': True + } + self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) + if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 0224c8f..05f219c 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -2159,6 +2159,110 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } return self._GetResultFromJSONRequest(cmd_dict) + def GetNTPThumbnailMode(self): + """Identifies whether or not each relevant NTP section is in thumbnail mode. + + Thumbnail mode applies to the Apps section and the Most Visited section. + When in thumbnail mode, large thumbnails appear for each item in the + section. When not in thumbnail mode, small icons appear instead. At any + given time, at most one section can be in thumbnail mode in the NTP. + + SAMPLE OUTPUT: + { + u'apps': True, + u'most_visited': False + } + + Returns: + A dictionary indicating whether or not each relevant section of the NTP + is in thumbnail mode. + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'GetNTPThumbnailMode', + } + return self._GetResultFromJSONRequest(cmd_dict) + + def SetNTPThumbnailMode(self, section, turn_on): + """Puts or removes a section of the NTP into/from thumbnail (expanded) mode. + + Thumbnail mode applies to the Apps section and the Most Visited section. + At any given time, at most one section can be in thumbnail mode in the NTP; + when a specified section is put into thumbnail mode, the other section is + removed from thumbnail mode. + + Args: + section: A string representing the NTP section to use. + Possible values: + 'apps': the "Apps" section. + 'most_visited': the "Most Visited" section. + turn_on: A boolean indicating whether to put the section into thumbnail + mode (True), or remove the section from thumbnail mode (False). + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'SetNTPThumbnailMode', + 'section': section, + 'turn_on': turn_on + } + return self._GetResultFromJSONRequest(cmd_dict) + + def GetNTPMenuMode(self): + """Identifies whether or not each relevant NTP section is in menu mode. + + Menu mode applies to the Apps section, the Most Visited section, and the + Recently Closed section. When in menu mode, the section is almost + completely hidden, appearing as a menu at the bottom of the NTP. When not + in menu mode, the section appears with all information in the regular + location in the NTP. + + SAMPLE OUTPUT: + { + u'apps': False, + u'most_visited': True, + u'recently_closed': True + } + + Returns: + A dictionary indicating whether or not each relevant section of the NTP + is in menu mode. + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'GetNTPMenuMode', + } + return self._GetResultFromJSONRequest(cmd_dict) + + def SetNTPMenuMode(self, section, turn_on): + """Puts or removes the specified section of the NTP into/from menu mode. + + Menu mode applies to the Apps section, the Most Visited section, and the + Recently Closed section. + + Args: + section: A string representing the NTP section to use. + Possible values: + 'apps': the "Apps" section. + 'most_visited': the "Most Visited" section. + 'recently_closed': the "Recently Closed" section. + turn_on: A boolean indicating whether to put the section into menu mode + (True), or remove the section from menu mode (False). + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'SetNTPMenuMode', + 'section': section, + 'turn_on': turn_on + } + return self._GetResultFromJSONRequest(cmd_dict) ## ChromeOS section |