Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/test/test_navigation_observer.h" | |
| 6 | |
| 7 #include "chrome/test/ui_test_utils.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 TestNavigationObserver::JsInjectionReadyObserver::JsInjectionReadyObserver() { | |
| 11 } | |
| 12 | |
| 13 TestNavigationObserver::JsInjectionReadyObserver::~JsInjectionReadyObserver() { | |
| 14 } | |
| 15 | |
| 16 TestNavigationObserver::TestNavigationObserver( | |
| 17 NavigationController* controller, | |
| 18 TestNavigationObserver::JsInjectionReadyObserver* | |
| 19 js_injection_ready_observer, | |
| 20 int number_of_navigations) | |
| 21 : navigation_started_(false), | |
| 22 navigation_entry_committed_(false), | |
| 23 navigations_completed_(0), | |
| 24 number_of_navigations_(number_of_navigations), | |
| 25 js_injection_ready_observer_(js_injection_ready_observer), | |
| 26 done_(false), | |
| 27 running_(false) { | |
| 28 RegisterAsObserver(controller); | |
| 29 } | |
| 30 | |
| 31 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.
| |
| 32 TestNavigationObserver::JsInjectionReadyObserver* | |
| 33 js_injection_ready_observer, | |
| 34 int number_of_navigations) | |
| 35 : navigation_started_(false), | |
| 36 navigations_completed_(0), | |
| 37 number_of_navigations_(number_of_navigations), | |
| 38 js_injection_ready_observer_(js_injection_ready_observer), | |
| 39 done_(false), | |
| 40 running_(false) { | |
| 41 } | |
| 42 | |
| 43 TestNavigationObserver::~TestNavigationObserver() { | |
| 44 } | |
| 45 | |
| 46 void TestNavigationObserver::RegisterAsObserver( | |
| 47 NavigationController* controller) { | |
| 48 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 49 Source<NavigationController>(controller)); | |
| 50 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | |
| 51 Source<NavigationController>(controller)); | |
| 52 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | |
| 53 Source<NavigationController>(controller)); | |
| 54 } | |
| 55 | |
| 56 void TestNavigationObserver::WaitForObservation() { | |
| 57 if (!done_) { | |
| 58 EXPECT_FALSE(running_); | |
| 59 running_ = true; | |
| 60 ui_test_utils::RunMessageLoop(); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void TestNavigationObserver::Observe( | |
| 65 int type, const NotificationSource& source, | |
| 66 const NotificationDetails& details) { | |
| 67 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.
| |
| 68 if (!navigation_entry_committed_ && js_injection_ready_observer_) | |
| 69 js_injection_ready_observer_->OnJsInjectionReady(); | |
| 70 navigation_started_ = true; | |
| 71 navigation_entry_committed_ = true; | |
| 72 } else if (type == content::NOTIFICATION_LOAD_START) { | |
| 73 navigation_started_ = true; | |
| 74 } else if (type == content::NOTIFICATION_LOAD_STOP) { | |
| 75 if (navigation_started_ && | |
| 76 ++navigations_completed_ == number_of_navigations_) { | |
| 77 navigation_started_ = false; | |
| 78 done_ = true; | |
| 79 if (running_) | |
| 80 MessageLoopForUI::current()->Quit(); | |
| 81 } | |
| 82 } | |
| 83 } | |
| OLD | NEW |