Add some missing ObservedPtr<> comparison operators

Change-Id: Ic406e21b53d904d710e96ec3050ed5aeba94e3c7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/61891
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/observed_ptr.h b/core/fxcrt/observed_ptr.h
index d938168..9568705 100644
--- a/core/fxcrt/observed_ptr.h
+++ b/core/fxcrt/observed_ptr.h
@@ -80,6 +80,17 @@
     return m_pObservable == that.m_pObservable;
   }
   bool operator!=(const ObservedPtr& that) const { return !(*this == that); }
+
+  template <typename U>
+  bool operator==(const U* that) const {
+    return Get() == that;
+  }
+
+  template <typename U>
+  bool operator!=(const U* that) const {
+    return !(*this == that);
+  }
+
   explicit operator bool() const { return HasObservable(); }
   T* Get() const { return m_pObservable; }
   T& operator*() const { return *m_pObservable; }
@@ -89,6 +100,16 @@
   T* m_pObservable = nullptr;
 };
 
+template <typename T, typename U>
+inline bool operator==(const U* lhs, const ObservedPtr<T>& rhs) {
+  return rhs == lhs;
+}
+
+template <typename T, typename U>
+inline bool operator!=(const U* lhs, const ObservedPtr<T>& rhs) {
+  return rhs != lhs;
+}
+
 }  // namespace fxcrt
 
 using fxcrt::Observable;
diff --git a/core/fxcrt/observed_ptr_unittest.cpp b/core/fxcrt/observed_ptr_unittest.cpp
index 4f6535d..81e114f 100644
--- a/core/fxcrt/observed_ptr_unittest.cpp
+++ b/core/fxcrt/observed_ptr_unittest.cpp
@@ -148,6 +148,10 @@
   ObservedPtr<PseudoObservable> null_ptr1;
   ObservedPtr<PseudoObservable> obj1_ptr1(&obj1);
   ObservedPtr<PseudoObservable> obj2_ptr1(&obj2);
+  EXPECT_TRUE(&obj1 == obj1_ptr1);
+  EXPECT_TRUE(obj1_ptr1 == &obj1);
+  EXPECT_TRUE(&obj2 == obj2_ptr1);
+  EXPECT_TRUE(obj2_ptr1 == &obj2);
   {
     ObservedPtr<PseudoObservable> null_ptr2;
     EXPECT_TRUE(null_ptr1 == null_ptr2);
@@ -169,6 +173,10 @@
   ObservedPtr<PseudoObservable> null_ptr1;
   ObservedPtr<PseudoObservable> obj1_ptr1(&obj1);
   ObservedPtr<PseudoObservable> obj2_ptr1(&obj2);
+  EXPECT_FALSE(&obj1 != obj1_ptr1);
+  EXPECT_FALSE(obj1_ptr1 != &obj1);
+  EXPECT_FALSE(&obj2 != obj2_ptr1);
+  EXPECT_FALSE(obj2_ptr1 != &obj2);
   {
     ObservedPtr<PseudoObservable> null_ptr2;
     ObservedPtr<PseudoObservable> obj1_ptr2(&obj1);