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

Unified Diff: metrics_library_test.cc

Issue 3571009: metrics: Add guest mode detection to metrics library and client (Closed) Base URL: http://git.chromium.org/git/metrics.git
Patch Set: Fix metrics_client semantics bug Created 10 years, 3 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
« metrics_library.cc ('K') | « metrics_library.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: metrics_library_test.cc
diff --git a/metrics_library_test.cc b/metrics_library_test.cc
index cbf4cce24280d8e7a2560d4992deaf13bacdb441..0cd695b1d0e411f3cc391239903c808fffbfa8f7 100644
--- a/metrics_library_test.cc
+++ b/metrics_library_test.cc
@@ -11,8 +11,8 @@
#include "metrics_library.h"
static const FilePath kTestUMAEventsFile("test-uma-events");
-
static const char kTestConsent[] = "test-consent";
+static const char kTestMounts[] = "test-mounts";
static void SetMetricsEnabled(bool enabled) {
if (enabled)
@@ -35,6 +35,8 @@ class MetricsLibraryTest : public testing::Test {
}
virtual void TearDown() {
+ file_util::Delete(FilePath(kTestConsent), false);
+ file_util::Delete(FilePath(kTestMounts), false);
file_util::Delete(kTestUMAEventsFile, false);
}
@@ -44,6 +46,65 @@ class MetricsLibraryTest : public testing::Test {
MetricsLibrary lib_;
};
+TEST_F(MetricsLibraryTest, IsDeviceMounted) {
+ static const char kTestContents[] =
+ "0123456789abcde 0123456789abcde\nguestfs foo bar\n";
+ char buffer[1024];
+ int block_sizes[] = { 1, 2, 3, 4, 5, 6, 8, 12, 14, 16, 32, 1024 };
+ bool result;
+ EXPECT_FALSE(lib_.IsDeviceMounted("guestfs",
+ "nonexistent",
+ buffer,
+ 1,
+ &result));
+ ASSERT_TRUE(file_util::WriteFile(FilePath(kTestMounts),
+ kTestContents,
+ strlen(kTestContents)));
+ EXPECT_FALSE(lib_.IsDeviceMounted("guestfs",
+ kTestMounts,
+ buffer,
+ 0,
+ &result));
+ for (size_t i = 0; i < arraysize(block_sizes); ++i) {
+ EXPECT_TRUE(lib_.IsDeviceMounted("0123456789abcde",
+ kTestMounts,
+ buffer,
+ block_sizes[i],
+ &result));
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(lib_.IsDeviceMounted("guestfs",
+ kTestMounts,
+ buffer,
+ block_sizes[i],
+ &result));
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(lib_.IsDeviceMounted("0123456",
+ kTestMounts,
+ buffer,
+ block_sizes[i],
+ &result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(lib_.IsDeviceMounted("9abcde",
+ kTestMounts,
+ buffer,
+ block_sizes[i],
+ &result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(lib_.IsDeviceMounted("foo",
+ kTestMounts,
+ buffer,
+ block_sizes[i],
+ &result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(lib_.IsDeviceMounted("bar",
+ kTestMounts,
+ buffer,
+ block_sizes[i],
+ &result));
+ EXPECT_FALSE(result);
+ }
+}
+
TEST_F(MetricsLibraryTest, AreMetricsEnabledFalse) {
SetMetricsEnabled(false);
EXPECT_FALSE(lib_.AreMetricsEnabled());
« metrics_library.cc ('K') | « metrics_library.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698