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

Side by Side Diff: client/settings_test.cc

Issue 988063003: Define the Settings interface for a CrashReportDatabase and provide a Mac implementation. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Drop plist, use binary Created 5 years, 9 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
« client/settings.cc ('K') | « client/settings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "client/settings.h"
16
17 #include "client/crash_report_database.h"
18 #include "gtest/gtest.h"
19 #include "util/file/file_io.h"
20 #include "util/test/scoped_temp_dir.h"
21
22 namespace crashpad {
23 namespace test {
24 namespace {
25
26 class SettingsTest : public testing::Test {
27 public:
28 SettingsTest() : settings_(settings_path()) {}
29
30 base::FilePath settings_path() {
31 return temp_dir_.path().Append("settings");
32 }
33
34 Settings* settings() { return &settings_; }
35
36 void InitializeBadFile() {
Mark Mentovai 2015/03/09 19:12:36 Also have something that removes settings_path() t
Robert Sesek 2015/03/09 21:16:28 Done.
37 ScopedFileHandle handle(
38 LoggingOpenFileForWrite(settings_path(),
39 FileWriteMode::kTruncateOrCreate,
40 FilePermissions::kWorldReadable));
41 ASSERT_TRUE(handle.is_valid());
42
43 const char kBuf[] = "test bad file";
44 ASSERT_TRUE(LoggingWriteFile(handle.get(), kBuf, sizeof(kBuf)));
45 handle.reset();
46 }
47
48 protected:
49 // testing::Test:
50 void SetUp() override {
51 ASSERT_TRUE(settings()->Initialize());
52 }
53
54 private:
55 ScopedTempDir temp_dir_;
56 Settings settings_;
57
58 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
59 };
60
61 TEST_F(SettingsTest, ClientID) {
62 UUID client_id;
63 EXPECT_TRUE(settings()->GetClientID(&client_id));
64 EXPECT_NE(UUID(), client_id);
65
66 Settings settings(settings_path());
67 UUID actual;
68 EXPECT_TRUE(settings.GetClientID(&actual));
69 EXPECT_EQ(client_id, actual);
70 }
71
72 TEST_F(SettingsTest, UploadsEnabled) {
73 bool enabled = true;
74 // Default value is false.
75 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled));
76 EXPECT_FALSE(enabled);
77
78 EXPECT_TRUE(settings()->SetUploadsEnabled(true));
Mark Mentovai 2015/03/09 19:12:36 Make sure that this sticks if you have another Set
Robert Sesek 2015/03/09 21:16:28 Done.
79 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled));
80 EXPECT_TRUE(enabled);
81
82 EXPECT_TRUE(settings()->SetUploadsEnabled(false));
83 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled));
84 EXPECT_FALSE(enabled);
85 }
86
87 TEST_F(SettingsTest, LastUploadAttemptTime) {
88 time_t actual = -1;
89 EXPECT_TRUE(settings()->GetLastUploadAttemptTime(&actual));
90 // Default value is 0.
91 EXPECT_EQ(0, actual);
92
93 time_t expected = time(nullptr);
Mark Mentovai 2015/03/09 19:12:36 Can be const.
Robert Sesek 2015/03/09 21:16:28 Done.
94 EXPECT_TRUE(settings()->SetLastUploadAttemptTime(expected));
Mark Mentovai 2015/03/09 19:12:36 Same.
Robert Sesek 2015/03/09 21:16:28 Done.
95 EXPECT_TRUE(settings()->GetLastUploadAttemptTime(&actual));
96 EXPECT_EQ(expected, actual);
97 }
98
99 // The following tests write a corrupt settings file and test the recovery
100 // operation.
101
102 TEST_F(SettingsTest, BadFileOnInitialize) {
103 InitializeBadFile();
104
105 Settings settings(settings_path());
106 EXPECT_TRUE(settings.Initialize());
107 }
108
109 TEST_F(SettingsTest, BadFileOnGet) {
110 InitializeBadFile();
111
112 UUID client_id;
113 EXPECT_TRUE(settings()->GetClientID(&client_id));
Mark Mentovai 2015/03/09 19:12:36 Make sure that this stored the client ID and that
Robert Sesek 2015/03/09 21:16:27 Done.
114 EXPECT_NE(UUID(), client_id);
115 }
116
117 TEST_F(SettingsTest, BadFileOnSet) {
118 InitializeBadFile();
119
120 EXPECT_TRUE(settings()->SetUploadsEnabled(true));
121 bool enabled = false;
122 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled));
123 EXPECT_TRUE(enabled);
124 }
125
126 } // namespace
127 } // namespace test
128 } // namespace crashpad
OLDNEW
« client/settings.cc ('K') | « client/settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698