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_application_id.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 class PushMessagingApplicationIdTest
: public testing::Test
{
10 PushMessagingApplicationId
GenerateId(
12 int64 service_worker_registration_id
) {
13 // To bypass DCHECK in PushMessagingApplicationId::Generate, we just use it
14 // to generate app_id_guid, and then use private constructor.
15 std::string app_id_guid
= PushMessagingApplicationId::Generate(
16 GURL("https://www.example.com/"), 1).app_id_guid();
17 return PushMessagingApplicationId(app_id_guid
, origin
,
18 service_worker_registration_id
);
22 TEST_F(PushMessagingApplicationIdTest
, ConstructorValidity
) {
23 EXPECT_TRUE(GenerateId(GURL("https://www.example.com/"), 1).IsValid());
24 EXPECT_TRUE(GenerateId(GURL("https://www.example.com"), 1).IsValid());
25 EXPECT_FALSE(GenerateId(GURL(""), 1).IsValid());
26 EXPECT_FALSE(GenerateId(GURL("foo"), 1).IsValid());
27 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/foo"), 1).IsValid());
28 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/#foo"), 1).IsValid());
29 EXPECT_FALSE(GenerateId(GURL("https://www.example.com/"), -1).IsValid());
32 TEST_F(PushMessagingApplicationIdTest
, UniqueGuids
) {
33 EXPECT_NE(PushMessagingApplicationId::Generate(
34 GURL("https://www.example.com/"), 1).app_id_guid(),
35 PushMessagingApplicationId::Generate(
36 GURL("https://www.example.com/"), 1).app_id_guid());