| OLD | NEW |
| 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 "chromecast/base/error_codes.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 5 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 6 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 7 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/test/scoped_path_override.h" | 13 #include "base/test/scoped_path_override.h" |
| 11 #include "chromecast/base/error_codes.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace chromecast { | 16 namespace chromecast { |
| 15 | 17 |
| 16 class ErrorCodesTest : public testing::Test { | 18 class ErrorCodesTest : public testing::Test { |
| 17 protected: | 19 protected: |
| 18 ErrorCodesTest() {} | 20 ErrorCodesTest() {} |
| 19 ~ErrorCodesTest() override {} | 21 ~ErrorCodesTest() override {} |
| 20 | 22 |
| 21 void SetUp() override { | 23 void SetUp() override { |
| 22 // Set up a temporary directory which will be used as our fake home dir. | 24 // Set up a temporary directory which will be used as our fake home dir. |
| 23 ASSERT_TRUE(fake_home_dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(fake_home_dir_.CreateUniqueTempDir()); |
| 24 path_override_.reset( | 26 path_override_.reset( |
| 25 new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_.path())); | 27 new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_.path())); |
| 26 } | 28 } |
| 27 | 29 |
| 28 base::FilePath home_path() const { return fake_home_dir_.path(); } | 30 base::FilePath home_path() const { return fake_home_dir_.path(); } |
| 29 | 31 |
| 30 private: | 32 private: |
| 31 base::ScopedTempDir fake_home_dir_; | 33 base::ScopedTempDir fake_home_dir_; |
| 32 scoped_ptr<base::ScopedPathOverride> path_override_; | 34 std::unique_ptr<base::ScopedPathOverride> path_override_; |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 TEST_F(ErrorCodesTest, GetInitialErrorCodeReturnsNoErrorIfMissingFile) { | 37 TEST_F(ErrorCodesTest, GetInitialErrorCodeReturnsNoErrorIfMissingFile) { |
| 36 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); | 38 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); |
| 37 } | 39 } |
| 38 | 40 |
| 39 TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithNoError) { | 41 TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithNoError) { |
| 40 ASSERT_TRUE(SetInitialErrorCode(NO_ERROR)); | 42 ASSERT_TRUE(SetInitialErrorCode(NO_ERROR)); |
| 41 | 43 |
| 42 // File should not be written. | 44 // File should not be written. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 EXPECT_TRUE(base::PathExists(home_path().Append("initial_error"))); | 62 EXPECT_TRUE(base::PathExists(home_path().Append("initial_error"))); |
| 61 EXPECT_EQ(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED, GetInitialErrorCode()); | 63 EXPECT_EQ(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED, GetInitialErrorCode()); |
| 62 | 64 |
| 63 // File should be removed after writing NO_ERROR. | 65 // File should be removed after writing NO_ERROR. |
| 64 EXPECT_TRUE(SetInitialErrorCode(NO_ERROR)); | 66 EXPECT_TRUE(SetInitialErrorCode(NO_ERROR)); |
| 65 EXPECT_FALSE(base::PathExists(home_path().Append("initial_error"))); | 67 EXPECT_FALSE(base::PathExists(home_path().Append("initial_error"))); |
| 66 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); | 68 EXPECT_EQ(NO_ERROR, GetInitialErrorCode()); |
| 67 } | 69 } |
| 68 | 70 |
| 69 } // namespace chromecast | 71 } // namespace chromecast |
| OLD | NEW |