| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/browser/download/save_package.h" | 12 #include "content/browser/download/save_package.h" |
| 13 #include "content/test/net/url_request_mock_http_job.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "content/test/test_render_view_host.h" | 14 #include "content/test/test_render_view_host.h" |
| 15 #include "content/test/test_web_contents.h" | 15 #include "content/test/test_web_contents.h" |
| 16 #include "net/test/url_request/url_request_mock_http_job.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 #define FPL FILE_PATH_LITERAL | 22 #define FPL FILE_PATH_LITERAL |
| 22 #define HTML_EXTENSION ".html" | 23 #define HTML_EXTENSION ".html" |
| 23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 24 #define FPL_HTML_EXTENSION L".html" | 25 #define FPL_HTML_EXTENSION L".html" |
| 25 #else | 26 #else |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 "Test case " << i; | 408 "Test case " << i; |
| 408 } | 409 } |
| 409 } | 410 } |
| 410 | 411 |
| 411 static const base::FilePath::CharType* kTestDir = | 412 static const base::FilePath::CharType* kTestDir = |
| 412 FILE_PATH_LITERAL("save_page"); | 413 FILE_PATH_LITERAL("save_page"); |
| 413 | 414 |
| 414 // GetUrlToBeSaved method should return correct url to be saved. | 415 // GetUrlToBeSaved method should return correct url to be saved. |
| 415 TEST_F(SavePackageTest, TestGetUrlToBeSaved) { | 416 TEST_F(SavePackageTest, TestGetUrlToBeSaved) { |
| 416 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 417 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
| 417 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 418 GURL url = net::URLRequestMockHTTPJob::GetMockUrl( |
| 418 base::FilePath(kTestDir).Append(file_name)); | 419 base::FilePath(kTestDir).Append(file_name)); |
| 419 NavigateAndCommit(url); | 420 NavigateAndCommit(url); |
| 420 EXPECT_EQ(url, GetUrlToBeSaved()); | 421 EXPECT_EQ(url, GetUrlToBeSaved()); |
| 421 } | 422 } |
| 422 | 423 |
| 423 // GetUrlToBeSaved method sould return actual url to be saved, | 424 // GetUrlToBeSaved method sould return actual url to be saved, |
| 424 // instead of the displayed url used to view source of a page. | 425 // instead of the displayed url used to view source of a page. |
| 425 // Ex:GetUrlToBeSaved method should return http://www.google.com | 426 // Ex:GetUrlToBeSaved method should return http://www.google.com |
| 426 // when user types view-source:http://www.google.com | 427 // when user types view-source:http://www.google.com |
| 427 TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) { | 428 TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) { |
| 428 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 429 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
| 429 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 430 GURL mock_url = net::URLRequestMockHTTPJob::GetMockUrl( |
| 430 base::FilePath(kTestDir).Append(file_name)); | 431 base::FilePath(kTestDir).Append(file_name)); |
| 431 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl( | 432 GURL view_source_url = |
| 432 base::FilePath(kTestDir).Append(file_name)); | 433 GURL(kViewSourceScheme + std::string(":") + mock_url.spec()); |
| 434 GURL actual_url = net::URLRequestMockHTTPJob::GetMockUrl( |
| 435 base::FilePath(kTestDir).Append(file_name)); |
| 433 NavigateAndCommit(view_source_url); | 436 NavigateAndCommit(view_source_url); |
| 434 EXPECT_EQ(actual_url, GetUrlToBeSaved()); | 437 EXPECT_EQ(actual_url, GetUrlToBeSaved()); |
| 435 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL()); | 438 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL()); |
| 436 } | 439 } |
| 437 | 440 |
| 438 } // namespace content | 441 } // namespace content |
| OLD | NEW |