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(switches. |
140 if (status.IsError()) | 140 GetSwitchValueNative("user-data-dir")); |
samuong
2014/10/21 01:01:43
can you put the "switches." on line 140? ie:
user
| |
141 return status; | |
142 } | 141 } |
143 | 142 |
143 Status status = internal::PrepareUserDataDir(user_data_dir_path, | |
144 capabilities.prefs.get(), | |
145 capabilities.local_state.get()); | |
146 if (status.IsError()) | |
147 return status; | |
148 | |
144 if (!extension_dir->CreateUniqueTempDir()) { | 149 if (!extension_dir->CreateUniqueTempDir()) { |
145 return Status(kUnknownError, | 150 return Status(kUnknownError, |
146 "cannot create temp dir for unpacking extensions"); | 151 "cannot create temp dir for unpacking extensions"); |
147 } | 152 } |
148 Status status = internal::ProcessExtensions(capabilities.extensions, | 153 status = internal::ProcessExtensions(capabilities.extensions, |
149 extension_dir->path(), | 154 extension_dir->path(), |
150 true, | 155 true, |
151 &switches, | 156 &switches, |
152 extension_bg_pages); | 157 extension_bg_pages); |
153 if (status.IsError()) | 158 if (status.IsError()) |
154 return status; | 159 return status; |
155 switches.AppendToCommandLine(&command); | 160 switches.AppendToCommandLine(&command); |
156 *prepared_command = command; | 161 *prepared_command = command; |
157 return Status(kOk); | 162 return Status(kOk); |
158 } | 163 } |
159 | 164 |
160 Status WaitForDevToolsAndCheckVersion( | 165 Status WaitForDevToolsAndCheckVersion( |
161 const NetAddress& address, | 166 const NetAddress& address, |
162 URLRequestContextGetter* context_getter, | 167 URLRequestContextGetter* context_getter, |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 | 770 |
766 Status PrepareUserDataDir( | 771 Status PrepareUserDataDir( |
767 const base::FilePath& user_data_dir, | 772 const base::FilePath& user_data_dir, |
768 const base::DictionaryValue* custom_prefs, | 773 const base::DictionaryValue* custom_prefs, |
769 const base::DictionaryValue* custom_local_state) { | 774 const base::DictionaryValue* custom_local_state) { |
770 base::FilePath default_dir = | 775 base::FilePath default_dir = |
771 user_data_dir.AppendASCII(chrome::kInitialProfile); | 776 user_data_dir.AppendASCII(chrome::kInitialProfile); |
772 if (!base::CreateDirectory(default_dir)) | 777 if (!base::CreateDirectory(default_dir)) |
773 return Status(kUnknownError, "cannot create default profile directory"); | 778 return Status(kUnknownError, "cannot create default profile directory"); |
774 | 779 |
780 std::string preferences; | |
781 base::FilePath preferences_path = | |
782 default_dir.Append(chrome::kPreferencesFilename); | |
783 | |
784 if (base::PathExists(preferences_path)) | |
785 base::ReadFileToString(preferences_path, &preferences); | |
786 else | |
787 preferences = kPreferences; | |
788 | |
775 Status status = | 789 Status status = |
776 WritePrefsFile(kPreferences, | 790 WritePrefsFile(preferences, |
777 custom_prefs, | 791 custom_prefs, |
778 default_dir.Append(chrome::kPreferencesFilename)); | 792 default_dir.Append(chrome::kPreferencesFilename)); |
779 if (status.IsError()) | 793 if (status.IsError()) |
780 return status; | 794 return status; |
781 | 795 |
782 status = WritePrefsFile(kLocalState, | 796 std::string local_state; |
797 base::FilePath local_state_path = | |
798 user_data_dir.Append(chrome::kLocalStateFilename); | |
799 | |
800 if (base::PathExists(local_state_path)) | |
801 base::ReadFileToString(local_state_path, &local_state); | |
802 else | |
803 local_state = kLocalState; | |
804 | |
805 status = WritePrefsFile(local_state, | |
783 custom_local_state, | 806 custom_local_state, |
784 user_data_dir.Append(chrome::kLocalStateFilename)); | 807 user_data_dir.Append(chrome::kLocalStateFilename)); |
785 if (status.IsError()) | 808 if (status.IsError()) |
786 return status; | 809 return status; |
787 | 810 |
788 // Write empty "First Run" file, otherwise Chrome will wipe the default | 811 // Write empty "First Run" file, otherwise Chrome will wipe the default |
789 // profile that was written. | 812 // profile that was written. |
790 if (base::WriteFile( | 813 if (base::WriteFile( |
791 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { | 814 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { |
792 return Status(kUnknownError, "failed to write first run file"); | 815 return Status(kUnknownError, "failed to write first run file"); |
793 } | 816 } |
794 return Status(kOk); | 817 return Status(kOk); |
795 } | 818 } |
796 | 819 |
797 } // namespace internal | 820 } // namespace internal |
OLD | NEW |