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.
4
5#include "chrome/browser/services/gcm/push_messaging_application_id.h"
6#include "testing/gtest/include/gtest/gtest.h"
7
8TEST(PushMessagingApplicationIdTest, ConstructorValidity) {
9  EXPECT_TRUE(gcm::PushMessagingApplicationId(GURL("https://www.example.com/"),
10                                              1).IsValid());
11  EXPECT_TRUE(gcm::PushMessagingApplicationId(GURL("https://www.example.com"),
12                                              1).IsValid());
13  EXPECT_FALSE(gcm::PushMessagingApplicationId(GURL(""), 1).IsValid());
14  EXPECT_FALSE(gcm::PushMessagingApplicationId(GURL("foo"), 1).IsValid());
15  EXPECT_FALSE(gcm::PushMessagingApplicationId(
16                   GURL("https://www.example.com/foo"), 1).IsValid());
17  EXPECT_FALSE(gcm::PushMessagingApplicationId(
18                   GURL("https://www.example.com/#foo"), 1).IsValid());
19  EXPECT_FALSE(gcm::PushMessagingApplicationId(GURL("https://www.example.com/"),
20                                               -1).IsValid());
21  EXPECT_FALSE(gcm::PushMessagingApplicationId().IsValid());
22}
23
24TEST(PushMessagingApplicationIdTest, ToString) {
25  EXPECT_EQ(gcm::PushMessagingApplicationId(GURL("https://www.example.com/"), 1)
26                .ToString(),
27            "push#https://www.example.com/#1");
28  EXPECT_EQ(gcm::PushMessagingApplicationId(GURL("https://www.example.com"), 1)
29                .ToString(),
30            "push#https://www.example.com/#1");
31}
32
33TEST(PushMessagingApplicationIdTest, ParseValidity) {
34  EXPECT_TRUE(gcm::PushMessagingApplicationId::Parse(
35                  "push#https://www.example.com/#1").IsValid());
36  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse("").IsValid());
37  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
38                   "sync#https://www.example.com/#1").IsValid());
39  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse("push#foo#1").IsValid());
40  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
41                   "push#https://www.example.com/foo#1").IsValid());
42  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
43                   "push#https://www.example.com/#one").IsValid());
44  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
45                   "push#https://www.example.com/#foo#1").IsValid());
46  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
47                   "push#https://www.example.com/#1#1").IsValid());
48  EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
49                   "push#https://www.example.com/#-1").IsValid());
50}
51