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

Side by Side Diff: components/offline_pages/background/save_page_request_unittest.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: more rebase Created 4 years 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/offline_pages/background/save_page_request.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace offline_pages {
10
11 namespace {
12 const int64_t kRequestId = 42;
13 const GURL kUrl("http://example.com");
14 const ClientId kClientId("bookmark", "1234");
15 const bool kUserRequested = true;
16 } // namespace
17
18 class SavePageRequestTest : public testing::Test {
19 public:
20 ~SavePageRequestTest() override;
21 };
22
23 SavePageRequestTest::~SavePageRequestTest() {}
24
25 TEST_F(SavePageRequestTest, CreatePendingReqeust) {
26 base::Time creation_time = base::Time::Now();
27 SavePageRequest request(
28 kRequestId, kUrl, kClientId, creation_time, kUserRequested);
29 ASSERT_EQ(kRequestId, request.request_id());
30 ASSERT_EQ(kUrl, request.url());
31 ASSERT_EQ(kClientId, request.client_id());
32 ASSERT_EQ(creation_time, request.creation_time());
33 ASSERT_EQ(creation_time, request.activation_time());
34 ASSERT_EQ(base::Time(), request.last_attempt_time());
35 ASSERT_EQ(0, request.completed_attempt_count());
36 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE, request.request_state());
37 ASSERT_EQ(0, request.started_attempt_count());
38 ASSERT_EQ(0, request.completed_attempt_count());
39 }
40
41 TEST_F(SavePageRequestTest, StartAndCompleteRequest) {
42 base::Time creation_time = base::Time::Now();
43 base::Time activation_time = creation_time + base::TimeDelta::FromHours(6);
44 SavePageRequest request(kRequestId, kUrl, kClientId, creation_time,
45 activation_time, kUserRequested);
46
47 base::Time start_time = activation_time + base::TimeDelta::FromHours(3);
48 request.MarkAttemptStarted(start_time);
49
50 // Most things don't change about the request.
51 ASSERT_EQ(kRequestId, request.request_id());
52 ASSERT_EQ(kUrl, request.url());
53 ASSERT_EQ(kClientId, request.client_id());
54 ASSERT_EQ(creation_time, request.creation_time());
55 ASSERT_EQ(activation_time, request.activation_time());
56
57 // Attempt time, attempt count and status will though.
58 ASSERT_EQ(start_time, request.last_attempt_time());
59 ASSERT_EQ(1, request.started_attempt_count());
60 ASSERT_EQ(SavePageRequest::RequestState::OFFLINING,
61 request.request_state());
62
63 request.MarkAttemptCompleted();
64
65 // Again, most things don't change about the request.
66 ASSERT_EQ(kRequestId, request.request_id());
67 ASSERT_EQ(kUrl, request.url());
68 ASSERT_EQ(kClientId, request.client_id());
69 ASSERT_EQ(creation_time, request.creation_time());
70 ASSERT_EQ(activation_time, request.activation_time());
71
72 // Last attempt time and status are updated.
73 ASSERT_EQ(1, request.completed_attempt_count());
74 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE, request.request_state());
75 }
76
77 TEST_F(SavePageRequestTest, StartAndAbortRequest) {
78 base::Time creation_time = base::Time::Now();
79 SavePageRequest request(kRequestId, kUrl, kClientId, creation_time,
80 kUserRequested);
81
82 base::Time start_time = creation_time + base::TimeDelta::FromHours(3);
83 request.MarkAttemptStarted(start_time);
84
85 // Most things don't change about the request.
86 ASSERT_EQ(kRequestId, request.request_id());
87 ASSERT_EQ(kUrl, request.url());
88 ASSERT_EQ(kClientId, request.client_id());
89 ASSERT_EQ(creation_time, request.creation_time());
90
91 // Attempt time and attempt count will though.
92 ASSERT_EQ(start_time, request.last_attempt_time());
93 ASSERT_EQ(1, request.started_attempt_count());
94 ASSERT_EQ(SavePageRequest::RequestState::OFFLINING,
95 request.request_state());
96
97 request.MarkAttemptAborted();
98
99 // Again, most things don't change about the request.
100 ASSERT_EQ(kRequestId, request.request_id());
101 ASSERT_EQ(kUrl, request.url());
102 ASSERT_EQ(kClientId, request.client_id());
103 ASSERT_EQ(creation_time, request.creation_time());
104
105 // Last attempt time is updated and completed attempt count did not rise.
106 ASSERT_EQ(0, request.completed_attempt_count());
107 ASSERT_EQ(SavePageRequest::RequestState::AVAILABLE, request.request_state());
108 }
109
110 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698