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

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

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <memory>
10 #include <sstream> 11 #include <sstream>
11 12
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
25 #include "components/policy/core/browser/browser_policy_connector.h" 25 #include "components/policy/core/browser/browser_policy_connector.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 else if (dict->HasKey("uncommitted")) 257 else if (dict->HasKey("uncommitted"))
258 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false)); 258 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false));
259 } 259 }
260 260
261 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json, 261 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json,
262 const std::string& name, 262 const std::string& name,
263 const base::Value* value, 263 const base::Value* value,
264 const std::string& controlledBy, 264 const std::string& controlledBy,
265 bool disabled, 265 bool disabled,
266 bool uncommitted) { 266 bool uncommitted) {
267 scoped_ptr<base::Value> observed_value_ptr = base::JSONReader::Read(json); 267 std::unique_ptr<base::Value> observed_value_ptr =
268 base::JSONReader::Read(json);
268 const base::DictionaryValue* observed_dict; 269 const base::DictionaryValue* observed_dict;
269 ASSERT_TRUE(observed_value_ptr.get()); 270 ASSERT_TRUE(observed_value_ptr.get());
270 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict)); 271 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict));
271 VerifyPref(observed_dict, name, value, controlledBy, disabled, uncommitted); 272 VerifyPref(observed_dict, name, value, controlledBy, disabled, uncommitted);
272 } 273 }
273 274
274 void PreferencesBrowserTest::VerifyObservedPrefs( 275 void PreferencesBrowserTest::VerifyObservedPrefs(
275 const std::string& json, 276 const std::string& json,
276 const std::vector<std::string>& names, 277 const std::vector<std::string>& names,
277 const std::vector<base::Value*>& values, 278 const std::vector<base::Value*>& values,
278 const std::string& controlledBy, 279 const std::string& controlledBy,
279 bool disabled, 280 bool disabled,
280 bool uncommitted) { 281 bool uncommitted) {
281 scoped_ptr<base::Value> observed_value_ptr = base::JSONReader::Read(json); 282 std::unique_ptr<base::Value> observed_value_ptr =
283 base::JSONReader::Read(json);
282 const base::DictionaryValue* observed_dict; 284 const base::DictionaryValue* observed_dict;
283 ASSERT_TRUE(observed_value_ptr.get()); 285 ASSERT_TRUE(observed_value_ptr.get());
284 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict)); 286 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict));
285 for (size_t i = 0; i < names.size(); ++i) { 287 for (size_t i = 0; i < names.size(); ++i) {
286 VerifyPref(observed_dict, names[i], values[i], controlledBy, disabled, 288 VerifyPref(observed_dict, names[i], values[i], controlledBy, disabled,
287 uncommitted); 289 uncommitted);
288 } 290 }
289 } 291 }
290 292
291 void PreferencesBrowserTest::ExpectNoCommit(const std::string& name) { 293 void PreferencesBrowserTest::ExpectNoCommit(const std::string& name) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 observed_json = &temp_observed_json; 341 observed_json = &temp_observed_json;
340 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 342 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
341 render_view_host_, javascript.str(), observed_json)); 343 render_view_host_, javascript.str(), observed_json));
342 } 344 }
343 345
344 void PreferencesBrowserTest::SetPref(const std::string& name, 346 void PreferencesBrowserTest::SetPref(const std::string& name,
345 const std::string& type, 347 const std::string& type,
346 const base::Value* value, 348 const base::Value* value,
347 bool commit, 349 bool commit,
348 std::string* observed_json) { 350 std::string* observed_json) {
349 scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit)); 351 std::unique_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit));
350 std::stringstream javascript; 352 std::stringstream javascript;
351 javascript << "testEnv.runAndReply(function() {" 353 javascript << "testEnv.runAndReply(function() {"
352 << " Preferences.set" << type << "Pref(" 354 << " Preferences.set" << type << "Pref("
353 << " '" << name << "'," 355 << " '" << name << "',"
354 << " " << *value << "," 356 << " " << *value << ","
355 << " " << *commit_ptr << ");" 357 << " " << *commit_ptr << ");"
356 << "});"; 358 << "});";
357 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 359 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
358 render_view_host_, javascript.str(), observed_json)); 360 render_view_host_, javascript.str(), observed_json));
359 } 361 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 VerifyObservedPrefs(observed_json, pref_names_, 714 VerifyObservedPrefs(observed_json, pref_names_,
713 decorated_non_default_values.get(), 715 decorated_non_default_values.get(),
714 std::string(), false, false); 716 std::string(), false, false);
715 } 717 }
716 718
717 class ManagedPreferencesBrowserTest : public PreferencesBrowserTest { 719 class ManagedPreferencesBrowserTest : public PreferencesBrowserTest {
718 protected: 720 protected:
719 // PreferencesBrowserTest implementation: 721 // PreferencesBrowserTest implementation:
720 void SetUpInProcessBrowserTestFixture() override { 722 void SetUpInProcessBrowserTestFixture() override {
721 // Set up fake install attributes. 723 // Set up fake install attributes.
722 scoped_ptr<policy::StubEnterpriseInstallAttributes> attributes( 724 std::unique_ptr<policy::StubEnterpriseInstallAttributes> attributes(
723 new policy::StubEnterpriseInstallAttributes()); 725 new policy::StubEnterpriseInstallAttributes());
724 attributes->SetDomain("example.com"); 726 attributes->SetDomain("example.com");
725 attributes->SetRegistrationUser("user@example.com"); 727 attributes->SetRegistrationUser("user@example.com");
726 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( 728 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
727 attributes.release()); 729 attributes.release());
728 730
729 PreferencesBrowserTest::SetUpInProcessBrowserTestFixture(); 731 PreferencesBrowserTest::SetUpInProcessBrowserTestFixture();
730 } 732 }
731 }; 733 };
732 734
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 const char* kUserProfilePath = "user_profile"; 814 const char* kUserProfilePath = "user_profile";
813 815
814 } // namespace 816 } // namespace
815 817
816 class ProxyPreferencesBrowserTest : public PreferencesBrowserTest { 818 class ProxyPreferencesBrowserTest : public PreferencesBrowserTest {
817 public: 819 public:
818 void SetUpOnMainThread() override { 820 void SetUpOnMainThread() override {
819 SetupNetworkEnvironment(); 821 SetupNetworkEnvironment();
820 content::RunAllPendingInMessageLoop(); 822 content::RunAllPendingInMessageLoop();
821 823
822 scoped_ptr<base::DictionaryValue> proxy_config_dict( 824 std::unique_ptr<base::DictionaryValue> proxy_config_dict(
823 ProxyConfigDictionary::CreateFixedServers("127.0.0.1:8080", 825 ProxyConfigDictionary::CreateFixedServers("127.0.0.1:8080",
824 "*.google.com, 1.2.3.4:22")); 826 "*.google.com, 1.2.3.4:22"));
825 827
826 ProxyConfigDictionary proxy_config(proxy_config_dict.get()); 828 ProxyConfigDictionary proxy_config(proxy_config_dict.get());
827 829
828 const chromeos::NetworkState* network = GetDefaultNetwork(); 830 const chromeos::NetworkState* network = GetDefaultNetwork();
829 ASSERT_TRUE(network); 831 ASSERT_TRUE(network);
830 chromeos::proxy_config::SetProxyConfigForNetwork(proxy_config, *network); 832 chromeos::proxy_config::SetProxyConfigForNetwork(proxy_config, *network);
831 833
832 std::string url = base::StringPrintf("%s?network=%s", 834 std::string url = base::StringPrintf("%s?network=%s",
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 915
914 std::string observed_json; 916 std::string observed_json;
915 SetPref(name, type, &value, true, &observed_json); 917 SetPref(name, type, &value, true, &observed_json);
916 } 918 }
917 919
918 void VerifyCurrentProxyServer(const std::string& expected_server, 920 void VerifyCurrentProxyServer(const std::string& expected_server,
919 onc::ONCSource expected_source) { 921 onc::ONCSource expected_source) {
920 const chromeos::NetworkState* network = GetDefaultNetwork(); 922 const chromeos::NetworkState* network = GetDefaultNetwork();
921 ASSERT_TRUE(network); 923 ASSERT_TRUE(network);
922 onc::ONCSource actual_source; 924 onc::ONCSource actual_source;
923 scoped_ptr<ProxyConfigDictionary> proxy_dict = 925 std::unique_ptr<ProxyConfigDictionary> proxy_dict =
924 chromeos::proxy_config::GetProxyConfigForNetwork( 926 chromeos::proxy_config::GetProxyConfigForNetwork(
925 pref_service_, 927 pref_service_, g_browser_process->local_state(), *network,
926 g_browser_process->local_state(),
927 *network,
928 &actual_source); 928 &actual_source);
929 ASSERT_TRUE(proxy_dict); 929 ASSERT_TRUE(proxy_dict);
930 std::string actual_proxy_server; 930 std::string actual_proxy_server;
931 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server)); 931 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server));
932 EXPECT_EQ(expected_server, actual_proxy_server); 932 EXPECT_EQ(expected_server, actual_proxy_server);
933 EXPECT_EQ(expected_source, actual_source); 933 EXPECT_EQ(expected_source, actual_source);
934 } 934 }
935 }; 935 };
936 936
937 // Verifies that proxy settings are correctly pushed to JavaScript during 937 // Verifies that proxy settings are correctly pushed to JavaScript during
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2)); 1082 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2));
1083 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3)); 1083 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3));
1084 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4)); 1084 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4));
1085 1085
1086 VerifyCurrentProxyServer( 1086 VerifyCurrentProxyServer(
1087 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4", 1087 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4",
1088 onc::ONC_SOURCE_NONE); 1088 onc::ONC_SOURCE_NONE);
1089 } 1089 }
1090 1090
1091 #endif 1091 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698