Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / download / save_package_browsertest.cc
blob2c7a652dd0d733f2db8f795a5b928e165d6518b5
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/files/scoped_temp_dir.h"
6 #include "content/browser/download/save_package.h"
7 #include "content/public/test/content_browser_test.h"
8 #include "content/public/test/content_browser_test_utils.h"
9 #include "content/shell/browser/shell.h"
11 namespace content {
13 const char kTestFile[] = "files/simple_page.html";
15 class SavePackageBrowserTest : public ContentBrowserTest {
16 protected:
17 virtual void SetUp() OVERRIDE {
18 ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
19 ContentBrowserTest::SetUp();
22 // Returns full paths of destination file and directory.
23 void GetDestinationPaths(const std::string& prefix,
24 base::FilePath* full_file_name,
25 base::FilePath* dir) {
26 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm");
27 *dir = save_dir_.path().AppendASCII(prefix + "_files");
30 // Temporary directory we will save pages to.
31 base::ScopedTempDir save_dir_;
34 // Create a SavePackage and delete it without calling Init.
35 // SavePackage dtor has various asserts/checks that should not fire.
36 IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, ImplicitCancel) {
37 ASSERT_TRUE(test_server()->Start());
38 GURL url = test_server()->GetURL(kTestFile);
39 NavigateToURL(shell(), url);
40 base::FilePath full_file_name, dir;
41 GetDestinationPaths("a", &full_file_name, &dir);
42 scoped_refptr<SavePackage> save_package(new SavePackage(
43 shell()->web_contents(), SAVE_PAGE_TYPE_AS_ONLY_HTML, full_file_name,
44 dir));
45 ASSERT_TRUE(test_server()->Stop());
48 // Create a SavePackage, call Cancel, then delete it.
49 // SavePackage dtor has various asserts/checks that should not fire.
50 IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, ExplicitCancel) {
51 ASSERT_TRUE(test_server()->Start());
52 GURL url = test_server()->GetURL(kTestFile);
53 NavigateToURL(shell(), url);
54 base::FilePath full_file_name, dir;
55 GetDestinationPaths("a", &full_file_name, &dir);
56 scoped_refptr<SavePackage> save_package(new SavePackage(
57 shell()->web_contents(), SAVE_PAGE_TYPE_AS_ONLY_HTML, full_file_name,
58 dir));
59 save_package->Cancel(true);
60 ASSERT_TRUE(test_server()->Stop());
63 } // namespace content