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

Side by Side Diff: base/metrics/statistics_recorder_unittest.cc

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « base/metrics/statistics_recorder.cc ('k') | base/numerics/safe_conversions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 TEST_F(StatisticsRecorderTest, ToJSON) { 255 TEST_F(StatisticsRecorderTest, ToJSON) {
256 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 30); 256 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 30);
257 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 40); 257 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 40);
258 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 30); 258 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 30);
259 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 40); 259 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 40);
260 260
261 std::string json(StatisticsRecorder::ToJSON(std::string())); 261 std::string json(StatisticsRecorder::ToJSON(std::string()));
262 262
263 // Check for valid JSON. 263 // Check for valid JSON.
264 scoped_ptr<Value> root; 264 scoped_ptr<Value> root;
265 root.reset(JSONReader::Read(json)); 265 root.reset(JSONReader::DeprecatedRead(json));
266 ASSERT_TRUE(root.get()); 266 ASSERT_TRUE(root.get());
267 267
268 DictionaryValue* root_dict = NULL; 268 DictionaryValue* root_dict = NULL;
269 ASSERT_TRUE(root->GetAsDictionary(&root_dict)); 269 ASSERT_TRUE(root->GetAsDictionary(&root_dict));
270 270
271 // No query should be set. 271 // No query should be set.
272 ASSERT_FALSE(root_dict->HasKey("query")); 272 ASSERT_FALSE(root_dict->HasKey("query"));
273 273
274 ListValue* histogram_list = NULL; 274 ListValue* histogram_list = NULL;
275 ASSERT_TRUE(root_dict->GetList("histograms", &histogram_list)); 275 ASSERT_TRUE(root_dict->GetList("histograms", &histogram_list));
276 ASSERT_EQ(2u, histogram_list->GetSize()); 276 ASSERT_EQ(2u, histogram_list->GetSize());
277 277
278 // Examine the first histogram. 278 // Examine the first histogram.
279 DictionaryValue* histogram_dict = NULL; 279 DictionaryValue* histogram_dict = NULL;
280 ASSERT_TRUE(histogram_list->GetDictionary(0, &histogram_dict)); 280 ASSERT_TRUE(histogram_list->GetDictionary(0, &histogram_dict));
281 281
282 int sample_count; 282 int sample_count;
283 ASSERT_TRUE(histogram_dict->GetInteger("count", &sample_count)); 283 ASSERT_TRUE(histogram_dict->GetInteger("count", &sample_count));
284 EXPECT_EQ(2, sample_count); 284 EXPECT_EQ(2, sample_count);
285 285
286 // Test the query filter. 286 // Test the query filter.
287 std::string query("TestHistogram2"); 287 std::string query("TestHistogram2");
288 json = StatisticsRecorder::ToJSON(query); 288 json = StatisticsRecorder::ToJSON(query);
289 289
290 root.reset(JSONReader::Read(json)); 290 root.reset(JSONReader::DeprecatedRead(json));
291 ASSERT_TRUE(root.get()); 291 ASSERT_TRUE(root.get());
292 ASSERT_TRUE(root->GetAsDictionary(&root_dict)); 292 ASSERT_TRUE(root->GetAsDictionary(&root_dict));
293 293
294 std::string query_value; 294 std::string query_value;
295 ASSERT_TRUE(root_dict->GetString("query", &query_value)); 295 ASSERT_TRUE(root_dict->GetString("query", &query_value));
296 EXPECT_EQ(query, query_value); 296 EXPECT_EQ(query, query_value);
297 297
298 ASSERT_TRUE(root_dict->GetList("histograms", &histogram_list)); 298 ASSERT_TRUE(root_dict->GetList("histograms", &histogram_list));
299 ASSERT_EQ(1u, histogram_list->GetSize()); 299 ASSERT_EQ(1u, histogram_list->GetSize());
300 300
301 ASSERT_TRUE(histogram_list->GetDictionary(0, &histogram_dict)); 301 ASSERT_TRUE(histogram_list->GetDictionary(0, &histogram_dict));
302 302
303 std::string histogram_name; 303 std::string histogram_name;
304 ASSERT_TRUE(histogram_dict->GetString("name", &histogram_name)); 304 ASSERT_TRUE(histogram_dict->GetString("name", &histogram_name));
305 EXPECT_EQ("TestHistogram2", histogram_name); 305 EXPECT_EQ("TestHistogram2", histogram_name);
306 306
307 json.clear(); 307 json.clear();
308 UninitializeStatisticsRecorder(); 308 UninitializeStatisticsRecorder();
309 309
310 // No data should be returned. 310 // No data should be returned.
311 json = StatisticsRecorder::ToJSON(query); 311 json = StatisticsRecorder::ToJSON(query);
312 EXPECT_TRUE(json.empty()); 312 EXPECT_TRUE(json.empty());
313 } 313 }
314 314
315 } // namespace base 315 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.cc ('k') | base/numerics/safe_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698