Remove some NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED from c/b/extensions Part2
[chromium-blink-merge.git] / chrome / browser / extensions / api / dial / dial_device_data_unittest.cc
blob4ccc4701405c663f14a268cefee66160e6f528e3
1 // Copyright (c) 2012 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/extensions/api/dial/dial_device_data.h"
6 #include "chrome/common/extensions/api/dial.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace extensions {
11 namespace {
13 // Asserts equality between the two objects.
14 void ExpectEqual(const DialDeviceData& first, const DialDeviceData& second) {
15 EXPECT_EQ(first.device_id(), second.device_id());
16 EXPECT_EQ(first.label(), second.label());
17 EXPECT_EQ(first.device_description_url(), second.device_description_url());
18 EXPECT_EQ(first.response_time(), second.response_time());
19 EXPECT_EQ(first.max_age(), second.max_age());
20 EXPECT_EQ(first.config_id(), second.config_id());
23 } // namespace
25 TEST(DialDeviceDataTest, TestFillDialDevice) {
26 api::dial::DialDevice api_device;
28 DialDeviceData device;
29 device.set_device_id("device");
30 device.set_label("label");
31 device.set_device_description_url(GURL("http://127.0.0.1/dd.xml"));
32 device.set_config_id(1);
34 device.FillDialDevice(&api_device);
35 EXPECT_EQ(api_device.device_label, device.label());
36 EXPECT_EQ(api_device.device_description_url,
37 device.device_description_url().spec());
38 EXPECT_EQ(*(api_device.config_id), device.config_id());
41 TEST(DialDeviceDataTest, TestUpdateFrom) {
42 DialDeviceData original;
43 original.set_device_id("device_a");
44 original.set_label("label_a");
45 original.set_device_description_url(GURL("http://127.0.0.1/dd-a.xml"));
46 original.set_response_time(base::Time::FromInternalValue(1000));
47 original.set_max_age(100);
48 original.set_config_id(1);
50 DialDeviceData new_data;
51 new_data.set_device_id("device_a");
52 new_data.set_device_description_url(GURL("http://127.0.0.1/dd-a.xml"));
53 new_data.set_response_time(base::Time::FromInternalValue(1000));
54 new_data.set_max_age(100);
55 new_data.set_config_id(1);
57 DialDeviceData original_1(original);
58 EXPECT_FALSE(original_1.UpdateFrom(new_data));
59 ExpectEqual(original_1, original);
61 DialDeviceData original_2(original);
62 new_data.set_max_age(200);
63 new_data.set_response_time(base::Time::FromInternalValue(2000));
64 EXPECT_FALSE(original_2.UpdateFrom(new_data));
66 EXPECT_EQ("device_a", original_2.device_id());
67 EXPECT_EQ(GURL("http://127.0.0.1/dd-a.xml"),
68 original_2.device_description_url());
69 EXPECT_EQ("label_a", original_2.label());
70 EXPECT_EQ(200, original_2.max_age());
71 EXPECT_EQ(base::Time::FromInternalValue(2000), original_2.response_time());
72 EXPECT_EQ(1, original_2.config_id());
74 DialDeviceData original_3(original);
75 new_data.set_device_description_url(GURL("http://127.0.0.2/dd-b.xml"));
76 new_data.set_config_id(2);
77 EXPECT_TRUE(original_3.UpdateFrom(new_data));
79 EXPECT_EQ("device_a", original_3.device_id());
80 EXPECT_EQ(GURL("http://127.0.0.2/dd-b.xml"),
81 original_3.device_description_url());
82 EXPECT_EQ("label_a", original_3.label());
83 EXPECT_EQ(200, original_3.max_age());
84 EXPECT_EQ(base::Time::FromInternalValue(2000), original_3.response_time());
85 EXPECT_EQ(2, original_3.config_id());
88 TEST(DialDeviceDataTest, TestIsDeviceDescriptionUrl) {
89 EXPECT_TRUE(DialDeviceData::IsDeviceDescriptionUrl(
90 GURL("http://some.device.com/dd.xml")));
91 EXPECT_TRUE(DialDeviceData::IsDeviceDescriptionUrl(
92 GURL("https://some.device.com/dd.xml")));
93 EXPECT_TRUE(DialDeviceData::IsDeviceDescriptionUrl(
94 GURL("http://192.168.1.1:1234/dd.xml")));
95 EXPECT_TRUE(DialDeviceData::IsDeviceDescriptionUrl(
96 GURL("https://192.168.1.1:1234/dd.xml")));
98 EXPECT_FALSE(DialDeviceData::IsDeviceDescriptionUrl(GURL()));
99 EXPECT_FALSE(DialDeviceData::IsDeviceDescriptionUrl(GURL(std::string())));
100 EXPECT_FALSE(
101 DialDeviceData::IsDeviceDescriptionUrl(GURL("file://path/to/file")));
104 } // namespace extensions