OLD | NEW |
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/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "chrome/app/chrome_dll_resource.h" |
7 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_window.h" | 9 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/net/url_request_mock_http_job.h" | 10 #include "chrome/browser/net/url_request_mock_http_job.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
11 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
12 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
13 #include "chrome/test/in_process_browser_test.h" | 14 #include "chrome/test/in_process_browser_test.h" |
14 #include "chrome/test/ui_test_utils.h" | 15 #include "chrome/test/ui_test_utils.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); | 18 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); |
18 | 19 |
| 20 static const char* kAppendedExtension = |
| 21 #if defined(OS_WIN) |
| 22 ".htm"; |
| 23 #else |
| 24 ".html"; |
| 25 #endif |
| 26 |
19 namespace { | 27 namespace { |
20 | 28 |
21 class SavePageFinishedObserver : public NotificationObserver { | 29 class SavePageFinishedObserver : public NotificationObserver { |
22 public: | 30 public: |
23 SavePageFinishedObserver() { | 31 SavePageFinishedObserver() { |
24 registrar_.Add(this, NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 32 registrar_.Add(this, NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
25 NotificationService::AllSources()); | 33 NotificationService::AllSources()); |
26 ui_test_utils::RunMessageLoop(); | 34 ui_test_utils::RunMessageLoop(); |
27 } | 35 } |
28 | 36 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 74 FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
67 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 75 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
68 FilePath(kTestDir).Append(file_name).ToWStringHack()); | 76 FilePath(kTestDir).Append(file_name).ToWStringHack()); |
69 ui_test_utils::NavigateToURL(browser(), url); | 77 ui_test_utils::NavigateToURL(browser(), url); |
70 | 78 |
71 TabContents* current_tab = browser()->GetSelectedTabContents(); | 79 TabContents* current_tab = browser()->GetSelectedTabContents(); |
72 ASSERT_TRUE(current_tab); | 80 ASSERT_TRUE(current_tab); |
73 | 81 |
74 FilePath full_file_name = save_dir_.path().Append(file_name); | 82 FilePath full_file_name = save_dir_.path().Append(file_name); |
75 FilePath dir = save_dir_.path().AppendASCII("a_files"); | 83 FilePath dir = save_dir_.path().AppendASCII("a_files"); |
76 current_tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(), | 84 ASSERT_TRUE(current_tab->SavePage(full_file_name.ToWStringHack(), |
77 SavePackage::SAVE_AS_ONLY_HTML); | 85 dir.ToWStringHack(), |
| 86 SavePackage::SAVE_AS_ONLY_HTML)); |
78 | 87 |
79 SavePageFinishedObserver observer; | 88 SavePageFinishedObserver observer; |
80 | 89 |
81 EXPECT_EQ(url, observer.page_url()); | 90 EXPECT_EQ(url, observer.page_url()); |
82 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 91 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
83 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 92 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
84 EXPECT_FALSE(file_util::PathExists(dir)); | 93 EXPECT_FALSE(file_util::PathExists(dir)); |
85 EXPECT_TRUE(file_util::ContentsEqual( | 94 EXPECT_TRUE(file_util::ContentsEqual( |
86 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 95 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
87 full_file_name)); | 96 full_file_name)); |
88 } | 97 } |
89 | 98 |
90 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 99 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
91 FilePath file_name(FILE_PATH_LITERAL("b.htm")); | 100 FilePath file_name(FILE_PATH_LITERAL("b.htm")); |
92 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 101 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
93 FilePath(kTestDir).Append(file_name).ToWStringHack()); | 102 FilePath(kTestDir).Append(file_name).ToWStringHack()); |
94 ui_test_utils::NavigateToURL(browser(), url); | 103 ui_test_utils::NavigateToURL(browser(), url); |
95 | 104 |
96 TabContents* current_tab = browser()->GetSelectedTabContents(); | 105 TabContents* current_tab = browser()->GetSelectedTabContents(); |
97 ASSERT_TRUE(current_tab); | 106 ASSERT_TRUE(current_tab); |
98 | 107 |
99 FilePath full_file_name = save_dir_.path().Append(file_name); | 108 FilePath full_file_name = save_dir_.path().Append(file_name); |
100 FilePath dir = save_dir_.path().AppendASCII("b_files"); | 109 FilePath dir = save_dir_.path().AppendASCII("b_files"); |
101 current_tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(), | 110 ASSERT_TRUE(current_tab->SavePage(full_file_name.ToWStringHack(), |
102 SavePackage::SAVE_AS_COMPLETE_HTML); | 111 dir.ToWStringHack(), |
| 112 SavePackage::SAVE_AS_COMPLETE_HTML)); |
103 | 113 |
104 SavePageFinishedObserver observer; | 114 SavePageFinishedObserver observer; |
105 | 115 |
106 EXPECT_EQ(url, observer.page_url()); | 116 EXPECT_EQ(url, observer.page_url()); |
107 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 117 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
108 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 118 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
109 EXPECT_TRUE(file_util::PathExists(dir)); | 119 EXPECT_TRUE(file_util::PathExists(dir)); |
110 // TODO(phajdan.jr): Check saved html file's contents (http://crbug.com/3791). | 120 EXPECT_TRUE(file_util::ContentsEqual( |
| 121 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 122 full_file_name)); |
111 EXPECT_TRUE(file_util::ContentsEqual( | 123 EXPECT_TRUE(file_util::ContentsEqual( |
112 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 124 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
113 dir.AppendASCII("1.png"))); | 125 dir.AppendASCII("1.png"))); |
| 126 EXPECT_TRUE(file_util::ContentsEqual( |
| 127 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
| 128 dir.AppendASCII("1.css"))); |
| 129 } |
| 130 |
| 131 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { |
| 132 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 133 ASSERT_TRUE(browser()->command_updater()->SupportsCommand(IDC_SAVE_PAGE)); |
| 134 EXPECT_FALSE(browser()->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)); |
| 135 } |
| 136 |
| 137 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { |
| 138 FilePath file_name(FILE_PATH_LITERAL("b.htm")); |
| 139 |
| 140 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
| 141 FilePath(kTestDir).Append(file_name).ToWStringHack()); |
| 142 ui_test_utils::NavigateToURL(browser(), url); |
| 143 |
| 144 FilePath full_file_name = save_dir_.path().AppendASCII( |
| 145 std::string("Test page for saving page feature") + kAppendedExtension); |
| 146 FilePath dir = save_dir_.path().AppendASCII( |
| 147 "Test page for saving page feature_files"); |
| 148 |
| 149 TabContents* current_tab = browser()->GetSelectedTabContents(); |
| 150 ASSERT_TRUE(current_tab); |
| 151 |
| 152 ASSERT_TRUE(current_tab->SavePage(full_file_name.ToWStringHack(), |
| 153 dir.ToWStringHack(), |
| 154 SavePackage::SAVE_AS_COMPLETE_HTML)); |
| 155 SavePageFinishedObserver observer; |
| 156 |
| 157 EXPECT_EQ(url, observer.page_url()); |
| 158 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 159 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 160 EXPECT_TRUE(file_util::PathExists(dir)); |
| 161 EXPECT_TRUE(file_util::ContentsEqual( |
| 162 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
| 163 full_file_name)); |
| 164 EXPECT_TRUE(file_util::ContentsEqual( |
| 165 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 166 dir.AppendASCII("1.png"))); |
114 EXPECT_TRUE(file_util::ContentsEqual( | 167 EXPECT_TRUE(file_util::ContentsEqual( |
115 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 168 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
116 dir.AppendASCII("1.css"))); | 169 dir.AppendASCII("1.css"))); |
117 } | 170 } |
118 | 171 |
119 } // namespace | 172 } // namespace |
OLD | NEW |