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

Side by Side Diff: extensions/browser/api/networking_private/networking_private_chromeos_unittest.cc

Issue 2754903002: Prevent networkingPrivate.forgetNetwork from removing shared configs (Closed)
Patch Set: . Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chromeos/dbus/dbus_thread_manager.h" 10 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 device_policy_ssid.c_str(), 170 device_policy_ssid.c_str(),
171 device_policy_ssid.size())) 171 device_policy_ssid.size()))
172 .Set("Security", "None") 172 .Set("Security", "None")
173 .Build()) 173 .Build())
174 .Build()) 174 .Build())
175 .Build(); 175 .Build();
176 config_handler->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY, "", 176 config_handler->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY, "",
177 *device_policy_onc, base::DictionaryValue()); 177 *device_policy_onc, base::DictionaryValue());
178 } 178 }
179 179
180 void AddSharedNetworkToUserProfile() { 180 void AddSharedNetworkToUserProfile(const std::string& service_path) {
181 service_test_->SetServiceProperty(kSharedWifiServicePath, 181 service_test_->SetServiceProperty(service_path, shill::kProfileProperty,
182 shill::kProfileProperty,
183 base::Value(kUserProfilePath)); 182 base::Value(kUserProfilePath));
184 profile_test_->AddService(kUserProfilePath, kSharedWifiServicePath); 183 profile_test_->AddService(kUserProfilePath, service_path);
185 184
186 base::RunLoop().RunUntilIdle(); 185 base::RunLoop().RunUntilIdle();
187 } 186 }
188 187
189 int GetNetworkPriority(const chromeos::NetworkState* network) { 188 int GetNetworkPriority(const chromeos::NetworkState* network) {
190 base::DictionaryValue properties; 189 base::DictionaryValue properties;
191 network->GetStateProperties(&properties); 190 network->GetStateProperties(&properties);
192 int priority; 191 int priority;
193 if (!properties.GetInteger(shill::kPriorityProperty, &priority)) 192 if (!properties.GetInteger(shill::kPriorityProperty, &priority))
194 return -1; 193 return -1;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 "Priority": 1, 457 "Priority": 1,
459 "Type": "WiFi", 458 "Type": "WiFi",
460 "WiFi": { 459 "WiFi": {
461 "HexSSID": "%s", 460 "HexSSID": "%s",
462 "Security": "WPA-PSK" 461 "Security": "WPA-PSK"
463 } 462 }
464 }])", 463 }])",
465 network_hex_ssid.c_str()))); 464 network_hex_ssid.c_str())));
466 } 465 }
467 466
467 TEST_F(NetworkingPrivateApiTest, ForgetSharedNetwork) {
468 EXPECT_EQ(networking_private::kErrorAccessToSharedConfig,
469 RunFunctionAndReturnError(
470 new NetworkingPrivateForgetNetworkFunction(),
471 base::StringPrintf(R"(["%s"])", kSharedWifiGuid)));
472
473 base::RunLoop().RunUntilIdle();
474 std::string profile_path;
475 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
476 EXPECT_EQ(chromeos::ShillProfileClient::GetSharedProfilePath(), profile_path);
477 }
478
479 TEST_F(NetworkingPrivateApiTest, ForgetPrivateNetwork) {
480 RunFunction(new NetworkingPrivateForgetNetworkFunction(),
481 base::StringPrintf(R"(["%s"])", kPrivateWifiGuid));
482
483 std::string profile_path;
484 EXPECT_FALSE(GetServiceProfile(kPrivateWifiServicePath, &profile_path));
485 }
486
487 TEST_F(NetworkingPrivateApiTest, ForgetPrivateNetworkWebUI) {
488 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
489 new NetworkingPrivateForgetNetworkFunction();
490 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
491
492 RunFunction(forget_network.get(),
493 base::StringPrintf(R"(["%s"])", kPrivateWifiGuid));
494
495 std::string profile_path;
496 EXPECT_FALSE(GetServiceProfile(kPrivateWifiServicePath, &profile_path));
497 }
498
499 TEST_F(NetworkingPrivateApiTest, ForgetUserPolicyNetwork) {
500 EXPECT_EQ(networking_private::kErrorPolicyControlled,
501 RunFunctionAndReturnError(
502 new NetworkingPrivateForgetNetworkFunction(),
503 base::StringPrintf(R"(["%s"])", kManagedUserWifiGuid)));
504
505 const chromeos::NetworkState* network =
506 chromeos::NetworkHandler::Get()
507 ->network_state_handler()
508 ->GetNetworkStateFromGuid(kManagedUserWifiGuid);
509
510 base::RunLoop().RunUntilIdle();
511 std::string profile_path;
512 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
513 EXPECT_EQ(kUserProfilePath, profile_path);
514 }
515
516 TEST_F(NetworkingPrivateApiTest, ForgetUserPolicyNetworkWebUI) {
517 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
518 new NetworkingPrivateForgetNetworkFunction();
519 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
520
521 EXPECT_EQ(networking_private::kErrorPolicyControlled,
522 RunFunctionAndReturnError(
523 forget_network.get(),
524 base::StringPrintf(R"(["%s"])", kManagedUserWifiGuid)));
525
526 const chromeos::NetworkState* network =
527 chromeos::NetworkHandler::Get()
528 ->network_state_handler()
529 ->GetNetworkStateFromGuid(kManagedUserWifiGuid);
530
531 base::RunLoop().RunUntilIdle();
532 std::string profile_path;
533 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
534 EXPECT_EQ(kUserProfilePath, profile_path);
535 }
536
537 TEST_F(NetworkingPrivateApiTest, ForgetDevicePolicyNetworkWebUI) {
538 const chromeos::NetworkState* network =
539 chromeos::NetworkHandler::Get()
540 ->network_state_handler()
541 ->GetNetworkStateFromGuid(kManagedDeviceWifiGuid);
542 ASSERT_TRUE(network);
543 AddSharedNetworkToUserProfile(network->path());
544
545 std::string profile_path;
546 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
547 ASSERT_EQ(kUserProfilePath, profile_path);
548
549 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
550 new NetworkingPrivateForgetNetworkFunction();
551 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
552 RunFunction(forget_network.get(),
553 base::StringPrintf(R"(["%s"])", kManagedDeviceWifiGuid));
554
555 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
556 EXPECT_EQ(chromeos::ShillProfileClient::GetSharedProfilePath(), profile_path);
557 }
558
559 // Tests that forgetNetwork in case there is a network config in both user and
560 // shared profile - only config from the user profile is expected to be removed.
561 TEST_F(NetworkingPrivateApiTest, ForgetNetworkInMultipleProfiles) {
562 AddSharedNetworkToUserProfile(kSharedWifiServicePath);
563
564 std::string profile_path;
565 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
566 ASSERT_EQ(kUserProfilePath, profile_path);
567
568 RunFunction(new NetworkingPrivateForgetNetworkFunction(),
569 base::StringPrintf(R"(["%s"])", kSharedWifiGuid));
570
571 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
572 EXPECT_EQ(chromeos::ShillProfileClient::GetSharedProfilePath(), profile_path);
573 }
574
575 TEST_F(NetworkingPrivateApiTest, ForgetNetworkInMultipleProfilesWebUI) {
576 AddSharedNetworkToUserProfile(kSharedWifiServicePath);
577
578 std::string profile_path;
579 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
580 ASSERT_EQ(kUserProfilePath, profile_path);
581
582 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
583 new NetworkingPrivateForgetNetworkFunction();
584 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
585
586 RunFunction(forget_network.get(),
587 base::StringPrintf(R"(["%s"])", kSharedWifiGuid));
588
589 EXPECT_FALSE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
590 }
591
468 } // namespace extensions 592 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698