Index: chrome/test/test_navigation_observer.cc |
diff --git a/chrome/test/test_navigation_observer.cc b/chrome/test/test_navigation_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b7bcc74790eaebf541b2123995865f5ba2638b27 |
--- /dev/null |
+++ b/chrome/test/test_navigation_observer.cc |
@@ -0,0 +1,83 @@ |
+// Copyright (c) 2011 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 "chrome/test/test_navigation_observer.h" |
+ |
+#include "chrome/test/ui_test_utils.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+TestNavigationObserver::JsInjectionReadyObserver::JsInjectionReadyObserver() { |
+} |
+ |
+TestNavigationObserver::JsInjectionReadyObserver::~JsInjectionReadyObserver() { |
+} |
+ |
+TestNavigationObserver::TestNavigationObserver( |
+ NavigationController* controller, |
+ TestNavigationObserver::JsInjectionReadyObserver* |
+ js_injection_ready_observer, |
+ int number_of_navigations) |
+ : navigation_started_(false), |
+ navigation_entry_committed_(false), |
+ navigations_completed_(0), |
+ number_of_navigations_(number_of_navigations), |
+ js_injection_ready_observer_(js_injection_ready_observer), |
+ done_(false), |
+ running_(false) { |
+ RegisterAsObserver(controller); |
+} |
+ |
+TestNavigationObserver::TestNavigationObserver( |
sky
2011/07/11 22:47:42
nit: order of methods doesn't match header.
Sheridan Rawlins
2011/07/12 04:37:49
Done.
|
+ TestNavigationObserver::JsInjectionReadyObserver* |
+ js_injection_ready_observer, |
+ int number_of_navigations) |
+ : navigation_started_(false), |
+ navigations_completed_(0), |
+ number_of_navigations_(number_of_navigations), |
+ js_injection_ready_observer_(js_injection_ready_observer), |
+ done_(false), |
+ running_(false) { |
+} |
+ |
+TestNavigationObserver::~TestNavigationObserver() { |
+} |
+ |
+void TestNavigationObserver::RegisterAsObserver( |
+ NavigationController* controller) { |
+ registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
+ Source<NavigationController>(controller)); |
+ registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
+ Source<NavigationController>(controller)); |
+ registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
+ Source<NavigationController>(controller)); |
+} |
+ |
+void TestNavigationObserver::WaitForObservation() { |
+ if (!done_) { |
+ EXPECT_FALSE(running_); |
+ running_ = true; |
+ ui_test_utils::RunMessageLoop(); |
+ } |
+} |
+ |
+void TestNavigationObserver::Observe( |
+ int type, const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
sky
2011/07/11 22:47:42
nit: looks like it's time for a switch here.
Sheridan Rawlins
2011/07/12 04:37:49
Done.
|
+ if (!navigation_entry_committed_ && js_injection_ready_observer_) |
+ js_injection_ready_observer_->OnJsInjectionReady(); |
+ navigation_started_ = true; |
+ navigation_entry_committed_ = true; |
+ } else if (type == content::NOTIFICATION_LOAD_START) { |
+ navigation_started_ = true; |
+ } else if (type == content::NOTIFICATION_LOAD_STOP) { |
+ if (navigation_started_ && |
+ ++navigations_completed_ == number_of_navigations_) { |
+ navigation_started_ = false; |
+ done_ = true; |
+ if (running_) |
+ MessageLoopForUI::current()->Quit(); |
+ } |
+ } |
+} |