OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 "chrome/test/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 | 853 |
854 if (*application_closed) { | 854 if (*application_closed) { |
855 // Let's wait until the process dies (if it is not gone already). | 855 // Let's wait until the process dies (if it is not gone already). |
856 bool success = base::WaitForSingleProcess(process_, base::kNoTimeout); | 856 bool success = base::WaitForSingleProcess(process_, base::kNoTimeout); |
857 DCHECK(success); | 857 DCHECK(success); |
858 } | 858 } |
859 | 859 |
860 return result; | 860 return result; |
861 } | 861 } |
862 | 862 |
863 GURL UITest::GetTestUrl(const std::wstring& test_directory, | 863 // Static |
864 const std::wstring &test_case) { | 864 FilePath UITest::GetTestFilePath(const std::wstring& test_directory, |
| 865 const std::wstring& test_case) { |
865 FilePath path; | 866 FilePath path; |
866 PathService::Get(chrome::DIR_TEST_DATA, &path); | 867 PathService::Get(chrome::DIR_TEST_DATA, &path); |
867 path = path.Append(FilePath::FromWStringHack(test_directory)); | 868 path = path.Append(FilePath::FromWStringHack(test_directory)); |
868 path = path.Append(FilePath::FromWStringHack(test_case)); | 869 path = path.Append(FilePath::FromWStringHack(test_case)); |
869 return net::FilePathToFileURL(path); | 870 return path; |
| 871 } |
| 872 |
| 873 // Static |
| 874 GURL UITest::GetTestUrl(const std::wstring& test_directory, |
| 875 const std::wstring &test_case) { |
| 876 return net::FilePathToFileURL(GetTestFilePath(test_directory, test_case)); |
870 } | 877 } |
871 | 878 |
872 void UITest::WaitForFinish(const std::string &name, | 879 void UITest::WaitForFinish(const std::string &name, |
873 const std::string &id, | 880 const std::string &id, |
874 const GURL &url, | 881 const GURL &url, |
875 const std::string& test_complete_cookie, | 882 const std::string& test_complete_cookie, |
876 const std::string& expected_cookie_value, | 883 const std::string& expected_cookie_value, |
877 const int wait_time) { | 884 const int wait_time) { |
878 const int kIntervalMilliSeconds = 50; | 885 const int kIntervalMilliSeconds = 50; |
879 // The webpage being tested has javascript which sets a cookie | 886 // The webpage being tested has javascript which sets a cookie |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 .AppendASCII("typical_history"); | 981 .AppendASCII("typical_history"); |
975 } else if (profile_type == UITest::COMPLEX_THEME) { | 982 } else if (profile_type == UITest::COMPLEX_THEME) { |
976 source_history_file = source_history_file.AppendASCII("profiles") | 983 source_history_file = source_history_file.AppendASCII("profiles") |
977 .AppendASCII("complex_theme"); | 984 .AppendASCII("complex_theme"); |
978 } else { | 985 } else { |
979 NOTREACHED(); | 986 NOTREACHED(); |
980 } | 987 } |
981 return source_history_file; | 988 return source_history_file; |
982 } | 989 } |
983 | 990 |
| 991 void UITest::WaitForGeneratedFileAndCheck(const FilePath& generated_file, |
| 992 const FilePath& original_file, |
| 993 bool compare_files, |
| 994 bool need_equal, |
| 995 bool delete_generated_file) { |
| 996 // Check whether the target file has been generated. |
| 997 file_util::FileInfo previous, current; |
| 998 bool exist = false; |
| 999 for (int i = 0; i < 20; ++i) { |
| 1000 if (exist) { |
| 1001 file_util::GetFileInfo(generated_file, ¤t); |
| 1002 if (current.size == previous.size) |
| 1003 break; |
| 1004 previous = current; |
| 1005 } else if (file_util::PathExists(generated_file)) { |
| 1006 file_util::GetFileInfo(generated_file, &previous); |
| 1007 exist = true; |
| 1008 } |
| 1009 PlatformThread::Sleep(sleep_timeout_ms()); |
| 1010 } |
| 1011 EXPECT_TRUE(exist); |
984 | 1012 |
| 1013 if (compare_files) { |
| 1014 // Check whether the generated file is equal with original file according to |
| 1015 // parameter: need_equal. |
| 1016 int64 generated_file_size = 0; |
| 1017 int64 original_file_size = 0; |
| 1018 EXPECT_TRUE(file_util::GetFileSize(generated_file, &generated_file_size)); |
| 1019 EXPECT_TRUE(file_util::GetFileSize(original_file, &original_file_size)); |
| 1020 if (need_equal) { |
| 1021 EXPECT_EQ(generated_file_size, original_file_size); |
| 1022 EXPECT_TRUE(file_util::ContentsEqual(generated_file, original_file)); |
| 1023 } else { |
| 1024 EXPECT_NE(generated_file_size, original_file_size); |
| 1025 EXPECT_FALSE(file_util::ContentsEqual(generated_file, original_file)); |
| 1026 } |
| 1027 } |
| 1028 if (delete_generated_file) |
| 1029 EXPECT_TRUE(file_util::DieFileDie(generated_file, false)); |
| 1030 } |
| 1031 |
OLD | NEW |