| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
| 34 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
| 35 #include "content/public/browser/download_item.h" | 35 #include "content/public/browser/download_item.h" |
| 36 #include "content/public/browser/download_manager.h" | 36 #include "content/public/browser/download_manager.h" |
| 37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
| 39 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/common/url_constants.h" |
| 40 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
| 41 #include "content/test/net/url_request_mock_http_job.h" | 42 #include "net/test/url_request/url_request_mock_http_job.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 43 | 44 |
| 44 using content::BrowserContext; | 45 using content::BrowserContext; |
| 45 using content::BrowserThread; | 46 using content::BrowserThread; |
| 46 using content::DownloadItem; | 47 using content::DownloadItem; |
| 47 using content::DownloadManager; | 48 using content::DownloadManager; |
| 48 using content::URLRequestMockHTTPJob; | |
| 49 using content::WebContents; | 49 using content::WebContents; |
| 50 using net::URLRequestMockHTTPJob; |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // Waits for an item record in the downloads database to match |filter|. See | 54 // Waits for an item record in the downloads database to match |filter|. See |
| 54 // DownloadStoredProperly() below for an example filter. | 55 // DownloadStoredProperly() below for an example filter. |
| 55 class DownloadPersistedObserver : public DownloadHistory::Observer { | 56 class DownloadPersistedObserver : public DownloadHistory::Observer { |
| 56 public: | 57 public: |
| 57 typedef base::Callback<bool( | 58 typedef base::Callback<bool( |
| 58 DownloadItem* item, | 59 DownloadItem* item, |
| 59 const history::DownloadRow&)> PersistedFilter; | 60 const history::DownloadRow&)> PersistedFilter; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 493 } |
| 493 | 494 |
| 494 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 495 // Disabled on Windows due to flakiness. http://crbug.com/162323 |
| 495 #if defined(OS_WIN) | 496 #if defined(OS_WIN) |
| 496 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly | 497 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly |
| 497 #else | 498 #else |
| 498 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly | 499 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly |
| 499 #endif | 500 #endif |
| 500 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { | 501 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { |
| 501 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 502 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
| 502 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 503 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl( |
| 503 base::FilePath(kTestDir).Append(file_name)); | 504 base::FilePath(kTestDir).Append(file_name)); |
| 505 GURL view_source_url = GURL( |
| 506 content::kViewSourceScheme + std::string(":") + mock_url.spec()); |
| 504 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 507 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
| 505 base::FilePath(kTestDir).Append(file_name)); | 508 base::FilePath(kTestDir).Append(file_name)); |
| 506 ui_test_utils::NavigateToURL(browser(), view_source_url); | 509 ui_test_utils::NavigateToURL(browser(), view_source_url); |
| 507 | 510 |
| 508 base::FilePath full_file_name, dir; | 511 base::FilePath full_file_name, dir; |
| 509 GetDestinationPaths("a", &full_file_name, &dir); | 512 GetDestinationPaths("a", &full_file_name, &dir); |
| 510 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( | 513 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( |
| 511 &DownloadStoredProperly, actual_page_url, full_file_name, 1, | 514 &DownloadStoredProperly, actual_page_url, full_file_name, 1, |
| 512 DownloadItem::COMPLETE)); | 515 DownloadItem::COMPLETE)); |
| 513 scoped_refptr<content::MessageLoopRunner> loop_runner( | 516 scoped_refptr<content::MessageLoopRunner> loop_runner( |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( | 803 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( |
| 801 GetDownloadManager())->DownloadPath(); | 804 GetDownloadManager())->DownloadPath(); |
| 802 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); | 805 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); |
| 803 ASSERT_TRUE(base::PathExists(filename)); | 806 ASSERT_TRUE(base::PathExists(filename)); |
| 804 std::string contents; | 807 std::string contents; |
| 805 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); | 808 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); |
| 806 EXPECT_EQ("foo", contents); | 809 EXPECT_EQ("foo", contents); |
| 807 } | 810 } |
| 808 | 811 |
| 809 } // namespace | 812 } // namespace |
| OLD | NEW |