| Index: chrome/browser/ui/webui/options/preferences_browsertest.cc
|
| diff --git a/chrome/browser/ui/webui/options/preferences_browsertest.cc b/chrome/browser/ui/webui/options/preferences_browsertest.cc
|
| index 3a51a60e032fa8a4699eca0dcfcc37266aefca34..eb3790aadc33a07211a30e6cafcb95013d980b2d 100644
|
| --- a/chrome/browser/ui/webui/options/preferences_browsertest.cc
|
| +++ b/chrome/browser/ui/webui/options/preferences_browsertest.cc
|
| @@ -81,84 +81,85 @@ void PreferencesBrowserTest::SetUpOnMainThread() {
|
| pref_change_registrar_.Init(
|
| PrefServiceBase::FromBrowserContext(browser()->profile()));
|
| pref_service_ = browser()->profile()->GetPrefs();
|
| - ASSERT_TRUE(content::ExecuteJavaScript(render_view_host_, L"",
|
| - L"function TestEnv() {"
|
| - L" this.sentinelName_ = 'download.prompt_for_download';"
|
| - L" this.prefs_ = [];"
|
| - L" TestEnv.instance_ = this;"
|
| - L"}"
|
| - L""
|
| - L"TestEnv.handleEvent = function(event) {"
|
| - L" var env = TestEnv.instance_;"
|
| - L" var name = event.type;"
|
| - L" env.removePrefListener_(name);"
|
| - L" if (name == TestEnv.sentinelName_)"
|
| - L" env.sentinelValue_ = event.value.value;"
|
| - L" else"
|
| - L" env.reply_[name] = event.value;"
|
| - L" if (env.fetching_ && !--env.fetching_ ||"
|
| - L" !env.fetching_ && name == env.sentinelName_) {"
|
| - L" env.removePrefListeners_();"
|
| - L" window.domAutomationController.send(JSON.stringify(env.reply_));"
|
| - L" delete env.reply_;"
|
| - L" }"
|
| - L"};"
|
| - L""
|
| - L"TestEnv.prototype = {"
|
| - L" addPrefListener_: function(name) {"
|
| - L" Preferences.getInstance().addEventListener(name,"
|
| - L" TestEnv.handleEvent);"
|
| - L" },"
|
| - L""
|
| - L" addPrefListeners_: function() {"
|
| - L" for (var i in this.prefs_)"
|
| - L" this.addPrefListener_(this.prefs_[i]);"
|
| - L" },"
|
| - L""
|
| - L" removePrefListener_: function(name) {"
|
| - L" Preferences.getInstance().removeEventListener(name,"
|
| - L" TestEnv.handleEvent);"
|
| - L" },"
|
| - L""
|
| - L" removePrefListeners_: function() {"
|
| - L" for (var i in this.prefs_)"
|
| - L" this.removePrefListener_(this.prefs_[i]);"
|
| - L" },"
|
| - L""
|
| - L""
|
| - L" addPref: function(name) {"
|
| - L" this.prefs_.push(name);"
|
| - L" },"
|
| - L""
|
| - L" setupAndReply: function() {"
|
| - L" this.reply_ = {};"
|
| - L" Preferences.instance_ = new Preferences();"
|
| - L" this.addPref(this.sentinelName_);"
|
| - L" this.fetching_ = this.prefs_.length;"
|
| - L" this.addPrefListeners_();"
|
| - L" Preferences.getInstance().initialize();"
|
| - L" },"
|
| - L""
|
| - L" runAndReply: function(test) {"
|
| - L" this.reply_ = {};"
|
| - L" this.addPrefListeners_();"
|
| - L" test();"
|
| - L" this.sentinelValue_ = !this.sentinelValue_;"
|
| - L" Preferences.setBooleanPref(this.sentinelName_, this.sentinelValue_,"
|
| - L" true);"
|
| - L" },"
|
| - L""
|
| - L" startObserving: function() {"
|
| - L" this.reply_ = {};"
|
| - L" this.addPrefListeners_();"
|
| - L" },"
|
| - L""
|
| - L" finishObservingAndReply: function() {"
|
| - L" this.sentinelValue_ = !this.sentinelValue_;"
|
| - L" Preferences.setBooleanPref(this.sentinelName_, this.sentinelValue_,"
|
| - L" true);"
|
| - L" }"
|
| - L"};"));
|
| + ASSERT_TRUE(content::ExecuteJavaScript(render_view_host_,
|
| + "",
|
| + "function TestEnv() {"
|
| + " this.sentinelName_ = 'download.prompt_for_download';"
|
| + " this.prefs_ = [];"
|
| + " TestEnv.instance_ = this;"
|
| + "}"
|
| + ""
|
| + "TestEnv.handleEvent = function(event) {"
|
| + " var env = TestEnv.instance_;"
|
| + " var name = event.type;"
|
| + " env.removePrefListener_(name);"
|
| + " if (name == TestEnv.sentinelName_)"
|
| + " env.sentinelValue_ = event.value.value;"
|
| + " else"
|
| + " env.reply_[name] = event.value;"
|
| + " if (env.fetching_ && !--env.fetching_ ||"
|
| + " !env.fetching_ && name == env.sentinelName_) {"
|
| + " env.removePrefListeners_();"
|
| + " window.domAutomationController.send(JSON.stringify(env.reply_));"
|
| + " delete env.reply_;"
|
| + " }"
|
| + "};"
|
| + ""
|
| + "TestEnv.prototype = {"
|
| + " addPrefListener_: function(name) {"
|
| + " Preferences.getInstance().addEventListener(name,"
|
| + " TestEnv.handleEvent);"
|
| + " },"
|
| + ""
|
| + " addPrefListeners_: function() {"
|
| + " for (var i in this.prefs_)"
|
| + " this.addPrefListener_(this.prefs_[i]);"
|
| + " },"
|
| + ""
|
| + " removePrefListener_: function(name) {"
|
| + " Preferences.getInstance().removeEventListener(name,"
|
| + " TestEnv.handleEvent);"
|
| + " },"
|
| + ""
|
| + " removePrefListeners_: function() {"
|
| + " for (var i in this.prefs_)"
|
| + " this.removePrefListener_(this.prefs_[i]);"
|
| + " },"
|
| + ""
|
| + ""
|
| + " addPref: function(name) {"
|
| + " this.prefs_.push(name);"
|
| + " },"
|
| + ""
|
| + " setupAndReply: function() {"
|
| + " this.reply_ = {};"
|
| + " Preferences.instance_ = new Preferences();"
|
| + " this.addPref(this.sentinelName_);"
|
| + " this.fetching_ = this.prefs_.length;"
|
| + " this.addPrefListeners_();"
|
| + " Preferences.getInstance().initialize();"
|
| + " },"
|
| + ""
|
| + " runAndReply: function(test) {"
|
| + " this.reply_ = {};"
|
| + " this.addPrefListeners_();"
|
| + " test();"
|
| + " this.sentinelValue_ = !this.sentinelValue_;"
|
| + " Preferences.setBooleanPref(this.sentinelName_, this.sentinelValue_,"
|
| + " true);"
|
| + " },"
|
| + ""
|
| + " startObserving: function() {"
|
| + " this.reply_ = {};"
|
| + " this.addPrefListeners_();"
|
| + " },"
|
| + ""
|
| + " finishObservingAndReply: function() {"
|
| + " this.sentinelValue_ = !this.sentinelValue_;"
|
| + " Preferences.setBooleanPref(this.sentinelName_, this.sentinelValue_,"
|
| + " true);"
|
| + " }"
|
| + "};"));
|
| }
|
|
|
| // Forwards notifications received when pref values change in the backend.
|
| @@ -303,7 +304,7 @@ void PreferencesBrowserTest::VerifyAndClearExpectations() {
|
| void PreferencesBrowserTest::SetupJavaScriptTestEnvironment(
|
| const std::vector<std::string>& pref_names,
|
| std::string* observed_json) const {
|
| - std::wstringstream javascript;
|
| + std::stringstream javascript;
|
| javascript << "var testEnv = new TestEnv();";
|
| for (std::vector<std::string>::const_iterator name = pref_names.begin();
|
| name != pref_names.end(); ++name)
|
| @@ -313,7 +314,7 @@ void PreferencesBrowserTest::SetupJavaScriptTestEnvironment(
|
| if (!observed_json)
|
| observed_json = &temp_observed_json;
|
| ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
|
| - render_view_host_, L"", javascript.str(), observed_json));
|
| + render_view_host_, "", javascript.str(), observed_json));
|
| }
|
|
|
| void PreferencesBrowserTest::VerifySetPref(const std::string& name,
|
| @@ -329,7 +330,7 @@ void PreferencesBrowserTest::VerifySetPref(const std::string& name,
|
| std::string commit_json;
|
| base::JSONWriter::Write(value, &value_json);
|
| base::JSONWriter::Write(commit_ptr.get(), &commit_json);
|
| - std::wstringstream javascript;
|
| + std::stringstream javascript;
|
| javascript << "testEnv.runAndReply(function() {"
|
| << " Preferences.set" << type.c_str() << "Pref("
|
| << " '" << name.c_str() << "',"
|
| @@ -337,7 +338,7 @@ void PreferencesBrowserTest::VerifySetPref(const std::string& name,
|
| << " " << commit_json.c_str() << ");});";
|
| std::string observed_json;
|
| ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
|
| - render_view_host_, L"", javascript.str(), &observed_json));
|
| + render_view_host_, "", javascript.str(), &observed_json));
|
| VerifyObservedPref(observed_json, name, value, "", false, !commit);
|
| VerifyAndClearExpectations();
|
| }
|
| @@ -352,14 +353,14 @@ void PreferencesBrowserTest::VerifyClearPref(const std::string& name,
|
| scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit));
|
| std::string commit_json;
|
| base::JSONWriter::Write(commit_ptr.get(), &commit_json);
|
| - std::wstringstream javascript;
|
| + std::stringstream javascript;
|
| javascript << "testEnv.runAndReply(function() {"
|
| << " Preferences.clearPref("
|
| << " '" << name.c_str() << "',"
|
| << " " << commit_json.c_str() << ");});";
|
| std::string observed_json;
|
| ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
|
| - render_view_host_, L"", javascript.str(), &observed_json));
|
| + render_view_host_, "", javascript.str(), &observed_json));
|
| VerifyObservedPref(observed_json, name, value, "recommended", false, !commit);
|
| VerifyAndClearExpectations();
|
| }
|
| @@ -367,13 +368,13 @@ void PreferencesBrowserTest::VerifyClearPref(const std::string& name,
|
| void PreferencesBrowserTest::VerifyCommit(const std::string& name,
|
| const base::Value* value,
|
| const std::string& controlledBy) {
|
| - std::wstringstream javascript;
|
| + std::stringstream javascript;
|
| javascript << "testEnv.runAndReply(function() {"
|
| << " Preferences.getInstance().commitPref("
|
| << " '" << name.c_str() << "');});";
|
| std::string observed_json;
|
| ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
|
| - render_view_host_, L"", javascript.str(), &observed_json));
|
| + render_view_host_, "", javascript.str(), &observed_json));
|
| VerifyObservedPref(observed_json, name, value, controlledBy, false, false);
|
| }
|
|
|
| @@ -395,25 +396,27 @@ void PreferencesBrowserTest::VerifyRollback(const std::string& name,
|
| const base::Value* value,
|
| const std::string& controlledBy) {
|
| ExpectNoCommit(name);
|
| - std::wstringstream javascript;
|
| + std::stringstream javascript;
|
| javascript << "testEnv.runAndReply(function() {"
|
| << " Preferences.getInstance().rollbackPref("
|
| << " '" << name.c_str() << "');});";
|
| std::string observed_json;
|
| ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
|
| - render_view_host_, L"", javascript.str(), &observed_json));
|
| + render_view_host_, "", javascript.str(), &observed_json));
|
| VerifyObservedPref(observed_json, name, value, controlledBy, false, true);
|
| VerifyAndClearExpectations();
|
| }
|
|
|
| void PreferencesBrowserTest::StartObserving() {
|
| ASSERT_TRUE(content::ExecuteJavaScript(
|
| - render_view_host_, L"", L"testEnv.startObserving();"));
|
| + render_view_host_, "", "testEnv.startObserving();"));
|
| }
|
|
|
| void PreferencesBrowserTest::FinishObserving(std::string* observed_json) {
|
| ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
|
| - render_view_host_, L"", L"testEnv.finishObservingAndReply();",
|
| + render_view_host_,
|
| + "",
|
| + "testEnv.finishObservingAndReply();",
|
| observed_json));
|
| }
|
|
|
|
|