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

Side by Side Diff: components/offline_pages/request_header/offline_page_header_unittest.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: 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/request_header/offline_page_header.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace offline_pages {
10
11 class OfflinePageHeaderTest : public testing::Test {
12 public:
13 OfflinePageHeaderTest() {}
14 ~OfflinePageHeaderTest() override {}
15
16 bool ParseFromHeaderValue(const std::string& header_value,
17 bool* need_to_persist,
18 OfflinePageHeader::Reason* reason,
19 std::string* id) {
20 OfflinePageHeader header(header_value);
21 *need_to_persist = header.need_to_persist;
22 *reason = header.reason;
23 *id = header.id;
24 return !header.did_fail_parsing_for_test;
25 }
26 };
27
28 TEST_F(OfflinePageHeaderTest, Parse) {
29 bool need_to_persist;
30 OfflinePageHeader::Reason reason;
31 std::string id;
32
33 EXPECT_FALSE(ParseFromHeaderValue("", &need_to_persist, &reason, &id));
34 EXPECT_FALSE(ParseFromHeaderValue(" ", &need_to_persist, &reason, &id));
35 EXPECT_FALSE(ParseFromHeaderValue(" , ", &need_to_persist, &reason, &id));
36 EXPECT_FALSE(ParseFromHeaderValue("reason", &need_to_persist, &reason, &id));
37 EXPECT_FALSE(ParseFromHeaderValue("a b c", &need_to_persist, &reason, &id));
38
39 EXPECT_FALSE(
40 ParseFromHeaderValue("persist=aa", &need_to_persist, &reason, &id));
41
42 EXPECT_TRUE(
43 ParseFromHeaderValue("persist=1", &need_to_persist, &reason, &id));
44 EXPECT_TRUE(need_to_persist);
45
46 EXPECT_TRUE(
47 ParseFromHeaderValue("persist=0", &need_to_persist, &reason, &id));
48 EXPECT_FALSE(need_to_persist);
49 EXPECT_EQ(OfflinePageHeader::Reason::NONE, reason);
50 EXPECT_EQ("", id);
51
52 EXPECT_FALSE(
53 ParseFromHeaderValue("reason=foo", &need_to_persist, &reason, &id));
54
55 EXPECT_TRUE(
56 ParseFromHeaderValue("reason=error", &need_to_persist, &reason, &id));
57 EXPECT_FALSE(need_to_persist);
58 EXPECT_EQ(OfflinePageHeader::Reason::NET_ERROR, reason);
59 EXPECT_EQ("", id);
60
61 EXPECT_TRUE(ParseFromHeaderValue("id=a1b2", &need_to_persist, &reason, &id));
62 EXPECT_FALSE(need_to_persist);
63 EXPECT_EQ(OfflinePageHeader::Reason::NONE, reason);
64 EXPECT_EQ("a1b2", id);
65
66 EXPECT_TRUE(ParseFromHeaderValue("persist=1 reason=download id=a1b2",
67 &need_to_persist, &reason, &id));
68 EXPECT_TRUE(need_to_persist);
69 EXPECT_EQ(OfflinePageHeader::Reason::DOWNLOAD, reason);
70 EXPECT_EQ("a1b2", id);
71 }
72
73 TEST_F(OfflinePageHeaderTest, ToString) {
74 OfflinePageHeader header;
75 header.need_to_persist = true;
76 header.reason = OfflinePageHeader::Reason::DOWNLOAD;
77 header.id = "a1b2";
78 EXPECT_EQ("X-Chrome-offline: persist=1 reason=download id=a1b2",
79 header.GetCompleteHeaderString());
80 }
81
82 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/request_header/offline_page_header.cc ('k') | components/offline_pages/snapshot_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698