OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 5 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 class PushMessagingAppIdentifierTest : public testing::Test { | 8 class PushMessagingAppIdentifierTest : public testing::Test { |
9 protected: | 9 protected: |
10 PushMessagingAppIdentifier GenerateId( | 10 PushMessagingAppIdentifier GenerateId( |
11 const GURL& origin, | 11 const GURL& origin, |
12 int64 service_worker_registration_id) { | 12 int64_t service_worker_registration_id) { |
13 // To bypass DCHECK in PushMessagingAppIdentifier::Generate, we just use it | 13 // To bypass DCHECK in PushMessagingAppIdentifier::Generate, we just use it |
14 // to generate app_id, and then use private constructor. | 14 // to generate app_id, and then use private constructor. |
15 std::string app_id = PushMessagingAppIdentifier::Generate( | 15 std::string app_id = PushMessagingAppIdentifier::Generate( |
16 GURL("https://www.example.com/"), 1).app_id(); | 16 GURL("https://www.example.com/"), 1).app_id(); |
17 return PushMessagingAppIdentifier(app_id, origin, | 17 return PushMessagingAppIdentifier(app_id, origin, |
18 service_worker_registration_id); | 18 service_worker_registration_id); |
19 } | 19 } |
20 }; | 20 }; |
21 | 21 |
22 TEST_F(PushMessagingAppIdentifierTest, ConstructorValidity) { | 22 TEST_F(PushMessagingAppIdentifierTest, ConstructorValidity) { |
23 EXPECT_TRUE(GenerateId(GURL("https://www.example.com/"), 1).IsValid()); | 23 // The following two are valid: |
24 EXPECT_TRUE(GenerateId(GURL("https://www.example.com"), 1).IsValid()); | 24 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/"), 1).is_null()); |
25 EXPECT_FALSE(GenerateId(GURL(""), 1).IsValid()); | 25 EXPECT_FALSE(GenerateId(GURL("https://www.example.com"), 1).is_null()); |
26 EXPECT_FALSE(GenerateId(GURL("foo"), 1).IsValid()); | 26 // The following four are invalid and will DCHECK in Generate: |
27 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/foo"), 1).IsValid()); | 27 EXPECT_FALSE(GenerateId(GURL(""), 1).is_null()); |
28 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/#foo"), 1).IsValid()); | 28 EXPECT_FALSE(GenerateId(GURL("foo"), 1).is_null()); |
29 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/"), -1).IsValid()); | 29 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/foo"), 1).is_null()); |
| 30 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/#foo"), 1).is_null()); |
| 31 // The following one is invalid and will DCHECK in Generate and be null: |
| 32 EXPECT_TRUE(GenerateId(GURL("https://www.example.com/"), -1).is_null()); |
30 } | 33 } |
31 | 34 |
32 TEST_F(PushMessagingAppIdentifierTest, UniqueGuids) { | 35 TEST_F(PushMessagingAppIdentifierTest, UniqueGuids) { |
33 EXPECT_NE(PushMessagingAppIdentifier::Generate( | 36 EXPECT_NE(PushMessagingAppIdentifier::Generate( |
34 GURL("https://www.example.com/"), 1).app_id(), | 37 GURL("https://www.example.com/"), 1).app_id(), |
35 PushMessagingAppIdentifier::Generate( | 38 PushMessagingAppIdentifier::Generate( |
36 GURL("https://www.example.com/"), 1).app_id()); | 39 GURL("https://www.example.com/"), 1).app_id()); |
37 } | 40 } |
OLD | NEW |