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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014, Google Inc. All rights reserved. 2 * Copyright (c) 2014, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 visitor->Trace(children_changed_nodes_); 242 visitor->Trace(children_changed_nodes_);
243 visitor->Trace(merge_text_nodes_records_); 243 visitor->Trace(merge_text_nodes_records_);
244 visitor->Trace(move_tree_to_new_document_nodes_); 244 visitor->Trace(move_tree_to_new_document_nodes_);
245 visitor->Trace(removed_children_nodes_); 245 visitor->Trace(removed_children_nodes_);
246 visitor->Trace(removed_nodes_); 246 visitor->Trace(removed_nodes_);
247 visitor->Trace(split_text_nodes_); 247 visitor->Trace(split_text_nodes_);
248 visitor->Trace(updated_character_data_records_); 248 visitor->Trace(updated_character_data_records_);
249 SynchronousMutationObserver::Trace(visitor); 249 SynchronousMutationObserver::Trace(visitor);
250 } 250 }
251 251
252 class TestDocumentShutdownObserver
253 : public GarbageCollectedFinalized<TestDocumentShutdownObserver>,
254 public DocumentShutdownObserver {
255 USING_GARBAGE_COLLECTED_MIXIN(TestDocumentShutdownObserver);
256
257 public:
258 TestDocumentShutdownObserver(Document&);
259 virtual ~TestDocumentShutdownObserver() = default;
260
261 int CountContextDestroyedCalled() const {
262 return context_destroyed_called_counter_;
263 }
264
265 DECLARE_TRACE();
266
267 private:
268 // Implement |DocumentShutdownObserver| member functions.
269 void ContextDestroyed(Document*) final;
270
271 int context_destroyed_called_counter_ = 0;
272
273 DISALLOW_COPY_AND_ASSIGN(TestDocumentShutdownObserver);
274 };
275
276 TestDocumentShutdownObserver::TestDocumentShutdownObserver(Document& document) {
277 SetContext(&document);
278 }
279
280 void TestDocumentShutdownObserver::ContextDestroyed(Document*) {
281 ++context_destroyed_called_counter_;
282 }
283
284 DEFINE_TRACE(TestDocumentShutdownObserver) {
285 DocumentShutdownObserver::Trace(visitor);
286 }
287
252 class MockValidationMessageClient 288 class MockValidationMessageClient
253 : public GarbageCollectedFinalized<MockValidationMessageClient>, 289 : public GarbageCollectedFinalized<MockValidationMessageClient>,
254 public ValidationMessageClient { 290 public ValidationMessageClient {
255 USING_GARBAGE_COLLECTED_MIXIN(MockValidationMessageClient); 291 USING_GARBAGE_COLLECTED_MIXIN(MockValidationMessageClient);
256 292
257 public: 293 public:
258 MockValidationMessageClient() { Reset(); } 294 MockValidationMessageClient() { Reset(); }
259 void Reset() { 295 void Reset() {
260 show_validation_message_was_called = false; 296 show_validation_message_was_called = false;
261 will_unload_document_was_called = false; 297 will_unload_document_was_called = false;
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 EXPECT_EQ(3u, observer.UpdatedCharacterDataRecords()[2]->new_length_); 761 EXPECT_EQ(3u, observer.UpdatedCharacterDataRecords()[2]->new_length_);
726 762
727 replace_sample->replaceData(6, 4, "ghi", ASSERT_NO_EXCEPTION); 763 replace_sample->replaceData(6, 4, "ghi", ASSERT_NO_EXCEPTION);
728 ASSERT_EQ(4u, observer.UpdatedCharacterDataRecords().size()); 764 ASSERT_EQ(4u, observer.UpdatedCharacterDataRecords().size());
729 EXPECT_EQ(replace_sample, observer.UpdatedCharacterDataRecords()[3]->node_); 765 EXPECT_EQ(replace_sample, observer.UpdatedCharacterDataRecords()[3]->node_);
730 EXPECT_EQ(6u, observer.UpdatedCharacterDataRecords()[3]->offset_); 766 EXPECT_EQ(6u, observer.UpdatedCharacterDataRecords()[3]->offset_);
731 EXPECT_EQ(4u, observer.UpdatedCharacterDataRecords()[3]->old_length_); 767 EXPECT_EQ(4u, observer.UpdatedCharacterDataRecords()[3]->old_length_);
732 EXPECT_EQ(3u, observer.UpdatedCharacterDataRecords()[3]->new_length_); 768 EXPECT_EQ(3u, observer.UpdatedCharacterDataRecords()[3]->new_length_);
733 } 769 }
734 770
771 TEST_F(DocumentTest, DocumentShutdownNotifier) {
772 auto& observer = *new TestDocumentShutdownObserver(GetDocument());
773
774 EXPECT_EQ(GetDocument(), observer.LifecycleContext());
775 EXPECT_EQ(0, observer.CountContextDestroyedCalled());
776
777 GetDocument().Shutdown();
778 EXPECT_EQ(nullptr, observer.LifecycleContext());
779 EXPECT_EQ(1, observer.CountContextDestroyedCalled());
780 }
781
735 // This tests that meta-theme-color can be found correctly 782 // This tests that meta-theme-color can be found correctly
736 TEST_F(DocumentTest, ThemeColor) { 783 TEST_F(DocumentTest, ThemeColor) {
737 { 784 {
738 SetHtmlInnerHTML( 785 SetHtmlInnerHTML(
739 "<meta name=\"theme-color\" content=\"#00ff00\">" 786 "<meta name=\"theme-color\" content=\"#00ff00\">"
740 "<body>"); 787 "<body>");
741 EXPECT_EQ(Color(0, 255, 0), GetDocument().ThemeColor()) 788 EXPECT_EQ(Color(0, 255, 0), GetDocument().ThemeColor())
742 << "Theme color should be bright green."; 789 << "Theme color should be bright green.";
743 } 790 }
744 791
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 EXPECT_EQ(DocumentLifecycle::kVisualUpdatePending, 913 EXPECT_EQ(DocumentLifecycle::kVisualUpdatePending,
867 GetDocument().Lifecycle().GetState()); 914 GetDocument().Lifecycle().GetState());
868 915
869 GetDocument().EnsurePaintLocationDataValidForNode( 916 GetDocument().EnsurePaintLocationDataValidForNode(
870 GetDocument().getElementById("stickyChild")); 917 GetDocument().getElementById("stickyChild"));
871 EXPECT_EQ(DocumentLifecycle::kCompositingInputsClean, 918 EXPECT_EQ(DocumentLifecycle::kCompositingInputsClean,
872 GetDocument().Lifecycle().GetState()); 919 GetDocument().Lifecycle().GetState());
873 } 920 }
874 921
875 } // namespace blink 922 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698