1 /* |
|
2 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 #ifndef TestNavigationController_h |
|
32 #define TestNavigationController_h |
|
33 |
|
34 #include "base/basictypes.h" |
|
35 #include "base/linked_ptr.h" |
|
36 #include "public/WebDataSource.h" |
|
37 #include "public/WebHistoryItem.h" |
|
38 #include "public/WebString.h" |
|
39 #include "public/WebURL.h" |
|
40 #include <string> |
|
41 #include <wtf/Vector.h> |
|
42 |
|
43 // Associated with browser-initated navigations to hold tracking data. |
|
44 class TestShellExtraData : public WebKit::WebDataSource::ExtraData { |
|
45 public: |
|
46 TestShellExtraData(int32_t pendingPageID) |
|
47 : pendingPageID(pendingPageID) |
|
48 , requestCommitted(false) {} |
|
49 |
|
50 // Contains the page_id for this navigation or -1 if there is none yet. |
|
51 int32_t pendingPageID; |
|
52 |
|
53 // True if we have already processed the "DidCommitLoad" event for this |
|
54 // request. Used by session history. |
|
55 bool requestCommitted; |
|
56 }; |
|
57 |
|
58 // Stores one back/forward navigation state for the test shell. |
|
59 class TestNavigationEntry: public Noncopyable { |
|
60 public: |
|
61 TestNavigationEntry(); |
|
62 TestNavigationEntry(int pageID, |
|
63 const WebKit::WebURL&, |
|
64 const WebKit::WebString& title, |
|
65 const WebKit::WebString& targetFrame); |
|
66 |
|
67 // Virtual to allow test_shell to extend the class. |
|
68 ~TestNavigationEntry(); |
|
69 |
|
70 // Set / Get the URI |
|
71 void setURL(const WebKit::WebURL& url) { m_url = url; } |
|
72 const WebKit::WebURL& URL() const { return m_url; } |
|
73 |
|
74 // Set / Get the title |
|
75 void setTitle(const WebKit::WebString& title) { m_title = title; } |
|
76 const WebKit::WebString& title() const { return m_title; } |
|
77 |
|
78 // Set / Get a state. |
|
79 void setContentState(const WebKit::WebHistoryItem&); |
|
80 const WebKit::WebHistoryItem& contentState() const { return m_state; } |
|
81 |
|
82 // Get the page id corresponding to the tab's state. |
|
83 void setPageID(int pageID) { m_pageID = pageID; } |
|
84 int32_t pageID() const { return m_pageID; } |
|
85 |
|
86 const WebKit::WebString& targetFrame() const { return m_targetFrame; } |
|
87 |
|
88 private: |
|
89 // Describes the current page that the tab represents. This is not relevant |
|
90 // for all tab contents types. |
|
91 int32_t m_pageID; |
|
92 |
|
93 WebKit::WebURL m_url; |
|
94 WebKit::WebString m_title; |
|
95 WebKit::WebHistoryItem m_state; |
|
96 WebKit::WebString m_targetFrame; |
|
97 }; |
|
98 |
|
99 class NavigationHost { |
|
100 public: |
|
101 virtual bool navigate(const TestNavigationEntry&, bool reload) = 0; |
|
102 }; |
|
103 |
|
104 // Test shell's NavigationController. The goal is to be as close to the Chrome |
|
105 // version as possible. |
|
106 class TestNavigationController: public Noncopyable { |
|
107 public: |
|
108 TestNavigationController(NavigationHost*); |
|
109 ~TestNavigationController(); |
|
110 |
|
111 void reset(); |
|
112 |
|
113 // Causes the controller to reload the current (or pending) entry. |
|
114 void reload(); |
|
115 |
|
116 // Causes the controller to go to the specified offset from current. Does |
|
117 // nothing if out of bounds. |
|
118 void goToOffset(int); |
|
119 |
|
120 // Causes the controller to go to the specified index. |
|
121 void goToIndex(int); |
|
122 |
|
123 // Causes the controller to load the specified entry. The controller |
|
124 // assumes ownership of the entry. |
|
125 // NOTE: Do not pass an entry that the controller already owns! |
|
126 void loadEntry(TestNavigationEntry*); |
|
127 |
|
128 // Returns the last committed entry, which may be null if there are no |
|
129 // committed entries. |
|
130 TestNavigationEntry* lastCommittedEntry() const; |
|
131 |
|
132 // Returns the number of entries in the NavigationControllerBase, excluding |
|
133 // the pending entry if there is one. |
|
134 int entryCount() const { return static_cast<int>(m_entries.size()); } |
|
135 |
|
136 // Returns the active entry, which is the pending entry if a navigation is in |
|
137 // progress or the last committed entry otherwise. NOTE: This can be 0!! |
|
138 // |
|
139 // If you are trying to get the current state of the NavigationControllerBase, |
|
140 // this is the method you will typically want to call. |
|
141 TestNavigationEntry* activeEntry() const; |
|
142 |
|
143 // Returns the index from which we would go back/forward or reload. This is |
|
144 // the m_lastCommittedEntryIndex if m_pendingEntryIndex is -1. Otherwise, |
|
145 // it is the m_pendingEntryIndex. |
|
146 int currentEntryIndex() const; |
|
147 |
|
148 // Returns the entry at the specified index. Returns 0 if out of |
|
149 // bounds. |
|
150 TestNavigationEntry* entryAtIndex(int) const; |
|
151 |
|
152 // Return the entry with the corresponding type and page ID, or 0 if |
|
153 // not found. |
|
154 TestNavigationEntry* entryWithPageID(int32_t) const; |
|
155 |
|
156 // Returns the index of the last committed entry. |
|
157 int lastCommittedEntryIndex() const { return m_lastCommittedEntryIndex; } |
|
158 |
|
159 // Used to inform us of a navigation being committed for a tab. We will take |
|
160 // ownership of the entry. Any entry located forward to the current entry will |
|
161 // be deleted. The new entry becomes the current entry. |
|
162 void didNavigateToEntry(TestNavigationEntry*); |
|
163 |
|
164 // Used to inform us to discard its pending entry. |
|
165 void discardPendingEntry(); |
|
166 |
|
167 private: |
|
168 // Inserts an entry after the current position, removing all entries after it. |
|
169 // The new entry will become the active one. |
|
170 void insertEntry(TestNavigationEntry*); |
|
171 |
|
172 int maxPageID() const { return m_maxPageID; } |
|
173 void navigateToPendingEntry(bool reload); |
|
174 |
|
175 // Return the index of the entry with the corresponding type and page ID, |
|
176 // or -1 if not found. |
|
177 int entryIndexWithPageID(int32_t) const; |
|
178 |
|
179 // Updates the max page ID with that of the given entry, if is larger. |
|
180 void updateMaxPageID(); |
|
181 |
|
182 // List of NavigationEntry for this tab |
|
183 typedef Vector<linked_ptr<TestNavigationEntry> > NavigationEntryList; |
|
184 typedef NavigationEntryList::iterator NavigationEntryListIterator; |
|
185 NavigationEntryList m_entries; |
|
186 |
|
187 // An entry we haven't gotten a response for yet. This will be discarded |
|
188 // when we navigate again. It's used only so we know what the currently |
|
189 // displayed tab is. |
|
190 TestNavigationEntry* m_pendingEntry; |
|
191 |
|
192 // currently visible entry |
|
193 int m_lastCommittedEntryIndex; |
|
194 |
|
195 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a |
|
196 // new entry (created by LoadURL). |
|
197 int m_pendingEntryIndex; |
|
198 |
|
199 NavigationHost* m_host; |
|
200 int m_maxPageID; |
|
201 }; |
|
202 |
|
203 #endif // TestNavigationController_h |
|
204 |
|