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

Side by Side Diff: chrome/browser/ui/webui/options/preferences_browsertest.cc

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/ui/webui/options/preferences_browsertest.h" 5 #include "chrome/browser/ui/webui/options/preferences_browsertest.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 namespace base { 61 namespace base {
62 62
63 // Helper for using EXPECT_EQ() with base::Value. 63 // Helper for using EXPECT_EQ() with base::Value.
64 bool operator==(const base::Value& first, const base::Value& second) { 64 bool operator==(const base::Value& first, const base::Value& second) {
65 return first.Equals(&second); 65 return first.Equals(&second);
66 } 66 }
67 67
68 // Helper for pretty-printing the contents of base::Value in case of failures. 68 // Helper for pretty-printing the contents of base::Value in case of failures.
69 void PrintTo(const base::Value& value, std::ostream* stream) { 69 void PrintTo(const base::Value& value, std::ostream* stream) {
70 std::string json; 70 std::string json;
71 JSONWriter::Write(&value, &json); 71 JSONWriter::Write(value, &json);
72 *stream << json; 72 *stream << json;
73 } 73 }
74 74
75 } // namespace base 75 } // namespace base
76 76
77 // Googlemock matcher for base::Value. 77 // Googlemock matcher for base::Value.
78 MATCHER_P(EqualsValue, expected, "") { 78 MATCHER_P(EqualsValue, expected, "") {
79 return arg && arg->Equals(expected); 79 return arg && arg->Equals(expected);
80 } 80 }
81 81
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void PreferencesBrowserTest::OnPreferenceChanged(const std::string& pref_name) { 185 void PreferencesBrowserTest::OnPreferenceChanged(const std::string& pref_name) {
186 OnCommit(pref_service_->FindPreference(pref_name.c_str())); 186 OnCommit(pref_service_->FindPreference(pref_name.c_str()));
187 } 187 }
188 188
189 void PreferencesBrowserTest::SetUpInProcessBrowserTestFixture() { 189 void PreferencesBrowserTest::SetUpInProcessBrowserTestFixture() {
190 // Sets up a mock policy provider for user and device policies. 190 // Sets up a mock policy provider for user and device policies.
191 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) 191 EXPECT_CALL(policy_provider_, IsInitializationComplete(_))
192 .WillRepeatedly(Return(true)); 192 .WillRepeatedly(Return(true));
193 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( 193 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
194 &policy_provider_); 194 &policy_provider_);
195 }; 195 }
196 196
197 void PreferencesBrowserTest::SetUserPolicies( 197 void PreferencesBrowserTest::SetUserPolicies(
198 const std::vector<std::string>& names, 198 const std::vector<std::string>& names,
199 const std::vector<base::Value*>& values, 199 const std::vector<base::Value*>& values,
200 policy::PolicyLevel level) { 200 policy::PolicyLevel level) {
201 policy::PolicyMap map; 201 policy::PolicyMap map;
202 for (size_t i = 0; i < names.size(); ++i) { 202 for (size_t i = 0; i < names.size(); ++i) {
203 map.Set(names[i], level, policy::POLICY_SCOPE_USER, 203 map.Set(names[i], level, policy::POLICY_SCOPE_USER,
204 values[i]->DeepCopy(), NULL); 204 values[i]->DeepCopy(), NULL);
205 } 205 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 VerifyAndClearExpectations(); 369 VerifyAndClearExpectations();
370 } 370 }
371 371
372 void PreferencesBrowserTest::VerifyClearPref(const std::string& name, 372 void PreferencesBrowserTest::VerifyClearPref(const std::string& name,
373 const base::Value* value, 373 const base::Value* value,
374 bool commit) { 374 bool commit) {
375 if (commit) 375 if (commit)
376 ExpectClearCommit(name); 376 ExpectClearCommit(name);
377 else 377 else
378 ExpectNoCommit(name); 378 ExpectNoCommit(name);
379 scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit));
380 std::string commit_json; 379 std::string commit_json;
381 base::JSONWriter::Write(commit_ptr.get(), &commit_json); 380 base::JSONWriter::Write(base::FundamentalValue(commit), &commit_json);
382 std::stringstream javascript; 381 std::stringstream javascript;
383 javascript << "testEnv.runAndReply(function() {" 382 javascript << "testEnv.runAndReply(function() {"
384 << " Preferences.clearPref(" 383 << " Preferences.clearPref("
385 << " '" << name.c_str() << "'," 384 << " '" << name.c_str() << "',"
386 << " " << commit_json.c_str() << ");});"; 385 << " " << commit_json.c_str() << ");});";
387 std::string observed_json; 386 std::string observed_json;
388 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 387 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
389 render_view_host_, javascript.str(), &observed_json)); 388 render_view_host_, javascript.str(), &observed_json));
390 VerifyObservedPref(observed_json, name, value, "recommended", false, !commit); 389 VerifyObservedPref(observed_json, name, value, "recommended", false, !commit);
391 VerifyAndClearExpectations(); 390 VerifyAndClearExpectations();
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2)); 1078 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2));
1080 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3)); 1079 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3));
1081 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4)); 1080 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4));
1082 1081
1083 VerifyCurrentProxyServer( 1082 VerifyCurrentProxyServer(
1084 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4", 1083 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4",
1085 onc::ONC_SOURCE_NONE); 1084 onc::ONC_SOURCE_NONE);
1086 } 1085 }
1087 1086
1088 #endif 1087 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/certificate_viewer_webui.cc ('k') | chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698