Commit 7e4dbb72 authored by ace@chromium.org's avatar ace@chromium.org

Modifying some downloads hooks to act per-window (so that incognito windows...

Modifying some downloads hooks to act per-window (so that incognito windows can be correctly targetted) and updating some surrounding test cases.

BUG=59259

Review URL: http://codereview.chromium.org/6159001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71856 0039d316-1c4b-4281-b951-d872f2087c98
parent 1a78769e
...@@ -2521,14 +2521,15 @@ void TestingAutomationProvider::GetDownloadsInfo(Browser* browser, ...@@ -2521,14 +2521,15 @@ void TestingAutomationProvider::GetDownloadsInfo(Browser* browser,
IPC::Message* reply_message) { IPC::Message* reply_message) {
AutomationJSONReply reply(this, reply_message); AutomationJSONReply reply(this, reply_message);
if (!profile_->HasCreatedDownloadManager()) { if (!browser->profile()->HasCreatedDownloadManager()) {
reply.SendError("no download manager"); reply.SendError("no download manager");
return; return;
} }
scoped_ptr<DictionaryValue> return_value(new DictionaryValue); scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
std::vector<DownloadItem*> downloads; std::vector<DownloadItem*> downloads;
profile_->GetDownloadManager()->GetAllDownloads(FilePath(), &downloads); browser->profile()->GetDownloadManager()->
GetAllDownloads(FilePath(), &downloads);
ListValue* list_of_downloads = new ListValue; ListValue* list_of_downloads = new ListValue;
for (std::vector<DownloadItem*>::iterator it = downloads.begin(); for (std::vector<DownloadItem*>::iterator it = downloads.begin();
...@@ -2548,18 +2549,18 @@ void TestingAutomationProvider::WaitForDownloadsToComplete( ...@@ -2548,18 +2549,18 @@ void TestingAutomationProvider::WaitForDownloadsToComplete(
IPC::Message* reply_message) { IPC::Message* reply_message) {
// Look for a quick return. // Look for a quick return.
if (!profile_->HasCreatedDownloadManager()) { if (!browser->profile()->HasCreatedDownloadManager()) {
// No download manager. // No download manager.
AutomationJSONReply(this, reply_message).SendSuccess(NULL); AutomationJSONReply(this, reply_message).SendSuccess(NULL);
return; return;
} }
std::vector<DownloadItem*> downloads; std::vector<DownloadItem*> downloads;
profile_->GetDownloadManager()->GetCurrentDownloads(FilePath(), &downloads); browser->profile()->GetDownloadManager()->
GetCurrentDownloads(FilePath(), &downloads);
if (downloads.empty()) { if (downloads.empty()) {
AutomationJSONReply(this, reply_message).SendSuccess(NULL); AutomationJSONReply(this, reply_message).SendSuccess(NULL);
return; return;
} }
// The observer owns itself. When the last observed item pings, it // The observer owns itself. When the last observed item pings, it
// deletes itself. // deletes itself.
AutomationProviderDownloadItemObserver* item_observer = AutomationProviderDownloadItemObserver* item_observer =
...@@ -2602,7 +2603,7 @@ void TestingAutomationProvider::PerformActionOnDownload( ...@@ -2602,7 +2603,7 @@ void TestingAutomationProvider::PerformActionOnDownload(
int id; int id;
std::string action; std::string action;
if (!profile_->HasCreatedDownloadManager()) { if (!browser->profile()->HasCreatedDownloadManager()) {
AutomationJSONReply(this, reply_message).SendError("No download manager."); AutomationJSONReply(this, reply_message).SendError("No download manager.");
return; return;
} }
...@@ -2612,7 +2613,7 @@ void TestingAutomationProvider::PerformActionOnDownload( ...@@ -2612,7 +2613,7 @@ void TestingAutomationProvider::PerformActionOnDownload(
return; return;
} }
DownloadManager* download_manager = profile_->GetDownloadManager(); DownloadManager* download_manager = browser->profile()->GetDownloadManager();
DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager);
if (!selected_item) { if (!selected_item) {
AutomationJSONReply(this, reply_message).SendError( AutomationJSONReply(this, reply_message).SendError(
......
...@@ -133,13 +133,15 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -133,13 +133,15 @@ class DownloadsTest(pyauto.PyUITest):
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
'a_zip_file.zip') 'a_zip_file.zip')
self._ClearLocalDownloadState(downloaded_pkg) self._ClearLocalDownloadState(downloaded_pkg)
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
# Trigger download and wait in new incognito window.
self.DownloadAndWaitForStart(file_url, 1)
self.WaitForAllDownloadsToComplete(1)
incognito_downloads = self.GetDownloadsInfo(1).Downloads()
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # open incognito window # Verify that download info exists in the correct profile.
# Downloads from incognito window do not figure in GetDownloadsInfo() self.assertEqual(len(incognito_downloads), 1)
# since the download manager's list doesn't contain it.
# Using WaitUntil is the only resort.
self.NavigateToURL(file_url, 1, 0)
self.assertTrue(self.WaitUntil(lambda: os.path.exists(downloaded_pkg)))
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg))
self.assertTrue(self.IsDownloadShelfVisible(1)) self.assertTrue(self.IsDownloadShelfVisible(1))
...@@ -518,7 +520,7 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -518,7 +520,7 @@ class DownloadsTest(pyauto.PyUITest):
self.PerformActionOnDownload(id, 'open') self.PerformActionOnDownload(id, 'open')
self.WaitForAllDownloadsToComplete() self.WaitForAllDownloadsToComplete()
unzip_file_name = downloaded_pkg + '.cpgz' unzip_file_name = downloaded_pkg + '.cpgz'
# Verify that the file was correctly downloaded # Verify that the file was correctly downloaded.
self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_file_name)), self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_file_name)),
'Unzipped folder %s missing.' % unzip_file_name) 'Unzipped folder %s missing.' % unzip_file_name)
self.assertTrue(os.path.exists(downloaded_pkg), self.assertTrue(os.path.exists(downloaded_pkg),
...@@ -548,7 +550,7 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -548,7 +550,7 @@ class DownloadsTest(pyauto.PyUITest):
return old_percentage == 100 or percent > old_percentage, return old_percentage == 100 or percent > old_percentage,
self.assertTrue(self.WaitUntil(_PercentInc), self.assertTrue(self.WaitUntil(_PercentInc),
msg='Download percentage value is not increasing') msg='Download percentage value is not increasing')
# Once download is completed, percentage is 100 # Once download is completed, percentage is 100.
self.WaitForAllDownloadsToComplete() self.WaitForAllDownloadsToComplete()
downloads = self.GetDownloadsInfo().Downloads() downloads = self.GetDownloadsInfo().Downloads()
self.assertEqual(downloads[0]['PercentComplete'], 100, self.assertEqual(downloads[0]['PercentComplete'], 100,
...@@ -570,17 +572,21 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -570,17 +572,21 @@ class DownloadsTest(pyauto.PyUITest):
'a_zip_file (1).zip') 'a_zip_file (1).zip')
self._ClearLocalDownloadState(downloaded_pkg_regul) self._ClearLocalDownloadState(downloaded_pkg_regul)
self._ClearLocalDownloadState(downloaded_pkg_incog) self._ClearLocalDownloadState(downloaded_pkg_incog)
self.NavigateToURL(file_url, 0, 0)
self.DownloadAndWaitForStart(file_url, 0)
self.WaitForAllDownloadsToComplete(0)
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
self.NavigateToURL(file_url, 1, 0) self.DownloadAndWaitForStart(file_url, 1)
self.WaitForAllDownloadsToComplete() self.WaitForAllDownloadsToComplete(1)
# Verify download in regular Window. # Verify download in regular window.
self.assertTrue(os.path.exists(downloaded_pkg_regul)) self.assertTrue(os.path.exists(downloaded_pkg_regul))
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul))
# Verify download in Incognito Window. # Verify download in incognito window.
# WaitForAllDownloadsToComplete does not wait for incognito downloads # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case.
# Using extra WaitUntil until this is resolved.
self.assertTrue(self.WaitUntil( self.assertTrue(self.WaitUntil(
lambda: os.path.exists(downloaded_pkg_incog))) lambda: os.path.exists(downloaded_pkg_incog)))
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog))
......
...@@ -388,7 +388,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -388,7 +388,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
""" """
return bookmark_model.BookmarkModel(self._GetBookmarksAsJSON()) return bookmark_model.BookmarkModel(self._GetBookmarksAsJSON())
def GetDownloadsInfo(self): def GetDownloadsInfo(self, windex=0):
"""Return info about downloads. """Return info about downloads.
This includes all the downloads recognized by the history system. This includes all the downloads recognized by the history system.
...@@ -397,7 +397,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -397,7 +397,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
an instance of downloads_info.DownloadInfo an instance of downloads_info.DownloadInfo
""" """
return download_info.DownloadInfo( return download_info.DownloadInfo(
self._SendJSONRequest(0, json.dumps({'command': 'GetDownloadsInfo'}))) self._SendJSONRequest(
windex, json.dumps({'command': 'GetDownloadsInfo'})))
def GetOmniboxInfo(self, windex=0): def GetOmniboxInfo(self, windex=0):
"""Return info about Omnibox. """Return info about Omnibox.
...@@ -657,13 +658,14 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -657,13 +658,14 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
} }
self._GetResultFromJSONRequest(cmd_dict) self._GetResultFromJSONRequest(cmd_dict)
def WaitForAllDownloadsToComplete(self): def WaitForAllDownloadsToComplete(self, windex=0):
"""Wait for all downloads to complete. """Wait for all downloads to complete.
Note: This method does not work for dangerous downloads. Use Note: This method does not work for dangerous downloads. Use
WaitForGivenDownloadsToComplete (below) instead. WaitForGivenDownloadsToComplete (below) instead.
""" """
self._GetResultFromJSONRequest({'command': 'WaitForAllDownloadsToComplete'}) cmd_dict = {'command': 'WaitForAllDownloadsToComplete'}
self._GetResultFromJSONRequest(cmd_dict, windex=windex)
def WaitForDownloadToComplete(self, download_path, timeout=-1): def WaitForDownloadToComplete(self, download_path, timeout=-1):
"""Wait for the given downloads to complete. """Wait for the given downloads to complete.
...@@ -728,7 +730,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -728,7 +730,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
} }
return self._GetResultFromJSONRequest(cmd_dict, windex=window_index) return self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
def DownloadAndWaitForStart(self, file_url): def DownloadAndWaitForStart(self, file_url, windex=0):
"""Trigger download for the given url and wait for downloads to start. """Trigger download for the given url and wait for downloads to start.
It waits for download by looking at the download info from Chrome, so It waits for download by looking at the download info from Chrome, so
...@@ -738,11 +740,16 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -738,11 +740,16 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
download, it's fine to start another one even if the first one hasn't download, it's fine to start another one even if the first one hasn't
completed. completed.
""" """
num_downloads = len(self.GetDownloadsInfo().Downloads()) try:
self.NavigateToURL(file_url) # Trigger download. num_downloads = len(self.GetDownloadsInfo(windex).Downloads())
except JSONInterfaceError:
num_downloads = 0
self.NavigateToURL(file_url, windex) # Trigger download.
# It might take a while for the download to kick in, hold on until then. # It might take a while for the download to kick in, hold on until then.
self.assertTrue(self.WaitUntil( self.assertTrue(self.WaitUntil(
lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1)) lambda: len(self.GetDownloadsInfo(windex).Downloads()) >
num_downloads))
def SetWindowDimensions( def SetWindowDimensions(
self, x=None, y=None, width=None, height=None, windex=0): self, x=None, y=None, width=None, height=None, windex=0):
......
...@@ -74,6 +74,11 @@ void PyUITestBase::NavigateToURL(const char* url_string) { ...@@ -74,6 +74,11 @@ void PyUITestBase::NavigateToURL(const char* url_string) {
UITestBase::NavigateToURL(url); UITestBase::NavigateToURL(url);
} }
void PyUITestBase::NavigateToURL(const char* url_string, int window_index) {
GURL url(url_string);
UITestBase::NavigateToURL(url, window_index);
}
void PyUITestBase::NavigateToURL( void PyUITestBase::NavigateToURL(
const char* url_string, int window_index, int tab_index) { const char* url_string, int window_index, int tab_index) {
GURL url(url_string); GURL url(url_string);
......
...@@ -54,6 +54,9 @@ class PyUITestBase : public UITestBase { ...@@ -54,6 +54,9 @@ class PyUITestBase : public UITestBase {
// Navigate to the given URL in the active tab. Blocks until page loaded. // Navigate to the given URL in the active tab. Blocks until page loaded.
void NavigateToURL(const char* url_string); void NavigateToURL(const char* url_string);
// Navigate to the given URL in the active tab in the given window.
void NavigateToURL(const char* url_string, int window_index);
// Navigate to the given URL in given tab in the given window. // Navigate to the given URL in given tab in the given window.
// Blocks until page loaded. // Blocks until page loaded.
void NavigateToURL(const char* url_string, int window_index, int tab_index); void NavigateToURL(const char* url_string, int window_index, int tab_index);
......
...@@ -220,6 +220,7 @@ class PyUITestBase { ...@@ -220,6 +220,7 @@ class PyUITestBase {
"if it's not active already. Blocks until page has loaded.") "if it's not active already. Blocks until page has loaded.")
NavigateToURL; NavigateToURL;
void NavigateToURL(const char* url_string); void NavigateToURL(const char* url_string);
void NavigateToURL(const char* url_string, int window_index);
void NavigateToURL(const char* url_string, int window_index, int tab_index); void NavigateToURL(const char* url_string, int window_index, int tab_index);
%feature("docstring", "Reload the active tab in the given window (or first " %feature("docstring", "Reload the active tab in the given window (or first "
......
...@@ -273,6 +273,10 @@ void UITestBase::NavigateToURL(const GURL& url) { ...@@ -273,6 +273,10 @@ void UITestBase::NavigateToURL(const GURL& url) {
NavigateToURL(url, 0, GetActiveTabIndex(0)); NavigateToURL(url, 0, GetActiveTabIndex(0));
} }
void UITestBase::NavigateToURL(const GURL& url, int window_index) {
NavigateToURL(url, window_index, GetActiveTabIndex(window_index));
}
void UITestBase::NavigateToURL(const GURL& url, int window_index, int void UITestBase::NavigateToURL(const GURL& url, int window_index, int
tab_index) { tab_index) {
NavigateToURLBlockUntilNavigationsComplete(url, 1, window_index, tab_index); NavigateToURLBlockUntilNavigationsComplete(url, 1, window_index, tab_index);
......
...@@ -120,6 +120,9 @@ class UITestBase { ...@@ -120,6 +120,9 @@ class UITestBase {
// This method doesn't return until the navigation is complete. // This method doesn't return until the navigation is complete.
void NavigateToURL(const GURL& url); void NavigateToURL(const GURL& url);
// Navigate to the given URL in the active tab of the given app window.
void NavigateToURL(const GURL& url, int window_index);
// Same as above, except in the given tab and window. // Same as above, except in the given tab and window.
void NavigateToURL(const GURL& url, int window_index, int tab_index); void NavigateToURL(const GURL& url, int window_index, int tab_index);
......
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