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

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, 10 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.
Paweł Hajdan Jr. 2011/02/18 11:11:35 This should clear history_urls_ to avoid possible
magnus 2011/02/18 17:54:01 Done.
69 for (size_t i = 0; i < entries->size(); ++i) {
70 history_urls_.push_back(entries->at(i).url);
71 }
72
73 // Indicate thet we have received the history and
74 // can continue.
75 MessageLoopForUI::current()->Quit();
76 }
77
78 // URLs found in the history.
79 std::vector<GURL> history_urls_;
80
48 // Path to directory containing test data. 81 // Path to directory containing test data.
49 FilePath test_dir_; 82 FilePath test_dir_;
50 83
51 // Temporary directory we will save pages to. 84 // Temporary directory we will save pages to.
52 ScopedTempDir save_dir_; 85 ScopedTempDir save_dir_;
53 }; 86 };
54 87
55 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { 88 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
56 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 89 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
57 GURL url = URLRequestMockHTTPJob::GetMockUrl( 90 GURL url = URLRequestMockHTTPJob::GetMockUrl(
58 FilePath(kTestDir).Append(file_name)); 91 FilePath(kTestDir).Append(file_name));
59 ui_test_utils::NavigateToURL(browser(), url); 92 ui_test_utils::NavigateToURL(browser(), url);
60 93
61 TabContents* current_tab = browser()->GetSelectedTabContents(); 94 TabContents* current_tab = browser()->GetSelectedTabContents();
62 ASSERT_TRUE(current_tab); 95 ASSERT_TRUE(current_tab);
63 96
64 FilePath full_file_name = save_dir_.path().Append(file_name); 97 FilePath full_file_name = save_dir_.path().Append(file_name);
65 FilePath dir = save_dir_.path().AppendASCII("a_files"); 98 FilePath dir = save_dir_.path().AppendASCII("a_files");
66 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 99 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
67 SavePackage::SAVE_AS_ONLY_HTML)); 100 SavePackage::SAVE_AS_ONLY_HTML));
68 101
69 EXPECT_EQ(url, WaitForSavePackageToFinish()); 102 EXPECT_EQ(url, WaitForSavePackageToFinish());
70 103
71 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 104 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
72 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 105 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
73 106
107 QueryDownloadHistory(current_tab);
108 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
109 url) != history_urls_.end());
110
74 EXPECT_TRUE(file_util::PathExists(full_file_name)); 111 EXPECT_TRUE(file_util::PathExists(full_file_name));
75 EXPECT_FALSE(file_util::PathExists(dir)); 112 EXPECT_FALSE(file_util::PathExists(dir));
76 EXPECT_TRUE(file_util::ContentsEqual( 113 EXPECT_TRUE(file_util::ContentsEqual(
77 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 114 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
78 full_file_name)); 115 full_file_name));
79 } 116 }
80 117
81 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { 118 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) {
82 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 119 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
83 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 120 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
84 FilePath(kTestDir).Append(file_name)); 121 FilePath(kTestDir).Append(file_name));
85 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 122 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
86 FilePath(kTestDir).Append(file_name)); 123 FilePath(kTestDir).Append(file_name));
87 ui_test_utils::NavigateToURL(browser(), view_source_url); 124 ui_test_utils::NavigateToURL(browser(), view_source_url);
88 125
89 TabContents* current_tab = browser()->GetSelectedTabContents(); 126 TabContents* current_tab = browser()->GetSelectedTabContents();
90 ASSERT_TRUE(current_tab); 127 ASSERT_TRUE(current_tab);
91 128
92 FilePath full_file_name = save_dir_.path().Append(file_name); 129 FilePath full_file_name = save_dir_.path().Append(file_name);
93 FilePath dir = save_dir_.path().AppendASCII("a_files"); 130 FilePath dir = save_dir_.path().AppendASCII("a_files");
94 131
95 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 132 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
96 SavePackage::SAVE_AS_ONLY_HTML)); 133 SavePackage::SAVE_AS_ONLY_HTML));
97 134
98 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 135 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
99 136
100 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 137 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
101 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 138 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
102 139
140 QueryDownloadHistory(current_tab);
141 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
142 actual_page_url) != history_urls_.end());
143
103 EXPECT_TRUE(file_util::PathExists(full_file_name)); 144 EXPECT_TRUE(file_util::PathExists(full_file_name));
104 EXPECT_FALSE(file_util::PathExists(dir)); 145 EXPECT_FALSE(file_util::PathExists(dir));
105 EXPECT_TRUE(file_util::ContentsEqual( 146 EXPECT_TRUE(file_util::ContentsEqual(
106 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 147 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
107 full_file_name)); 148 full_file_name));
108 } 149 }
109 150
110 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 151 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
111 FilePath file_name(FILE_PATH_LITERAL("b.htm")); 152 FilePath file_name(FILE_PATH_LITERAL("b.htm"));
112 GURL url = URLRequestMockHTTPJob::GetMockUrl( 153 GURL url = URLRequestMockHTTPJob::GetMockUrl(
113 FilePath(kTestDir).Append(file_name)); 154 FilePath(kTestDir).Append(file_name));
114 ui_test_utils::NavigateToURL(browser(), url); 155 ui_test_utils::NavigateToURL(browser(), url);
115 156
116 TabContents* current_tab = browser()->GetSelectedTabContents(); 157 TabContents* current_tab = browser()->GetSelectedTabContents();
117 ASSERT_TRUE(current_tab); 158 ASSERT_TRUE(current_tab);
118 159
119 FilePath full_file_name = save_dir_.path().Append(file_name); 160 FilePath full_file_name = save_dir_.path().Append(file_name);
120 FilePath dir = save_dir_.path().AppendASCII("b_files"); 161 FilePath dir = save_dir_.path().AppendASCII("b_files");
121 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 162 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
122 SavePackage::SAVE_AS_COMPLETE_HTML)); 163 SavePackage::SAVE_AS_COMPLETE_HTML));
123 164
124 EXPECT_EQ(url, WaitForSavePackageToFinish()); 165 EXPECT_EQ(url, WaitForSavePackageToFinish());
125 166
126 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 167 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
127 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 168 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
128 169
170 QueryDownloadHistory(current_tab);
171 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
172 url) != history_urls_.end());
173
129 EXPECT_TRUE(file_util::PathExists(full_file_name)); 174 EXPECT_TRUE(file_util::PathExists(full_file_name));
130 EXPECT_TRUE(file_util::PathExists(dir)); 175 EXPECT_TRUE(file_util::PathExists(dir));
131 EXPECT_TRUE(file_util::TextContentsEqual( 176 EXPECT_TRUE(file_util::TextContentsEqual(
132 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 177 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
133 full_file_name)); 178 full_file_name));
134 EXPECT_TRUE(file_util::ContentsEqual( 179 EXPECT_TRUE(file_util::ContentsEqual(
135 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 180 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
136 dir.AppendASCII("1.png"))); 181 dir.AppendASCII("1.png")));
137 EXPECT_TRUE(file_util::ContentsEqual( 182 EXPECT_TRUE(file_util::ContentsEqual(
138 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 183 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
(...skipping 22 matching lines...) Expand all
161 ASSERT_TRUE(current_tab); 206 ASSERT_TRUE(current_tab);
162 207
163 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 208 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
164 SavePackage::SAVE_AS_COMPLETE_HTML)); 209 SavePackage::SAVE_AS_COMPLETE_HTML));
165 210
166 EXPECT_EQ(url, WaitForSavePackageToFinish()); 211 EXPECT_EQ(url, WaitForSavePackageToFinish());
167 212
168 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 213 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
169 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 214 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
170 215
216 QueryDownloadHistory(current_tab);
217 EXPECT_TRUE(std::find(history_urls_.begin(), history_urls_.end(),
218 url) != history_urls_.end());
219
171 EXPECT_TRUE(file_util::PathExists(full_file_name)); 220 EXPECT_TRUE(file_util::PathExists(full_file_name));
172 EXPECT_TRUE(file_util::PathExists(dir)); 221 EXPECT_TRUE(file_util::PathExists(dir));
173 EXPECT_TRUE(file_util::TextContentsEqual( 222 EXPECT_TRUE(file_util::TextContentsEqual(
174 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 223 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
175 full_file_name)); 224 full_file_name));
176 EXPECT_TRUE(file_util::ContentsEqual( 225 EXPECT_TRUE(file_util::ContentsEqual(
177 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 226 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
178 dir.AppendASCII("1.png"))); 227 dir.AppendASCII("1.png")));
179 EXPECT_TRUE(file_util::ContentsEqual( 228 EXPECT_TRUE(file_util::ContentsEqual(
180 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 229 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
181 dir.AppendASCII("1.css"))); 230 dir.AppendASCII("1.css")));
182 } 231 }
183 232
184 } // namespace 233 } // 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