Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/download/save_package_unittest.cc

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/file_path.h" 7 #include "base/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/download/save_package.h" 13 #include "content/browser/download/save_package.h"
14 #include "content/browser/renderer_host/test_render_view_host.h" 14 #include "content/browser/renderer_host/test_render_view_host.h"
15 #include "content/browser/tab_contents/test_tab_contents.h" 15 #include "content/browser/tab_contents/test_tab_contents.h"
16 #include "content/test/net/url_request_mock_http_job.h" 16 #include "content/test/net/url_request_mock_http_job.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using content::BrowserThread;
20 using content::BrowserThreadImpl; 21 using content::BrowserThreadImpl;
22 using content::RenderViewHostImplTestHarness;
21 23
22 #define FPL FILE_PATH_LITERAL 24 #define FPL FILE_PATH_LITERAL
23 #if defined(OS_WIN) 25 #if defined(OS_WIN)
24 #define HTML_EXTENSION ".htm" 26 #define HTML_EXTENSION ".htm"
25 // This second define is needed because MSVC is broken. 27 // This second define is needed because MSVC is broken.
26 #define FPL_HTML_EXTENSION L".htm" 28 #define FPL_HTML_EXTENSION L".htm"
27 #else 29 #else
28 #define HTML_EXTENSION ".html" 30 #define HTML_EXTENSION ".html"
29 #define FPL_HTML_EXTENSION ".html" 31 #define FPL_HTML_EXTENSION ".html"
30 #endif 32 #endif
31 33
32 using content::BrowserThread;
33
34 namespace { 34 namespace {
35 35
36 // This constant copied from save_package.cc. 36 // This constant copied from save_package.cc.
37 #if defined(OS_WIN) 37 #if defined(OS_WIN)
38 const uint32 kMaxFilePathLength = MAX_PATH - 1; 38 const uint32 kMaxFilePathLength = MAX_PATH - 1;
39 const uint32 kMaxFileNameLength = MAX_PATH - 1; 39 const uint32 kMaxFileNameLength = MAX_PATH - 1;
40 #elif defined(OS_POSIX) 40 #elif defined(OS_POSIX)
41 const uint32 kMaxFilePathLength = PATH_MAX - 1; 41 const uint32 kMaxFilePathLength = PATH_MAX - 1;
42 const uint32 kMaxFileNameLength = NAME_MAX; 42 const uint32 kMaxFileNameLength = NAME_MAX;
43 #endif 43 #endif
(...skipping 15 matching lines...) Expand all
59 i != r_paren_index; ++i) { 59 i != r_paren_index; ++i) {
60 if (!IsAsciiDigit(filename[i])) 60 if (!IsAsciiDigit(filename[i]))
61 return false; 61 return false;
62 } 62 }
63 63
64 return true; 64 return true;
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
69 class SavePackageTest : public RenderViewHostTestHarness { 69 class SavePackageTest : public RenderViewHostImplTestHarness {
70 public: 70 public:
71 SavePackageTest() : browser_thread_(BrowserThread::UI, &message_loop_) { 71 SavePackageTest() : browser_thread_(BrowserThread::UI, &message_loop_) {
72 } 72 }
73 73
74 bool GetGeneratedFilename(bool need_success_generate_filename, 74 bool GetGeneratedFilename(bool need_success_generate_filename,
75 const std::string& disposition, 75 const std::string& disposition,
76 const std::string& url, 76 const std::string& url,
77 bool need_htm_ext, 77 bool need_htm_ext,
78 FilePath::StringType* generated_name) { 78 FilePath::StringType* generated_name) {
79 SavePackage* save_package; 79 SavePackage* save_package;
(...skipping 13 matching lines...) Expand all
93 const std::string& content_mime_type) { 93 const std::string& content_mime_type) {
94 return SavePackage::EnsureMimeExtension(name, content_mime_type); 94 return SavePackage::EnsureMimeExtension(name, content_mime_type);
95 } 95 }
96 96
97 GURL GetUrlToBeSaved() { 97 GURL GetUrlToBeSaved() {
98 return save_package_success_->GetUrlToBeSaved(); 98 return save_package_success_->GetUrlToBeSaved();
99 } 99 }
100 100
101 protected: 101 protected:
102 virtual void SetUp() { 102 virtual void SetUp() {
103 RenderViewHostTestHarness::SetUp(); 103 RenderViewHostImplTestHarness::SetUp();
104 104
105 // Do the initialization in SetUp so contents() is initialized by 105 // Do the initialization in SetUp so contents() is initialized by
106 // RenderViewHostTestHarness::SetUp. 106 // RenderViewHostImplTestHarness::SetUp.
107 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 107 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
108 108
109 save_package_success_ = new SavePackage(contents(), 109 save_package_success_ = new SavePackage(contents(),
110 temp_dir_.path().AppendASCII("testfile" HTML_EXTENSION), 110 temp_dir_.path().AppendASCII("testfile" HTML_EXTENSION),
111 temp_dir_.path().AppendASCII("testfile_files")); 111 temp_dir_.path().AppendASCII("testfile_files"));
112 112
113 // We need to construct a path that is *almost* kMaxFilePathLength long 113 // We need to construct a path that is *almost* kMaxFilePathLength long
114 long_file_name.resize(kMaxFilePathLength + long_file_name.length()); 114 long_file_name.resize(kMaxFilePathLength + long_file_name.length());
115 while (long_file_name.length() < kMaxFilePathLength) 115 while (long_file_name.length() < kMaxFilePathLength)
116 long_file_name += long_file_name; 116 long_file_name += long_file_name;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) { 421 TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) {
422 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 422 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
423 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 423 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
424 FilePath(kTestDir).Append(file_name)); 424 FilePath(kTestDir).Append(file_name));
425 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl( 425 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl(
426 FilePath(kTestDir).Append(file_name)); 426 FilePath(kTestDir).Append(file_name));
427 NavigateAndCommit(view_source_url); 427 NavigateAndCommit(view_source_url);
428 EXPECT_EQ(actual_url, GetUrlToBeSaved()); 428 EXPECT_EQ(actual_url, GetUrlToBeSaved());
429 EXPECT_EQ(view_source_url, contents()->GetURL()); 429 EXPECT_EQ(view_source_url, contents()->GetURL());
430 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698