| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Main entry point for all unit tests. | 5 // Main entry point for all unit tests. |
| 6 | 6 |
| 7 #include "rlz_test_helpers.h" | 7 #include "rlz_test_helpers.h" |
| 8 | 8 |
| 9 #include "rlz/lib/rlz_lib.h" | 9 #include "rlz/lib/rlz_lib.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
| 13 #include <shlwapi.h> | 13 #include <shlwapi.h> |
| 14 #include "base/win/registry.h" | 14 #include "base/win/registry.h" |
| 15 #include "rlz/win/lib/rlz_lib.h" | 15 #include "rlz/win/lib/rlz_lib.h" |
| 16 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 16 #elif defined(OS_POSIX) |
| 17 #include "base/file_path.h" | 17 #include "base/file_path.h" |
| 18 #include "rlz/lib/rlz_value_store.h" | 18 #include "rlz/lib/rlz_value_store.h" |
| 19 #endif | 19 #endif |
| 20 #if defined(OS_CHROMEOS) | |
| 21 #include "rlz/chromeos/lib/rlz_value_store_chromeos.h" | |
| 22 #endif | |
| 23 | 20 |
| 24 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 const wchar_t* kHKCUReplacement = L"Software\\Google\\RlzUtilUnittest\\HKCU"; | 24 const wchar_t* kHKCUReplacement = L"Software\\Google\\RlzUtilUnittest\\HKCU"; |
| 28 const wchar_t* kHKLMReplacement = L"Software\\Google\\RlzUtilUnittest\\HKLM"; | 25 const wchar_t* kHKLMReplacement = L"Software\\Google\\RlzUtilUnittest\\HKLM"; |
| 29 | 26 |
| 30 void OverrideRegistryHives() { | 27 void OverrideRegistryHives() { |
| 31 // Wipe the keys we redirect to. | 28 // Wipe the keys we redirect to. |
| 32 // This gives us a stable run, even in the presence of previous | 29 // This gives us a stable run, even in the presence of previous |
| (...skipping 22 matching lines...) Expand all Loading... |
| 55 | 52 |
| 56 void UndoOverrideRegistryHives() { | 53 void UndoOverrideRegistryHives() { |
| 57 // Undo the redirection. | 54 // Undo the redirection. |
| 58 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | 55 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); |
| 59 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, NULL)); | 56 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, NULL)); |
| 60 } | 57 } |
| 61 | 58 |
| 62 } // namespace | 59 } // namespace |
| 63 #endif // defined(OS_WIN) | 60 #endif // defined(OS_WIN) |
| 64 | 61 |
| 65 | |
| 66 #if defined(OS_CHROMEOS) | |
| 67 RlzLibTestNoMachineState::RlzLibTestNoMachineState() | |
| 68 : pref_store_io_thread_("test_rlz_pref_store_io_thread") { | |
| 69 } | |
| 70 #endif // defined(OS_CHROMEOS) | |
| 71 | |
| 72 void RlzLibTestNoMachineState::SetUp() { | 62 void RlzLibTestNoMachineState::SetUp() { |
| 73 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
| 74 OverrideRegistryHives(); | 64 OverrideRegistryHives(); |
| 75 #elif defined(OS_MACOSX) | 65 #elif defined(OS_MACOSX) |
| 76 base::mac::ScopedNSAutoreleasePool pool; | 66 base::mac::ScopedNSAutoreleasePool pool; |
| 77 #endif // defined(OS_WIN) | 67 #endif // defined(OS_WIN) |
| 78 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 68 #if defined(OS_POSIX) |
| 79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 80 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); | 70 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); |
| 81 #endif // defined(OS_MACOSX) || defined(OS_CHROMEOS) | 71 #endif // defined(OS_POSIX) |
| 82 #if defined(OS_CHROMEOS) | |
| 83 base::Thread::Options options; | |
| 84 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 85 ASSERT_TRUE(pref_store_io_thread_.StartWithOptions(options)); | |
| 86 rlz_lib::SetIOTaskRunner(pref_store_io_thread_.message_loop_proxy()); | |
| 87 rlz_lib::RlzValueStoreChromeOS::ResetForTesting(); | |
| 88 #endif // defined(OS_CHROMEOS) | |
| 89 } | 72 } |
| 90 | 73 |
| 91 void RlzLibTestNoMachineState::TearDown() { | 74 void RlzLibTestNoMachineState::TearDown() { |
| 92 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 93 UndoOverrideRegistryHives(); | 76 UndoOverrideRegistryHives(); |
| 94 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 77 #elif defined(OS_POSIX) |
| 95 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); | 78 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); |
| 96 #endif // defined(OS_WIN) | 79 #endif // defined(OS_WIN) |
| 97 #if defined(OS_CHROMEOS) | |
| 98 pref_store_io_thread_.Stop(); | |
| 99 #endif // defined(OS_CHROMEOS) | |
| 100 } | 80 } |
| 101 | 81 |
| 102 void RlzLibTestBase::SetUp() { | 82 void RlzLibTestBase::SetUp() { |
| 103 RlzLibTestNoMachineState::SetUp(); | 83 RlzLibTestNoMachineState::SetUp(); |
| 104 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
| 105 rlz_lib::CreateMachineState(); | 85 rlz_lib::CreateMachineState(); |
| 106 #endif // defined(OS_WIN) | 86 #endif // defined(OS_WIN) |
| 107 } | 87 } |
| OLD | NEW |