Index: components/crash/core/common/crash_keys_unittest.cc |
diff --git a/chrome/common/crash_keys_unittest.cc b/components/crash/core/common/crash_keys_unittest.cc |
similarity index 50% |
copy from chrome/common/crash_keys_unittest.cc |
copy to components/crash/core/common/crash_keys_unittest.cc |
index 5dd04b2235b2405097558cb44eafc6d74b73b3c1..270698091e74975b32a9d2f8a3061a82f00fe792 100644 |
--- a/chrome/common/crash_keys_unittest.cc |
+++ b/components/crash/core/common/crash_keys_unittest.cc |
@@ -2,10 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/common/crash_keys.h" |
+#include "components/crash/core/common/crash_keys.h" |
#include <map> |
-#include <set> |
#include <string> |
#include "base/command_line.h" |
@@ -21,7 +20,11 @@ class CrashKeysTest : public testing::Test { |
self_ = this; |
base::debug::SetCrashKeyReportingFunctions( |
&SetCrashKeyValue, &ClearCrashKey); |
- crash_keys::RegisterChromeCrashKeys(); |
+ |
+ std::vector<base::debug::CrashKey> keys; |
+ crash_keys::GetCrashKeysForCommandLineSwitches(&keys); |
+ base::debug::InitCrashKeys(keys.data(), keys.size(), |
+ crash_keys::kChunkMaxLength); |
} |
void TearDown() override { |
@@ -63,7 +66,7 @@ TEST_F(CrashKeysTest, Switches) { |
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
for (int i = 1; i <= 3; ++i) |
command_line.AppendSwitch(base::StringPrintf("--flag-%d", i)); |
- crash_keys::SetSwitchesFromCommandLine(&command_line); |
+ crash_keys::SetSwitchesFromCommandLine(command_line); |
EXPECT_EQ("--flag-1", GetKeyValue("switch-1")); |
EXPECT_EQ("--flag-2", GetKeyValue("switch-2")); |
EXPECT_EQ("--flag-3", GetKeyValue("switch-3")); |
@@ -77,7 +80,7 @@ TEST_F(CrashKeysTest, Switches) { |
EXPECT_GT(kMax, 15); |
for (int i = 1; i <= kMax; ++i) |
command_line.AppendSwitch(base::StringPrintf("--many-%d", i)); |
- crash_keys::SetSwitchesFromCommandLine(&command_line); |
+ crash_keys::SetSwitchesFromCommandLine(command_line); |
EXPECT_EQ("--many-1", GetKeyValue("switch-1")); |
EXPECT_EQ("--many-9", GetKeyValue("switch-9")); |
EXPECT_EQ("--many-15", GetKeyValue("switch-15")); |
@@ -90,97 +93,46 @@ TEST_F(CrashKeysTest, Switches) { |
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
for (int i = 1; i <= 5; ++i) |
command_line.AppendSwitch(base::StringPrintf("--fewer-%d", i)); |
- crash_keys::SetSwitchesFromCommandLine(&command_line); |
+ crash_keys::SetSwitchesFromCommandLine(command_line); |
EXPECT_EQ("--fewer-1", GetKeyValue("switch-1")); |
EXPECT_EQ("--fewer-2", GetKeyValue("switch-2")); |
EXPECT_EQ("--fewer-3", GetKeyValue("switch-3")); |
EXPECT_EQ("--fewer-4", GetKeyValue("switch-4")); |
EXPECT_EQ("--fewer-5", GetKeyValue("switch-5")); |
for (int i = 6; i < 20; ++i) |
- EXPECT_FALSE(HasCrashKey(base::StringPrintf(crash_keys::kSwitch, i))); |
+ EXPECT_FALSE(HasCrashKey(base::StringPrintf(crash_keys::kSwitchFormat, |
+ i))); |
} |
} |
-TEST_F(CrashKeysTest, Extensions) { |
- // Set three extensions. |
- { |
- std::set<std::string> extensions; |
- extensions.insert("ext.1"); |
- extensions.insert("ext.2"); |
- extensions.insert("ext.3"); |
- |
- crash_keys::SetActiveExtensions(extensions); |
- |
- extensions.erase(GetKeyValue("extension-1")); |
- extensions.erase(GetKeyValue("extension-2")); |
- extensions.erase(GetKeyValue("extension-3")); |
- EXPECT_EQ(0u, extensions.size()); |
+namespace { |
- EXPECT_EQ("3", GetKeyValue("num-extensions")); |
- EXPECT_FALSE(HasCrashKey("extension-4")); |
- } |
+bool IsBoringFlag(const std::string& flag) { |
+ return flag.compare("--boring") == 0; |
+} |
- // Set more than the max switches. |
- { |
- std::set<std::string> extensions; |
- const int kMax = crash_keys::kExtensionIDMaxCount + 2; |
- EXPECT_GT(kMax, 10); |
- for (int i = 1; i <= kMax; ++i) |
- extensions.insert(base::StringPrintf("ext.%d", i)); |
- crash_keys::SetActiveExtensions(extensions); |
- |
- for (int i = 1; i <= kMax; ++i) { |
- extensions.erase( |
- GetKeyValue(base::StringPrintf(crash_keys::kExtensionID, i))); |
- } |
- EXPECT_EQ(2u, extensions.size()); |
- |
- EXPECT_EQ("12", GetKeyValue("num-extensions")); |
- EXPECT_FALSE(HasCrashKey("extension-13")); |
- EXPECT_FALSE(HasCrashKey("extension-14")); |
- } |
+} // namespace |
- // Set fewer to ensure that old ones are erased. |
- { |
- std::set<std::string> extensions; |
- for (int i = 1; i <= 5; ++i) |
- extensions.insert(base::StringPrintf("ext.%d", i)); |
- crash_keys::SetActiveExtensions(extensions); |
- |
- extensions.erase(GetKeyValue("extension-1")); |
- extensions.erase(GetKeyValue("extension-2")); |
- extensions.erase(GetKeyValue("extension-3")); |
- extensions.erase(GetKeyValue("extension-4")); |
- extensions.erase(GetKeyValue("extension-5")); |
- EXPECT_EQ(0u, extensions.size()); |
- |
- EXPECT_EQ("5", GetKeyValue("num-extensions")); |
- for (int i = 6; i < 20; ++i) { |
- std::string key = base::StringPrintf(crash_keys::kExtensionID, i); |
- EXPECT_FALSE(HasCrashKey(key)) << key; |
- } |
- } |
-} |
+TEST_F(CrashKeysTest, FilterFlags) { |
+ using crash_keys::kSwitchesMaxCount; |
-#if defined(OS_CHROMEOS) |
-TEST_F(CrashKeysTest, IgnoreBoringFlags) { |
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
- command_line.AppendSwitch("--enable-logging"); |
- command_line.AppendSwitch("--user-data-dir=/tmp"); |
- command_line.AppendSwitch("--v=1"); |
- command_line.AppendSwitch("--default-wallpaper-small=test.png"); |
- |
- command_line.AppendSwitch("--vv=1"); |
- command_line.AppendSwitch("--vvv"); |
- command_line.AppendSwitch("--enable-multi-profiles"); |
- command_line.AppendSwitch("--device-management-url=https://foo/bar"); |
- |
- crash_keys::SetSwitchesFromCommandLine(&command_line); |
- |
- EXPECT_EQ("--vv=1", GetKeyValue("switch-1")); |
- EXPECT_EQ("--vvv", GetKeyValue("switch-2")); |
- EXPECT_EQ("--enable-multi-profiles", GetKeyValue("switch-3")); |
- EXPECT_EQ("--device-management-url=https://foo/bar", GetKeyValue("switch-4")); |
- EXPECT_FALSE(HasCrashKey("switch-5")); |
+ command_line.AppendSwitch("--not-boring-1"); |
+ command_line.AppendSwitch("--boring"); |
+ |
+ // Include the max number of non-boring switches, to make sure that only the |
+ // switches actually included in the crash keys are counted. |
+ for (int i = 2; i <= kSwitchesMaxCount; ++i) |
+ command_line.AppendSwitch(base::StringPrintf("--not-boring-%d", i)); |
+ |
+ crash_keys::SetSwitchesFromCommandLine(command_line, &IsBoringFlag); |
+ |
+ // If the boring keys are filtered out, every single key should now be |
+ // not-boring. |
+ for (int i = 1; i <= kSwitchesMaxCount; ++i) { |
+ std::string switch_name = base::StringPrintf(crash_keys::kSwitchFormat, i); |
+ std::string switch_value = base::StringPrintf("--not-boring-%d", i); |
+ EXPECT_EQ(switch_value, GetKeyValue(switch_name)) << "switch_name is " << |
+ switch_name; |
+ } |
} |
-#endif |