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

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

Issue 7212017: Add save package download items to history. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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/download_manager.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/download/download_item.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/download/download_tab_helper.h" 13 #include "chrome/browser/ui/download/download_tab_helper.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/browser/ui/webui/active_downloads_ui.h"
14 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
16 #include "chrome/test/in_process_browser_test.h" 18 #include "chrome/test/in_process_browser_test.h"
17 #include "chrome/test/ui_test_utils.h" 19 #include "chrome/test/ui_test_utils.h"
18 #include "content/browser/net/url_request_mock_http_job.h" 20 #include "content/browser/net/url_request_mock_http_job.h"
19 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
20 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 namespace { 25 namespace {
(...skipping 16 matching lines...) Expand all
40 } 42 }
41 43
42 GURL WaitForSavePackageToFinish() { 44 GURL WaitForSavePackageToFinish() {
43 ui_test_utils::TestNotificationObserver observer; 45 ui_test_utils::TestNotificationObserver observer;
44 ui_test_utils::RegisterAndWait(&observer, 46 ui_test_utils::RegisterAndWait(&observer,
45 NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 47 NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
46 NotificationService::AllSources()); 48 NotificationService::AllSources());
47 return *Details<GURL>(observer.details()).ptr(); 49 return *Details<GURL>(observer.details()).ptr();
48 } 50 }
49 51
52 void CheckDownloadUI(const FilePath& download_path) {
53 #if defined(OS_CHROMEOS)
54 Browser* popup = ActiveDownloadsUI::GetPopup();
55 EXPECT_TRUE(popup);
56 ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>(
57 popup->GetSelectedTabContents()->web_ui());
58 ASSERT_TRUE(downloads_ui);
59 const ActiveDownloadsUI::DownloadList& downloads =
60 downloads_ui->GetDownloads();
61 EXPECT_EQ(downloads.size(), 1U);
62
63 bool found = false;
64 for (size_t i = 0; i < downloads.size(); ++i) {
65 if (downloads[i]->full_path() == download_path) {
66 found = true;
67 break;
68 }
69 }
70 EXPECT_TRUE(found);
71 #else
72 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
73 #endif
74 }
75
50 // Path to directory containing test data. 76 // Path to directory containing test data.
51 FilePath test_dir_; 77 FilePath test_dir_;
52 78
53 // Temporary directory we will save pages to. 79 // Temporary directory we will save pages to.
54 ScopedTempDir save_dir_; 80 ScopedTempDir save_dir_;
55 }; 81 };
56 82
57 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { 83 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
58 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 84 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
59 GURL url = URLRequestMockHTTPJob::GetMockUrl( 85 GURL url = URLRequestMockHTTPJob::GetMockUrl(
60 FilePath(kTestDir).Append(file_name)); 86 FilePath(kTestDir).Append(file_name));
61 ui_test_utils::NavigateToURL(browser(), url); 87 ui_test_utils::NavigateToURL(browser(), url);
62 88
63 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); 89 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper();
64 ASSERT_TRUE(current_tab); 90 ASSERT_TRUE(current_tab);
65 91
66 FilePath full_file_name = save_dir_.path().Append(file_name); 92 FilePath full_file_name = save_dir_.path().Append(file_name);
67 FilePath dir = save_dir_.path().AppendASCII("a_files"); 93 FilePath dir = save_dir_.path().AppendASCII("a_files");
68 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( 94 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage(
69 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); 95 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML));
70 96
71 EXPECT_EQ(url, WaitForSavePackageToFinish()); 97 EXPECT_EQ(url, WaitForSavePackageToFinish());
72 98
73 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 99 CheckDownloadUI(full_file_name);
74 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
75 100
76 EXPECT_TRUE(file_util::PathExists(full_file_name)); 101 EXPECT_TRUE(file_util::PathExists(full_file_name));
77 EXPECT_FALSE(file_util::PathExists(dir)); 102 EXPECT_FALSE(file_util::PathExists(dir));
78 EXPECT_TRUE(file_util::ContentsEqual( 103 EXPECT_TRUE(file_util::ContentsEqual(
79 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 104 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
80 full_file_name)); 105 full_file_name));
81 } 106 }
82 107
83 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { 108 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) {
84 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 109 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
85 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 110 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
86 FilePath(kTestDir).Append(file_name)); 111 FilePath(kTestDir).Append(file_name));
87 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 112 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
88 FilePath(kTestDir).Append(file_name)); 113 FilePath(kTestDir).Append(file_name));
89 ui_test_utils::NavigateToURL(browser(), view_source_url); 114 ui_test_utils::NavigateToURL(browser(), view_source_url);
90 115
91 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); 116 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper();
92 ASSERT_TRUE(current_tab); 117 ASSERT_TRUE(current_tab);
93 118
94 FilePath full_file_name = save_dir_.path().Append(file_name); 119 FilePath full_file_name = save_dir_.path().Append(file_name);
95 FilePath dir = save_dir_.path().AppendASCII("a_files"); 120 FilePath dir = save_dir_.path().AppendASCII("a_files");
96 121
97 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( 122 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage(
98 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); 123 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML));
99 124
100 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 125 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
101 126
102 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 127 CheckDownloadUI(full_file_name);
103 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
104 128
105 EXPECT_TRUE(file_util::PathExists(full_file_name)); 129 EXPECT_TRUE(file_util::PathExists(full_file_name));
106 EXPECT_FALSE(file_util::PathExists(dir)); 130 EXPECT_FALSE(file_util::PathExists(dir));
107 EXPECT_TRUE(file_util::ContentsEqual( 131 EXPECT_TRUE(file_util::ContentsEqual(
108 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 132 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
109 full_file_name)); 133 full_file_name));
110 } 134 }
111 135
112 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 136 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
113 FilePath file_name(FILE_PATH_LITERAL("b.htm")); 137 FilePath file_name(FILE_PATH_LITERAL("b.htm"));
114 GURL url = URLRequestMockHTTPJob::GetMockUrl( 138 GURL url = URLRequestMockHTTPJob::GetMockUrl(
115 FilePath(kTestDir).Append(file_name)); 139 FilePath(kTestDir).Append(file_name));
116 ui_test_utils::NavigateToURL(browser(), url); 140 ui_test_utils::NavigateToURL(browser(), url);
117 141
118 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); 142 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper();
119 ASSERT_TRUE(current_tab); 143 ASSERT_TRUE(current_tab);
120 144
121 FilePath full_file_name = save_dir_.path().Append(file_name); 145 FilePath full_file_name = save_dir_.path().Append(file_name);
122 FilePath dir = save_dir_.path().AppendASCII("b_files"); 146 FilePath dir = save_dir_.path().AppendASCII("b_files");
123 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( 147 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage(
124 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); 148 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML));
125 149
126 EXPECT_EQ(url, WaitForSavePackageToFinish()); 150 EXPECT_EQ(url, WaitForSavePackageToFinish());
127 151
128 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 152 CheckDownloadUI(full_file_name);
129 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
130 153
131 EXPECT_TRUE(file_util::PathExists(full_file_name)); 154 EXPECT_TRUE(file_util::PathExists(full_file_name));
132 EXPECT_TRUE(file_util::PathExists(dir)); 155 EXPECT_TRUE(file_util::PathExists(dir));
133 EXPECT_TRUE(file_util::TextContentsEqual( 156 EXPECT_TRUE(file_util::TextContentsEqual(
134 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 157 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
135 full_file_name)); 158 full_file_name));
136 EXPECT_TRUE(file_util::ContentsEqual( 159 EXPECT_TRUE(file_util::ContentsEqual(
137 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 160 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
138 dir.AppendASCII("1.png"))); 161 dir.AppendASCII("1.png")));
139 EXPECT_TRUE(file_util::ContentsEqual( 162 EXPECT_TRUE(file_util::ContentsEqual(
(...skipping 20 matching lines...) Expand all
160 "Test page for saving page feature_files"); 183 "Test page for saving page feature_files");
161 184
162 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); 185 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper();
163 ASSERT_TRUE(current_tab); 186 ASSERT_TRUE(current_tab);
164 187
165 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( 188 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage(
166 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); 189 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML));
167 190
168 EXPECT_EQ(url, WaitForSavePackageToFinish()); 191 EXPECT_EQ(url, WaitForSavePackageToFinish());
169 192
170 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 193 CheckDownloadUI(full_file_name);
171 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
172 194
173 EXPECT_TRUE(file_util::PathExists(full_file_name)); 195 EXPECT_TRUE(file_util::PathExists(full_file_name));
174 EXPECT_TRUE(file_util::PathExists(dir)); 196 EXPECT_TRUE(file_util::PathExists(dir));
175 EXPECT_TRUE(file_util::TextContentsEqual( 197 EXPECT_TRUE(file_util::TextContentsEqual(
176 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 198 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
177 full_file_name)); 199 full_file_name));
178 EXPECT_TRUE(file_util::ContentsEqual( 200 EXPECT_TRUE(file_util::ContentsEqual(
179 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 201 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
180 dir.AppendASCII("1.png"))); 202 dir.AppendASCII("1.png")));
181 EXPECT_TRUE(file_util::ContentsEqual( 203 EXPECT_TRUE(file_util::ContentsEqual(
182 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 204 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
183 dir.AppendASCII("1.css"))); 205 dir.AppendASCII("1.css")));
184 } 206 }
185 207
186 } // namespace 208 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698