[web] Fix web_runner_integration_tests to wait for main-document-load.

WebEngine now delivers events for changes in navigation state before
the main document has loaded, so tests must wait specifically for that
state before verifying URL & title expectations.

Bug: WEB-42

Change-Id: I168911b1bf75420f39f03ccbc0f5996d70aff836
diff --git a/tests/web_runner_tests/web_runner_integration_tests.cc b/tests/web_runner_tests/web_runner_integration_tests.cc
index 2ad716b..b7060a4 100644
--- a/tests/web_runner_tests/web_runner_integration_tests.cc
+++ b/tests/web_runner_tests/web_runner_integration_tests.cc
@@ -114,9 +114,15 @@
   std::string observed_url;
   std::string observed_title;
 
+  // If set, the URL and title events are used to determine if a page has
+  // loaded. Otherwise, |is_main_document_loaded| is used instead.
+  // TODO(WEB-42): Remove this workaround once Chromium has rolled with the new
+  // behavior.
+  bool use_legacy_observer_behavior = true;
+
   navigation_event_listener.set_on_navigation_state_changed(
-      [this, &navigation_event_listener, &observed_url,
-       &observed_title](fuchsia::web::NavigationState change) {
+      [this, &navigation_event_listener, &observed_url, &observed_title,
+       &use_legacy_observer_behavior](fuchsia::web::NavigationState change) {
         if (change.has_url()) {
           observed_url = change.url();
         }
@@ -128,7 +134,14 @@
           EXPECT_EQ(change.page_type(), fuchsia::web::PageType::NORMAL);
         }
 
-        if (!(observed_url.empty() || observed_title.empty())) {
+        if (change.has_is_main_document_loaded())
+          use_legacy_observer_behavior = false;
+
+        if ((use_legacy_observer_behavior &&
+             !(observed_url.empty() || observed_title.empty())) ||
+            (!use_legacy_observer_behavior &&
+             (change.has_is_main_document_loaded() &&
+              change.is_main_document_loaded()))) {
           navigation_event_listener.set_on_navigation_state_changed(nullptr);
           QuitLoop();
         }