OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
9 #include "chrome/browser/automation/url_request_mock_http_job.h" | 9 #include "chrome/browser/automation/url_request_mock_http_job.h" |
10 #include "chrome/browser/download/save_package.h" | 10 #include "chrome/browser/download/save_package.h" |
11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
12 #include "chrome/test/automation/browser_proxy.h" | 12 #include "chrome/test/automation/browser_proxy.h" |
13 #include "chrome/test/automation/tab_proxy.h" | 13 #include "chrome/test/automation/tab_proxy.h" |
14 #include "chrome/test/ui/ui_test.h" | 14 #include "chrome/test/ui/ui_test.h" |
15 #include "net/url_request/url_request_unittest.h" | 15 #include "net/url_request/url_request_unittest.h" |
16 | 16 |
17 const std::wstring kTestDir = L"save_page"; | 17 const std::wstring kTestDir = L"save_page"; |
18 | 18 |
19 class SavePageTest : public UITest { | 19 class SavePageTest : public UITest { |
20 protected: | 20 protected: |
21 SavePageTest() : UITest() {} | 21 SavePageTest() : UITest() {} |
22 | 22 |
23 void CheckFile(const std::wstring& client_file, | 23 void CheckFile(const std::wstring& generated_file, |
24 const std::wstring& server_file, | 24 const std::wstring& expect_result_file, |
25 bool check_equal) { | 25 bool check_equal) { |
26 bool exist = false; | 26 std::wstring expect_result_filepath = |
27 for (int i = 0; i < 20; ++i) { | 27 UITest::GetTestFilePath(kTestDir, expect_result_file); |
28 if (file_util::PathExists(client_file)) { | |
29 exist = true; | |
30 break; | |
31 } | |
32 Sleep(sleep_timeout_ms()); | |
33 } | |
34 EXPECT_TRUE(exist); | |
35 | 28 |
36 if (check_equal) { | 29 ASSERT_TRUE(file_util::PathExists(expect_result_filepath)); |
37 std::wstring server_file_name; | 30 WaitForGeneratedFileAndCheck(generated_file, |
38 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, | 31 expect_result_filepath, |
39 &server_file_name)); | 32 check_equal, true); |
40 server_file_name += L"\\" + kTestDir + L"\\" + server_file; | |
41 ASSERT_TRUE(file_util::PathExists(server_file_name)); | |
42 | |
43 int64 client_file_size = 0; | |
44 int64 server_file_size = 0; | |
45 EXPECT_TRUE(file_util::GetFileSize(client_file, &client_file_size)); | |
46 EXPECT_TRUE(file_util::GetFileSize(server_file_name, &server_file_size)); | |
47 EXPECT_EQ(client_file_size, server_file_size); | |
48 EXPECT_TRUE(file_util::ContentsEqual(client_file, server_file_name)); | |
49 } | |
50 | |
51 EXPECT_TRUE(DieFileDie(client_file, false)); | |
52 } | 33 } |
53 | 34 |
54 virtual void SetUp() { | 35 virtual void SetUp() { |
55 UITest::SetUp(); | 36 UITest::SetUp(); |
56 EXPECT_TRUE(file_util::CreateNewTempDirectory(L"", &save_dir_)); | 37 EXPECT_TRUE(file_util::CreateNewTempDirectory(L"", &save_dir_)); |
57 save_dir_ += FilePath::kSeparators[0]; | 38 save_dir_ += FilePath::kSeparators[0]; |
58 | 39 |
59 download_dir_ = GetDownloadDirectory(); | 40 download_dir_ = GetDownloadDirectory(); |
60 download_dir_ += FilePath::kSeparators[0]; | 41 download_dir_ += FilePath::kSeparators[0]; |
61 } | 42 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 140 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
160 automation()->SavePackageShouldPromptUser(false); | 141 automation()->SavePackageShouldPromptUser(false); |
161 EXPECT_TRUE(browser->RunCommand(IDC_SAVE_PAGE)); | 142 EXPECT_TRUE(browser->RunCommand(IDC_SAVE_PAGE)); |
162 EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get())); | 143 EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get())); |
163 automation()->SavePackageShouldPromptUser(true); | 144 automation()->SavePackageShouldPromptUser(true); |
164 | 145 |
165 CheckFile(full_file_name, file_name, false); | 146 CheckFile(full_file_name, file_name, false); |
166 EXPECT_TRUE(DieFileDie(full_file_name, false)); | 147 EXPECT_TRUE(DieFileDie(full_file_name, false)); |
167 EXPECT_TRUE(DieFileDie(dir, true)); | 148 EXPECT_TRUE(DieFileDie(dir, true)); |
168 } | 149 } |
OLD | NEW |