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

Side by Side Diff: components/browser_watcher/stability_debugging_win_unittest.cc

Issue 2344343002: Wire in postmortem report collection (Closed)
Patch Set: Address Siggi's second round Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "components/browser_watcher/stability_debugging_win.h"
6
7 #include "base/files/file_enumerator.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/process/process.h"
12 #include "base/test/multiprocess_test.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/multiprocess_func_list.h"
15
16 namespace browser_watcher {
17
18 class StabilityDebuggingWinMultiProcTest : public base::MultiProcessTest {};
19
20 MULTIPROCESS_TEST_MAIN(DummyProcess) {
21 return 0;
22 }
23
24 TEST_F(StabilityDebuggingWinMultiProcTest, GetFileForProcessTest) {
25 const base::FilePath empty_path;
26
27 // Get the path for the current process.
28 base::FilePath stability_path;
29 ASSERT_TRUE(StabilityDebugging::GetFileForProcess(
30 base::Process::Current(), empty_path, &stability_path));
31
32 // Ensure requesting a second time produces the same.
33 base::FilePath stability_path_two;
34 ASSERT_TRUE(StabilityDebugging::GetFileForProcess(
35 base::Process::Current(), empty_path, &stability_path_two));
36 EXPECT_EQ(stability_path, stability_path_two);
37
38 // Ensure a different process has a different stability path.
39 base::FilePath stability_path_other;
40 ASSERT_TRUE(StabilityDebugging::GetFileForProcess(
41 SpawnChild("DummyProcess"), empty_path, &stability_path_other));
42 EXPECT_NE(stability_path, stability_path_other);
43 }
44
45 TEST(StabilityDebuggingWinTest, GetFilePatternMatchesGetFileForProcessResult) {
46 // GetFileForProcess file names must match GetFilePattern according to
47 // FileEnumerator's algorithm. We test this by writing out some files and
48 // validating what is matched.
49
50 base::ScopedTempDir temp_dir;
51 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
52 base::FilePath user_data_dir = temp_dir.path();
53
54 // Create the stability directory.
55 base::FilePath stability_dir = StabilityDebugging::GetDir(user_data_dir);
56 ASSERT_TRUE(base::CreateDirectory(stability_dir));
57
58 // Write a stability file.
59 base::FilePath stability_file;
60 ASSERT_TRUE(StabilityDebugging::GetFileForProcess(
61 base::Process::Current(), user_data_dir, &stability_file));
62 {
63 base::ScopedFILE file(base::OpenFile(stability_file, "w"));
64 ASSERT_TRUE(file.get());
65 }
66
67 // Write a file that shouldn't match.
68 base::FilePath non_matching_file =
69 stability_dir.AppendASCII("non_matching.foo");
70 {
71 base::ScopedFILE file(base::OpenFile(non_matching_file, "w"));
72 ASSERT_TRUE(file.get());
73 }
74
75 // Validate only the stability file matches.
76 base::FileEnumerator enumerator(stability_dir, false /* recursive */,
77 base::FileEnumerator::FILES,
78 StabilityDebugging::GetFilePattern());
79 ASSERT_EQ(stability_file, enumerator.Next());
80 ASSERT_TRUE(enumerator.Next().empty());
81 }
82
83 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698