OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_TEST_TEST_TAB_STRIP_MODEL_OBSERVER_H_ | 5 #ifndef CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ |
6 #define CHROME_TEST_TEST_TAB_STRIP_MODEL_OBSERVER_H_ | 6 #define CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "chrome/browser/tabs/tab_strip_model_observer.h" | |
11 #include "content/common/notification_observer.h" | 10 #include "content/common/notification_observer.h" |
12 #include "content/common/notification_registrar.h" | 11 #include "content/common/notification_registrar.h" |
13 | 12 |
14 class TabStripModel; | 13 class TabContentsWrapper; |
15 | 14 |
16 // In order to support testing of print preview, we need to wait for the tab to | 15 // In order to support testing of print preview, we need to wait for the tab to |
17 // be inserted, and then observe notifications on the newly added tab's | 16 // be inserted, and then observe notifications on the newly added tab's |
18 // controller to wait for it to be loaded. To support tests registering | 17 // controller to wait for it to be loaded. To support tests registering |
19 // javascript WebUI handlers, we need to inject the framework & registration | 18 // javascript WebUI handlers, we need to inject the framework & registration |
20 // javascript before the webui page loads by calling back through the | 19 // javascript before the webui page loads by calling back through the |
21 // TestTabStripModelObserver::LoadStartObserver when the new page starts | 20 // TestTabStripModelObserver::LoadStartObserver when the new page starts |
22 // loading. | 21 // loading. |
23 class TestTabStripModelObserver : public TabStripModelObserver, | 22 class TestNavigationObserver : public NotificationObserver { |
24 public NotificationObserver { | |
25 public: | 23 public: |
26 class LoadStartObserver { | 24 class LoadStartObserver { |
27 public: | 25 public: |
28 LoadStartObserver(); | 26 LoadStartObserver(); |
29 virtual ~LoadStartObserver(); | 27 virtual ~LoadStartObserver(); |
30 | 28 |
31 // Called to indicate page load starting. | 29 // Called to indicate page load starting. |
32 virtual void OnLoadStart() = 0; | 30 virtual void OnLoadStart() = 0; |
33 }; | 31 }; |
34 | 32 |
35 // Observe the |tab_strip_model|, which may not be NULL. If | 33 TestNavigationObserver(TabContentsWrapper* contents, |
36 // |load_start_observer| is non-NULL, notify when the page load starts. | 34 LoadStartObserver* load_start_observer); |
37 TestTabStripModelObserver(TabStripModel* tab_strip_model, | 35 |
38 LoadStartObserver* load_start_observer); | 36 virtual ~TestNavigationObserver(); |
39 virtual ~TestTabStripModelObserver(); | |
40 | 37 |
41 // Run the UI message loop until |done_| becomes true. | 38 // Run the UI message loop until |done_| becomes true. |
42 void WaitForObservation(); | 39 void WaitForObservation(); |
43 | 40 |
| 41 protected: |
| 42 explicit TestNavigationObserver(LoadStartObserver* load_start_observer); |
| 43 |
| 44 void RegisterAsObserver(TabContentsWrapper* contents); |
| 45 |
44 private: | 46 private: |
45 // TabStripModelObserver: | |
46 virtual void TabInsertedAt(TabContentsWrapper* contents, int index, | |
47 bool foreground) OVERRIDE; | |
48 | |
49 // NotificationObserver: | 47 // NotificationObserver: |
50 virtual void Observe(NotificationType type, const NotificationSource& source, | 48 virtual void Observe(NotificationType type, const NotificationSource& source, |
51 const NotificationDetails& details) OVERRIDE; | 49 const NotificationDetails& details) OVERRIDE; |
52 | 50 |
53 NotificationRegistrar registrar_; | 51 NotificationRegistrar registrar_; |
54 | 52 |
55 // If true the navigation has started. | 53 // If true the navigation has started. |
56 bool navigation_started_; | 54 bool navigation_started_; |
57 | 55 |
| 56 // If true the navigation has been committed. |
| 57 bool navigation_entry_committed_; |
| 58 |
58 // The number of navigations that have been completed. | 59 // The number of navigations that have been completed. |
59 int navigations_completed_; | 60 int navigations_completed_; |
60 | 61 |
61 // The number of navigations to wait for. | 62 // The number of navigations to wait for. |
62 int number_of_navigations_; | 63 int number_of_navigations_; |
63 | 64 |
64 // |tab_strip_model_| is the object this observes. The constructor will | |
65 // register this as an observer, and the destructor will remove the observer. | |
66 TabStripModel* tab_strip_model_; | |
67 | |
68 // Observer to take some action when the page load starts. | 65 // Observer to take some action when the page load starts. |
69 LoadStartObserver* load_start_observer_; | 66 LoadStartObserver* load_start_observer_; |
70 | 67 |
71 // |done_| will get set when this object observes a TabStripModel event. | 68 // |done_| will get set when this object observes a TabStripModel event. |
72 bool done_; | 69 bool done_; |
73 | 70 |
74 // |running_| will be true during WaitForObservation until |done_| is true. | 71 // |running_| will be true during WaitForObservation until |done_| is true. |
75 bool running_; | 72 bool running_; |
76 | 73 |
77 DISALLOW_COPY_AND_ASSIGN(TestTabStripModelObserver); | 74 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); |
78 }; | 75 }; |
79 | 76 |
80 #endif // CHROME_TEST_TEST_TAB_STRIP_MODEL_OBSERVER_H_ | 77 #endif // CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ |
OLD | NEW |