summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordennisjeffrey@google.com <dennisjeffrey@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-15 21:37:22 +0000
committerdennisjeffrey@google.com <dennisjeffrey@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-15 21:37:22 +0000
commitfc643f52f16712e1dcaea0aed8bc61f6b587286d (patch)
tree14006c0a0aad2ae175c40f578ba8422c8257cf14
parenta3e1b635a1f31e1c736ebb5dad2e772b12ac7aac (diff)
downloadchromium_src-fc643f52f16712e1dcaea0aed8bc61f6b587286d.zip
chromium_src-fc643f52f16712e1dcaea0aed8bc61f6b587286d.tar.gz
chromium_src-fc643f52f16712e1dcaea0aed8bc61f6b587286d.tar.bz2
New automation hook to set the app launch type (e.g., window vs. tab).
This hook allows the launch type for a specified app to be set as either a regular tab, a pinned tab, a fullscreen tab, or a tab in a new window. Sample PyAuto tests are included that exercise this hook. The GetBrowserInfo automation hook is also slightly modified to return information about whether each existing tab is pinned or not. BUG=75205 TEST=None. Review URL: http://codereview.chromium.org/6852005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81808 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc16
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc58
-rw-r--r--chrome/browser/automation/testing_automation_provider.h5
-rw-r--r--chrome/test/functional/ntp.py93
-rw-r--r--chrome/test/pyautolib/pyauto.py37
5 files changed, 192 insertions, 17 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 1e73430..c9a47a7 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -1861,6 +1861,22 @@ std::vector<DictionaryValue*>* GetAppInfoFromExtensions(
AppLauncherHandler::CreateAppInfo(*ext, ext_prefs, app_info);
app_info->SetBoolean("is_component_extension",
(*ext)->location() == Extension::COMPONENT);
+
+ // Convert the launch_type integer into a more descriptive string.
+ int launch_type;
+ app_info->GetInteger("launch_type", &launch_type);
+ if (launch_type == ExtensionPrefs::LAUNCH_PINNED) {
+ app_info->SetString("launch_type", "pinned");
+ } else if (launch_type == ExtensionPrefs::LAUNCH_REGULAR) {
+ app_info->SetString("launch_type", "regular");
+ } else if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN) {
+ app_info->SetString("launch_type", "fullscreen");
+ } else if (launch_type == ExtensionPrefs::LAUNCH_WINDOW) {
+ app_info->SetString("launch_type", "window");
+ } else {
+ app_info->SetString("launch_type", "unknown");
+ }
+
apps_list->push_back(app_info);
}
}
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 1e62e93..3d3538d 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -2275,6 +2275,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
&TestingAutomationProvider::SetNTPMenuMode;
browser_handler_map["LaunchApp"] = &TestingAutomationProvider::LaunchApp;
+ browser_handler_map["SetAppLaunchType"] =
+ &TestingAutomationProvider::SetAppLaunchType;
if (handler_map.find(std::string(command)) != handler_map.end()) {
(this->*handler_map[command])(dict_value, reply_message);
@@ -2541,6 +2543,7 @@ void TestingAutomationProvider::GetBrowserInfo(
tab->SetInteger("renderer_pid",
base::GetProcId(tc->GetRenderProcessHost()->GetHandle()));
tab->Set("infobars", GetInfobarsInfo(tc));
+ tab->SetBoolean("pinned", browser->IsTabPinned(i));
tabs->Append(tab);
}
browser_item->Set("tabs", tabs);
@@ -4959,6 +4962,61 @@ void TestingAutomationProvider::LaunchApp(
old_contents);
}
+// Sample JSON input: { "command": "SetAppLaunchType",
+// "id": "ahfgeienlihckogmohjhadlkjgocpleb",
+// "launch_type": "pinned" }
+// Sample JSON output: {}
+void TestingAutomationProvider::SetAppLaunchType(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+
+ std::string id;
+ if (!args->GetString("id", &id)) {
+ reply.SendError("Must include string id.");
+ return;
+ }
+
+ std::string launch_type_str;
+ if (!args->GetString("launch_type", &launch_type_str)) {
+ reply.SendError("Must specify app launch type.");
+ return;
+ }
+
+ ExtensionService* service = browser->profile()->GetExtensionService();
+ if (!service) {
+ reply.SendError("No extensions service.");
+ return;
+ }
+
+ const Extension* extension = service->GetExtensionById(
+ id, true /* include disabled extensions */);
+ if (!extension) {
+ reply.SendError(
+ StringPrintf("Extension with ID '%s' doesn't exist.", id.c_str()));
+ return;
+ }
+
+ ExtensionPrefs::LaunchType launch_type;
+ if (launch_type_str == "pinned") {
+ launch_type = ExtensionPrefs::LAUNCH_PINNED;
+ } else if (launch_type_str == "regular") {
+ launch_type = ExtensionPrefs::LAUNCH_REGULAR;
+ } else if (launch_type_str == "fullscreen") {
+ launch_type = ExtensionPrefs::LAUNCH_FULLSCREEN;
+ } else if (launch_type_str == "window") {
+ launch_type = ExtensionPrefs::LAUNCH_WINDOW;
+ } else {
+ reply.SendError(
+ StringPrintf("Unexpected launch type '%s'.", launch_type_str.c_str()));
+ return;
+ }
+
+ service->extension_prefs()->SetLaunchType(extension->id(), launch_type);
+ 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 b77c37c..624bae4 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -787,6 +787,11 @@ class TestingAutomationProvider : public AutomationProvider,
DictionaryValue* args,
IPC::Message* reply_message);
+ // Sets the launch type for the specified app.
+ void SetAppLaunchType(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/test/functional/ntp.py b/chrome/test/functional/ntp.py
index 7f74f2b..e4f3754 100644
--- a/chrome/test/functional/ntp.py
+++ b/chrome/test/functional/ntp.py
@@ -338,6 +338,19 @@ class NTPTest(pyauto.PyUITest):
'"%s".' % (attribute, expected_app[attribute],
actual_info[i][attribute]))
+ def _InstallAndVerifySamplePackagedApp(self):
+ """Installs a sample packaged app and verifies the install is successful.
+
+ Returns:
+ The string ID of the installed app.
+ """
+ app_crx_file = pyauto.FilePath(
+ os.path.abspath(os.path.join(self.DataDir(), 'pyauto_private', 'apps',
+ 'countdown.crx')))
+ installed_app_id = self.InstallApp(app_crx_file)
+ self.assertTrue(installed_app_id, msg='App install failed.')
+ return installed_app_id
+
def testGetAppsInNewProfile(self):
"""Ensures that the only app in a new profile is the Web Store app."""
app_info = self.GetNTPApps()
@@ -345,10 +358,7 @@ class NTPTest(pyauto.PyUITest):
def testGetAppsWhenInstallApp(self):
"""Ensures that an installed app is reflected in the app info in the NTP."""
- app_crx_file = pyauto.FilePath(
- os.path.abspath(os.path.join(self.DataDir(), 'pyauto_private', 'apps',
- 'countdown.crx')))
- self.assertTrue(self.InstallApp(app_crx_file), msg='App install failed.')
+ self._InstallAndVerifySamplePackagedApp()
app_info = self.GetNTPApps()
expected_app_info = [
{
@@ -377,11 +387,7 @@ class NTPTest(pyauto.PyUITest):
def testUninstallApp(self):
"""Ensures that an uninstalled app is reflected in the NTP app info."""
# First, install an app and verify that it exists in the NTP app info.
- app_crx_file = pyauto.FilePath(
- os.path.abspath(os.path.join(self.DataDir(), 'pyauto_private', 'apps',
- 'countdown.crx')))
- installed_app_id = self.InstallApp(app_crx_file)
- self.assertTrue(installed_app_id, msg='App install failed.')
+ installed_app_id = self._InstallAndVerifySamplePackagedApp()
app_info = self.GetNTPApps()
expected_app_info = [
{
@@ -415,11 +421,7 @@ class NTPTest(pyauto.PyUITest):
def testLaunchAppWithDefaultSettings(self):
"""Verifies that an app can be launched with the default settings."""
# Install an app.
- app_crx_file = pyauto.FilePath(
- os.path.abspath(os.path.join(self.DataDir(), 'pyauto_private', 'apps',
- 'countdown.crx')))
- installed_app_id = self.InstallApp(app_crx_file)
- self.assertTrue(installed_app_id, msg='App install failed.')
+ installed_app_id = self._InstallAndVerifySamplePackagedApp()
# Launch the app from the NTP.
self.LaunchApp(installed_app_id)
@@ -434,6 +436,69 @@ class NTPTest(pyauto.PyUITest):
self.assertTrue(actual_tab_url.startswith(expected_app_url_start),
msg='The app was not launched.')
+ def testLaunchAppRegularTab(self):
+ """Verifies that an app can be launched in a regular tab."""
+ installed_app_id = self._InstallAndVerifySamplePackagedApp()
+
+ self.SetAppLaunchType(installed_app_id, 'regular', windex=0)
+ self.LaunchApp(installed_app_id)
+
+ # Verify that the second tab in the first window is the app launch URL.
+ info = self.GetBrowserInfo()
+ actual_tab_url = info['windows'][0]['tabs'][1]['url']
+ expected_app_url_start = 'chrome-extension://' + installed_app_id
+ self.assertTrue(actual_tab_url.startswith(expected_app_url_start),
+ msg='The app was not launched in a regular tab.')
+
+ def testLaunchAppPinnedTab(self):
+ """Verifies that an app can be launched in a pinned tab."""
+ installed_app_id = self._InstallAndVerifySamplePackagedApp()
+
+ self.SetAppLaunchType(installed_app_id, 'pinned', windex=0)
+ self.LaunchApp(installed_app_id)
+
+ # Verify that the first tab in the first window is the app launch URL, and
+ # that it is a pinned tab.
+ info = self.GetBrowserInfo()
+ actual_tab_url = info['windows'][0]['tabs'][0]['url']
+ expected_app_url_start = 'chrome-extension://' + installed_app_id
+ self.assertTrue(actual_tab_url.startswith(expected_app_url_start) and
+ info['windows'][0]['tabs'][0]['pinned'],
+ msg='The app was not launched in a pinned tab.')
+
+ def testLaunchAppFullScreen(self):
+ """Verifies that an app can be launched in fullscreen mode."""
+ installed_app_id = self._InstallAndVerifySamplePackagedApp()
+
+ self.SetAppLaunchType(installed_app_id, 'fullscreen', windex=0)
+ self.LaunchApp(installed_app_id)
+
+ # Verify that the second tab in the first window is the app launch URL, and
+ # that the window is fullscreen.
+ info = self.GetBrowserInfo()
+ actual_tab_url = info['windows'][0]['tabs'][1]['url']
+ expected_app_url_start = 'chrome-extension://' + installed_app_id
+ self.assertTrue(actual_tab_url.startswith(expected_app_url_start) and
+ info['windows'][0]['fullscreen'],
+ msg='The app was not launched in fullscreen mode.')
+
+ def testLaunchAppNewWindow(self):
+ """Verifies that an app can be launched in a new window."""
+ installed_app_id = self._InstallAndVerifySamplePackagedApp()
+
+ self.SetAppLaunchType(installed_app_id, 'window', windex=0)
+ self.LaunchApp(installed_app_id)
+
+ # Verify that a second window exists (at index 1), and that its first tab
+ # is the app launch URL.
+ info = self.GetBrowserInfo()
+ self.assertTrue(len(info['windows']) == 2,
+ msg='A second window does not exist.')
+ actual_tab_url = info['windows'][1]['tabs'][0]['url']
+ expected_app_url_start = 'chrome-extension://' + installed_app_id
+ self.assertTrue(actual_tab_url.startswith(expected_app_url_start),
+ msg='The app was not launched in the new window.')
+
def _VerifyThumbnailOrMenuMode(self, actual_info, expected_info):
"""Verifies that the expected thumbnail/menu info matches the actual info.
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index ea34c54..d799c64 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1081,11 +1081,12 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'tabs': [ {
u'index': 0,
u'infobars': [],
+ u'pinned': True,
u'renderer_pid': 93747,
u'url': u'http://www.google.com/' }, {
-
u'index': 1,
u'infobars': [],
+ u'pinned': False,
u'renderer_pid': 93919,
u'url': u'https://chrome.google.com/'}, {
u'index': 2,
@@ -1095,6 +1096,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'text': u'slides.html5rocks.com wants to track '
'your physical location',
u'type': u'confirm_infobar'}],
+ u'pinned': False,
u'renderer_pid': 93929,
u'url': u'http://slides.html5rocks.com/#slide14'},
],
@@ -2202,6 +2204,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
def GetNTPApps(self):
"""Retrieves information about the apps listed on the NTP.
+ In the sample data below, the "launch_type" will be one of the following
+ strings: "pinned", "regular", "fullscreen", "window", or "unknown".
+
SAMPLE:
[
{
@@ -2213,7 +2218,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'is_component_extension': True,
u'is_disabled': False,
u'launch_container': 2,
- u'launch_type': 1,
+ u'launch_type': u'regular',
u'launch_url': u'https://chrome.google.com/webstore',
u'name': u'Chrome Web Store',
u'options_url': u'',
@@ -2230,7 +2235,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'is_component_extension': False,
u'is_disabled': False,
u'launch_container': 2,
- u'launch_type': 1
+ u'launch_type': u'regular',
u'launch_url': (u'chrome-extension://aeabikdlfbfeihglecobdkdflahfgcpd/'
u'launchLocalPath.html'),
u'name': u'Countdown',
@@ -2321,6 +2326,32 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict)
+ def SetAppLaunchType(self, app_id, launch_type, windex=0):
+ """Sets the launch type for the specified app.
+
+ Args:
+ app_id: The string ID of the app whose launch type should be set.
+ launch_type: The string launch type, which must be one of the following:
+ 'pinned': Launch in a pinned tab.
+ 'regular': Launch in a regular tab.
+ 'fullscreen': Launch in a fullscreen tab.
+ 'window': Launch in a new browser window.
+ windex: The index of the browser window to work on. Defaults to 0 (the
+ first window).
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ """
+ self.assertTrue(launch_type in ('pinned', 'regular', 'fullscreen',
+ 'window'),
+ msg='Unexpected launch type value: "%s"' % launch_type)
+ cmd_dict = {
+ 'command': 'SetAppLaunchType',
+ 'id': app_id,
+ 'launch_type': launch_type,
+ }
+ return self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+
def KillRendererProcess(self, pid):
"""Kills the given renderer process.