| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/media/router/media_route.h" | 5 #include "chrome/browser/media/router/media_route.h" |
| 6 #include "chrome/browser/media/router/media_sink.h" | 6 #include "chrome/browser/media/router/media_sink.h" |
| 7 #include "chrome/browser/media/router/media_source_helper.h" | 7 #include "chrome/browser/media/router/media_source_helper.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 | 9 |
| 10 namespace { |
| 11 const char kRouteId1[] = |
| 12 "urn:x-org.chromium:media:route:1/cast-sink1/http://foo.com"; |
| 13 const char kRouteId2[] = |
| 14 "urn:x-org.chromium:media:route:2/cast-sink2/http://foo.com"; |
| 15 } // namespace |
| 16 |
| 10 namespace media_router { | 17 namespace media_router { |
| 11 | 18 |
| 12 // Tests the == operator to ensure that only route ID equality is being checked. | 19 // Tests the == operator to ensure that only route ID equality is being checked. |
| 13 TEST(MediaRouteTest, Equals) { | 20 TEST(MediaRouteTest, Equals) { |
| 14 MediaRoute route1("routeId1", MediaSourceForCastApp("DialApp"), | 21 MediaRoute route1(kRouteId1, MediaSourceForCastApp("DialApp"), |
| 15 MediaSink("sinkId", "sinkName"), "Description", false); | 22 MediaSink("sinkId", "sinkName"), "Description", false); |
| 16 | 23 |
| 17 // Same as route1 with different sink ID. | 24 // Same as route1 with different sink ID. |
| 18 MediaRoute route2("routeId1", MediaSourceForCastApp("DialApp"), | 25 MediaRoute route2(kRouteId1, MediaSourceForCastApp("DialApp"), |
| 19 MediaSink("differentSinkId", "different sink"), | 26 MediaSink("differentSinkId", "different sink"), |
| 20 "Description", false); | 27 "Description", false); |
| 21 EXPECT_TRUE(route1.Equals(route2)); | 28 EXPECT_TRUE(route1.Equals(route2)); |
| 22 | 29 |
| 23 // Same as route1 with different description. | 30 // Same as route1 with different description. |
| 24 MediaRoute route3("routeId1", MediaSourceForCastApp("DialApp"), | 31 MediaRoute route3(kRouteId1, MediaSourceForCastApp("DialApp"), |
| 25 MediaSink("sinkId", "sinkName"), "differentDescription", | 32 MediaSink("sinkId", "sinkName"), "differentDescription", |
| 26 false); | 33 false); |
| 27 EXPECT_TRUE(route1.Equals(route3)); | 34 EXPECT_TRUE(route1.Equals(route3)); |
| 28 | 35 |
| 29 // Same as route1 with different is_local. | 36 // Same as route1 with different is_local. |
| 30 MediaRoute route4("routeId1", MediaSourceForCastApp("DialApp"), | 37 MediaRoute route4(kRouteId1, MediaSourceForCastApp("DialApp"), |
| 31 MediaSink("sinkId", "sinkName"), "Description", true); | 38 MediaSink("sinkId", "sinkName"), "Description", true); |
| 32 EXPECT_TRUE(route1.Equals(route4)); | 39 EXPECT_TRUE(route1.Equals(route4)); |
| 33 | 40 |
| 34 // The ID is different from route1's. | 41 // The ID is different from route1's. |
| 35 MediaRoute route5("routeId2", MediaSourceForCastApp("DialApp"), | 42 MediaRoute route5(kRouteId2, MediaSourceForCastApp("DialApp"), |
| 36 MediaSink("sinkId", "sinkName"), "Description", false); | 43 MediaSink("sinkId", "sinkName"), "Description", false); |
| 37 EXPECT_FALSE(route1.Equals(route5)); | 44 EXPECT_FALSE(route1.Equals(route5)); |
| 38 } | 45 } |
| 39 | 46 |
| 47 TEST(MediaRouteTest, ParseId) { |
| 48 EXPECT_EQ("1", GetPresentationIdAndUrl(kRouteId1).first); |
| 49 EXPECT_EQ("http://foo.com", GetPresentationIdAndUrl(kRouteId1).second); |
| 50 auto invalid = std::make_pair(std::string(), std::string()); |
| 51 EXPECT_EQ(invalid, GetPresentationIdAndUrl("invalid")); |
| 52 EXPECT_EQ(invalid, GetPresentationIdAndUrl( |
| 53 "urn:x-org.chromium:media:route:2")); |
| 54 EXPECT_EQ(invalid, GetPresentationIdAndUrl( |
| 55 "urn:x-org.chromium:media:route:2/")); |
| 56 EXPECT_EQ(invalid, GetPresentationIdAndUrl( |
| 57 "urn:x-org.chromium:media:route:2/cast-sink2/")); |
| 58 EXPECT_EQ(invalid, GetPresentationIdAndUrl( |
| 59 "urn:x-org.chromium:media:route:2//http://foo.com")); |
| 60 } |
| 61 |
| 40 } // namespace media_router | 62 } // namespace media_router |
| OLD | NEW |