| 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 WEBKIT_TOOLS_TEST_SHELL_TEST_NAVIGATION_CONTROLLER_H_ | |
| 6 #define WEBKIT_TOOLS_TEST_SHELL_TEST_NAVIGATION_CONTROLLER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/string16.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | |
| 17 | |
| 18 class GURL; | |
| 19 class TestShell; | |
| 20 | |
| 21 // Associated with browser-initated navigations to hold tracking data. | |
| 22 class TestShellExtraData : public WebKit::WebDataSource::ExtraData { | |
| 23 public: | |
| 24 TestShellExtraData(int32 pending_page_id) | |
| 25 : pending_page_id(pending_page_id), | |
| 26 request_committed(false) { | |
| 27 } | |
| 28 | |
| 29 // Contains the page_id for this navigation or -1 if there is none yet. | |
| 30 int32 pending_page_id; | |
| 31 | |
| 32 // True if we have already processed the "DidCommitLoad" event for this | |
| 33 // request. Used by session history. | |
| 34 bool request_committed; | |
| 35 }; | |
| 36 | |
| 37 // Stores one back/forward navigation state for the test shell. | |
| 38 class TestNavigationEntry { | |
| 39 public: | |
| 40 TestNavigationEntry(); | |
| 41 TestNavigationEntry(int page_id, | |
| 42 const GURL& url, | |
| 43 const base::string16& target_frame); | |
| 44 | |
| 45 // Virtual to allow test_shell to extend the class. | |
| 46 ~TestNavigationEntry(); | |
| 47 | |
| 48 // Set / Get the URI | |
| 49 void SetURL(const GURL& url) { url_ = url; } | |
| 50 const GURL& GetURL() const { return url_; } | |
| 51 | |
| 52 // Set / Get opaque state. | |
| 53 // WARNING: This state is saved to the database and used to restore previous | |
| 54 // states. If you use write a custom TabContents and provide your own | |
| 55 // state make sure you have the ability to modify the format in the future | |
| 56 // while being able to deal with older versions. | |
| 57 void SetContentState(const std::string& state); | |
| 58 const std::string& GetContentState() const { return state_; } | |
| 59 | |
| 60 // Get the page id corresponding to the tab's state. | |
| 61 void SetPageID(int page_id) { page_id_ = page_id; } | |
| 62 int32 GetPageID() const { return page_id_; } | |
| 63 | |
| 64 const base::string16& GetTargetFrame() const { return target_frame_; } | |
| 65 | |
| 66 private: | |
| 67 // Describes the current page that the tab represents. This is not relevant | |
| 68 // for all tab contents types. | |
| 69 int32 page_id_; | |
| 70 | |
| 71 GURL url_; | |
| 72 std::string state_; | |
| 73 | |
| 74 base::string16 target_frame_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(TestNavigationEntry); | |
| 77 }; | |
| 78 | |
| 79 // Test shell's NavigationController. The goal is to be as close to the Chrome | |
| 80 // version as possible. | |
| 81 class TestNavigationController { | |
| 82 public: | |
| 83 TestNavigationController(TestShell* shell); | |
| 84 ~TestNavigationController(); | |
| 85 | |
| 86 void Reset(); | |
| 87 | |
| 88 // Causes the controller to reload the current (or pending) entry. | |
| 89 void Reload(); | |
| 90 | |
| 91 // Causes the controller to go to the specified offset from current. Does | |
| 92 // nothing if out of bounds. | |
| 93 void GoToOffset(int offset); | |
| 94 | |
| 95 // Causes the controller to go to the specified index. | |
| 96 void GoToIndex(int index); | |
| 97 | |
| 98 // Causes the controller to load the specified entry. The controller | |
| 99 // assumes ownership of the entry. | |
| 100 // NOTE: Do not pass an entry that the controller already owns! | |
| 101 void LoadEntry(TestNavigationEntry* entry); | |
| 102 | |
| 103 // Returns the last committed entry, which may be null if there are no | |
| 104 // committed entries. | |
| 105 TestNavigationEntry* GetLastCommittedEntry() const; | |
| 106 | |
| 107 // Returns the number of entries in the NavigationControllerBase, excluding | |
| 108 // the pending entry if there is one. | |
| 109 int GetEntryCount() const { | |
| 110 return static_cast<int>(entries_.size()); | |
| 111 } | |
| 112 | |
| 113 // Returns the active entry, which is the pending entry if a navigation is in | |
| 114 // progress or the last committed entry otherwise. NOTE: This can be NULL!! | |
| 115 // | |
| 116 // If you are trying to get the current state of the NavigationControllerBase, | |
| 117 // this is the method you will typically want to call. | |
| 118 TestNavigationEntry* GetActiveEntry() const; | |
| 119 | |
| 120 // Returns the index from which we would go back/forward or reload. This is | |
| 121 // the last_committed_entry_index_ if pending_entry_index_ is -1. Otherwise, | |
| 122 // it is the pending_entry_index_. | |
| 123 int GetCurrentEntryIndex() const; | |
| 124 | |
| 125 // Returns the entry at the specified index. Returns NULL if out of | |
| 126 // bounds. | |
| 127 TestNavigationEntry* GetEntryAtIndex(int index) const; | |
| 128 | |
| 129 // Return the entry with the corresponding type and page_id, or NULL if | |
| 130 // not found. | |
| 131 TestNavigationEntry* GetEntryWithPageID(int32 page_id) const; | |
| 132 | |
| 133 // Returns the index of the last committed entry. | |
| 134 int GetLastCommittedEntryIndex() const { | |
| 135 return last_committed_entry_index_; | |
| 136 } | |
| 137 | |
| 138 // Used to inform us of a navigation being committed for a tab. We will take | |
| 139 // ownership of the entry. Any entry located forward to the current entry will | |
| 140 // be deleted. The new entry becomes the current entry. | |
| 141 void DidNavigateToEntry(TestNavigationEntry* entry); | |
| 142 | |
| 143 // Used to inform us to discard its pending entry. | |
| 144 void DiscardPendingEntry(); | |
| 145 | |
| 146 private: | |
| 147 // Inserts an entry after the current position, removing all entries after it. | |
| 148 // The new entry will become the active one. | |
| 149 void InsertEntry(TestNavigationEntry* entry); | |
| 150 | |
| 151 int GetMaxPageID() const { return max_page_id_; } | |
| 152 void NavigateToPendingEntry(bool reload); | |
| 153 | |
| 154 // Return the index of the entry with the corresponding type and page_id, | |
| 155 // or -1 if not found. | |
| 156 int GetEntryIndexWithPageID(int32 page_id) const; | |
| 157 | |
| 158 // Updates the max page ID with that of the given entry, if is larger. | |
| 159 void UpdateMaxPageID(); | |
| 160 | |
| 161 // List of NavigationEntry for this tab | |
| 162 typedef std::vector< linked_ptr<TestNavigationEntry> > NavigationEntryList; | |
| 163 typedef NavigationEntryList::iterator NavigationEntryListIterator; | |
| 164 NavigationEntryList entries_; | |
| 165 | |
| 166 // An entry we haven't gotten a response for yet. This will be discarded | |
| 167 // when we navigate again. It's used only so we know what the currently | |
| 168 // displayed tab is. | |
| 169 TestNavigationEntry* pending_entry_; | |
| 170 | |
| 171 // currently visible entry | |
| 172 int last_committed_entry_index_; | |
| 173 | |
| 174 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a | |
| 175 // new entry (created by LoadURL). | |
| 176 int pending_entry_index_; | |
| 177 | |
| 178 TestShell* shell_; | |
| 179 int max_page_id_; | |
| 180 | |
| 181 DISALLOW_COPY_AND_ASSIGN(TestNavigationController); | |
| 182 }; | |
| 183 | |
| 184 #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_NAVIGATION_CONTROLLER_H_ | |
| OLD | NEW |