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

Side by Side Diff: components/precache/core/precache_database_unittest.cc

Issue 1961153003: Add pause/resume functionality to precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a proto Created 4 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/precache/core/precache_database.h" 5 #include "components/precache/core/precache_database.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram_base.h" 16 #include "base/metrics/histogram_base.h"
17 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "components/history/core/browser/history_constants.h" 19 #include "components/history/core/browser/history_constants.h"
20 #include "components/precache/core/proto/unfinished_work.pb.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace { 25 namespace {
25 26
26 using ::testing::ContainerEq; 27 using ::testing::ContainerEq;
27 using ::testing::ElementsAre; 28 using ::testing::ElementsAre;
28 using base::Bucket; 29 using base::Bucket;
29 30
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 EXPECT_THAT(histograms_.GetAllSamples("Precache.Latency.NonPrefetch"), 375 EXPECT_THAT(histograms_.GetAllSamples("Precache.Latency.NonPrefetch"),
375 ElementsAre(Bucket(0, 6), Bucket(kLatency.InMilliseconds(), 3))); 376 ElementsAre(Bucket(0, 6), Bucket(kLatency.InMilliseconds(), 3)));
376 377
377 EXPECT_THAT(histograms_.GetAllSamples("Precache.Saved"), 378 EXPECT_THAT(histograms_.GetAllSamples("Precache.Saved"),
378 ElementsAre(Bucket(kSize1, 1), Bucket(kSize3, 1))); 379 ElementsAre(Bucket(kSize1, 1), Bucket(kSize3, 1)));
379 380
380 EXPECT_THAT(histograms_.GetAllSamples("Precache.Saved.Cellular"), 381 EXPECT_THAT(histograms_.GetAllSamples("Precache.Saved.Cellular"),
381 ElementsAre(Bucket(kSize1, 1))); 382 ElementsAre(Bucket(kSize1, 1)));
382 } 383 }
383 384
385 TEST_F(PrecacheDatabaseTest, SaveAndGetUnfinishedWork) {
sclittle 2016/05/19 01:59:45 You could probably just remove this test, since th
bengr 2016/05/19 23:19:31 Done.
386 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work(
387 new PrecacheUnfinishedWork());
388 unfinished_work->add_top_host()->set_hostname("foo.com");
389 unfinished_work->add_top_host()->set_hostname("bar.com");
390 auto s = unfinished_work->mutable_config_settings();
391 s->set_top_sites_count(11);
392 s->add_forced_site("baz.com");
393 s->set_top_resources_count(12);
394 s->set_max_bytes_per_resource(501);
395 s->set_max_bytes_total(1001);
396 unfinished_work->add_manifest()->set_url("http://a.com/");
397 unfinished_work->add_manifest()->set_url("http://b.com/");
398 unfinished_work->add_manifest()->set_url("http://c.com/");
399 unfinished_work->add_resource()->set_url("http://x.com/");
400 unfinished_work->add_resource()->set_url("http://y.com/");
401 unfinished_work->add_resource()->set_url("http://z.com/");
402 unfinished_work->set_total_bytes(13);
403 unfinished_work->set_network_bytes(14);
404 unfinished_work->set_num_manifest_urls(15);
405 base::Time sometime = base::Time::UnixEpoch();
406 unfinished_work->set_start_time(sometime.ToInternalValue());
407
408 precache_database_->SaveUnfinishedWork(std::move(unfinished_work));
409 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work2 =
410 precache_database_->GetUnfinishedWork();
411
412 EXPECT_EQ("foo.com", unfinished_work2->top_host(0).hostname());
413 EXPECT_EQ("bar.com", unfinished_work2->top_host(1).hostname());
414 EXPECT_EQ(11, unfinished_work2->config_settings().top_sites_count());
415 EXPECT_EQ(1, unfinished_work2->config_settings().forced_site_size());
416 EXPECT_EQ("baz.com", unfinished_work2->config_settings().forced_site(0));
417 EXPECT_EQ(12, unfinished_work2->config_settings().top_resources_count());
418 EXPECT_EQ(501ul,
419 unfinished_work2->config_settings().max_bytes_per_resource());
420 EXPECT_EQ(1001ul, unfinished_work2->config_settings().max_bytes_total());
421 EXPECT_EQ(3, unfinished_work2->manifest_size());
422 EXPECT_EQ("http://a.com/", unfinished_work2->manifest(0).url());
423 EXPECT_EQ("http://b.com/", unfinished_work2->manifest(1).url());
424 EXPECT_EQ("http://c.com/", unfinished_work2->manifest(2).url());
425 EXPECT_EQ(3, unfinished_work2->resource_size());
426 EXPECT_EQ("http://x.com/", unfinished_work2->resource(0).url());
427 EXPECT_EQ("http://y.com/", unfinished_work2->resource(1).url());
428 EXPECT_EQ("http://z.com/", unfinished_work2->resource(2).url());
429 EXPECT_EQ(13ul, unfinished_work2->total_bytes());
430 EXPECT_EQ(14ul, unfinished_work2->network_bytes());
431 EXPECT_EQ(15ul, unfinished_work2->num_manifest_urls());
432 EXPECT_EQ(base::Time::UnixEpoch(),
433 base::Time::FromInternalValue(unfinished_work2->start_time()));
434 }
435
384 } // namespace 436 } // namespace
385 437
386 } // namespace precache 438 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698