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 #ifndef CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ | |
| 6 #define CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "content/common/notification_observer.h" | |
| 11 #include "content/common/notification_registrar.h" | |
| 12 | |
| 13 class NavigationController; | |
| 14 | |
| 15 // In order to support testing of print preview, we need to wait for the tab to | |
| 16 // be inserted, and then observe notifications on the newly added tab's | |
| 17 // controller to wait for it to be loaded. To support tests registering | |
| 18 // javascript WebUI handlers, we need to inject the framework & registration | |
| 19 // javascript before the webui page loads by calling back through the | |
| 20 // TestTabStripModelObserver::LoadStartObserver when the new page starts | |
| 21 // loading. | |
| 22 class TestNavigationObserver : public NotificationObserver { | |
| 23 public: | |
| 24 class JsInjectionReadyObserver { | |
| 25 public: | |
| 26 JsInjectionReadyObserver(); | |
| 27 virtual ~JsInjectionReadyObserver(); | |
| 28 | |
| 29 // Called to indicate page entry committed and ready for javascript | |
| 30 // injection. | |
| 31 virtual void OnJsInjectionReady() = 0; | |
| 32 }; | |
| 33 | |
| 34 // Create and register a new TestNavigationObserver against the | |
| 35 // |controller|. When |js_injection_ready_observer| is non-null, notify with | |
| 36 // OnEntryCommitted() after |number_of_navigations| navigations. | |
| 37 // Note: |js_injection_ready_observer| is owned by the caller and should be | |
| 38 // valid until this class is destroyed. | |
| 39 TestNavigationObserver(NavigationController* controller, | |
| 40 JsInjectionReadyObserver* js_injection_ready_observer, | |
| 41 int number_of_navigations); | |
| 42 | |
| 43 virtual ~TestNavigationObserver(); | |
| 44 | |
| 45 // Run the UI message loop until |done_| becomes true. | |
| 46 void WaitForObservation(); | |
| 47 | |
| 48 protected: | |
| 49 // Note: |js_injection_ready_observer| is owned by the caller and should be | |
| 50 // valid until this class is destroyed. | |
|
sky
2011/07/11 22:47:42
You should document that subclasses must explicitl
Sheridan Rawlins
2011/07/12 04:37:49
Done.
| |
| 51 explicit TestNavigationObserver( | |
| 52 JsInjectionReadyObserver* js_injection_ready_observer, | |
| 53 int number_of_navigations); | |
| 54 | |
| 55 // Register this TestNavigationObserver as an observer of the |controller|. | |
| 56 void RegisterAsObserver(NavigationController* controller); | |
| 57 | |
| 58 private: | |
| 59 // NotificationObserver: | |
| 60 virtual void Observe(int type, const NotificationSource& source, | |
| 61 const NotificationDetails& details) OVERRIDE; | |
| 62 | |
| 63 NotificationRegistrar registrar_; | |
| 64 | |
| 65 // If true the navigation has started. | |
| 66 bool navigation_started_; | |
| 67 | |
| 68 // If true the navigation has been committed. | |
| 69 bool navigation_entry_committed_; | |
| 70 | |
| 71 // The number of navigations that have been completed. | |
| 72 int navigations_completed_; | |
| 73 | |
| 74 // The number of navigations to wait for. | |
| 75 int number_of_navigations_; | |
| 76 | |
| 77 // Observer to take some action when the page is ready for javascript | |
| 78 // injection. | |
| 79 JsInjectionReadyObserver* js_injection_ready_observer_; | |
| 80 | |
| 81 // |done_| will get set when this object observes a TabStripModel event. | |
| 82 bool done_; | |
| 83 | |
| 84 // |running_| will be true during WaitForObservation until |done_| is true. | |
| 85 bool running_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); | |
| 88 }; | |
| 89 | |
| 90 #endif // CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ | |
| OLD | NEW |