forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update remoting::HostConfig to use non-deprecated JSON methods
Bug: NO_BUG Change-Id: I9eb09f684d8051c7a38af801a1ddfbf81061c40d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3213389 Reviewed-by: Yuwei Huang <[email protected]> Commit-Queue: Joe Downing <[email protected]> Cr-Commit-Position: refs/heads/main@{#929825}
- Loading branch information
Showing
8 changed files
with
124 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#include "base/memory/ref_counted.h" | ||
#include "base/values.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/abseil-cpp/absl/types/optional.h" | ||
|
||
namespace remoting { | ||
|
||
|
@@ -53,54 +54,50 @@ TEST_F(HostConfigTest, Read) { | |
ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | ||
base::FilePath test_file = test_dir_.GetPath().AppendASCII("read.json"); | ||
WriteTestFile(test_file); | ||
std::unique_ptr<base::DictionaryValue> target( | ||
HostConfigFromJsonFile(test_file)); | ||
ASSERT_TRUE(target); | ||
|
||
std::string value; | ||
EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); | ||
EXPECT_EQ("[email protected]", value); | ||
EXPECT_TRUE(target->GetString(kOAuthRefreshTokenConfigPath, &value)); | ||
EXPECT_EQ("TEST_REFRESH_TOKEN", value); | ||
EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); | ||
EXPECT_EQ("TEST_HOST_ID", value); | ||
EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); | ||
EXPECT_EQ("TEST_MACHINE_NAME", value); | ||
EXPECT_TRUE(target->GetString(kPrivateKeyConfigPath, &value)); | ||
EXPECT_EQ("TEST_PRIVATE_KEY", value); | ||
|
||
EXPECT_FALSE(target->GetString("non_existent_value", &value)); | ||
absl::optional<base::Value> target(HostConfigFromJsonFile(test_file)); | ||
ASSERT_TRUE(target.has_value()); | ||
|
||
std::string* value = target->FindStringKey(kXmppLoginConfigPath); | ||
EXPECT_EQ("[email protected]", *value); | ||
value = target->FindStringKey(kOAuthRefreshTokenConfigPath); | ||
EXPECT_EQ("TEST_REFRESH_TOKEN", *value); | ||
value = target->FindStringKey(kHostIdConfigPath); | ||
EXPECT_EQ("TEST_HOST_ID", *value); | ||
value = target->FindStringKey(kHostNameConfigPath); | ||
EXPECT_EQ("TEST_MACHINE_NAME", *value); | ||
value = target->FindStringKey(kPrivateKeyConfigPath); | ||
EXPECT_EQ("TEST_PRIVATE_KEY", *value); | ||
|
||
value = target->FindStringKey("non_existent_value"); | ||
EXPECT_EQ(nullptr, value); | ||
} | ||
|
||
TEST_F(HostConfigTest, Write) { | ||
ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | ||
|
||
base::FilePath test_file = test_dir_.GetPath().AppendASCII("write.json"); | ||
WriteTestFile(test_file); | ||
std::unique_ptr<base::DictionaryValue> target( | ||
HostConfigFromJsonFile(test_file)); | ||
ASSERT_TRUE(target); | ||
absl::optional<base::Value> target(HostConfigFromJsonFile(test_file)); | ||
ASSERT_TRUE(target.has_value()); | ||
|
||
std::string new_refresh_token_value = "NEW_REFRESH_TOKEN"; | ||
target->SetString(kOAuthRefreshTokenConfigPath, new_refresh_token_value); | ||
target->SetStringKey(kOAuthRefreshTokenConfigPath, new_refresh_token_value); | ||
ASSERT_TRUE(HostConfigToJsonFile(*target, test_file)); | ||
|
||
// Now read the file again and check that the value has been written. | ||
std::unique_ptr<base::DictionaryValue> reader( | ||
HostConfigFromJsonFile(test_file)); | ||
absl::optional<base::Value> reader(HostConfigFromJsonFile(test_file)); | ||
ASSERT_TRUE(reader); | ||
|
||
std::string value; | ||
EXPECT_TRUE(reader->GetString(kXmppLoginConfigPath, &value)); | ||
EXPECT_EQ("[email protected]", value); | ||
EXPECT_TRUE(reader->GetString(kOAuthRefreshTokenConfigPath, &value)); | ||
EXPECT_EQ(new_refresh_token_value, value); | ||
EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); | ||
EXPECT_EQ("TEST_HOST_ID", value); | ||
EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); | ||
EXPECT_EQ("TEST_MACHINE_NAME", value); | ||
EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); | ||
EXPECT_EQ("TEST_PRIVATE_KEY", value); | ||
std::string* value = target->FindStringKey(kXmppLoginConfigPath); | ||
EXPECT_EQ("[email protected]", *value); | ||
value = target->FindStringKey(kOAuthRefreshTokenConfigPath); | ||
EXPECT_EQ(new_refresh_token_value, *value); | ||
value = target->FindStringKey(kHostIdConfigPath); | ||
EXPECT_EQ("TEST_HOST_ID", *value); | ||
value = target->FindStringKey(kHostNameConfigPath); | ||
EXPECT_EQ("TEST_MACHINE_NAME", *value); | ||
value = target->FindStringKey(kPrivateKeyConfigPath); | ||
EXPECT_EQ("TEST_PRIVATE_KEY", *value); | ||
} | ||
|
||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.