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

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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 "Priority": 1, 458 "Priority": 1,
459 "Type": "WiFi", 459 "Type": "WiFi",
460 "WiFi": { 460 "WiFi": {
461 "HexSSID": "%s", 461 "HexSSID": "%s",
462 "Security": "WPA-PSK" 462 "Security": "WPA-PSK"
463 } 463 }
464 }])", 464 }])",
465 network_hex_ssid.c_str()))); 465 network_hex_ssid.c_str())));
466 } 466 }
467 467
468 TEST_F(NetworkingPrivateApiTest, ForgetSharedNetwork) {
469 EXPECT_EQ(networking_private::kErrorAccessToSharedConfig,
470 RunFunctionAndReturnError(
471 new NetworkingPrivateForgetNetworkFunction(),
472 base::StringPrintf(R"(["%s"])", kSharedWifiGuid)));
473
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 std::string profile_path;
510 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
511 EXPECT_EQ(kUserProfilePath, profile_path);
512 }
513
514 TEST_F(NetworkingPrivateApiTest, ForgetUserPolicyNetworkWebUI) {
515 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
516 new NetworkingPrivateForgetNetworkFunction();
517 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
518
519 EXPECT_EQ(networking_private::kErrorPolicyControlled,
520 RunFunctionAndReturnError(
521 forget_network.get(),
522 base::StringPrintf(R"(["%s"])", kManagedUserWifiGuid)));
523
524 const chromeos::NetworkState* network =
525 chromeos::NetworkHandler::Get()
526 ->network_state_handler()
527 ->GetNetworkStateFromGuid(kManagedUserWifiGuid);
528 std::string profile_path;
529 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
530 EXPECT_EQ(kUserProfilePath, profile_path);
531 }
532
533 TEST_F(NetworkingPrivateApiTest, ForgetDevicePolicyNetworkWebUI) {
534 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
535 new NetworkingPrivateForgetNetworkFunction();
536 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
537
538 EXPECT_EQ(networking_private::kErrorPolicyControlled,
539 RunFunctionAndReturnError(
540 forget_network.get(),
541 base::StringPrintf(R"(["%s"])", kManagedDeviceWifiGuid)));
542
543 const chromeos::NetworkState* network =
544 chromeos::NetworkHandler::Get()
545 ->network_state_handler()
546 ->GetNetworkStateFromGuid(kManagedDeviceWifiGuid);
547 std::string profile_path;
548 EXPECT_TRUE(GetServiceProfile(network->path(), &profile_path));
549 EXPECT_EQ(chromeos::ShillProfileClient::GetSharedProfilePath(), profile_path);
550 }
551
552 // Tests that forgetNetwork in case there is a network config in both user and
553 // shared profile - only config from the user profile is expected to be removed.
554 TEST_F(NetworkingPrivateApiTest, ForgetNetworkInMultipleProfiles) {
555 AddSharedNetworkToUserProfile();
556
557 std::string profile_path;
558 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
559 ASSERT_EQ(kUserProfilePath, profile_path);
560
561 RunFunction(new NetworkingPrivateForgetNetworkFunction(),
562 base::StringPrintf(R"(["%s"])", kSharedWifiGuid));
563
564 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
565 EXPECT_EQ(chromeos::ShillProfileClient::GetSharedProfilePath(), profile_path);
566 }
567
568 TEST_F(NetworkingPrivateApiTest, ForgetNetworkInMultipleProfilesWebUI) {
569 AddSharedNetworkToUserProfile();
570
571 std::string profile_path;
572 EXPECT_TRUE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
573 ASSERT_EQ(kUserProfilePath, profile_path);
574
575 scoped_refptr<NetworkingPrivateForgetNetworkFunction> forget_network =
576 new NetworkingPrivateForgetNetworkFunction();
577 forget_network->set_source_context_type(Feature::WEBUI_CONTEXT);
578
579 RunFunction(forget_network.get(),
580 base::StringPrintf(R"(["%s"])", kSharedWifiGuid));
581
582 EXPECT_FALSE(GetServiceProfile(kSharedWifiServicePath, &profile_path));
583 }
584
468 } // namespace extensions 585 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698