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

Unified Diff: third_party/WebKit/Source/core/dom/DocumentTest.cpp

Issue 2939223003: Add DocumentShutdown{Notifier,Observer} (Closed)
Patch Set: Add CORE_EXPORT to DocumentShutdownNotifier Created 3 years, 6 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: third_party/WebKit/Source/core/dom/DocumentTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/DocumentTest.cpp b/third_party/WebKit/Source/core/dom/DocumentTest.cpp
index d06b908fbdbaf9f1fe161442c382920a4ad7efb7..6ebc46890eeef4d90d98152d69f39b9e2ec812a1 100644
--- a/third_party/WebKit/Source/core/dom/DocumentTest.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentTest.cpp
@@ -249,6 +249,42 @@ DEFINE_TRACE(TestSynchronousMutationObserver) {
SynchronousMutationObserver::Trace(visitor);
}
+class TestDocumentShutdownObserver
+ : public GarbageCollectedFinalized<TestDocumentShutdownObserver>,
+ public DocumentShutdownObserver {
+ USING_GARBAGE_COLLECTED_MIXIN(TestDocumentShutdownObserver);
+
+ public:
+ TestDocumentShutdownObserver(Document&);
+ virtual ~TestDocumentShutdownObserver() = default;
+
+ int CountContextDestroyedCalled() const {
+ return context_destroyed_called_counter_;
+ }
+
+ DECLARE_TRACE();
+
+ private:
+ // Implement |DocumentShutdownObserver| member functions.
+ void ContextDestroyed(Document*) final;
+
+ int context_destroyed_called_counter_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDocumentShutdownObserver);
+};
+
+TestDocumentShutdownObserver::TestDocumentShutdownObserver(Document& document) {
+ SetContext(&document);
+}
+
+void TestDocumentShutdownObserver::ContextDestroyed(Document*) {
+ ++context_destroyed_called_counter_;
+}
+
+DEFINE_TRACE(TestDocumentShutdownObserver) {
+ DocumentShutdownObserver::Trace(visitor);
+}
+
class MockValidationMessageClient
: public GarbageCollectedFinalized<MockValidationMessageClient>,
public ValidationMessageClient {
@@ -732,6 +768,17 @@ TEST_F(DocumentTest, SynchronousMutationNotifierUpdateCharacterData) {
EXPECT_EQ(3u, observer.UpdatedCharacterDataRecords()[3]->new_length_);
}
+TEST_F(DocumentTest, DocumentShutdownNotifier) {
+ auto& observer = *new TestDocumentShutdownObserver(GetDocument());
+
+ EXPECT_EQ(GetDocument(), observer.LifecycleContext());
+ EXPECT_EQ(0, observer.CountContextDestroyedCalled());
+
+ GetDocument().Shutdown();
+ EXPECT_EQ(nullptr, observer.LifecycleContext());
+ EXPECT_EQ(1, observer.CountContextDestroyedCalled());
+}
+
// This tests that meta-theme-color can be found correctly
TEST_F(DocumentTest, ThemeColor) {
{

Powered by Google App Engine
This is Rietveld 408576698