Commit 55e165e5 authored by danhn@chromium.org's avatar danhn@chromium.org

Added webdriver support for App v2.

This change allows testing using Chrome webdriver on App v2 windows.  It exposes (via window_handles) and allows switching control to App v2 windows for testing.

BUG=6801177

Review URL: https://chromiumcodereview.appspot.com/10854026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151328 0039d316-1c4b-4281-b951-d872f2087c98
parent bda19f8e
......@@ -428,6 +428,9 @@ AutomationId GetIdForExtensionView(
case chrome::VIEW_TYPE_EXTENSION_INFOBAR:
type = AutomationId::kTypeExtensionInfobar;
break;
case chrome::VIEW_TYPE_APP_SHELL:
type = AutomationId::kTypeAppShell;
break;
default:
type = AutomationId::kTypeInvalid;
break;
......@@ -517,6 +520,7 @@ bool GetRenderViewForId(
case AutomationId::kTypeExtensionPopup:
case AutomationId::kTypeExtensionBgPage:
case AutomationId::kTypeExtensionInfobar:
case AutomationId::kTypeAppShell:
if (!GetExtensionRenderViewForId(id, profile, rvh))
return false;
break;
......@@ -548,7 +552,8 @@ bool DoesObjectWithIdExist(const AutomationId& id, Profile* profile) {
}
case AutomationId::kTypeExtensionPopup:
case AutomationId::kTypeExtensionBgPage:
case AutomationId::kTypeExtensionInfobar: {
case AutomationId::kTypeExtensionInfobar:
case AutomationId::kTypeAppShell: {
RenderViewHost* rvh;
return GetExtensionRenderViewForId(id, profile, &rvh);
}
......
......@@ -28,6 +28,7 @@ class AutomationId {
kTypeExtensionBgPage,
kTypeExtensionInfobar,
kTypeExtension,
kTypeAppShell,
};
static bool FromValue(
......
......@@ -52,7 +52,8 @@ void WindowHandlesCommand::ExecuteGet(Response* const response) {
}
base::ListValue* id_list = new base::ListValue();
for (size_t i = 0; i < views.size(); ++i) {
if (!views[i].view_id.IsTab())
if (!views[i].view_id.IsTab() &&
views[i].view_id.GetId().type() != AutomationId::kTypeAppShell)
continue;
id_list->Append(Value::CreateStringValue(
WebViewIdToString(views[i].view_id)));
......
// Copyright (c) 2012 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.
chrome.experimental.app.onLaunched.addListener(function(data) {
chrome.app.window.create('view_checks.html', {
frame: 'chrome',
width: 1024,
height: 768,
minWidth: 1024,
minHeight: 768
});
});
{
"name": "App Shell",
"manifest_version": 2,
"version": "1.0",
"app": {
"background": {
"scripts": [ "bg.js" ]
}
},
"permissions": [ "experimental" ]
}
<html>
<head>
<title>test</title>
</head>
<body>
<span>Should be in page source</span>
<input id='checkbox' type='checkbox'>Click me</input>
<input id='textfield' type='text'></input>
</body>
</html>
......@@ -17,11 +17,16 @@ from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
class _ViewType(object):
"""Constants representing different web view types in Chrome."""
"""Constants representing different web view types in Chrome.
They mirror the enum AutomationId::Type in chrome/common/automation_id.h.
"""
TAB = 1
EXTENSION_POPUP = 2
EXTENSION_BG_PAGE = 3
EXTENSION_INFOBAR = 4
APP_SHELL = 6
class WebDriver(RemoteWebDriver):
......@@ -164,33 +169,17 @@ class Extension(object):
self._execute(WebDriver._CHROME_MODIFY_EXTENSION,
{'click_button': 'page_action'})
def get_bg_page_handle(self):
"""Returns the window handle for the background page.
def get_app_shell_handle(self):
"""Returns the window handle for the app shell."""
return self._get_handle(_ViewType.APP_SHELL)
This handle can be used with |WebDriver.switch_to_window|.
Returns:
The window handle, or None if there is no background page.
"""
bg_pages = filter(lambda view: view['type'] == _ViewType.EXTENSION_BG_PAGE,
self._get_views())
if len(bg_pages) > 0:
return bg_pages[0]['handle']
return None
def get_bg_page_handle(self):
"""Returns the window handle for the background page."""
return self._get_handle(_ViewType.EXTENSION_BG_PAGE)
def get_popup_handle(self):
"""Returns the window handle for the open browser/page action popup.
This handle can be used with |WebDriver.switch_to_window|.
Returns:
The window handle, or None if there is no popup open.
"""
popups = filter(lambda view: view['type'] == _ViewType.EXTENSION_POPUP,
self._get_views())
if len(popups) > 0:
return popups[0]['handle']
return None
"""Returns the window handle for the open browser/page action popup."""
return self._get_handle(_ViewType.EXTENSION_POPUP)
def get_infobar_handles(self):
"""Returns a list of window handles for all open infobars of this extension.
......@@ -201,6 +190,22 @@ class Extension(object):
self._get_views())
return map(lambda view: view['handle'], infobars)
def _get_handle(self, type):
"""Returns the window handle for the page of given type.
This handle can be used with |WebDriver.switch_to_window|.
Args:
type: The type of the window as defined in _ViewType.
Returns:
The window handle, or None if there is no page with the given type.
"""
pages = filter(lambda view: view['type'] == type, self._get_views())
if len(pages) > 0:
return pages[0]['handle']
return None
def _get_info(self):
"""Returns a dictionary of all this extension's info."""
return self._execute(WebDriver._CHROME_GET_EXTENSION_INFO)['value']
......
......@@ -1068,6 +1068,8 @@ class ExtensionTest(ChromeDriverTest):
'/infobar_browser_action_extension'
PAGE_ACTION_EXTENSION = test_paths.TEST_DATA_PATH + \
'/page_action_extension'
APP_SHELL = test_paths.TEST_DATA_PATH + \
'/app_shell_extension'
def testExtensionInstallAndUninstall(self):
driver = self.GetNewDriver()
......@@ -1138,6 +1140,20 @@ class ExtensionTest(ChromeDriverTest):
ext.click_page_action()
self._testExtensionView(driver, ext.get_popup_handle(), ext)
def testAppShellView(self):
driver = self.GetNewDriver({'chrome.switches':
['enable-experimental-extension-apis']})
ext = driver.install_extension(self.APP_SHELL)
# Navigates to the new tab page to launch the app.
driver.get('chrome:newtab')
app = driver.find_element_by_xpath("//div[@title='App Shell']")
app.click()
def is_app_window_launched(driver):
return ext.get_app_shell_handle() is not None
WebDriverWait(driver, 10).until(is_app_window_launched)
self._testExtensionView(driver, ext.get_app_shell_handle(), ext)
class BadJSTest(ChromeDriverTest):
"""Tests that ensure sites with hacky JS don't break ChromeDriver."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment