Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Unified Diff: chrome_elf/chrome_elf_util_unittest.cc

Issue 154653002: Breakpad coverage for chrome_elf start up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests and Greg's comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome_elf/chrome_elf_util_unittest.cc
diff --git a/chrome_elf/chrome_elf_util_unittest.cc b/chrome_elf/chrome_elf_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6d17cde07264fd5d613c76692190f9b9e99a6fb5
--- /dev/null
+++ b/chrome_elf/chrome_elf_util_unittest.cc
@@ -0,0 +1,175 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome_elf/chrome_elf_util.h"
+
+#include "base/test/test_reg_util_win.h"
+#include "base/win/registry.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
+const wchar_t kRegPathClientStateMedium[] =
+ L"Software\\Google\\Update\\ClientStateMedium";
+const wchar_t kRegValueUsageStats[] = L"usagestats";
+const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
+
+const wchar_t kAppGuidCanary[] =
+ L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
+const wchar_t kAppGuidGoogleChrome[] =
+ L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
+const wchar_t kAppGuidGoogleBinaries[] =
+ L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
+
+const wchar_t kCanaryExePath[] =
+ L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe";
+const wchar_t kChromeSystemExePath[] =
+ L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
+const wchar_t kChromeUserExePath[] =
+ L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
+const wchar_t kChromiumExePath[] =
+ L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
+
+class ChromeElfUtilTest : public testing::Test {
+ public:
+ virtual void SetUp() OVERRIDE {
grt (UTC plus 2) 2014/02/14 16:37:33 SetUp should be protected, too
Cait (Slow) 2014/02/14 23:12:04 Done.
+ override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE,
+ L"chrome_elf_test_local");
grt (UTC plus 2) 2014/02/14 16:37:33 indentation
Cait (Slow) 2014/02/14 23:12:04 Done.
+ override_manager_.OverrideRegistry(HKEY_CURRENT_USER,
+ L"chrome_elf_test_current");
+ }
+
+ protected:
+ base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) {
+ base::string16 full_key_path(path);
+ full_key_path.append(1, L'\\');
+ full_key_path.append(guid);
+ return full_key_path;
+ }
+
+ void SetMultiInstall(bool is_multi, bool is_system) {
+ base::win::RegKey key;
+ key.Create(is_system? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
grt (UTC plus 2) 2014/02/14 16:37:33 space after ?
Cait (Slow) 2014/02/14 23:12:04 Done.
+ BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(),
grt (UTC plus 2) 2014/02/14 16:37:33 align with the open paren of Create(
Cait (Slow) 2014/02/14 23:12:04 Done.
+ KEY_ALL_ACCESS);
grt (UTC plus 2) 2014/02/14 16:37:33 only request the access you need: KEY_SET_VALUE
Cait (Slow) 2014/02/14 23:12:04 Done.
+ if (is_multi) {
+ key.WriteValue(kUninstallArgumentsField,
+ L"yadda yadda --multi-install yadda yadda");
+ } else {
+ key.DeleteValue(kUninstallArgumentsField);
+ }
+ key.Close();
grt (UTC plus 2) 2014/02/14 16:37:33 RegKey's dtor does this for you
Cait (Slow) 2014/02/14 23:12:04 Done.
+ }
+
+ void SetStatsEnabled(const wchar_t* path, const wchar_t* guid,
+ bool enabled, bool is_system) {
+ base::win::RegKey key;
+ key.Create(is_system? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
grt (UTC plus 2) 2014/02/14 16:37:33 use RegKey's ctor rather than calling Create here
Cait (Slow) 2014/02/14 23:12:04 Done.
+ BuildKey(path, guid).c_str(),
grt (UTC plus 2) 2014/02/14 16:37:33 align with the open paren above
Cait (Slow) 2014/02/14 23:12:04 Done.
+ KEY_ALL_ACCESS);
grt (UTC plus 2) 2014/02/14 16:37:33 KEY_SET_VALUE
Cait (Slow) 2014/02/14 23:12:04 Done.
+ key.WriteValue(kRegValueUsageStats, enabled ? 1 : 0);
+ key.Close();
grt (UTC plus 2) 2014/02/14 16:37:33 remove
Cait (Slow) 2014/02/14 23:12:04 Done.
+ }
+
+ void TestUsageStats(bool canary, bool chrome_system, bool chrome_user) {
+ EXPECT_EQ(canary, AreUsageStatsEnabled(kCanaryExePath));
+ EXPECT_EQ(chrome_system, AreUsageStatsEnabled(kChromeSystemExePath));
+ EXPECT_EQ(chrome_user, AreUsageStatsEnabled(kChromeUserExePath));
+ }
+
+ registry_util::RegistryOverrideManager override_manager_;
+
+};
+
+TEST_F(ChromeElfUtilTest, CanaryTest) {
+ EXPECT_TRUE(IsCanary(kCanaryExePath));
+ EXPECT_FALSE(IsCanary(kChromeUserExePath));
+ EXPECT_FALSE(IsCanary(kChromiumExePath));
+}
+
+TEST_F(ChromeElfUtilTest, SystemInstallTest) {
+ EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
+ EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
+}
+
+TEST_F(ChromeElfUtilTest, MultiInstallTest_SingleUser) {
+ bool system_install = false;
+ SetMultiInstall(true, system_install);
+ EXPECT_TRUE(IsMultiInstall(system_install));
+
+ SetMultiInstall(false, system_install);
+ EXPECT_FALSE(IsMultiInstall(system_install));
+}
+
+TEST_F(ChromeElfUtilTest, MultiInstallTest_System) {
+ bool system_install = true;
+ SetMultiInstall(true, system_install);
+ EXPECT_TRUE(IsMultiInstall(system_install));
+
+ SetMultiInstall(false, system_install);
+ EXPECT_FALSE(IsMultiInstall(system_install));
+}
+
+TEST_F(ChromeElfUtilTest, UsageStatsTest_Canary) {
grt (UTC plus 2) 2014/02/14 16:37:33 i think this is a good case for a parameterized te
Cait (Slow) 2014/02/14 23:12:04 Done -- wow! I had no idea these existed. They mak
+ SetStatsEnabled(kRegPathClientState, kAppGuidCanary, true, false);
+ TestUsageStats(true, false, false);
+ SetStatsEnabled(kRegPathClientState, kAppGuidCanary, false, false);
+ TestUsageStats(false, false, false);
+}
+
+TEST_F(ChromeElfUtilTest, UsageStatsTest_Chrome_System) {
+ bool system_install = true;
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, true,
+ system_install);
+ TestUsageStats(false, true, false);
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, false,
+ system_install);
+ TestUsageStats(false, false, false);
+
+ SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleChrome, true,
+ system_install);
+ TestUsageStats(false, true, false);
+ SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleChrome, false,
+ system_install);
+ TestUsageStats(false, false, false);
+
+ SetMultiInstall(true, system_install);
+
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, true,
+ system_install);
+ TestUsageStats(false, true, false);
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, false,
+ system_install);
+ TestUsageStats(false, false, false);
+
+ SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleBinaries, true,
+ system_install);
+ TestUsageStats(false, true, false);
+ SetStatsEnabled(kRegPathClientStateMedium, kAppGuidGoogleBinaries, false,
+ system_install);
+ TestUsageStats(false, false, false);
+}
+
+TEST_F(ChromeElfUtilTest, UsageStatsTest_Chrome_User) {
+ bool system_install = false;
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, true,
+ system_install);
+ TestUsageStats(false, false, true);
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleChrome, false,
+ system_install);
+ TestUsageStats(false, false, false);
+
+ SetMultiInstall(true, system_install);
+
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, true,
+ system_install);
+ TestUsageStats(false, false, true);
+ SetStatsEnabled(kRegPathClientState, kAppGuidGoogleBinaries, false,
+ system_install);
+ TestUsageStats(false, false, false);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698