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

Unified Diff: chrome/test/chromedriver/chrome_launcher.cc

Issue 613163004: [chromedriver] setting browser default download directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified codes based on reviewer's comments Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/chrome_launcher.cc
diff --git a/chrome/test/chromedriver/chrome_launcher.cc b/chrome/test/chromedriver/chrome_launcher.cc
index 21595b0c8b3fab8f83af37918ef29e7f2e2eb8b5..99566d73eb0834995c09a29b0db7acccf4347e24 100644
--- a/chrome/test/chromedriver/chrome_launcher.cc
+++ b/chrome/test/chromedriver/chrome_launcher.cc
@@ -128,24 +128,29 @@ Status PrepareCommandLine(int port,
switches.RemoveSwitch(*iter);
}
switches.SetFromSwitches(capabilities.switches);
-
+ base::FilePath user_data_dir_path;
if (!switches.HasSwitch("user-data-dir")) {
command.AppendArg("data:,");
if (!user_data_dir->CreateUniqueTempDir())
return Status(kUnknownError, "cannot create temp dir for user data dir");
switches.SetSwitch("user-data-dir", user_data_dir->path().value());
- Status status = internal::PrepareUserDataDir(
- user_data_dir->path(), capabilities.prefs.get(),
- capabilities.local_state.get());
- if (status.IsError())
- return status;
+ user_data_dir_path = user_data_dir->path();
+ } else {
+ user_data_dir_path = base::FilePath(
+ switches.GetSwitchValue("user-data-dir"));
}
+ Status status = internal::PrepareUserDataDir(
+ user_data_dir_path , capabilities.prefs.get(),
samuong 2014/10/16 20:23:40 I've just noticed that if you unconditionally call
+ capabilities.local_state.get());
+ if (status.IsError())
+ return status;
samuong 2014/10/16 20:23:40 This is indented too far in.
+
if (!extension_dir->CreateUniqueTempDir()) {
return Status(kUnknownError,
"cannot create temp dir for unpacking extensions");
}
- Status status = internal::ProcessExtensions(capabilities.extensions,
+ status = internal::ProcessExtensions(capabilities.extensions,
extension_dir->path(),
true,
&switches,
@@ -763,6 +768,39 @@ Status WritePrefsFile(
return Status(kOk);
}
+Status MergeExistPrefFile(const base::DictionaryValue* custom_prefs,
+ const base::FilePath& path, base::DictionaryValue* merge_prefs) {
+
+ if (base::PathExists(path)) { // if exist, import it
+ std::string data_read;
+ base::ReadFileToString(path, &data_read);
+ //
+ int code;
+ std::string error_msg;
+ scoped_ptr<base::Value> template_value(
+ base::JSONReader::ReadAndReturnError(data_read, 0, &code, &error_msg));
+
+ base::DictionaryValue* prefs = NULL;
+ if (!template_value || !template_value->GetAsDictionary(&prefs)) {
+ return Status(kUnknownError,
+ "cannot parse default Preference: " + error_msg);
+ }
+ merge_prefs->MergeDictionary(prefs);
+ // overwrite if any custom prefs
+ if (custom_prefs) {
+ for (base::DictionaryValue::Iterator it(*custom_prefs); !it.IsAtEnd();
+ it.Advance()) {
+ merge_prefs->Set(it.key(), it.value().DeepCopy());
+ }
+ }
+
+ } else { // nothing to read - copy user define data directly
+ if (custom_prefs)
+ merge_prefs->MergeDictionary(custom_prefs);
+ }
+ return Status(kOk);
+}
+
Status PrepareUserDataDir(
const base::FilePath& user_data_dir,
const base::DictionaryValue* custom_prefs,
@@ -772,10 +810,17 @@ Status PrepareUserDataDir(
if (!base::CreateDirectory(default_dir))
return Status(kUnknownError, "cannot create default profile directory");
- Status status =
- WritePrefsFile(kPreferences,
- custom_prefs,
- default_dir.Append(chrome::kPreferencesFilename));
+ base::DictionaryValue merge_prefs;
+ // merge to existed Preferences
+ Status status = MergeExistPrefFile(custom_prefs,
+ default_dir.Append(chrome::kPreferencesFilename),
+ &merge_prefs);
+ if (status.IsError())
+ return status;
+ // merge to template
+ status = WritePrefsFile(kPreferences,
+ &merge_prefs,
+ default_dir.Append(chrome::kPreferencesFilename));
if (status.IsError())
return status;

Powered by Google App Engine
This is Rietveld 408576698