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

Side by Side Diff: chromecast/app/linux/cast_crash_reporter_client_unittest.cc

Issue 1254113004: [Chromecast] Consolidate duplicated crash test functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fixed namespace footer comment Created 5 years, 4 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
« no previous file with comments | « chromecast/app/BUILD.gn ('k') | chromecast/chromecast_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <fstream> 5 #include <fstream>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/test/scoped_path_override.h" 12 #include "base/test/scoped_path_override.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chromecast/app/linux/cast_crash_reporter_client.h" 15 #include "chromecast/app/linux/cast_crash_reporter_client.h"
16 #include "chromecast/base/serializers.h"
17 #include "chromecast/crash/app_state_tracker.h" 16 #include "chromecast/crash/app_state_tracker.h"
17 #include "chromecast/crash/linux/crash_testing_utils.h"
18 #include "chromecast/crash/linux/crash_util.h" 18 #include "chromecast/crash/linux/crash_util.h"
19 #include "chromecast/crash/linux/dump_info.h" 19 #include "chromecast/crash/linux/dump_info.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace chromecast { 22 namespace chromecast {
23 namespace { 23 namespace {
24 24
25 const char kFakeDumpstateContents[] = "Dumpstate Contents\nDumpdumpdumpdump\n"; 25 const char kFakeDumpstateContents[] = "Dumpstate Contents\nDumpdumpdumpdump\n";
26 const char kFakeMinidumpContents[] = "Minidump Contents\nLine1\nLine2\n"; 26 const char kFakeMinidumpContents[] = "Minidump Contents\nLine1\nLine2\n";
27 const char kDumpsKey[] = "dumps";
28 27
29 int WriteFakeDumpStateFile(const std::string& path) { 28 int WriteFakeDumpStateFile(const std::string& path) {
30 // Append the correct extension and write the data to file. 29 // Append the correct extension and write the data to file.
31 base::File dumpstate(base::FilePath(path).AddExtension(".txt.gz"), 30 base::File dumpstate(base::FilePath(path).AddExtension(".txt.gz"),
32 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); 31 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
33 dumpstate.Write( 32 dumpstate.Write(
34 0, kFakeDumpstateContents, sizeof(kFakeDumpstateContents) - 1); 33 0, kFakeDumpstateContents, sizeof(kFakeDumpstateContents) - 1);
35 return 0; 34 return 0;
36 } 35 }
37 36
38 bool FetchDumps(const std::string& lockfile_path,
39 ScopedVector<DumpInfo>* dumps) {
40 if (!dumps) {
41 return false;
42 }
43 dumps->clear();
44
45 base::FilePath path(lockfile_path);
46 scoped_ptr<base::Value> contents(DeserializeJsonFromFile(path));
47
48 base::DictionaryValue* dict;
49 base::ListValue* dump_list;
50 if (!contents || !contents->GetAsDictionary(&dict) ||
51 !dict->GetList(kDumpsKey, &dump_list) || !dump_list) {
52 return false;
53 }
54
55 for (base::Value* elem : *dump_list) {
56 scoped_ptr<DumpInfo> dump = make_scoped_ptr(new DumpInfo(elem));
57 if (!dump->valid()) {
58 return false;
59 }
60 dumps->push_back(dump.Pass());
61 }
62
63 return true;
64 }
65
66 } // namespace 37 } // namespace
67 38
68 class CastCrashReporterClientTest : public testing::Test { 39 class CastCrashReporterClientTest : public testing::Test {
69 protected: 40 protected:
70 CastCrashReporterClientTest() {} 41 CastCrashReporterClientTest() {}
71 ~CastCrashReporterClientTest() override {} 42 ~CastCrashReporterClientTest() override {}
72 43
73 static void SetUpTestCase() { 44 static void SetUpTestCase() {
74 // Set a callback to be used in place of the |dumpstate| executable. 45 // Set a callback to be used in place of the |dumpstate| executable.
75 CrashUtil::SetDumpStateCbForTest(base::Bind(&WriteFakeDumpStateFile)); 46 CrashUtil::SetDumpStateCbForTest(base::Bind(&WriteFakeDumpStateFile));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 base::ThreadRestrictions::SetIOAllowed(true); 142 base::ThreadRestrictions::SetIOAllowed(true);
172 CastCrashReporterClient client; 143 CastCrashReporterClient client;
173 ASSERT_TRUE(client.HandleCrashDump(minidump_path().value().c_str())); 144 ASSERT_TRUE(client.HandleCrashDump(minidump_path().value().c_str()));
174 145
175 // Assert that the thread is not IO restricted when the function exits. 146 // Assert that the thread is not IO restricted when the function exits.
176 // Note that SetIOAllowed returns the previous value. 147 // Note that SetIOAllowed returns the previous value.
177 ASSERT_TRUE(base::ThreadRestrictions::SetIOAllowed(true)); 148 ASSERT_TRUE(base::ThreadRestrictions::SetIOAllowed(true));
178 } 149 }
179 150
180 } // namespace chromecast 151 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/app/BUILD.gn ('k') | chromecast/chromecast_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698