Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / logging_chrome_unittest.cc
blobd6d79b6139d21b4962e0c2770eaced9b519c213e
1 // Copyright 2013 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.
5 #include "base/environment.h"
6 #include "base/files/file_path.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/common/env_vars.h"
9 #include "chrome/common/logging_chrome.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 class ChromeLoggingTest : public testing::Test {
13 public:
14 // Stores the current value of the log file name environment
15 // variable and sets the variable to new_value.
16 void SaveEnvironmentVariable(std::string new_value) {
17 scoped_ptr<base::Environment> env(base::Environment::Create());
18 if (!env->GetVar(env_vars::kLogFileName, &environment_filename_))
19 environment_filename_ = "";
21 env->SetVar(env_vars::kLogFileName, new_value);
24 // Restores the value of the log file nave environment variable
25 // previously saved by SaveEnvironmentVariable().
26 void RestoreEnvironmentVariable() {
27 scoped_ptr<base::Environment> env(base::Environment::Create());
28 env->SetVar(env_vars::kLogFileName, environment_filename_);
31 private:
32 std::string environment_filename_; // Saves real environment value.
35 // Tests the log file name getter without an environment variable.
36 TEST_F(ChromeLoggingTest, LogFileName) {
37 SaveEnvironmentVariable(std::string());
39 base::FilePath filename = logging::GetLogFileName();
40 ASSERT_NE(base::FilePath::StringType::npos,
41 filename.value().find(FILE_PATH_LITERAL("chrome_debug.log")));
43 RestoreEnvironmentVariable();
46 // Tests the log file name getter with an environment variable.
47 TEST_F(ChromeLoggingTest, EnvironmentLogFileName) {
48 SaveEnvironmentVariable("test value");
50 base::FilePath filename = logging::GetLogFileName();
51 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("test value")).value(),
52 filename.value());
54 RestoreEnvironmentVariable();