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

Side by Side Diff: content/browser/background_fetch/background_fetch_registration_id_unittest.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Add GetVisualsForItem support Created 3 years, 8 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
(Empty)
1 // Copyright 2017 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 "content/browser/background_fetch/background_fetch_registration_id.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h"
9 #include "url/origin.h"
10
11 namespace content {
12
13 namespace {
14
15 const char kTestOrigin[] = "https://www.example.com";
16 const int64_t kTestServiceWorkerRegistrationId = 9001;
17 const int64_t kTestLongServiceWorkerRegistrationId = 14294967296;
18 const char kTestTag[] = "test_tag";
19 const char kExpectedSerialized[] = "0#9001#https://www.example.com#test_tag";
20 const char kExpectedLongServiceWorkerIdSerialized[] =
21 "0#14294967296#https://www.example.com#test_tag";
22
23 } // anonymous namespace
24
25 TEST(BackgroundFetchRegistrationIdTest, SerializeTest) {
26 BackgroundFetchRegistrationId registration_id(
27 kTestServiceWorkerRegistrationId, url::Origin(GURL(kTestOrigin)),
28 kTestTag);
29 std::string serialized_id = registration_id.Serialize();
30 EXPECT_EQ(kExpectedSerialized, serialized_id);
31 }
32
33 TEST(BackgroundFetchRegistrationIdTest, SerializeLongServiceWorkerIdTest) {
34 BackgroundFetchRegistrationId registration_id(
35 kTestLongServiceWorkerRegistrationId, url::Origin(GURL(kTestOrigin)),
36 kTestTag);
37 std::string serialized_id = registration_id.Serialize();
38 EXPECT_EQ(kExpectedLongServiceWorkerIdSerialized, serialized_id);
39 }
40
41 TEST(BackgroundFetchRegistrationIdTest, DeserializeSuccessTest) {
42 BackgroundFetchRegistrationId registration_id;
43 ASSERT_TRUE(BackgroundFetchRegistrationId::Deserialize(
44 kExpectedLongServiceWorkerIdSerialized, &registration_id));
45
46 EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize());
47 EXPECT_EQ(kTestLongServiceWorkerRegistrationId,
48 registration_id.service_worker_registration_id());
49 EXPECT_EQ(kTestTag, registration_id.tag());
50 }
51
52 TEST(BackgroundFetchRegistrationIdTest,
53 DeserializeLongServiceWorkerSuccessTest) {
54 BackgroundFetchRegistrationId registration_id;
55 ASSERT_TRUE(BackgroundFetchRegistrationId::Deserialize(kExpectedSerialized,
56 &registration_id));
57
58 EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize());
59 EXPECT_EQ(kTestServiceWorkerRegistrationId,
60 registration_id.service_worker_registration_id());
61 EXPECT_EQ(kTestTag, registration_id.tag());
62 }
63
64 TEST(BackgroundFetchRegistrationIdTest, DeserializeComplexTagTest) {
65 BackgroundFetchRegistrationId registration_id;
66 std::string silly_tag("0#9001#https://www.example.com#this#is#a#stupid#tag");
67 ASSERT_TRUE(
68 BackgroundFetchRegistrationId::Deserialize(silly_tag, &registration_id));
69
70 EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize());
71 EXPECT_EQ(kTestServiceWorkerRegistrationId,
72 registration_id.service_worker_registration_id());
73 EXPECT_EQ("this#is#a#stupid#tag", registration_id.tag());
74 }
75
76 TEST(BackgroundFetchRegistrationIdTest, DeserializeFailureTest) {
77 BackgroundFetchRegistrationId registration_id;
78
79 // Should fail: Invalid version.
80 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
81 "1#1#https://www.example.com#tag", &registration_id));
82
83 // Should fail: Invalid service worker registration id.
84 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
85 "0#abc#https://www.example.com#tag", &registration_id));
86
87 // Should fail: Too large service worker registration id.
88 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
89 "0#11111111111111111111111111111111111#https://www.example.com#tag",
90 &registration_id));
91
92 // Should fail: Invalid origin.
93 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
94 "0#1#www.example.com#tag", &registration_id));
95
96 // Should fail: Empty origin.
97 EXPECT_FALSE(
98 BackgroundFetchRegistrationId::Deserialize("0#1##tag", &registration_id));
99
100 // Should fail: Not enough fields.
101 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
102 "0#1#https://www.example.com", &registration_id));
103
104 // Should fail: Invalid tag
105 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
106 "0#1#https://www.example.com#", &registration_id));
107 }
108
109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698