Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: components/physical_web/data_source/physical_web_data_source_impl_unittest.cc

Issue 2565023002: Use GURLs in Physical Web data source (Closed)
Patch Set: Register missing dependencies Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/values.h" 5 #include "base/values.h"
6 #include "components/physical_web/data_source/physical_web_data_source_impl.h" 6 #include "components/physical_web/data_source/physical_web_data_source_impl.h"
7 #include "components/physical_web/data_source/physical_web_listener.h" 7 #include "components/physical_web/data_source/physical_web_listener.h"
8
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
10 10
11 namespace physical_web { 11 namespace physical_web {
12 12
13 // Test Values ---------------------------------------------------------------- 13 // Test Values ----------------------------------------------------------------
14 const char kUrl[] = "https://www.google.com"; 14 GURL kUrl = GURL("https://www.google.com");
15 15
16 // TestPhysicalWebDataSource -------------------------------------------------- 16 // TestPhysicalWebDataSource --------------------------------------------------
17 17
18 class TestPhysicalWebDataSource : public PhysicalWebDataSourceImpl { 18 class TestPhysicalWebDataSource : public PhysicalWebDataSourceImpl {
19 public: 19 public:
20 TestPhysicalWebDataSource() {} 20 TestPhysicalWebDataSource() {}
21 ~TestPhysicalWebDataSource() override {} 21 ~TestPhysicalWebDataSource() override {}
22 22
23 void StartDiscovery(bool network_request_enabled) override; 23 void StartDiscovery(bool network_request_enabled) override;
24 void StopDiscovery() override; 24 void StopDiscovery() override;
(...skipping 16 matching lines...) Expand all
41 41
42 class TestPhysicalWebListener : public PhysicalWebListener { 42 class TestPhysicalWebListener : public PhysicalWebListener {
43 public: 43 public:
44 TestPhysicalWebListener() 44 TestPhysicalWebListener()
45 : on_found_notified_(false), 45 : on_found_notified_(false),
46 on_lost_notified_(false), 46 on_lost_notified_(false),
47 on_distance_changed_notified_(false) {} 47 on_distance_changed_notified_(false) {}
48 48
49 ~TestPhysicalWebListener() {} 49 ~TestPhysicalWebListener() {}
50 50
51 void OnFound(const std::string& url) override { 51 void OnFound(const GURL& url) override {
52 on_found_notified_ = true; 52 on_found_notified_ = true;
53 last_event_url_ = url; 53 last_event_url_ = url;
54 } 54 }
55 55
56 void OnLost(const std::string& url) override { 56 void OnLost(const GURL& url) override {
57 on_lost_notified_ = true; 57 on_lost_notified_ = true;
58 last_event_url_ = url; 58 last_event_url_ = url;
59 } 59 }
60 60
61 void OnDistanceChanged(const std::string& url, 61 void OnDistanceChanged(const GURL& url, double distance_estimate) override {
62 double distance_estimate) override {
63 on_distance_changed_notified_ = true; 62 on_distance_changed_notified_ = true;
64 last_event_url_ = url; 63 last_event_url_ = url;
65 } 64 }
66 65
67 bool OnFoundNotified() { return on_found_notified_; } 66 bool OnFoundNotified() { return on_found_notified_; }
68 67
69 bool OnLostNotified() { return on_lost_notified_; } 68 bool OnLostNotified() { return on_lost_notified_; }
70 69
71 bool OnDistanceChangedNotified() { return on_distance_changed_notified_; } 70 bool OnDistanceChangedNotified() { return on_distance_changed_notified_; }
72 71
73 std::string LastEventUrl() { return last_event_url_; } 72 GURL LastEventUrl() { return last_event_url_; }
74 73
75 private: 74 private:
76 bool on_found_notified_; 75 bool on_found_notified_;
77 bool on_lost_notified_; 76 bool on_lost_notified_;
78 bool on_distance_changed_notified_; 77 bool on_distance_changed_notified_;
79 std::string last_event_url_; 78 GURL last_event_url_;
80 }; 79 };
81 80
82 // PhysicalWebDataSourceImplTest ---------------------------------------------- 81 // PhysicalWebDataSourceImplTest ----------------------------------------------
83 82
84 class PhysicalWebDataSourceImplTest : public ::testing::Test { 83 class PhysicalWebDataSourceImplTest : public ::testing::Test {
85 public: 84 public:
86 PhysicalWebDataSourceImplTest() {} 85 PhysicalWebDataSourceImplTest() {}
87 ~PhysicalWebDataSourceImplTest() override {} 86 ~PhysicalWebDataSourceImplTest() override {}
88 87
89 // testing::Test 88 // testing::Test
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 EXPECT_TRUE(listener_.OnDistanceChangedNotified()); 127 EXPECT_TRUE(listener_.OnDistanceChangedNotified());
129 EXPECT_EQ(kUrl, listener_.LastEventUrl()); 128 EXPECT_EQ(kUrl, listener_.LastEventUrl());
130 } 129 }
131 130
132 TEST_F(PhysicalWebDataSourceImplTest, OnFoundNotRegistered) { 131 TEST_F(PhysicalWebDataSourceImplTest, OnFoundNotRegistered) {
133 data_source_.UnregisterListener(&listener_); 132 data_source_.UnregisterListener(&listener_);
134 data_source_.NotifyOnFound(kUrl); 133 data_source_.NotifyOnFound(kUrl);
135 EXPECT_FALSE(listener_.OnFoundNotified()); 134 EXPECT_FALSE(listener_.OnFoundNotified());
136 EXPECT_FALSE(listener_.OnLostNotified()); 135 EXPECT_FALSE(listener_.OnLostNotified());
137 EXPECT_FALSE(listener_.OnDistanceChangedNotified()); 136 EXPECT_FALSE(listener_.OnDistanceChangedNotified());
138 EXPECT_TRUE(listener_.LastEventUrl().empty()); 137 EXPECT_TRUE(listener_.LastEventUrl().is_empty());
139 } 138 }
140 139
141 TEST_F(PhysicalWebDataSourceImplTest, OnLostNotRegistered) { 140 TEST_F(PhysicalWebDataSourceImplTest, OnLostNotRegistered) {
142 data_source_.UnregisterListener(&listener_); 141 data_source_.UnregisterListener(&listener_);
143 data_source_.NotifyOnLost(kUrl); 142 data_source_.NotifyOnLost(kUrl);
144 EXPECT_FALSE(listener_.OnFoundNotified()); 143 EXPECT_FALSE(listener_.OnFoundNotified());
145 EXPECT_FALSE(listener_.OnLostNotified()); 144 EXPECT_FALSE(listener_.OnLostNotified());
146 EXPECT_FALSE(listener_.OnDistanceChangedNotified()); 145 EXPECT_FALSE(listener_.OnDistanceChangedNotified());
147 EXPECT_TRUE(listener_.LastEventUrl().empty()); 146 EXPECT_TRUE(listener_.LastEventUrl().is_empty());
148 } 147 }
149 148
150 TEST_F(PhysicalWebDataSourceImplTest, OnDistanceChangedNotRegistered) { 149 TEST_F(PhysicalWebDataSourceImplTest, OnDistanceChangedNotRegistered) {
151 data_source_.UnregisterListener(&listener_); 150 data_source_.UnregisterListener(&listener_);
152 data_source_.NotifyOnDistanceChanged(kUrl, 0.0); 151 data_source_.NotifyOnDistanceChanged(kUrl, 0.0);
153 EXPECT_FALSE(listener_.OnFoundNotified()); 152 EXPECT_FALSE(listener_.OnFoundNotified());
154 EXPECT_FALSE(listener_.OnLostNotified()); 153 EXPECT_FALSE(listener_.OnLostNotified());
155 EXPECT_FALSE(listener_.OnDistanceChangedNotified()); 154 EXPECT_FALSE(listener_.OnDistanceChangedNotified());
156 EXPECT_TRUE(listener_.LastEventUrl().empty()); 155 EXPECT_TRUE(listener_.LastEventUrl().is_empty());
157 } 156 }
158 157
159 } // namespace physical_web 158 } // namespace physical_web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698