| 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/common/crash_keys.h" | 5 #include "chrome/common/crash_keys.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 self_->keys_.erase(key.as_string()); | 50 self_->keys_.erase(key.as_string()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static CrashKeysTest* self_; | 53 static CrashKeysTest* self_; |
| 54 | 54 |
| 55 std::map<std::string, std::string> keys_; | 55 std::map<std::string, std::string> keys_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 CrashKeysTest* CrashKeysTest::self_ = NULL; | 58 CrashKeysTest* CrashKeysTest::self_ = NULL; |
| 59 | 59 |
| 60 TEST_F(CrashKeysTest, Switches) { | |
| 61 // Set three switches. | |
| 62 { | |
| 63 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
| 64 for (int i = 1; i <= 3; ++i) | |
| 65 command_line.AppendSwitch(base::StringPrintf("--flag-%d", i)); | |
| 66 crash_keys::SetSwitchesFromCommandLine(&command_line); | |
| 67 EXPECT_EQ("--flag-1", GetKeyValue("switch-1")); | |
| 68 EXPECT_EQ("--flag-2", GetKeyValue("switch-2")); | |
| 69 EXPECT_EQ("--flag-3", GetKeyValue("switch-3")); | |
| 70 EXPECT_FALSE(HasCrashKey("switch-4")); | |
| 71 } | |
| 72 | |
| 73 // Set more than the max switches. | |
| 74 { | |
| 75 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
| 76 const int kMax = crash_keys::kSwitchesMaxCount + 2; | |
| 77 EXPECT_GT(kMax, 15); | |
| 78 for (int i = 1; i <= kMax; ++i) | |
| 79 command_line.AppendSwitch(base::StringPrintf("--many-%d", i)); | |
| 80 crash_keys::SetSwitchesFromCommandLine(&command_line); | |
| 81 EXPECT_EQ("--many-1", GetKeyValue("switch-1")); | |
| 82 EXPECT_EQ("--many-9", GetKeyValue("switch-9")); | |
| 83 EXPECT_EQ("--many-15", GetKeyValue("switch-15")); | |
| 84 EXPECT_FALSE(HasCrashKey("switch-16")); | |
| 85 EXPECT_FALSE(HasCrashKey("switch-17")); | |
| 86 } | |
| 87 | |
| 88 // Set fewer to ensure that old ones are erased. | |
| 89 { | |
| 90 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
| 91 for (int i = 1; i <= 5; ++i) | |
| 92 command_line.AppendSwitch(base::StringPrintf("--fewer-%d", i)); | |
| 93 crash_keys::SetSwitchesFromCommandLine(&command_line); | |
| 94 EXPECT_EQ("--fewer-1", GetKeyValue("switch-1")); | |
| 95 EXPECT_EQ("--fewer-2", GetKeyValue("switch-2")); | |
| 96 EXPECT_EQ("--fewer-3", GetKeyValue("switch-3")); | |
| 97 EXPECT_EQ("--fewer-4", GetKeyValue("switch-4")); | |
| 98 EXPECT_EQ("--fewer-5", GetKeyValue("switch-5")); | |
| 99 for (int i = 6; i < 20; ++i) | |
| 100 EXPECT_FALSE(HasCrashKey(base::StringPrintf(crash_keys::kSwitch, i))); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 TEST_F(CrashKeysTest, Extensions) { | 60 TEST_F(CrashKeysTest, Extensions) { |
| 105 // Set three extensions. | 61 // Set three extensions. |
| 106 { | 62 { |
| 107 std::set<std::string> extensions; | 63 std::set<std::string> extensions; |
| 108 extensions.insert("ext.1"); | 64 extensions.insert("ext.1"); |
| 109 extensions.insert("ext.2"); | 65 extensions.insert("ext.2"); |
| 110 extensions.insert("ext.3"); | 66 extensions.insert("ext.3"); |
| 111 | 67 |
| 112 crash_keys::SetActiveExtensions(extensions); | 68 crash_keys::SetActiveExtensions(extensions); |
| 113 | 69 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 EXPECT_EQ(0u, extensions.size()); | 111 EXPECT_EQ(0u, extensions.size()); |
| 156 | 112 |
| 157 EXPECT_EQ("5", GetKeyValue("num-extensions")); | 113 EXPECT_EQ("5", GetKeyValue("num-extensions")); |
| 158 for (int i = 6; i < 20; ++i) { | 114 for (int i = 6; i < 20; ++i) { |
| 159 std::string key = base::StringPrintf(crash_keys::kExtensionID, i); | 115 std::string key = base::StringPrintf(crash_keys::kExtensionID, i); |
| 160 EXPECT_FALSE(HasCrashKey(key)) << key; | 116 EXPECT_FALSE(HasCrashKey(key)) << key; |
| 161 } | 117 } |
| 162 } | 118 } |
| 163 } | 119 } |
| 164 | 120 |
| 165 #if defined(OS_CHROMEOS) | |
| 166 TEST_F(CrashKeysTest, IgnoreBoringFlags) { | 121 TEST_F(CrashKeysTest, IgnoreBoringFlags) { |
| 167 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 122 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 168 command_line.AppendSwitch("--enable-logging"); | 123 command_line.AppendSwitch("--enable-logging"); |
| 169 command_line.AppendSwitch("--user-data-dir=/tmp"); | |
| 170 command_line.AppendSwitch("--v=1"); | 124 command_line.AppendSwitch("--v=1"); |
| 171 command_line.AppendSwitch("--default-wallpaper-small=test.png"); | |
| 172 | 125 |
| 173 command_line.AppendSwitch("--vv=1"); | 126 command_line.AppendSwitch("--vv=1"); |
| 174 command_line.AppendSwitch("--vvv"); | 127 command_line.AppendSwitch("--vvv"); |
| 175 command_line.AppendSwitch("--enable-multi-profiles"); | 128 command_line.AppendSwitch("--enable-multi-profiles"); |
| 176 command_line.AppendSwitch("--device-management-url=https://foo/bar"); | 129 command_line.AppendSwitch("--device-management-url=https://foo/bar"); |
| 130 #if defined(OS_CHROMEOS) |
| 131 command_line.AppendSwitch("--user-data-dir=/tmp"); |
| 132 command_line.AppendSwitch("--default-wallpaper-small=test.png"); |
| 133 #endif |
| 177 | 134 |
| 178 crash_keys::SetSwitchesFromCommandLine(&command_line); | 135 crash_keys::SetCrashKeysFromCommandLine(command_line); |
| 179 | 136 |
| 180 EXPECT_EQ("--vv=1", GetKeyValue("switch-1")); | 137 EXPECT_EQ("--vv=1", GetKeyValue("switch-1")); |
| 181 EXPECT_EQ("--vvv", GetKeyValue("switch-2")); | 138 EXPECT_EQ("--vvv", GetKeyValue("switch-2")); |
| 182 EXPECT_EQ("--enable-multi-profiles", GetKeyValue("switch-3")); | 139 EXPECT_EQ("--enable-multi-profiles", GetKeyValue("switch-3")); |
| 183 EXPECT_EQ("--device-management-url=https://foo/bar", GetKeyValue("switch-4")); | 140 EXPECT_EQ("--device-management-url=https://foo/bar", GetKeyValue("switch-4")); |
| 184 EXPECT_FALSE(HasCrashKey("switch-5")); | 141 EXPECT_FALSE(HasCrashKey("switch-5")); |
| 185 } | 142 } |
| 186 #endif | |
| OLD | NEW |