| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/port.h" | 10 #include "base/port.h" |
| 10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "base/time.h" | 16 #include "base/time.h" |
| 16 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
| 17 #include "chrome/browser/google/google_util.h" | 18 #include "chrome/browser/google/google_util.h" |
| 18 #include "chrome/browser/metrics/metrics_log.h" | 19 #include "chrome/browser/metrics/metrics_log.h" |
| 19 #include "chrome/browser/prefs/browser_prefs.h" | 20 #include "chrome/browser/prefs/browser_prefs.h" |
| 20 #include "chrome/common/chrome_process_type.h" | 21 #include "chrome/common/chrome_process_type.h" |
| 21 #include "chrome/common/metrics/proto/profiler_event.pb.h" | 22 #include "chrome/common/metrics/proto/profiler_event.pb.h" |
| 22 #include "chrome/common/metrics/proto/system_profile.pb.h" | 23 #include "chrome/common/metrics/proto/system_profile.pb.h" |
| 23 #include "chrome/common/metrics/variations/variations_util.h" | 24 #include "chrome/common/metrics/variations/variations_util.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/installer/util/google_update_settings.h" | 26 #include "chrome/installer/util/google_update_settings.h" |
| 26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/gfx/size.h" | 31 #include "ui/gfx/size.h" |
| 31 #include "webkit/plugins/webplugininfo.h" | 32 #include "webkit/plugins/webplugininfo.h" |
| 32 | 33 |
| 34 #if defined(OS_CHROMEOS) |
| 35 #include "chromeos/chromeos_switches.h" |
| 36 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" |
| 37 #endif // OS_CHROMEOS |
| 38 |
| 33 using base::TimeDelta; | 39 using base::TimeDelta; |
| 34 using metrics::ProfilerEventProto; | 40 using metrics::ProfilerEventProto; |
| 35 using tracked_objects::ProcessDataSnapshot; | 41 using tracked_objects::ProcessDataSnapshot; |
| 36 using tracked_objects::TaskSnapshot; | 42 using tracked_objects::TaskSnapshot; |
| 37 | 43 |
| 38 namespace { | 44 namespace { |
| 39 | 45 |
| 40 const char kClientId[] = "bogus client ID"; | 46 const char kClientId[] = "bogus client ID"; |
| 41 const int kSessionId = 127; | 47 const int kSessionId = 127; |
| 42 const int kScreenWidth = 1024; | 48 const int kScreenWidth = 1024; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 system_profile.hardware(); | 150 system_profile.hardware(); |
| 145 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width()); | 151 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width()); |
| 146 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height()); | 152 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height()); |
| 147 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor()); | 153 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor()); |
| 148 EXPECT_EQ(kScreenCount, hardware.screen_count()); | 154 EXPECT_EQ(kScreenCount, hardware.screen_count()); |
| 149 | 155 |
| 150 // TODO(isherman): Verify other data written into the protobuf as a result | 156 // TODO(isherman): Verify other data written into the protobuf as a result |
| 151 // of this call. | 157 // of this call. |
| 152 } | 158 } |
| 153 | 159 |
| 160 virtual void SetUp() OVERRIDE { |
| 161 #if defined(OS_CHROMEOS) |
| 162 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 163 chromeos::switches::kEnableExperimentalBluetooth)) |
| 164 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 165 chromeos::switches::kEnableExperimentalBluetooth); |
| 166 |
| 167 mock_dbus_thread_manager_ = |
| 168 new chromeos::MockDBusThreadManagerWithoutGMock(); |
| 169 chromeos::DBusThreadManager::InitializeForTesting( |
| 170 mock_dbus_thread_manager_); |
| 171 #endif // OS_CHROMEOS |
| 172 } |
| 173 |
| 154 virtual void TearDown() OVERRIDE { | 174 virtual void TearDown() OVERRIDE { |
| 155 // Drain the blocking pool from PostTaskAndReply executed by | 175 // Drain the blocking pool from PostTaskAndReply executed by |
| 156 // MetrticsLog.network_observer_. | 176 // MetrticsLog.network_observer_. |
| 157 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 177 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 158 content::RunAllPendingInMessageLoop(); | 178 content::RunAllPendingInMessageLoop(); |
| 179 |
| 180 #if defined(OS_CHROMEOS) |
| 181 chromeos::DBusThreadManager::Shutdown(); |
| 182 #endif // OS_CHROMEOS |
| 159 } | 183 } |
| 160 | 184 |
| 161 private: | 185 private: |
| 162 // This is necessary because eventually some tests call base::RepeatingTimer | 186 // This is necessary because eventually some tests call base::RepeatingTimer |
| 163 // functions and a message loop is required for that. | 187 // functions and a message loop is required for that. |
| 164 MessageLoop message_loop_; | 188 MessageLoop message_loop_; |
| 189 |
| 190 #if defined(OS_CHROMEOS) |
| 191 chromeos::MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager_; |
| 192 #endif // OS_CHROMEOS |
| 165 }; | 193 }; |
| 166 | 194 |
| 167 TEST_F(MetricsLogTest, RecordEnvironment) { | 195 TEST_F(MetricsLogTest, RecordEnvironment) { |
| 168 // Test that recording the environment works via both of the public methods | 196 // Test that recording the environment works via both of the public methods |
| 169 // RecordEnvironment() and RecordEnvironmentProto(). | 197 // RecordEnvironment() and RecordEnvironmentProto(). |
| 170 TestRecordEnvironment(false); | 198 TestRecordEnvironment(false); |
| 171 TestRecordEnvironment(true); | 199 TestRecordEnvironment(true); |
| 172 } | 200 } |
| 173 | 201 |
| 174 // Test that we properly write profiler data to the log. | 202 // Test that we properly write profiler data to the log. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 EXPECT_NE(std::string::npos, | 361 EXPECT_NE(std::string::npos, |
| 334 encoded.find(" childprocesscrashcount=\"10\"")); | 362 encoded.find(" childprocesscrashcount=\"10\"")); |
| 335 EXPECT_EQ(std::string::npos, | 363 EXPECT_EQ(std::string::npos, |
| 336 encoded.find(" otherusercrashcount=")); | 364 encoded.find(" otherusercrashcount=")); |
| 337 EXPECT_EQ(std::string::npos, | 365 EXPECT_EQ(std::string::npos, |
| 338 encoded.find(" kernelcrashcount=")); | 366 encoded.find(" kernelcrashcount=")); |
| 339 EXPECT_EQ(std::string::npos, | 367 EXPECT_EQ(std::string::npos, |
| 340 encoded.find(" systemuncleanshutdowns=")); | 368 encoded.find(" systemuncleanshutdowns=")); |
| 341 } | 369 } |
| 342 #endif // OS_CHROMEOS | 370 #endif // OS_CHROMEOS |
| OLD | NEW |