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

Unified Diff: remoting/host/linux/certificate_watcher_unittest.cc

Issue 1977963002: [remoting host] Only watch for material changes to NSS DB files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/linux/certificate_watcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/linux/certificate_watcher_unittest.cc
diff --git a/remoting/host/linux/certificate_watcher_unittest.cc b/remoting/host/linux/certificate_watcher_unittest.cc
index 97c3b2ae7f75af9bcd1b8d0a81dd90e64dad24d8..62c9821569c808de86b7c12b36adb85e9aade8ac 100644
--- a/remoting/host/linux/certificate_watcher_unittest.cc
+++ b/remoting/host/linux/certificate_watcher_unittest.cc
@@ -16,21 +16,23 @@
namespace remoting {
-const char kWatchFileName[] = "testfile.txt";
+const char kCertFileName[] = "cert9.db";
+const char kKeyFileName[] = "key4.db";
+const char kPKCSFileName[] = "pkcs11.txt";
+const char kOtherFileName[] = "testfile.txt";
const int kMessageLoopWaitMsecs = 150;
class CertificateWatcherTest : public testing::Test {
public:
- CertificateWatcherTest()
- : task_runner_(message_loop_.task_runner()),
- watch_path_(CreateAndGetUniqueTempDir().AppendASCII(kWatchFileName)) {
+ CertificateWatcherTest() : task_runner_(message_loop_.task_runner()) {
+ EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
watcher_.reset(new CertificateWatcher(
base::Bind(&CertificateWatcherTest::OnRestart,
base::Unretained(this)),
task_runner_));
watcher_->SetDelayForTests(base::TimeDelta::FromSeconds(0));
- watcher_->SetWatchPathForTests(watch_path_);
+ watcher_->SetWatchPathForTests(temp_dir_.path());
}
~CertificateWatcherTest() override {
@@ -74,23 +76,28 @@ class CertificateWatcherTest : public testing::Test {
base::Unretained(watcher_.get()), ""));
}
- void TouchFile() {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&CertificateWatcherTest::TouchFileTask,
- base::Unretained(this)));
+ void TouchFile(const char* filename) {
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&CertificateWatcherTest::TouchFileTask,
+ base::Unretained(this), filename));
}
- void TouchFileTask() {
+ void TouchFileTask(const char* filename) {
std::string testWriteString = std::to_string(rand());
-
- base::WriteFile(watch_path_, testWriteString.c_str(),
- testWriteString.length());
+ base::FilePath path = temp_dir_.path().AppendASCII(filename);
+
+ if (base::PathExists(path)) {
+ EXPECT_TRUE(base::AppendToFile(path, testWriteString.c_str(),
+ testWriteString.length()));
+ } else {
+ EXPECT_TRUE(base::WriteFile(path, testWriteString.c_str(),
+ testWriteString.length()));
+ }
}
base::MessageLoopForIO message_loop_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::ScopedTempDir temp_dir_;
- base::FilePath watch_path_;
std::unique_ptr<CertificateWatcher> watcher_;
int restart_count_ = 0;
base::TimeDelta loop_wait_ =
@@ -98,11 +105,6 @@ class CertificateWatcherTest : public testing::Test {
base::Closure quit_loop_closure_;
private:
- const base::FilePath& CreateAndGetUniqueTempDir() {
- EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
- return temp_dir_.path();
- }
-
void OnRestart() {
restart_count_++;
quit_loop_closure_.Run();
@@ -113,7 +115,17 @@ TEST_F(CertificateWatcherTest, OneTouch) {
EXPECT_EQ(0, restart_count_);
Start();
EXPECT_EQ(0, restart_count_);
- TouchFile();
+ TouchFile(kCertFileName);
+ RunLoop();
+ EXPECT_EQ(1, restart_count_);
+}
+
+TEST_F(CertificateWatcherTest, OneTouchAppend) {
+ EXPECT_EQ(0, restart_count_);
+ TouchFileTask(kKeyFileName);
+ Start();
+ EXPECT_EQ(0, restart_count_);
+ TouchFile(kKeyFileName); // Appends to existing file.
RunLoop();
EXPECT_EQ(1, restart_count_);
}
@@ -123,7 +135,7 @@ TEST_F(CertificateWatcherTest, InhibitDeferRestart) {
EXPECT_EQ(0, restart_count_);
Connect();
EXPECT_EQ(0, restart_count_);
- TouchFile();
+ TouchFile(kPKCSFileName);
RunAndWait();
EXPECT_EQ(0, restart_count_);
Disconnect();
@@ -139,9 +151,20 @@ TEST_F(CertificateWatcherTest, UninhibitAndRestart) {
Disconnect();
RunAndWait();
EXPECT_EQ(0, restart_count_);
- TouchFile();
+ TouchFile(kCertFileName);
RunLoop();
EXPECT_EQ(1, restart_count_);
}
+TEST_F(CertificateWatcherTest, TouchOtherFile) {
+ // The watcher should not trigger if changes are made that don't affect the
+ // NSS DB contents.
+ EXPECT_EQ(0, restart_count_);
+ Start();
+ EXPECT_EQ(0, restart_count_);
+ TouchFile(kOtherFileName);
+ RunAndWait();
+ EXPECT_EQ(0, restart_count_);
+}
+
} // namespace remoting
« no previous file with comments | « remoting/host/linux/certificate_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698