summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-09 21:55:12 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-09 21:55:12 +0000
commitbcc8f0143757eeb33da94e9ff11b853c97b867f8 (patch)
tree8dd01af59e6f9f795165c693ec7531f74cf4a349 /chrome
parente05fafe0e94262151e1660da9dc5629c7a016352 (diff)
downloadchromium_src-bcc8f0143757eeb33da94e9ff11b853c97b867f8.zip
chromium_src-bcc8f0143757eeb33da94e9ff11b853c97b867f8.tar.gz
chromium_src-bcc8f0143757eeb33da94e9ff11b853c97b867f8.tar.bz2
Move ChromeURLAfterDownload to download_browsertest
BUG=77762,14505,12745 TEST= Review URL: http://codereview.chromium.org/6691049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download/download_browsertest.cc91
-rw-r--r--chrome/browser/extensions/extension_management_apitest.cc7
-rw-r--r--chrome/test/ui_test_utils.cc94
-rw-r--r--chrome/test/ui_test_utils.h4
4 files changed, 84 insertions, 112 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index dd84c02..f64dbc1 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -31,14 +31,13 @@
#include "chrome/test/ui_test_utils.h"
#include "content/browser/cancelable_request.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
+#include "content/browser/tab_contents/tab_contents.h"
#include "content/common/page_transition_types.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-// Variation of DownloadsCompleteObserver from ui_test_utils.cc; the
-// specifically targeted download tests need finer granularity on waiting.
// Construction of this class defines a system state, based on some number
// of downloads being seen in a particular state + other events that
// may occur in the download system. That state will be recorded if it
@@ -391,8 +390,6 @@ class CancelTestDataCollector
DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector);
};
-} // namespace
-
class DownloadTest : public InProcessBrowserTest {
public:
enum SelectExpectation {
@@ -401,6 +398,10 @@ class DownloadTest : public InProcessBrowserTest {
EXPECT_SELECT_DIALOG
};
+ DownloadTest() {
+ EnableDOMAutomation();
+ }
+
// Returning false indicates a failure of the setup, and should be asserted
// in the caller.
virtual bool InitialSetup(bool prompt_for_download) {
@@ -924,15 +925,20 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) {
bool is_shelf_visible = IsDownloadUIVisible(incognito);
EXPECT_TRUE(is_shelf_visible);
- // Close the Incognito window and don't crash.
- incognito->CloseWindow();
#if !defined(OS_MACOSX)
// On Mac OS X, the UI window close is delayed until the outermost
// message loop runs. So it isn't possible to get a BROWSER_CLOSED
// notification inside of a test.
- ui_test_utils::WaitForNotificationFrom(NotificationType::BROWSER_CLOSED,
- Source<Browser>(incognito));
+ ui_test_utils::WindowedNotificationObserver signal(
+ NotificationType::BROWSER_CLOSED,
+ Source<Browser>(incognito));
+#endif
+ // Close the Incognito window and don't crash.
+ incognito->CloseWindow();
+
+#if !defined(OS_MACOSX)
+ signal.Wait();
ExpectWindowCountAfterDownload(1);
#endif
@@ -1180,14 +1186,20 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) {
EXPECT_EQ(1, download_browser->tab_count());
EXPECT_TRUE(IsDownloadUIVisible(download_browser));
- // Close the new window.
- download_browser->CloseWindow();
#if !defined(OS_MACOSX)
// On Mac OS X, the UI window close is delayed until the outermost
// message loop runs. So it isn't possible to get a BROWSER_CLOSED
// notification inside of a test.
- ui_test_utils::WaitForNotificationFrom(NotificationType::BROWSER_CLOSED,
- Source<Browser>(download_browser));
+ ui_test_utils::WindowedNotificationObserver signal(
+ NotificationType::BROWSER_CLOSED,
+ Source<Browser>(download_browser));
+#endif
+
+ // Close the new window.
+ download_browser->CloseWindow();
+
+#if !defined(OS_MACOSX)
+ signal.Wait();
EXPECT_EQ(first_browser, browser());
ExpectWindowCountAfterDownload(1);
#endif
@@ -1306,3 +1318,58 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
EXPECT_EQ(origin_size, info.total_bytes);
EXPECT_EQ(DownloadItem::COMPLETE, info.state);
}
+
+// Test for crbug.com/14505. This tests that chrome:// urls are still functional
+// after download of a file while viewing another chrome://.
+IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) {
+ ASSERT_TRUE(InitialSetup(false));
+ FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
+ GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL flags_url(chrome::kAboutFlagsURL);
+ GURL extensions_url(chrome::kChromeUIExtensionsURL);
+
+ ui_test_utils::NavigateToURL(browser(), flags_url);
+ DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
+ ui_test_utils::NavigateToURL(browser(), extensions_url);
+ TabContents* contents = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(contents);
+ bool webui_responded = false;
+ EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ contents->render_view_host(),
+ L"",
+ L"window.domAutomationController.send(window.webui_responded_);",
+ &webui_responded));
+ EXPECT_TRUE(webui_responded);
+}
+
+// Test for crbug.com/12745. This tests that if a download is initiated from
+// a chrome:// page that has registered and onunload handler, the browser
+// will be able to close.
+IN_PROC_BROWSER_TEST_F(DownloadTest,
+ BrowserCloseAfterDownload) {
+ GURL downloads_url(chrome::kAboutFlagsURL);
+ FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
+ GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
+
+ ui_test_utils::NavigateToURL(browser(), downloads_url);
+ TabContents* contents = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(contents);
+ bool result = false;
+ EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ contents->render_view_host(),
+ L"",
+ L"window.onunload = function() { var do_nothing = 0; }; "
+ L"window.domAutomationController.send(true);",
+ &result));
+ EXPECT_TRUE(result);
+
+ DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
+
+ ui_test_utils::WindowedNotificationObserver signal(
+ NotificationType::BROWSER_CLOSED,
+ Source<Browser>(browser()));
+ browser()->CloseWindow();
+ signal.Wait();
+}
+
+} // namespace
diff --git a/chrome/browser/extensions/extension_management_apitest.cc b/chrome/browser/extensions/extension_management_apitest.cc
index 064f188..d18972f 100644
--- a/chrome/browser/extensions/extension_management_apitest.cc
+++ b/chrome/browser/extensions/extension_management_apitest.cc
@@ -96,9 +96,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchPanelApp) {
ASSERT_TRUE(app_browser->is_app());
// Close the app panel.
+ ui_test_utils::WindowedNotificationObserver signal(
+ NotificationType::BROWSER_CLOSED,
+ Source<Browser>(app_browser));
+
app_browser->CloseWindow();
- ui_test_utils::WaitForNotificationFrom(NotificationType::BROWSER_CLOSED,
- Source<Browser>(app_browser));
+ signal.Wait();
// Unload the extension.
UninstallExtension(app_id);
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 5d863e0..e7c84aa 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -150,96 +150,6 @@ class DOMOperationObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
};
-// DownloadsCompleteObserver waits for a given number of downloads to complete.
-// Example usage:
-//
-// ui_test_utils::NavigateToURL(browser(), zip_url);
-// DownloadsCompleteObserver wait_on_download(
-// browser()->profile()->GetDownloadManager(), 1);
-// /* |zip_url| download will be complete by this line. */
-//
-class DownloadsCompleteObserver : public DownloadManager::Observer,
- public DownloadItem::Observer {
- public:
- explicit DownloadsCompleteObserver(DownloadManager* download_manager,
- size_t wait_count)
- : download_manager_(download_manager),
- wait_count_(wait_count),
- waiting_(false) {
- download_manager_->AddObserver(this);
- }
-
- // CheckAllDownloadsComplete will be called when the DownloadManager
- // fires it's ModelChanged() call, and also when incomplete downloads
- // fire their OnDownloadUpdated().
- bool CheckAllDownloadsComplete() {
- if (downloads_.size() < wait_count_)
- return false;
-
- bool still_waiting = false;
- std::vector<DownloadItem*>::iterator it = downloads_.begin();
- for (; it != downloads_.end(); ++it) {
- // We always remove ourselves as an observer, then re-add if the download
- // isn't complete. This is to avoid having to track which downloads we
- // are currently observing. Removing has no effect if we are not currently
- // an observer.
- (*it)->RemoveObserver(this);
- if ((*it)->IsInProgress()) {
- (*it)->AddObserver(this);
- still_waiting = true;
- }
- }
-
- if (still_waiting)
- return false;
-
- download_manager_->RemoveObserver(this);
- // waiting_ will have been set if not all downloads were complete on first
- // pass below in ModelChanged().
- if (waiting_)
- MessageLoopForUI::current()->Quit();
- return true;
- }
-
- // DownloadItem::Observer
- virtual void OnDownloadUpdated(DownloadItem* download) {
- if (download->IsComplete())
- CheckAllDownloadsComplete();
- }
-
- virtual void OnDownloadOpened(DownloadItem* download) {}
-
- // DownloadManager::Observer
- virtual void ModelChanged() {
- downloads_.clear();
- download_manager_->SearchDownloads(string16(), &downloads_);
-
- if (CheckAllDownloadsComplete())
- return;
-
- if (!waiting_) {
- waiting_ = true;
- ui_test_utils::RunMessageLoop();
- }
- }
-
- private:
- // The observed download manager.
- DownloadManager* download_manager_;
-
- // The current downloads being tracked.
- std::vector<DownloadItem*> downloads_;
-
- // The number of downloads to wait on completing.
- size_t wait_count_;
-
- // Whether an internal message loop has been started and must be quit upon
- // all downloads completing.
- bool waiting_;
-
- DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver);
-};
-
class FindInPageNotificationObserver : public NotificationObserver {
public:
explicit FindInPageNotificationObserver(TabContentsWrapper* parent_tab)
@@ -627,10 +537,6 @@ GURL GetTestUrl(const FilePath& dir, const FilePath& file) {
return net::FilePathToFileURL(GetTestFilePath(dir, file));
}
-void WaitForDownloadCount(DownloadManager* download_manager, size_t count) {
- DownloadsCompleteObserver download_observer(download_manager, count);
-}
-
AppModalDialog* WaitForAppModalDialog() {
TestNotificationObserver observer;
RegisterAndWait(&observer, NotificationType::APP_MODAL_DIALOG_SHOWN,
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index fe3c71da..ae4a411 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -191,10 +191,6 @@ FilePath GetTestFilePath(const FilePath& dir, const FilePath& file);
// The returned path is GURL format.
GURL GetTestUrl(const FilePath& dir, const FilePath& file);
-// Creates an observer that waits for |download_manager| to report that it
-// has a total of |count| downloads that have been handles
-void WaitForDownloadCount(DownloadManager* download_manager, size_t count);
-
// Blocks until an application modal dialog is showns and returns it.
AppModalDialog* WaitForAppModalDialog();