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

Unified Diff: chrome/test/test_navigation_observer.cc

Issue 7237030: Added options browser_tests using the generator and js handler framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TestNavigationController in ui_test_utils, renamed LoadStart->JsInjectionReady, reordered methods. Created 9 years, 5 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: 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();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698