| Index: content/browser/download/save_package_browsertest.cc
|
| diff --git a/content/browser/download/save_package_browsertest.cc b/content/browser/download/save_package_browsertest.cc
|
| index 2c7a652dd0d733f2db8f795a5b928e165d6518b5..ca933d6b3be167ef131b146d45202b4930cee91e 100644
|
| --- a/content/browser/download/save_package_browsertest.cc
|
| +++ b/content/browser/download/save_package_browsertest.cc
|
| @@ -4,13 +4,18 @@
|
|
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "content/browser/download/save_package.h"
|
| +#include "content/public/browser/browser_context.h"
|
| +#include "content/public/browser/download_manager.h"
|
| +#include "content/public/browser/web_contents.h"
|
| #include "content/public/test/content_browser_test.h"
|
| #include "content/public/test/content_browser_test_utils.h"
|
| +#include "content/public/test/test_utils.h"
|
| #include "content/shell/browser/shell.h"
|
|
|
| namespace content {
|
|
|
| const char kTestFile[] = "files/simple_page.html";
|
| +const char kIframeDocumentWrite[] = "files/iframe_doc_write.htm";
|
|
|
| class SavePackageBrowserTest : public ContentBrowserTest {
|
| protected:
|
| @@ -31,6 +36,46 @@ class SavePackageBrowserTest : public ContentBrowserTest {
|
| base::ScopedTempDir save_dir_;
|
| };
|
|
|
| +class SavePackageFinishedObserver : public DownloadManager::Observer {
|
| + public:
|
| + SavePackageFinishedObserver(content::DownloadManager* manager,
|
| + const base::Closure& callback)
|
| + : download_manager_(manager),
|
| + callback_(callback),
|
| + successfully_finished_(false) {
|
| + download_manager_->AddObserver(this);
|
| + }
|
| +
|
| + virtual ~SavePackageFinishedObserver() {
|
| + if (download_manager_)
|
| + download_manager_->RemoveObserver(this);
|
| + }
|
| +
|
| + // DownloadManager::Observer:
|
| + virtual void OnSavePackageFinished(
|
| + bool success,
|
| + content::DownloadManager* manager,
|
| + content::DownloadItem* item) OVERRIDE{
|
| + successfully_finished_ = success;
|
| + callback_.Run();
|
| + }
|
| +
|
| + virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE{
|
| + download_manager_->RemoveObserver(this);
|
| + download_manager_ = NULL;
|
| + }
|
| +
|
| + bool successfully_finished() const { return successfully_finished_; }
|
| +
|
| +private:
|
| + content::DownloadManager* download_manager_;
|
| + base::Closure callback_;
|
| +
|
| + bool successfully_finished_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SavePackageFinishedObserver);
|
| +};
|
| +
|
| // Create a SavePackage and delete it without calling Init.
|
| // SavePackage dtor has various asserts/checks that should not fire.
|
| IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, ImplicitCancel) {
|
| @@ -60,4 +105,30 @@ IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, ExplicitCancel) {
|
| ASSERT_TRUE(test_server()->Stop());
|
| }
|
|
|
| +// We should not cancel saving a main document html file in case of an
|
| +// having the same url. That is possible in the used TC.
|
| +IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, DuplicateURLForFrames) {
|
| + ASSERT_TRUE(test_server()->Start());
|
| + GURL url = test_server()->GetURL(kIframeDocumentWrite);
|
| + NavigateToURL(shell(), url);
|
| +
|
| + scoped_refptr<content::MessageLoopRunner> loop_runner(
|
| + new MessageLoopRunner);
|
| + SavePackageFinishedObserver observer(
|
| + BrowserContext::GetDownloadManager(
|
| + shell()->web_contents()->GetBrowserContext()),
|
| + loop_runner->QuitClosure());
|
| +
|
| + base::FilePath full_file_name, dir;
|
| + GetDestinationPaths("a", &full_file_name, &dir);
|
| + ASSERT_TRUE(shell()->web_contents()->SavePage(
|
| + full_file_name,
|
| + dir,
|
| + SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
|
| +
|
| + loop_runner->Run();
|
| +
|
| + EXPECT_TRUE(observer.successfully_finished());
|
| +}
|
| +
|
| } // namespace content
|
|
|