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

Side by Side Diff: chrome/test/automated_ui_tests/automated_ui_tests.cc

Issue 18248: CommandLine API rework (Closed)
Patch Set: fixes Created 11 years, 11 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
« no previous file with comments | « chrome/renderer/renderer_main.cc ('k') | chrome/test/automation/automation_proxy_uitest.cc » ('j') | 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) 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 <fstream> 5 #include <fstream>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 "EditSearchEngines", 72 "EditSearchEngines",
73 "ViewPasswords" 73 "ViewPasswords"
74 }; 74 };
75 75
76 AutomatedUITest::AutomatedUITest() 76 AutomatedUITest::AutomatedUITest()
77 : total_crashes_(0), 77 : total_crashes_(0),
78 debug_logging_enabled_(false), 78 debug_logging_enabled_(false),
79 post_action_delay_(0) { 79 post_action_delay_(0) {
80 show_window_ = true; 80 show_window_ = true;
81 GetSystemTimeAsFileTime(&test_start_time_); 81 GetSystemTimeAsFileTime(&test_start_time_);
82 CommandLine parsed_command_line; 82 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
83 if (parsed_command_line.HasSwitch(kDebugModeSwitch)) 83 if (parsed_command_line.HasSwitch(kDebugModeSwitch))
84 debug_logging_enabled_ = true; 84 debug_logging_enabled_ = true;
85 if (parsed_command_line.HasSwitch(kWaitSwitch)) { 85 if (parsed_command_line.HasSwitch(kWaitSwitch)) {
86 std::wstring str = parsed_command_line.GetSwitchValue(kWaitSwitch); 86 std::wstring str = parsed_command_line.GetSwitchValue(kWaitSwitch);
87 if (str.empty()) { 87 if (str.empty()) {
88 post_action_delay_ = 1; 88 post_action_delay_ = 1;
89 } else { 89 } else {
90 post_action_delay_ = static_cast<int>(StringToInt64(str)); 90 post_action_delay_ = static_cast<int>(StringToInt64(str));
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 AutomatedUITest::~AutomatedUITest() {} 95 AutomatedUITest::~AutomatedUITest() {}
96 96
97 void AutomatedUITest::RunReproduction() { 97 void AutomatedUITest::RunReproduction() {
98 CommandLine parsed_command_line; 98 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
99 xml_writer_.StartWriting(); 99 xml_writer_.StartWriting();
100 xml_writer_.StartElement("Report"); 100 xml_writer_.StartElement("Report");
101 std::string action_string = 101 std::string action_string =
102 WideToASCII(parsed_command_line.GetSwitchValue(kReproSwitch)); 102 WideToASCII(parsed_command_line.GetSwitchValue(kReproSwitch));
103 103
104 int64 num_reproductions = 1; 104 int64 num_reproductions = 1;
105 if (parsed_command_line.HasSwitch(kReproRepeatSwitch)) { 105 if (parsed_command_line.HasSwitch(kReproRepeatSwitch)) {
106 std::wstring num_reproductions_string = 106 std::wstring num_reproductions_string =
107 parsed_command_line.GetSwitchValue(kReproRepeatSwitch); 107 parsed_command_line.GetSwitchValue(kReproRepeatSwitch);
108 std::string test = WideToASCII(num_reproductions_string); 108 std::string test = WideToASCII(num_reproductions_string);
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 } 856 }
857 if (!window->SimulateOSKeyPress(key, flags)) { 857 if (!window->SimulateOSKeyPress(key, flags)) {
858 AddWarningAttribute("failure_simulating_key_press"); 858 AddWarningAttribute("failure_simulating_key_press");
859 return false; 859 return false;
860 } 860 }
861 return true; 861 return true;
862 } 862 }
863 863
864 bool AutomatedUITest::InitXMLReader() { 864 bool AutomatedUITest::InitXMLReader() {
865 std::wstring input_path; 865 std::wstring input_path;
866 CommandLine parsed_command_line; 866 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
867 if (parsed_command_line.HasSwitch(kInputFilePathSwitch)) 867 if (parsed_command_line.HasSwitch(kInputFilePathSwitch))
868 input_path = parsed_command_line.GetSwitchValue(kInputFilePathSwitch); 868 input_path = parsed_command_line.GetSwitchValue(kInputFilePathSwitch);
869 else 869 else
870 input_path = kDefaultInputFilePath; 870 input_path = kDefaultInputFilePath;
871 871
872 if (!file_util::ReadFileToString(input_path, &xml_init_file_)) 872 if (!file_util::ReadFileToString(input_path, &xml_init_file_))
873 return false; 873 return false;
874 return init_reader_.Load(xml_init_file_); 874 return init_reader_.Load(xml_init_file_);
875 } 875 }
876 876
877 bool AutomatedUITest::WriteReportToFile() { 877 bool AutomatedUITest::WriteReportToFile() {
878 std::ofstream error_file; 878 std::ofstream error_file;
879 std::wstring path; 879 std::wstring path;
880 CommandLine parsed_command_line; 880 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
881 if (parsed_command_line.HasSwitch(kOutputFilePathSwitch)) 881 if (parsed_command_line.HasSwitch(kOutputFilePathSwitch))
882 path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch); 882 path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch);
883 else 883 else
884 path = kDefaultOutputFilePath; 884 path = kDefaultOutputFilePath;
885 885
886 if (!path.empty()) 886 if (!path.empty())
887 error_file.open(path.c_str(), std::ios::out); 887 error_file.open(path.c_str(), std::ios::out);
888 888
889 // Closes all open elements and free the writer. This is required 889 // Closes all open elements and free the writer. This is required
890 // in order to retrieve the contents of the buffer. 890 // in order to retrieve the contents of the buffer.
891 xml_writer_.StopWriting(); 891 xml_writer_.StopWriting();
892 error_file << xml_writer_.GetWrittenString(); 892 error_file << xml_writer_.GetWrittenString();
893 error_file.close(); 893 error_file.close();
894 return true; 894 return true;
895 } 895 }
896 896
897 void AutomatedUITest::AppendToOutputFile(const std::string &append_string) { 897 void AutomatedUITest::AppendToOutputFile(const std::string &append_string) {
898 std::ofstream error_file; 898 std::ofstream error_file;
899 std::wstring path; 899 std::wstring path;
900 CommandLine parsed_command_line; 900 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
901 if (parsed_command_line.HasSwitch(kOutputFilePathSwitch)) 901 if (parsed_command_line.HasSwitch(kOutputFilePathSwitch))
902 path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch); 902 path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch);
903 else 903 else
904 path = kDefaultOutputFilePath; 904 path = kDefaultOutputFilePath;
905 905
906 if (!path.empty()) 906 if (!path.empty())
907 error_file.open(path.c_str(), std::ios::out | std::ios_base::app); 907 error_file.open(path.c_str(), std::ios::out | std::ios_base::app);
908 908
909 error_file << append_string << " "; 909 error_file << append_string << " ";
910 error_file.close(); 910 error_file.close();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 if (actual_crashes > total_crashes_) { 994 if (actual_crashes > total_crashes_) {
995 if (update_total_crashes) 995 if (update_total_crashes)
996 total_crashes_ = actual_crashes; 996 total_crashes_ = actual_crashes;
997 return true; 997 return true;
998 } else { 998 } else {
999 return false; 999 return false;
1000 } 1000 }
1001 } 1001 }
1002 1002
1003 TEST_F(AutomatedUITest, TheOneAndOnlyTest) { 1003 TEST_F(AutomatedUITest, TheOneAndOnlyTest) {
1004 CommandLine parsed_command_line; 1004 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
1005 if (parsed_command_line.HasSwitch(kReproSwitch)) 1005 if (parsed_command_line.HasSwitch(kReproSwitch))
1006 RunReproduction(); 1006 RunReproduction();
1007 else 1007 else
1008 RunAutomatedUITest(); 1008 RunAutomatedUITest();
1009 } 1009 }
1010 1010
OLDNEW
« no previous file with comments | « chrome/renderer/renderer_main.cc ('k') | chrome/test/automation/automation_proxy_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698