Chromium Code Reviews| 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..7828057423e64b72bf5c7383e9400b09e241c1f6 100644 |
| --- a/chrome/common/crash_keys_unittest.cc |
| +++ b/components/crash/core/common/crash_keys_unittest.cc |
| @@ -2,12 +2,12 @@ |
| // 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/bind.h" |
| #include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "base/debug/crash_logging.h" |
| @@ -21,7 +21,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 +67,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 +81,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,7 +94,7 @@ 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")); |
| @@ -101,86 +105,18 @@ TEST_F(CrashKeysTest, Switches) { |
| } |
| } |
| -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()); |
| - |
| - EXPECT_EQ("3", GetKeyValue("num-extensions")); |
| - EXPECT_FALSE(HasCrashKey("extension-4")); |
| - } |
| - |
| - // 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")); |
| - } |
| - |
| - // 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; |
| - } |
| - } |
| +static bool IsBoringFlag(const std::string& flag) { |
|
grt (UTC plus 2)
2015/11/27 18:51:21
nit: put this in an unnamed namespace rather than
|
| + return flag.compare("--boring") == 0; |
| } |
| -#if defined(OS_CHROMEOS) |
| -TEST_F(CrashKeysTest, IgnoreBoringFlags) { |
| +TEST_F(CrashKeysTest, FilterFlags) { |
| 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("--boring"); |
| + command_line.AppendSwitch("--not-boring"); |
| + |
| + crash_keys::SetSwitchesFromCommandLine(command_line, |
| + base::Bind(&IsBoringFlag)); |
| + |
| + EXPECT_EQ("--not-boring", GetKeyValue("switch-1")); |
| + EXPECT_FALSE(HasCrashKey("switch-2")); |
| } |
| -#endif |