OLD | NEW |
---|---|
(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; | |
Peter Beverloo
2017/03/31 01:32:24
Can we try this with a >32 bit value too?
harkness
2017/03/31 10:11:44
Done.
| |
17 const char kTestTag[] = "test_tag"; | |
18 const char kExpectedSerialized[] = "0#9001#https://www.example.com#test_tag"; | |
19 | |
20 } // anonymous namespace | |
21 | |
22 class BackgroundFetchRegistrationIdTest : public ::testing::Test {}; | |
Peter Beverloo
2017/03/31 01:32:24
Since the test fixture doesn't do anything, you ca
harkness
2017/03/31 10:11:44
Done.
| |
23 | |
24 TEST_F(BackgroundFetchRegistrationIdTest, SerializeTest) { | |
25 BackgroundFetchRegistrationId registration_id( | |
26 kTestServiceWorkerRegistrationId, url::Origin(GURL(kTestOrigin)), | |
27 kTestTag); | |
28 std::string serialized_id = registration_id.Serialize(); | |
29 EXPECT_EQ(kExpectedSerialized, serialized_id); | |
30 } | |
31 | |
32 TEST_F(BackgroundFetchRegistrationIdTest, DeserializeSuccessTest) { | |
33 BackgroundFetchRegistrationId registration_id; | |
34 ASSERT_TRUE(BackgroundFetchRegistrationId::Deserialize(kExpectedSerialized, | |
35 registration_id)); | |
36 | |
37 EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize()); | |
38 EXPECT_EQ(kTestServiceWorkerRegistrationId, | |
39 registration_id.service_worker_registration_id()); | |
40 EXPECT_EQ(kTestTag, registration_id.tag()); | |
41 } | |
42 | |
43 TEST_F(BackgroundFetchRegistrationIdTest, DeserializeComplexTagTest) { | |
44 BackgroundFetchRegistrationId registration_id; | |
45 std::string silly_tag("0#9001#https://www.example.com#this#is#a#stupid#tag"); | |
46 ASSERT_TRUE( | |
47 BackgroundFetchRegistrationId::Deserialize(silly_tag, registration_id)); | |
48 | |
49 EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize()); | |
50 EXPECT_EQ(kTestServiceWorkerRegistrationId, | |
51 registration_id.service_worker_registration_id()); | |
52 EXPECT_EQ("this#is#a#stupid#tag", registration_id.tag()); | |
53 } | |
54 | |
55 TEST_F(BackgroundFetchRegistrationIdTest, DeserializeFailureTest) { | |
56 BackgroundFetchRegistrationId registration_id; | |
57 | |
58 // Should fail: Invalid version. | |
59 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize( | |
60 "1#1#https://www.example.com#tag", registration_id)); | |
61 | |
62 // Should fail: Invalid service worker registration id. | |
63 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize( | |
64 "0#abc#https://www.example.com#tag", registration_id)); | |
65 | |
66 // Should fail: Invalid origin. | |
67 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize( | |
68 "0#1#www.example.com#tag", registration_id)); | |
69 | |
70 // Should fail: Empty origin. | |
71 EXPECT_FALSE( | |
72 BackgroundFetchRegistrationId::Deserialize("0#1##tag", registration_id)); | |
73 | |
74 // Should fail: Not enough fields. | |
75 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize( | |
76 "0#1#https://www.example.com", registration_id)); | |
77 | |
78 // Should fail: Invalid tag | |
79 EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize( | |
80 "0#1#https://www.example.com#", registration_id)); | |
81 } | |
82 | |
83 } // namespace content | |
OLD | NEW |