Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome_frame/registry_watcher.h" | |
| 6 | |
| 7 #include "base/synchronization/waitable_event.h" | |
| 8 #include "base/time.h" | |
| 9 #include "base/win/registry.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using base::win::RegKey; | |
| 13 | |
| 14 const wchar_t test_root[] = L"CFRegistryWatcherTest"; | |
|
grt (UTC plus 2)
2011/05/26 17:08:58
kTestRoot
robertshield
2011/05/27 03:34:59
Done.
| |
| 15 const wchar_t kTestWindowClass[] = L"TestWndClass"; | |
| 16 const wchar_t kTestWindowName[] = L"TestWndName"; | |
| 17 | |
| 18 // Give notifications 30 seconds to stick. Hopefully long enough to avoid | |
| 19 // flakiness. | |
| 20 const int64 kWaitSeconds = 30; | |
| 21 | |
| 22 class RegistryWatcherUnittest : public testing::Test { | |
| 23 public: | |
| 24 void SetUp() { | |
| 25 // Create a temporary key for testing | |
| 26 temp_key_.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); | |
|
grt (UTC plus 2)
2011/05/26 17:08:58
Don't need all access to delete a subkey. KEY_QUE
robertshield
2011/05/27 03:34:59
Done.
| |
| 27 temp_key_.DeleteKey(test_root); | |
| 28 ASSERT_NE(ERROR_SUCCESS, temp_key_.Open(HKEY_CURRENT_USER, | |
| 29 test_root, | |
| 30 KEY_READ)); | |
| 31 ASSERT_EQ(ERROR_SUCCESS, | |
| 32 temp_key_.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); | |
| 33 | |
| 34 reg_change_count_ = 0; | |
| 35 } | |
| 36 | |
| 37 void TearDown() { | |
| 38 // Clean up the temporary key | |
| 39 temp_key_.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); | |
|
grt (UTC plus 2)
2011/05/26 17:08:58
Don't need all access to delete a subkey. KEY_QUE
robertshield
2011/05/27 03:34:59
Done.
| |
| 40 ASSERT_EQ(ERROR_SUCCESS, temp_key_.DeleteKey(test_root)); | |
| 41 | |
|
grt (UTC plus 2)
2011/05/26 17:08:58
temp_key_.Close();
robertshield
2011/05/27 03:34:59
Done.
| |
| 42 reg_change_count_ = 0; | |
| 43 } | |
| 44 | |
| 45 static void CALLBACK WaitCallback(void* param, BOOLEAN wait_fired) { | |
| 46 reg_change_count_++; | |
| 47 event_.Signal(); | |
| 48 } | |
| 49 | |
| 50 protected: | |
| 51 RegKey temp_key_; | |
| 52 static unsigned int reg_change_count_; | |
| 53 static base::WaitableEvent event_; | |
| 54 }; | |
| 55 | |
| 56 unsigned int RegistryWatcherUnittest::reg_change_count_ = 0; | |
| 57 base::WaitableEvent RegistryWatcherUnittest::event_( | |
| 58 false, // auto reset | |
| 59 false); // initially unsignalled | |
| 60 | |
| 61 TEST_F(RegistryWatcherUnittest, Basic) { | |
| 62 RegistryWatcher watcher(HKEY_CURRENT_USER, | |
| 63 test_root, | |
| 64 &RegistryWatcherUnittest::WaitCallback); | |
| 65 ASSERT_TRUE(watcher.StartWatching()); | |
| 66 EXPECT_EQ(0, reg_change_count_); | |
| 67 | |
| 68 EXPECT_EQ(ERROR_SUCCESS, temp_key_.CreateKey(L"foo", KEY_ALL_ACCESS)); | |
| 69 EXPECT_TRUE(event_.TimedWait(base::TimeDelta::FromSeconds(kWaitSeconds))); | |
| 70 EXPECT_EQ(1, reg_change_count_); | |
| 71 } | |
| OLD | NEW |