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

Side by Side Diff: chrome/browser/download/save_page_browsertest.cc

Issue 6312027: Add files saved using 'Save page as' to the download history.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 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
« no previous file with comments | « chrome/browser/download/save_package.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
11 #include "chrome/browser/download/download_history.h"
12 #include "chrome/browser/download/download_manager.h"
11 #include "chrome/browser/net/url_request_mock_http_job.h" 13 #include "chrome/browser/net/url_request_mock_http_job.h"
14 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
16 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
17 #include "chrome/test/in_process_browser_test.h" 20 #include "chrome/test/in_process_browser_test.h"
18 #include "chrome/test/ui_test_utils.h" 21 #include "chrome/test/ui_test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
20 23
21 namespace { 24 namespace {
(...skipping 16 matching lines...) Expand all
38 } 41 }
39 42
40 GURL WaitForSavePackageToFinish() { 43 GURL WaitForSavePackageToFinish() {
41 ui_test_utils::TestNotificationObserver observer; 44 ui_test_utils::TestNotificationObserver observer;
42 ui_test_utils::RegisterAndWait(&observer, 45 ui_test_utils::RegisterAndWait(&observer,
43 NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 46 NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
44 NotificationService::AllSources()); 47 NotificationService::AllSources());
45 return *Details<GURL>(observer.details()).ptr(); 48 return *Details<GURL>(observer.details()).ptr();
46 } 49 }
47 50
51 void QueryDownloadHistory(TabContents* current_tab) {
52 DownloadManager* download_manager =
53 current_tab->profile()->GetDownloadManager();
54
55 // Query the history system.
56 download_manager->download_history()->Load(
57 NewCallback(this,
58 &SavePageBrowserTest::OnQueryDownloadEntriesComplete));
59
60 // Run message loop until a quit message is sent from
61 // OnQueryDownloadEntriesComplete().
62 ui_test_utils::RunMessageLoop();
63 }
64
65 void OnQueryDownloadEntriesComplete(
66 std::vector<DownloadCreateInfo>* entries) {
67
68 // Make a copy of the URLs returned by the history system.
69 history_urls_.clear();
70 for (size_t i = 0; i < entries->size(); ++i) {
71 history_urls_.push_back(entries->at(i).url);
72 }
73
74 // Indicate thet we have received the history and
75 // can continue.
76 MessageLoopForUI::current()->Quit();
77 }
78
79 // URLs found in the history.
80 std::vector<GURL> history_urls_;
81
48 // Path to directory containing test data. 82 // Path to directory containing test data.
49 FilePath test_dir_; 83 FilePath test_dir_;
50 84
51 // Temporary directory we will save pages to. 85 // Temporary directory we will save pages to.
52 ScopedTempDir save_dir_; 86 ScopedTempDir save_dir_;
53 }; 87 };
54 88
55 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { 89 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
56 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 90 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
57 GURL url = URLRequestMockHTTPJob::GetMockUrl( 91 GURL url = URLRequestMockHTTPJob::GetMockUrl(
58 FilePath(kTestDir).Append(file_name)); 92 FilePath(kTestDir).Append(file_name));
59 ui_test_utils::NavigateToURL(browser(), url); 93 ui_test_utils::NavigateToURL(browser(), url);
60 94
61 TabContents* current_tab = browser()->GetSelectedTabContents(); 95 TabContents* current_tab = browser()->GetSelectedTabContents();
62 ASSERT_TRUE(current_tab); 96 ASSERT_TRUE(current_tab);
63 97
64 FilePath full_file_name = save_dir_.path().Append(file_name); 98 FilePath full_file_name = save_dir_.path().Append(file_name);
65 FilePath dir = save_dir_.path().AppendASCII("a_files"); 99 FilePath dir = save_dir_.path().AppendASCII("a_files");
66 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 100 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
67 SavePackage::SAVE_AS_ONLY_HTML)); 101 SavePackage::SAVE_AS_ONLY_HTML));
68 102
69 EXPECT_EQ(url, WaitForSavePackageToFinish()); 103 EXPECT_EQ(url, WaitForSavePackageToFinish());
70 104
71 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 105 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
72 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 106 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
73 107
108 QueryDownloadHistory(current_tab);
109 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
110 url) != history_urls_.end());
111
74 EXPECT_TRUE(file_util::PathExists(full_file_name)); 112 EXPECT_TRUE(file_util::PathExists(full_file_name));
75 EXPECT_FALSE(file_util::PathExists(dir)); 113 EXPECT_FALSE(file_util::PathExists(dir));
76 EXPECT_TRUE(file_util::ContentsEqual( 114 EXPECT_TRUE(file_util::ContentsEqual(
77 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 115 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
78 full_file_name)); 116 full_file_name));
79 } 117 }
80 118
81 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { 119 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) {
82 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 120 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
83 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 121 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
84 FilePath(kTestDir).Append(file_name)); 122 FilePath(kTestDir).Append(file_name));
85 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 123 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
86 FilePath(kTestDir).Append(file_name)); 124 FilePath(kTestDir).Append(file_name));
87 ui_test_utils::NavigateToURL(browser(), view_source_url); 125 ui_test_utils::NavigateToURL(browser(), view_source_url);
88 126
89 TabContents* current_tab = browser()->GetSelectedTabContents(); 127 TabContents* current_tab = browser()->GetSelectedTabContents();
90 ASSERT_TRUE(current_tab); 128 ASSERT_TRUE(current_tab);
91 129
92 FilePath full_file_name = save_dir_.path().Append(file_name); 130 FilePath full_file_name = save_dir_.path().Append(file_name);
93 FilePath dir = save_dir_.path().AppendASCII("a_files"); 131 FilePath dir = save_dir_.path().AppendASCII("a_files");
94 132
95 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 133 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
96 SavePackage::SAVE_AS_ONLY_HTML)); 134 SavePackage::SAVE_AS_ONLY_HTML));
97 135
98 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 136 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
99 137
100 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 138 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
101 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 139 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
102 140
141 QueryDownloadHistory(current_tab);
142 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
143 actual_page_url) != history_urls_.end());
144
103 EXPECT_TRUE(file_util::PathExists(full_file_name)); 145 EXPECT_TRUE(file_util::PathExists(full_file_name));
104 EXPECT_FALSE(file_util::PathExists(dir)); 146 EXPECT_FALSE(file_util::PathExists(dir));
105 EXPECT_TRUE(file_util::ContentsEqual( 147 EXPECT_TRUE(file_util::ContentsEqual(
106 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 148 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
107 full_file_name)); 149 full_file_name));
108 } 150 }
109 151
110 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 152 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
111 FilePath file_name(FILE_PATH_LITERAL("b.htm")); 153 FilePath file_name(FILE_PATH_LITERAL("b.htm"));
112 GURL url = URLRequestMockHTTPJob::GetMockUrl( 154 GURL url = URLRequestMockHTTPJob::GetMockUrl(
113 FilePath(kTestDir).Append(file_name)); 155 FilePath(kTestDir).Append(file_name));
114 ui_test_utils::NavigateToURL(browser(), url); 156 ui_test_utils::NavigateToURL(browser(), url);
115 157
116 TabContents* current_tab = browser()->GetSelectedTabContents(); 158 TabContents* current_tab = browser()->GetSelectedTabContents();
117 ASSERT_TRUE(current_tab); 159 ASSERT_TRUE(current_tab);
118 160
119 FilePath full_file_name = save_dir_.path().Append(file_name); 161 FilePath full_file_name = save_dir_.path().Append(file_name);
120 FilePath dir = save_dir_.path().AppendASCII("b_files"); 162 FilePath dir = save_dir_.path().AppendASCII("b_files");
121 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 163 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
122 SavePackage::SAVE_AS_COMPLETE_HTML)); 164 SavePackage::SAVE_AS_COMPLETE_HTML));
123 165
124 EXPECT_EQ(url, WaitForSavePackageToFinish()); 166 EXPECT_EQ(url, WaitForSavePackageToFinish());
125 167
126 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 168 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
127 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 169 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
128 170
171 QueryDownloadHistory(current_tab);
172 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
173 url) != history_urls_.end());
174
129 EXPECT_TRUE(file_util::PathExists(full_file_name)); 175 EXPECT_TRUE(file_util::PathExists(full_file_name));
130 EXPECT_TRUE(file_util::PathExists(dir)); 176 EXPECT_TRUE(file_util::PathExists(dir));
131 EXPECT_TRUE(file_util::TextContentsEqual( 177 EXPECT_TRUE(file_util::TextContentsEqual(
132 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 178 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
133 full_file_name)); 179 full_file_name));
134 EXPECT_TRUE(file_util::ContentsEqual( 180 EXPECT_TRUE(file_util::ContentsEqual(
135 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 181 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
136 dir.AppendASCII("1.png"))); 182 dir.AppendASCII("1.png")));
137 EXPECT_TRUE(file_util::ContentsEqual( 183 EXPECT_TRUE(file_util::ContentsEqual(
138 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 184 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
(...skipping 22 matching lines...) Expand all
161 ASSERT_TRUE(current_tab); 207 ASSERT_TRUE(current_tab);
162 208
163 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 209 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
164 SavePackage::SAVE_AS_COMPLETE_HTML)); 210 SavePackage::SAVE_AS_COMPLETE_HTML));
165 211
166 EXPECT_EQ(url, WaitForSavePackageToFinish()); 212 EXPECT_EQ(url, WaitForSavePackageToFinish());
167 213
168 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 214 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
169 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 215 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
170 216
217 QueryDownloadHistory(current_tab);
218 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
219 url) != history_urls_.end());
220
171 EXPECT_TRUE(file_util::PathExists(full_file_name)); 221 EXPECT_TRUE(file_util::PathExists(full_file_name));
172 EXPECT_TRUE(file_util::PathExists(dir)); 222 EXPECT_TRUE(file_util::PathExists(dir));
173 EXPECT_TRUE(file_util::TextContentsEqual( 223 EXPECT_TRUE(file_util::TextContentsEqual(
174 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 224 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
175 full_file_name)); 225 full_file_name));
176 EXPECT_TRUE(file_util::ContentsEqual( 226 EXPECT_TRUE(file_util::ContentsEqual(
177 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 227 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
178 dir.AppendASCII("1.png"))); 228 dir.AppendASCII("1.png")));
179 EXPECT_TRUE(file_util::ContentsEqual( 229 EXPECT_TRUE(file_util::ContentsEqual(
180 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 230 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
181 dir.AppendASCII("1.css"))); 231 dir.AppendASCII("1.css")));
182 } 232 }
183 233
184 } // namespace 234 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/download/save_package.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698