Cleanup PushMessagingAppIdentifier
[chromium-blink-merge.git] / chrome / browser / push_messaging / push_messaging_app_identifier_unittest.cc
blobe79364d22d2b08bbb06beb12f30580f399cb1f57
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
3 // found in the LICENSE file.
5 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 class PushMessagingAppIdentifierTest : public testing::Test {
9 protected:
10 PushMessagingAppIdentifier GenerateId(
11 const GURL& origin,
12 int64_t service_worker_registration_id) {
13 // To bypass DCHECK in PushMessagingAppIdentifier::Generate, we just use it
14 // to generate app_id, and then use private constructor.
15 std::string app_id = PushMessagingAppIdentifier::Generate(
16 GURL("https://www.example.com/"), 1).app_id();
17 return PushMessagingAppIdentifier(app_id, origin,
18 service_worker_registration_id);
22 TEST_F(PushMessagingAppIdentifierTest, ConstructorValidity) {
23 // The following two are valid:
24 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/"), 1).is_null());
25 EXPECT_FALSE(GenerateId(GURL("https://www.example.com"), 1).is_null());
26 // The following four are invalid and will DCHECK in Generate:
27 EXPECT_FALSE(GenerateId(GURL(""), 1).is_null());
28 EXPECT_FALSE(GenerateId(GURL("foo"), 1).is_null());
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());
35 TEST_F(PushMessagingAppIdentifierTest, UniqueGuids) {
36 EXPECT_NE(PushMessagingAppIdentifier::Generate(
37 GURL("https://www.example.com/"), 1).app_id(),
38 PushMessagingAppIdentifier::Generate(
39 GURL("https://www.example.com/"), 1).app_id());