OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "components/browser_watcher/exit_funnel_win.h" | 5 #include "components/browser_watcher/exit_funnel_win.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <map> | 10 #include <map> |
8 | 11 |
9 #include "base/command_line.h" | 12 #include "base/command_line.h" |
10 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
11 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
14 #include "base/test/test_reg_util_win.h" | 17 #include "base/test/test_reg_util_win.h" |
15 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
17 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
19 | 22 |
20 namespace browser_watcher { | 23 namespace browser_watcher { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 const wchar_t kRegistryPath[] = L"Software\\ExitFunnelWinTest"; | 27 const wchar_t kRegistryPath[] = L"Software\\ExitFunnelWinTest"; |
25 | 28 |
26 class ExitFunnelWinTest : public testing::Test { | 29 class ExitFunnelWinTest : public testing::Test { |
27 public: | 30 public: |
28 typedef testing::Test Super; | 31 typedef testing::Test Super; |
29 typedef std::map<base::string16, int64> EventMap; | 32 typedef std::map<base::string16, int64_t> EventMap; |
30 | 33 |
31 void SetUp() override { | 34 void SetUp() override { |
32 Super::SetUp(); | 35 Super::SetUp(); |
33 | 36 |
34 override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | 37 override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
35 } | 38 } |
36 | 39 |
37 base::string16 GetEventSubkey() { | 40 base::string16 GetEventSubkey() { |
38 // There should be a single subkey named after this process' pid. | 41 // There should be a single subkey named after this process' pid. |
39 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); | 42 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); |
(...skipping 12 matching lines...) Expand all Loading... |
52 base::StringPrintf(L"%ls\\%ls", kRegistryPath, subkey_name.c_str())); | 55 base::StringPrintf(L"%ls\\%ls", kRegistryPath, subkey_name.c_str())); |
53 | 56 |
54 base::win::RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); | 57 base::win::RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
55 EXPECT_TRUE(key.Valid()); | 58 EXPECT_TRUE(key.Valid()); |
56 EXPECT_EQ(2u, key.GetValueCount()); | 59 EXPECT_EQ(2u, key.GetValueCount()); |
57 | 60 |
58 EventMap events; | 61 EventMap events; |
59 for (size_t i = 0; i < key.GetValueCount(); ++i) { | 62 for (size_t i = 0; i < key.GetValueCount(); ++i) { |
60 base::string16 name; | 63 base::string16 name; |
61 EXPECT_EQ(key.GetValueNameAt(i, &name), ERROR_SUCCESS); | 64 EXPECT_EQ(key.GetValueNameAt(i, &name), ERROR_SUCCESS); |
62 int64 value = 0; | 65 int64_t value = 0; |
63 EXPECT_EQ(key.ReadInt64(name.c_str(), &value), ERROR_SUCCESS); | 66 EXPECT_EQ(key.ReadInt64(name.c_str(), &value), ERROR_SUCCESS); |
64 | 67 |
65 events[name] = value; | 68 events[name] = value; |
66 } | 69 } |
67 | 70 |
68 return events; | 71 return events; |
69 } | 72 } |
70 | 73 |
71 EventMap ReadEvents() { | 74 EventMap ReadEvents() { |
72 base::string16 name = GetEventSubkey(); | 75 base::string16 name = GetEventSubkey(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 110 |
108 base::TimeDelta one = base::TimeDelta::FromInternalValue(events[L"One"]); | 111 base::TimeDelta one = base::TimeDelta::FromInternalValue(events[L"One"]); |
109 base::TimeDelta two = base::TimeDelta::FromInternalValue(events[L"Two"]); | 112 base::TimeDelta two = base::TimeDelta::FromInternalValue(events[L"Two"]); |
110 | 113 |
111 // Sleep is not accurate, it may over or under sleep. To minimize flakes, | 114 // Sleep is not accurate, it may over or under sleep. To minimize flakes, |
112 // this test only compares relative ordering of the events. | 115 // this test only compares relative ordering of the events. |
113 ASSERT_LT(one, two); | 116 ASSERT_LT(one, two); |
114 } | 117 } |
115 | 118 |
116 } // namespace browser_watcher | 119 } // namespace browser_watcher |
OLD | NEW |