OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/shell_integration_linux.h" | 5 #include "chrome/browser/shell_integration_linux.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cstdlib> | 10 #include <cstdlib> |
(...skipping 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 namespace shell_integration_linux { | 35 namespace shell_integration_linux { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Provides mock environment variables values based on a stored map. | 39 // Provides mock environment variables values based on a stored map. |
40 class MockEnvironment : public base::Environment { | 40 class MockEnvironment : public base::Environment { |
41 public: | 41 public: |
42 MockEnvironment() {} | 42 MockEnvironment() {} |
43 | 43 |
44 void Set(const std::string& name, const std::string& value) { | 44 void Set(base::StringPiece name, const std::string& value) { |
45 variables_[name] = value; | 45 variables_[name] = value; |
46 } | 46 } |
47 | 47 |
48 bool GetVar(const char* variable_name, std::string* result) override { | 48 bool GetVar(base::StringPiece variable_name, std::string* result) override { |
49 if (ContainsKey(variables_, variable_name)) { | 49 if (ContainsKey(variables_, variable_name)) { |
50 *result = variables_[variable_name]; | 50 *result = variables_[variable_name]; |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
57 bool SetVar(const char* variable_name, | 57 bool SetVar(base::StringPiece variable_name, |
58 const std::string& new_value) override { | 58 const std::string& new_value) override { |
59 ADD_FAILURE(); | 59 ADD_FAILURE(); |
60 return false; | 60 return false; |
61 } | 61 } |
62 | 62 |
63 bool UnSetVar(const char* variable_name) override { | 63 bool UnSetVar(base::StringPiece variable_name) override { |
64 ADD_FAILURE(); | 64 ADD_FAILURE(); |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 std::map<std::string, std::string> variables_; | 69 std::map<base::StringPiece, std::string> variables_; |
dcheng
2016/06/24 17:28:35
It's not obvious that this is safe (or that it wil
Lei Zhang
2016/06/24 18:56:03
Sure. I don't have strong feelings about creating
| |
70 | 70 |
71 DISALLOW_COPY_AND_ASSIGN(MockEnvironment); | 71 DISALLOW_COPY_AND_ASSIGN(MockEnvironment); |
72 }; | 72 }; |
73 | 73 |
74 // This helps EXPECT_THAT(..., ElementsAre(...)) print out more meaningful | 74 // This helps EXPECT_THAT(..., ElementsAre(...)) print out more meaningful |
75 // failure messages. | 75 // failure messages. |
76 std::vector<std::string> FilePathsToStrings( | 76 std::vector<std::string> FilePathsToStrings( |
77 const std::vector<base::FilePath>& paths) { | 77 const std::vector<base::FilePath>& paths) { |
78 std::vector<std::string> values; | 78 std::vector<std::string> values; |
79 for (const auto& path : paths) | 79 for (const auto& path : paths) |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 | 648 |
649 for (size_t i = 0; i < arraysize(test_cases); i++) { | 649 for (size_t i = 0; i < arraysize(test_cases); i++) { |
650 SCOPED_TRACE(i); | 650 SCOPED_TRACE(i); |
651 EXPECT_EQ(test_cases[i].expected_output, | 651 EXPECT_EQ(test_cases[i].expected_output, |
652 GetDirectoryFileContents(base::ASCIIToUTF16(test_cases[i].title), | 652 GetDirectoryFileContents(base::ASCIIToUTF16(test_cases[i].title), |
653 test_cases[i].icon_name)); | 653 test_cases[i].icon_name)); |
654 } | 654 } |
655 } | 655 } |
656 | 656 |
657 } // namespace shell_integration_linux | 657 } // namespace shell_integration_linux |
OLD | NEW |