Index: chrome/test/test_navigation_observer.cc |
diff --git a/chrome/test/test_tab_strip_model_observer.cc b/chrome/test/test_navigation_observer.cc |
similarity index 54% |
copy from chrome/test/test_tab_strip_model_observer.cc |
copy to chrome/test/test_navigation_observer.cc |
index 41a2f7124eb09b2a3b695bcb4a8b29cf48e6fcab..5c959f8ee8f5e0553aadd9b85e587cfa45b98404 100644 |
--- a/chrome/test/test_tab_strip_model_observer.cc |
+++ b/chrome/test/test_navigation_observer.cc |
@@ -2,46 +2,45 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/test/test_tab_strip_model_observer.h" |
+#include "chrome/test/test_navigation_observer.h" |
-#include "chrome/browser/tabs/tab_strip_model.h" |
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
#include "chrome/test/ui_test_utils.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-TestTabStripModelObserver::LoadStartObserver::LoadStartObserver() { |
+TestNavigationObserver::LoadStartObserver::LoadStartObserver() { |
} |
-TestTabStripModelObserver::LoadStartObserver::~LoadStartObserver() { |
+TestNavigationObserver::LoadStartObserver::~LoadStartObserver() { |
} |
-TestTabStripModelObserver::TestTabStripModelObserver( |
- TabStripModel* tab_strip_model, |
- TestTabStripModelObserver::LoadStartObserver* load_start_observer) |
+TestNavigationObserver::TestNavigationObserver( |
+ TabContentsWrapper* contents, |
+ TestNavigationObserver::LoadStartObserver* load_start_observer) |
: navigation_started_(false), |
+ navigation_entry_committed_(false), |
navigations_completed_(0), |
number_of_navigations_(1), |
- tab_strip_model_(tab_strip_model), |
load_start_observer_(load_start_observer), |
done_(false), |
running_(false) { |
- tab_strip_model_->AddObserver(this); |
+ RegisterAsObserver(contents); |
} |
-TestTabStripModelObserver::~TestTabStripModelObserver() { |
- tab_strip_model_->RemoveObserver(this); |
+TestNavigationObserver::TestNavigationObserver( |
+ TestNavigationObserver::LoadStartObserver* load_start_observer) |
+ : navigation_started_(false), |
+ navigations_completed_(0), |
+ number_of_navigations_(1), |
+ load_start_observer_(load_start_observer), |
+ done_(false), |
+ running_(false) { |
} |
-void TestTabStripModelObserver::WaitForObservation() { |
- if (!done_) { |
- EXPECT_FALSE(running_); |
- running_ = true; |
- ui_test_utils::RunMessageLoop(); |
- } |
+TestNavigationObserver::~TestNavigationObserver() { |
} |
-void TestTabStripModelObserver::TabInsertedAt( |
- TabContentsWrapper* contents, int index, bool foreground) { |
+void TestNavigationObserver::RegisterAsObserver(TabContentsWrapper* contents) { |
NavigationController* controller = &contents->controller(); |
registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
Source<NavigationController>(controller)); |
@@ -51,15 +50,24 @@ void TestTabStripModelObserver::TabInsertedAt( |
Source<NavigationController>(controller)); |
} |
-void TestTabStripModelObserver::Observe( |
+void TestNavigationObserver::WaitForObservation() { |
+ if (!done_) { |
+ EXPECT_FALSE(running_); |
+ running_ = true; |
+ ui_test_utils::RunMessageLoop(); |
+ } |
+} |
+ |
+void TestNavigationObserver::Observe( |
NotificationType type, const NotificationSource& source, |
const NotificationDetails& details) { |
- if (type == NotificationType::NAV_ENTRY_COMMITTED || |
- type == NotificationType::LOAD_START) { |
- if (!navigation_started_) { |
+ if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
+ if (!navigation_entry_committed_ && load_start_observer_) |
load_start_observer_->OnLoadStart(); |
- navigation_started_ = true; |
- } |
+ navigation_started_ = true; |
+ navigation_entry_committed_ = true; |
+ } else if (type == NotificationType::LOAD_START) { |
+ navigation_started_ = true; |
} else if (type == NotificationType::LOAD_STOP) { |
if (navigation_started_ && |
++navigations_completed_ == number_of_navigations_) { |