OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromedriver/chrome_launcher.h" | 5 #include "chrome/test/chromedriver/chrome_launcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 switches.SetSwitch("remote-debugging-port", base::IntToString(port)); | 121 switches.SetSwitch("remote-debugging-port", base::IntToString(port)); |
122 switches.SetSwitch("test-type", "webdriver"); | 122 switches.SetSwitch("test-type", "webdriver"); |
123 | 123 |
124 for (std::set<std::string>::const_iterator iter = | 124 for (std::set<std::string>::const_iterator iter = |
125 capabilities.exclude_switches.begin(); | 125 capabilities.exclude_switches.begin(); |
126 iter != capabilities.exclude_switches.end(); | 126 iter != capabilities.exclude_switches.end(); |
127 ++iter) { | 127 ++iter) { |
128 switches.RemoveSwitch(*iter); | 128 switches.RemoveSwitch(*iter); |
129 } | 129 } |
130 switches.SetFromSwitches(capabilities.switches); | 130 switches.SetFromSwitches(capabilities.switches); |
131 | 131 base::FilePath user_data_dir_path; |
132 if (!switches.HasSwitch("user-data-dir")) { | 132 if (!switches.HasSwitch("user-data-dir")) { |
133 command.AppendArg("data:,"); | 133 command.AppendArg("data:,"); |
134 if (!user_data_dir->CreateUniqueTempDir()) | 134 if (!user_data_dir->CreateUniqueTempDir()) |
135 return Status(kUnknownError, "cannot create temp dir for user data dir"); | 135 return Status(kUnknownError, "cannot create temp dir for user data dir"); |
136 switches.SetSwitch("user-data-dir", user_data_dir->path().value()); | 136 switches.SetSwitch("user-data-dir", user_data_dir->path().value()); |
137 Status status = internal::PrepareUserDataDir( | 137 user_data_dir_path = user_data_dir->path(); |
138 user_data_dir->path(), capabilities.prefs.get(), | 138 } else { |
139 capabilities.local_state.get()); | 139 user_data_dir_path = base::FilePath( |
140 if (status.IsError()) | 140 switches.GetSwitchValue("user-data-dir")); |
141 } | |
142 | |
143 Status status = internal::PrepareUserDataDir( | |
144 user_data_dir_path, | |
145 capabilities.prefs.get(), | |
146 capabilities.local_state.get()); | |
samuong
2014/10/17 23:30:34
please fix indenting for arguments - they should e
andrewcheng
2014/10/18 00:45:46
Done.
| |
147 if (status.IsError()) | |
141 return status; | 148 return status; |
samuong
2014/10/17 23:30:34
please fix indenting for "return status;" (it shou
andrewcheng
2014/10/18 00:45:46
Done.
| |
142 } | |
143 | 149 |
144 if (!extension_dir->CreateUniqueTempDir()) { | 150 if (!extension_dir->CreateUniqueTempDir()) { |
145 return Status(kUnknownError, | 151 return Status(kUnknownError, |
146 "cannot create temp dir for unpacking extensions"); | 152 "cannot create temp dir for unpacking extensions"); |
147 } | 153 } |
148 Status status = internal::ProcessExtensions(capabilities.extensions, | 154 status = internal::ProcessExtensions(capabilities.extensions, |
149 extension_dir->path(), | 155 extension_dir->path(), |
150 true, | 156 true, |
151 &switches, | 157 &switches, |
152 extension_bg_pages); | 158 extension_bg_pages); |
153 if (status.IsError()) | 159 if (status.IsError()) |
154 return status; | 160 return status; |
155 switches.AppendToCommandLine(&command); | 161 switches.AppendToCommandLine(&command); |
156 *prepared_command = command; | 162 *prepared_command = command; |
157 return Status(kOk); | 163 return Status(kOk); |
158 } | 164 } |
159 | 165 |
160 Status WaitForDevToolsAndCheckVersion( | 166 Status WaitForDevToolsAndCheckVersion( |
161 const NetAddress& address, | 167 const NetAddress& address, |
162 URLRequestContextGetter* context_getter, | 168 URLRequestContextGetter* context_getter, |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 | 771 |
766 Status PrepareUserDataDir( | 772 Status PrepareUserDataDir( |
767 const base::FilePath& user_data_dir, | 773 const base::FilePath& user_data_dir, |
768 const base::DictionaryValue* custom_prefs, | 774 const base::DictionaryValue* custom_prefs, |
769 const base::DictionaryValue* custom_local_state) { | 775 const base::DictionaryValue* custom_local_state) { |
770 base::FilePath default_dir = | 776 base::FilePath default_dir = |
771 user_data_dir.AppendASCII(chrome::kInitialProfile); | 777 user_data_dir.AppendASCII(chrome::kInitialProfile); |
772 if (!base::CreateDirectory(default_dir)) | 778 if (!base::CreateDirectory(default_dir)) |
773 return Status(kUnknownError, "cannot create default profile directory"); | 779 return Status(kUnknownError, "cannot create default profile directory"); |
774 | 780 |
781 std::string preferences; | |
782 base::FilePath preferences_path = | |
783 default_dir.Append(chrome::kPreferencesFilename); | |
samuong
2014/10/17 23:30:35
fix indenting (should be 6 spaces, not 9)
andrewcheng
2014/10/18 00:45:46
Done.
| |
784 | |
785 if (base::PathExists(preferences_path)) | |
786 base::ReadFileToString(preferences_path, &preferences); | |
787 else | |
788 preferences = std::string(kPreferences); | |
samuong
2014/10/17 23:30:34
why not just do "preferences = kPreferences;"?
andrewcheng
2014/10/18 00:45:46
Done.
| |
789 | |
775 Status status = | 790 Status status = |
776 WritePrefsFile(kPreferences, | 791 WritePrefsFile(preferences, |
777 custom_prefs, | 792 custom_prefs, |
778 default_dir.Append(chrome::kPreferencesFilename)); | 793 default_dir.Append(chrome::kPreferencesFilename)); |
779 if (status.IsError()) | 794 if (status.IsError()) |
780 return status; | 795 return status; |
781 | 796 |
782 status = WritePrefsFile(kLocalState, | 797 std::string local_state; |
798 base::FilePath local_state_path = | |
799 user_data_dir.Append(chrome::kLocalStateFilename); | |
samuong
2014/10/17 23:30:34
fix indenting (should be 6 spaces, not 8)
andrewcheng
2014/10/18 00:45:46
Done.
| |
800 | |
801 if (base::PathExists(local_state_path)) | |
802 base::ReadFileToString(local_state_path, &local_state); | |
803 else | |
804 local_state = std::string(kLocalState); | |
samuong
2014/10/17 23:30:35
similar to above, why not just do "local_state = k
andrewcheng
2014/10/18 00:45:46
Done.
| |
805 | |
806 status = WritePrefsFile(local_state, | |
783 custom_local_state, | 807 custom_local_state, |
784 user_data_dir.Append(chrome::kLocalStateFilename)); | 808 user_data_dir.Append(chrome::kLocalStateFilename)); |
785 if (status.IsError()) | 809 if (status.IsError()) |
786 return status; | 810 return status; |
787 | 811 |
788 // Write empty "First Run" file, otherwise Chrome will wipe the default | 812 // Write empty "First Run" file, otherwise Chrome will wipe the default |
789 // profile that was written. | 813 // profile that was written. |
790 if (base::WriteFile( | 814 if (base::WriteFile( |
791 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { | 815 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { |
792 return Status(kUnknownError, "failed to write first run file"); | 816 return Status(kUnknownError, "failed to write first run file"); |
793 } | 817 } |
794 return Status(kOk); | 818 return Status(kOk); |
795 } | 819 } |
796 | 820 |
797 } // namespace internal | 821 } // namespace internal |
OLD | NEW |