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

Unified Diff: components/physical_web/data_source/physical_web_data_source_impl_unittest.cc

Issue 2349483002: Implement Physical Web listener registration (Closed)
Patch Set: Address mattreynolds comments Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: components/physical_web/data_source/physical_web_data_source_impl_unittest.cc
diff --git a/components/physical_web/data_source/physical_web_data_source_impl_unittest.cc b/components/physical_web/data_source/physical_web_data_source_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d51d827ddbb9c001b65a42bb1333dc016a3b51de
--- /dev/null
+++ b/components/physical_web/data_source/physical_web_data_source_impl_unittest.cc
@@ -0,0 +1,159 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "components/physical_web/data_source/physical_web_data_source_impl.h"
+#include "components/physical_web/data_source/physical_web_listener.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace physical_web {
+
+// Test Values ----------------------------------------------------------------
+std::string url = "https://www.google.com";
mattreynolds 2016/09/21 22:01:34 Declare this as a char array, make it const, and r
hayesjordan 2016/09/21 22:25:07 Done.
+
+// TestPhysicalWebDataSource --------------------------------------------------
+
+class TestPhysicalWebDataSource : public PhysicalWebDataSourceImpl {
+ public:
+ TestPhysicalWebDataSource() {}
+ ~TestPhysicalWebDataSource() override {}
+
+ void StartDiscovery(bool network_request_enabled) override;
+ void StopDiscovery() override;
+ std::unique_ptr<base::ListValue> GetMetadata() override;
+ bool HasUnresolvedDiscoveries() override;
+};
+void TestPhysicalWebDataSource::StartDiscovery(bool network_request_enabled) {}
+
+void TestPhysicalWebDataSource::StopDiscovery() {}
+
+std::unique_ptr<base::ListValue> TestPhysicalWebDataSource::GetMetadata() {
+ return NULL;
+}
+
+bool TestPhysicalWebDataSource::HasUnresolvedDiscoveries() {
+ return false;
+}
+
+// TestPhysicalWebListener ----------------------------------------------------
+
+class TestPhysicalWebListener : public PhysicalWebListener {
+ public:
+ TestPhysicalWebListener() {
+ on_found_notified_ = false;
+ on_lost_notified_ = false;
+ on_distance_changed_notified_ = false;
+ last_event_url_.clear();
mattreynolds 2016/09/21 22:01:34 You can use member initialization here TestPhysic
hayesjordan 2016/09/21 22:25:07 Done.
+ }
+ ~TestPhysicalWebListener() {}
+
+ void OnFound(const std::string& url) override {
+ on_found_notified_ = true;
+ last_event_url_ = url;
+ }
+
+ void OnLost(const std::string& url) override {
+ on_lost_notified_ = true;
+ last_event_url_ = url;
+ }
+
+ void OnDistanceChanged(const std::string& url,
+ double distance_estimate) override {
+ on_distance_changed_notified_ = true;
+ last_event_url_ = url;
+ }
+
+ bool OnFoundNotified() { return on_found_notified_; }
+
+ bool OnLostNotified() { return on_lost_notified_; }
+
+ bool OnDistanceChangedNotified() { return on_distance_changed_notified_; }
+
+ std::string LastEventUrl() { return last_event_url_; }
+
+ private:
+ bool on_found_notified_;
+ bool on_lost_notified_;
+ bool on_distance_changed_notified_;
+ std::string last_event_url_;
+};
+
+// PhysicalWebDataSourceImplTest ----------------------------------------------
+
+class PhysicalWebDataSourceImplTest : public ::testing::Test {
+ public:
+ PhysicalWebDataSourceImplTest() {}
+ ~PhysicalWebDataSourceImplTest() override {}
+
+ // testing::Test
+ void SetUp() override;
+ void TearDown() override;
+
+ protected:
+ TestPhysicalWebDataSource data_source_;
+ TestPhysicalWebListener listener_;
+};
+
+void PhysicalWebDataSourceImplTest::SetUp() {
+ data_source_.RegisterListener(&listener_);
+}
+
+void PhysicalWebDataSourceImplTest::TearDown() {
+ data_source_.UnregisterListener(&listener_);
+}
+
+// Tests ----------------------------------------------------------------------
+
+TEST_F(PhysicalWebDataSourceImplTest, OnFound) {
+ data_source_.NotifyOnFound(url);
+ EXPECT_TRUE(listener_.OnFoundNotified());
+ EXPECT_FALSE(listener_.OnLostNotified());
+ EXPECT_FALSE(listener_.OnDistanceChangedNotified());
+ EXPECT_EQ(url, listener_.LastEventUrl());
+}
+
+TEST_F(PhysicalWebDataSourceImplTest, OnLost) {
+ data_source_.NotifyOnLost(url);
+ EXPECT_FALSE(listener_.OnFoundNotified());
+ EXPECT_TRUE(listener_.OnLostNotified());
+ EXPECT_FALSE(listener_.OnDistanceChangedNotified());
+ EXPECT_EQ(url, listener_.LastEventUrl());
+}
+
+TEST_F(PhysicalWebDataSourceImplTest, OnDistanceChanged) {
+ data_source_.NotifyOnDistanceChanged(url, 0.0);
+ EXPECT_FALSE(listener_.OnFoundNotified());
+ EXPECT_FALSE(listener_.OnLostNotified());
+ EXPECT_TRUE(listener_.OnDistanceChangedNotified());
+ EXPECT_EQ(url, listener_.LastEventUrl());
+}
+
+TEST_F(PhysicalWebDataSourceImplTest, OnFoundNotRegistered) {
+ data_source_.UnregisterListener(&listener_);
+ data_source_.NotifyOnFound(url);
+ EXPECT_FALSE(listener_.OnFoundNotified());
+ EXPECT_FALSE(listener_.OnLostNotified());
+ EXPECT_FALSE(listener_.OnDistanceChangedNotified());
+ EXPECT_TRUE(listener_.LastEventUrl().empty());
+}
+
+TEST_F(PhysicalWebDataSourceImplTest, OnLostNotRegistered) {
+ data_source_.UnregisterListener(&listener_);
+ data_source_.NotifyOnLost(url);
+ EXPECT_FALSE(listener_.OnFoundNotified());
+ EXPECT_FALSE(listener_.OnLostNotified());
+ EXPECT_FALSE(listener_.OnDistanceChangedNotified());
+ EXPECT_TRUE(listener_.LastEventUrl().empty());
+}
+
+TEST_F(PhysicalWebDataSourceImplTest, OnDistanceChangedNotRegistered) {
+ data_source_.UnregisterListener(&listener_);
+ data_source_.NotifyOnDistanceChanged(url, 0.0);
+ EXPECT_FALSE(listener_.OnFoundNotified());
+ EXPECT_FALSE(listener_.OnLostNotified());
+ EXPECT_FALSE(listener_.OnDistanceChangedNotified());
+ EXPECT_TRUE(listener_.LastEventUrl().empty());
+}
+} // namespace physical_web

Powered by Google App Engine
This is Rietveld 408576698