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

Side by Side Diff: chromecast/base/error_codes_unittest.cc

Issue 1484713003: [Chromecast] Use ScopedTemp[File|Dir] in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Style Created 5 years 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
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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/test/scoped_path_override.h" 10 #include "base/test/scoped_path_override.h"
10 #include "chromecast/base/error_codes.h" 11 #include "chromecast/base/error_codes.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace chromecast { 14 namespace chromecast {
14 15
15 class ErrorCodesTest : public testing::Test { 16 class ErrorCodesTest : public testing::Test {
16 protected: 17 protected:
17 ErrorCodesTest() {} 18 ErrorCodesTest() {}
18 ~ErrorCodesTest() override {} 19 ~ErrorCodesTest() override {}
19 20
20 void SetUp() override { 21 void SetUp() override {
21 // Set up a temporary directory which will be used as our fake home dir. 22 // Set up a temporary directory which will be used as our fake home dir.
22 ASSERT_TRUE(base::CreateNewTempDirectory("", &fake_home_dir_)); 23 ASSERT_TRUE(fake_home_dir_.CreateUniqueTempDir());
23 path_override_.reset( 24 path_override_.reset(
24 new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_)); 25 new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_.path()));
25 } 26 }
26 27
27 base::FilePath fake_home_dir_; 28 base::FilePath home_path() const { return fake_home_dir_.path(); }
29
30 private:
31 base::ScopedTempDir fake_home_dir_;
28 scoped_ptr<base::ScopedPathOverride> path_override_; 32 scoped_ptr<base::ScopedPathOverride> path_override_;
29 }; 33 };
30 34
31 TEST_F(ErrorCodesTest, GetInitialErrorCodeReturnsNoErrorIfMissingFile) { 35 TEST_F(ErrorCodesTest, GetInitialErrorCodeReturnsNoErrorIfMissingFile) {
32 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); 36 EXPECT_EQ(NO_ERROR, GetInitialErrorCode());
33 } 37 }
34 38
35 TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithNoError) { 39 TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithNoError) {
36 ASSERT_TRUE(SetInitialErrorCode(NO_ERROR)); 40 ASSERT_TRUE(SetInitialErrorCode(NO_ERROR));
37 41
38 // File should not be written. 42 // File should not be written.
39 ASSERT_FALSE(base::PathExists(fake_home_dir_.Append("initial_error"))); 43 ASSERT_FALSE(base::PathExists(home_path().Append("initial_error")));
40 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); 44 EXPECT_EQ(NO_ERROR, GetInitialErrorCode());
41 } 45 }
42 46
43 TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithValidErrors) { 47 TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithValidErrors) {
44 // Write initial error and read it from the file. 48 // Write initial error and read it from the file.
45 EXPECT_TRUE(SetInitialErrorCode(ERROR_WEB_CONTENT_RENDER_VIEW_GONE)); 49 EXPECT_TRUE(SetInitialErrorCode(ERROR_WEB_CONTENT_RENDER_VIEW_GONE));
46 EXPECT_TRUE(base::PathExists(fake_home_dir_.Append("initial_error"))); 50 EXPECT_TRUE(base::PathExists(home_path().Append("initial_error")));
47 EXPECT_EQ(ERROR_WEB_CONTENT_RENDER_VIEW_GONE, GetInitialErrorCode()); 51 EXPECT_EQ(ERROR_WEB_CONTENT_RENDER_VIEW_GONE, GetInitialErrorCode());
48 52
49 // File should be updated with most recent error. 53 // File should be updated with most recent error.
50 EXPECT_TRUE(SetInitialErrorCode(ERROR_UNKNOWN)); 54 EXPECT_TRUE(SetInitialErrorCode(ERROR_UNKNOWN));
51 EXPECT_TRUE(base::PathExists(fake_home_dir_.Append("initial_error"))); 55 EXPECT_TRUE(base::PathExists(home_path().Append("initial_error")));
52 EXPECT_EQ(ERROR_UNKNOWN, GetInitialErrorCode()); 56 EXPECT_EQ(ERROR_UNKNOWN, GetInitialErrorCode());
53 57
54 // File should be updated with most recent error. 58 // File should be updated with most recent error.
55 EXPECT_TRUE(SetInitialErrorCode(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED)); 59 EXPECT_TRUE(SetInitialErrorCode(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED));
56 EXPECT_TRUE(base::PathExists(fake_home_dir_.Append("initial_error"))); 60 EXPECT_TRUE(base::PathExists(home_path().Append("initial_error")));
57 EXPECT_EQ(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED, GetInitialErrorCode()); 61 EXPECT_EQ(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED, GetInitialErrorCode());
58 62
59 // File should be removed after writing NO_ERROR. 63 // File should be removed after writing NO_ERROR.
60 EXPECT_TRUE(SetInitialErrorCode(NO_ERROR)); 64 EXPECT_TRUE(SetInitialErrorCode(NO_ERROR));
61 EXPECT_FALSE(base::PathExists(fake_home_dir_.Append("initial_error"))); 65 EXPECT_FALSE(base::PathExists(home_path().Append("initial_error")));
62 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); 66 EXPECT_EQ(NO_ERROR, GetInitialErrorCode());
63 } 67 }
64 68
65 } // namespace chromecast 69 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698