Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/sessions/session_service_unittest.cc

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/defaults.h" 16 #include "chrome/browser/defaults.h"
17 #include "chrome/browser/sessions/session_backend.h" 17 #include "chrome/browser/sessions/session_backend.h"
18 #include "chrome/browser/sessions/session_service.h" 18 #include "chrome/browser/sessions/session_service.h"
19 #include "chrome/browser/sessions/session_service_test_helper.h" 19 #include "chrome/browser/sessions/session_service_test_helper.h"
20 #include "chrome/browser/sessions/session_types.h" 20 #include "chrome/browser/sessions/session_types.h"
21 #include "chrome/browser/sessions/session_types_test_helper.h"
21 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/test/base/browser_with_test_window_test.h" 24 #include "chrome/test/base/browser_with_test_window_test.h"
24 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
25 #include "content/public/browser/navigation_entry.h" 26 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/notification_observer.h" 27 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_registrar.h" 28 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 70
70 virtual void TearDown() { 71 virtual void TearDown() {
71 helper_.set_service(NULL); 72 helper_.set_service(NULL);
72 BrowserWithTestWindowTest::TearDown(); 73 BrowserWithTestWindowTest::TearDown();
73 } 74 }
74 75
75 void UpdateNavigation(const SessionID& window_id, 76 void UpdateNavigation(const SessionID& window_id,
76 const SessionID& tab_id, 77 const SessionID& tab_id,
77 const TabNavigation& navigation, 78 const TabNavigation& navigation,
78 int index,
79 bool select) { 79 bool select) {
80 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); 80 service()->UpdateTabNavigation(window_id, tab_id, navigation);
81 entry->SetURL(navigation.virtual_url()); 81 if (select) {
82 entry->SetReferrer(navigation.referrer()); 82 service()->SetSelectedNavigationIndex(
83 entry->SetTitle(navigation.title()); 83 window_id, tab_id, navigation.index());
84 entry->SetContentState(navigation.state()); 84 }
85 entry->SetTransitionType(navigation.transition());
86 entry->SetHasPostData(
87 navigation.type_mask() & TabNavigation::HAS_POST_DATA);
88 entry->SetOriginalRequestURL(navigation.original_request_url());
89 entry->SetIsOverridingUserAgent(navigation.is_overriding_user_agent());
90 service()->UpdateTabNavigation(window_id, tab_id, index, *entry.get());
91 if (select)
92 service()->SetSelectedNavigationIndex(window_id, tab_id, index);
93 } 85 }
94 86
95 void ReadWindows(std::vector<SessionWindow*>* windows) { 87 void ReadWindows(std::vector<SessionWindow*>* windows) {
96 // Forces closing the file. 88 // Forces closing the file.
97 helper_.set_service(NULL); 89 helper_.set_service(NULL);
98 90
99 SessionService* session_service = new SessionService(path_); 91 SessionService* session_service = new SessionService(path_);
100 helper_.set_service(session_service); 92 helper_.set_service(session_service);
101 helper_.ReadWindows(windows); 93 helper_.ReadWindows(windows);
102 } 94 }
103 95
104 // Configures the session service with one window with one tab and a single 96 // Configures the session service with one window with one tab and a single
105 // navigation. If |pinned_state| is true or |write_always| is true, the 97 // navigation. If |pinned_state| is true or |write_always| is true, the
106 // pinned state of the tab is updated. The session service is then recreated 98 // pinned state of the tab is updated. The session service is then recreated
107 // and the pinned state of the read back tab is returned. 99 // and the pinned state of the read back tab is returned.
108 bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) { 100 bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) {
109 SessionID tab_id; 101 SessionID tab_id;
110 TabNavigation nav1(0, GURL("http://google.com"), 102 TabNavigation nav1 =
111 content::Referrer(GURL("http://www.referrer.com"), 103 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
112 WebKit::WebReferrerPolicyDefault),
113 ASCIIToUTF16("abc"), "def",
114 content::PAGE_TRANSITION_QUALIFIER_MASK);
115 104
116 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 105 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
117 UpdateNavigation(window_id, tab_id, nav1, 0, true); 106 UpdateNavigation(window_id, tab_id, nav1, true);
118 107
119 if (pinned_state || write_always) 108 if (pinned_state || write_always)
120 helper_.service()->SetPinnedState(window_id, tab_id, pinned_state); 109 helper_.service()->SetPinnedState(window_id, tab_id, pinned_state);
121 110
122 ScopedVector<SessionWindow> windows; 111 ScopedVector<SessionWindow> windows;
123 ReadWindows(&(windows.get())); 112 ReadWindows(&(windows.get()));
124 113
125 EXPECT_EQ(1U, windows.size()); 114 EXPECT_EQ(1U, windows.size());
126 if (HasFatalFailure()) 115 if (HasFatalFailure())
127 return false; 116 return false;
(...skipping 21 matching lines...) Expand all
149 ScopedTempDir temp_dir_; 138 ScopedTempDir temp_dir_;
150 FilePath path_; 139 FilePath path_;
151 140
152 SessionServiceTestHelper helper_; 141 SessionServiceTestHelper helper_;
153 }; 142 };
154 143
155 TEST_F(SessionServiceTest, Basic) { 144 TEST_F(SessionServiceTest, Basic) {
156 SessionID tab_id; 145 SessionID tab_id;
157 ASSERT_NE(window_id.id(), tab_id.id()); 146 ASSERT_NE(window_id.id(), tab_id.id());
158 147
159 TabNavigation nav1(0, GURL("http://google.com"), 148 TabNavigation nav1 =
160 content::Referrer(GURL("http://www.referrer.com"), 149 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
161 WebKit::WebReferrerPolicyDefault), 150 SessionTypesTestHelper::SetOriginalRequestURL(
162 ASCIIToUTF16("abc"), "def", 151 &nav1, GURL("http://original.request.com"));
163 content::PAGE_TRANSITION_QUALIFIER_MASK);
164 nav1.set_original_request_url(GURL("http://original.request.com"));
165 152
166 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 153 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
167 UpdateNavigation(window_id, tab_id, nav1, 0, true); 154 UpdateNavigation(window_id, tab_id, nav1, true);
168 155
169 ScopedVector<SessionWindow> windows; 156 ScopedVector<SessionWindow> windows;
170 ReadWindows(&(windows.get())); 157 ReadWindows(&(windows.get()));
171 158
172 ASSERT_EQ(1U, windows.size()); 159 ASSERT_EQ(1U, windows.size());
173 ASSERT_TRUE(window_bounds == windows[0]->bounds); 160 ASSERT_TRUE(window_bounds == windows[0]->bounds);
174 ASSERT_EQ(0, windows[0]->selected_tab_index); 161 ASSERT_EQ(0, windows[0]->selected_tab_index);
175 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 162 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
176 ASSERT_EQ(1U, windows[0]->tabs.size()); 163 ASSERT_EQ(1U, windows[0]->tabs.size());
177 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); 164 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type);
178 165
179 SessionTab* tab = windows[0]->tabs[0]; 166 SessionTab* tab = windows[0]->tabs[0];
180 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 167 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
181 168
182 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 169 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
183 } 170 }
184 171
185 // Make sure we persist post entries. 172 // Make sure we persist post entries.
186 TEST_F(SessionServiceTest, PersistPostData) { 173 TEST_F(SessionServiceTest, PersistPostData) {
187 SessionID tab_id; 174 SessionID tab_id;
188 ASSERT_NE(window_id.id(), tab_id.id()); 175 ASSERT_NE(window_id.id(), tab_id.id());
189 176
190 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 177 TabNavigation nav1 =
191 ASCIIToUTF16("abc"), std::string(), 178 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
192 content::PAGE_TRANSITION_QUALIFIER_MASK); 179 SessionTypesTestHelper::SetHasPostData(&nav1, true);
193 nav1.set_type_mask(TabNavigation::HAS_POST_DATA);
194 180
195 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 181 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
196 UpdateNavigation(window_id, tab_id, nav1, 0, true); 182 UpdateNavigation(window_id, tab_id, nav1, true);
197 183
198 ScopedVector<SessionWindow> windows; 184 ScopedVector<SessionWindow> windows;
199 ReadWindows(&(windows.get())); 185 ReadWindows(&(windows.get()));
200 186
201 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); 187 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1);
202 } 188 }
203 189
204 TEST_F(SessionServiceTest, ClosingTabStaysClosed) { 190 TEST_F(SessionServiceTest, ClosingTabStaysClosed) {
205 SessionID tab_id; 191 SessionID tab_id;
206 SessionID tab2_id; 192 SessionID tab2_id;
207 ASSERT_NE(tab_id.id(), tab2_id.id()); 193 ASSERT_NE(tab_id.id(), tab2_id.id());
208 194
209 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 195 TabNavigation nav1 =
210 ASCIIToUTF16("abc"), "def", 196 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
211 content::PAGE_TRANSITION_QUALIFIER_MASK); 197 TabNavigation nav2 =
212 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 198 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
213 ASCIIToUTF16("abcd"), "defg",
214 content::PAGE_TRANSITION_AUTO_BOOKMARK);
215 199
216 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 200 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
217 UpdateNavigation(window_id, tab_id, nav1, 0, true); 201 UpdateNavigation(window_id, tab_id, nav1, true);
218 202
219 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); 203 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false);
220 UpdateNavigation(window_id, tab2_id, nav2, 0, true); 204 UpdateNavigation(window_id, tab2_id, nav2, true);
221 service()->TabClosed(window_id, tab2_id, false); 205 service()->TabClosed(window_id, tab2_id, false);
222 206
223 ScopedVector<SessionWindow> windows; 207 ScopedVector<SessionWindow> windows;
224 ReadWindows(&(windows.get())); 208 ReadWindows(&(windows.get()));
225 209
226 ASSERT_EQ(1U, windows.size()); 210 ASSERT_EQ(1U, windows.size());
227 ASSERT_EQ(0, windows[0]->selected_tab_index); 211 ASSERT_EQ(0, windows[0]->selected_tab_index);
228 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 212 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
229 ASSERT_EQ(1U, windows[0]->tabs.size()); 213 ASSERT_EQ(1U, windows[0]->tabs.size());
230 214
231 SessionTab* tab = windows[0]->tabs[0]; 215 SessionTab* tab = windows[0]->tabs[0];
232 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 216 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
233 217
234 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 218 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
235 } 219 }
236 220
237 TEST_F(SessionServiceTest, Pruning) { 221 TEST_F(SessionServiceTest, Pruning) {
238 SessionID tab_id; 222 SessionID tab_id;
239 223
240 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 224 TabNavigation nav1 =
241 ASCIIToUTF16("abc"), "def", 225 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
242 content::PAGE_TRANSITION_QUALIFIER_MASK); 226 TabNavigation nav2 =
243 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 227 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
244 ASCIIToUTF16("abcd"), "defg",
245 content::PAGE_TRANSITION_AUTO_BOOKMARK);
246 228
247 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 229 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
248 for (int i = 0; i < 6; ++i) { 230 for (int i = 0; i < 6; ++i) {
249 TabNavigation& nav = (i % 2) == 0 ? nav1 : nav2; 231 TabNavigation* nav = (i % 2) == 0 ? &nav1 : &nav2;
250 UpdateNavigation(window_id, tab_id, nav, i, true); 232 nav->set_index(i);
233 UpdateNavigation(window_id, tab_id, *nav, true);
251 } 234 }
252 service()->TabNavigationPathPrunedFromBack(window_id, tab_id, 3); 235 service()->TabNavigationPathPrunedFromBack(window_id, tab_id, 3);
253 236
254 ScopedVector<SessionWindow> windows; 237 ScopedVector<SessionWindow> windows;
255 ReadWindows(&(windows.get())); 238 ReadWindows(&(windows.get()));
256 239
257 ASSERT_EQ(1U, windows.size()); 240 ASSERT_EQ(1U, windows.size());
258 ASSERT_EQ(0, windows[0]->selected_tab_index); 241 ASSERT_EQ(0, windows[0]->selected_tab_index);
259 ASSERT_EQ(1U, windows[0]->tabs.size()); 242 ASSERT_EQ(1U, windows[0]->tabs.size());
260 243
261 SessionTab* tab = windows[0]->tabs[0]; 244 SessionTab* tab = windows[0]->tabs[0];
262 // We left the selected index at 5, then pruned. When rereading the 245 // We left the selected index at 5, then pruned. When rereading the
263 // index should get reset to last valid navigation, which is 2. 246 // index should get reset to last valid navigation, which is 2.
264 helper_.AssertTabEquals(window_id, tab_id, 0, 2, 3, *tab); 247 helper_.AssertTabEquals(window_id, tab_id, 0, 2, 3, *tab);
265 248
249 ASSERT_EQ(3u, tab->navigations.size());
266 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 250 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
267 helper_.AssertNavigationEquals(nav2, tab->navigations[1]); 251 helper_.AssertNavigationEquals(nav2, tab->navigations[1]);
268 helper_.AssertNavigationEquals(nav1, tab->navigations[2]); 252 helper_.AssertNavigationEquals(nav1, tab->navigations[2]);
269 } 253 }
270 254
271 TEST_F(SessionServiceTest, TwoWindows) { 255 TEST_F(SessionServiceTest, TwoWindows) {
272 SessionID window2_id; 256 SessionID window2_id;
273 SessionID tab1_id; 257 SessionID tab1_id;
274 SessionID tab2_id; 258 SessionID tab2_id;
275 259
276 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 260 TabNavigation nav1 =
277 ASCIIToUTF16("abc"), "def", 261 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
278 content::PAGE_TRANSITION_QUALIFIER_MASK); 262 TabNavigation nav2 =
279 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 263 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
280 ASCIIToUTF16("abcd"), "defg",
281 content::PAGE_TRANSITION_AUTO_BOOKMARK);
282 264
283 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 265 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
284 UpdateNavigation(window_id, tab1_id, nav1, 0, true); 266 UpdateNavigation(window_id, tab1_id, nav1, true);
285 267
286 const gfx::Rect window2_bounds(3, 4, 5, 6); 268 const gfx::Rect window2_bounds(3, 4, 5, 6);
287 service()->SetWindowType( 269 service()->SetWindowType(
288 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 270 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
289 service()->SetWindowBounds(window2_id, 271 service()->SetWindowBounds(window2_id,
290 window2_bounds, 272 window2_bounds,
291 ui::SHOW_STATE_MAXIMIZED); 273 ui::SHOW_STATE_MAXIMIZED);
292 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 274 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
293 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 275 UpdateNavigation(window2_id, tab2_id, nav2, true);
294 276
295 ScopedVector<SessionWindow> windows; 277 ScopedVector<SessionWindow> windows;
296 ReadWindows(&(windows.get())); 278 ReadWindows(&(windows.get()));
297 279
298 ASSERT_EQ(2U, windows.size()); 280 ASSERT_EQ(2U, windows.size());
299 ASSERT_EQ(0, windows[0]->selected_tab_index); 281 ASSERT_EQ(0, windows[0]->selected_tab_index);
300 ASSERT_EQ(0, windows[1]->selected_tab_index); 282 ASSERT_EQ(0, windows[1]->selected_tab_index);
301 ASSERT_EQ(1U, windows[0]->tabs.size()); 283 ASSERT_EQ(1U, windows[0]->tabs.size());
302 ASSERT_EQ(1U, windows[1]->tabs.size()); 284 ASSERT_EQ(1U, windows[1]->tabs.size());
303 285
(...skipping 20 matching lines...) Expand all
324 tab = rt2; 306 tab = rt2;
325 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); 307 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
326 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 308 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
327 } 309 }
328 310
329 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { 311 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) {
330 SessionID window2_id; 312 SessionID window2_id;
331 SessionID tab1_id; 313 SessionID tab1_id;
332 SessionID tab2_id; 314 SessionID tab2_id;
333 315
334 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 316 TabNavigation nav1 =
335 ASCIIToUTF16("abc"), "def", 317 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
336 content::PAGE_TRANSITION_QUALIFIER_MASK);
337 318
338 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 319 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
339 UpdateNavigation(window_id, tab1_id, nav1, 0, true); 320 UpdateNavigation(window_id, tab1_id, nav1, true);
340 321
341 const gfx::Rect window2_bounds(3, 4, 5, 6); 322 const gfx::Rect window2_bounds(3, 4, 5, 6);
342 service()->SetWindowType( 323 service()->SetWindowType(
343 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 324 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
344 service()->SetWindowBounds(window2_id, 325 service()->SetWindowBounds(window2_id,
345 window2_bounds, 326 window2_bounds,
346 ui::SHOW_STATE_NORMAL); 327 ui::SHOW_STATE_NORMAL);
347 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 328 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
348 329
349 ScopedVector<SessionWindow> windows; 330 ScopedVector<SessionWindow> windows;
350 ReadWindows(&(windows.get())); 331 ReadWindows(&(windows.get()));
351 332
352 ASSERT_EQ(1U, windows.size()); 333 ASSERT_EQ(1U, windows.size());
353 ASSERT_EQ(0, windows[0]->selected_tab_index); 334 ASSERT_EQ(0, windows[0]->selected_tab_index);
354 ASSERT_EQ(1U, windows[0]->tabs.size()); 335 ASSERT_EQ(1U, windows[0]->tabs.size());
355 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 336 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
356 337
357 SessionTab* tab = windows[0]->tabs[0]; 338 SessionTab* tab = windows[0]->tabs[0];
358 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab); 339 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab);
359 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 340 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
360 } 341 }
361 342
362 TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { 343 TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) {
363 SessionID tab_id; 344 SessionID tab_id;
364 SessionID tab2_id; 345 SessionID tab2_id;
365 ASSERT_NE(tab_id.id(), tab2_id.id()); 346 ASSERT_NE(tab_id.id(), tab2_id.id());
366 347
367 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 348 TabNavigation nav1 =
368 ASCIIToUTF16("abc"), "def", 349 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
369 content::PAGE_TRANSITION_QUALIFIER_MASK); 350 TabNavigation nav2 =
370 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 351 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
371 ASCIIToUTF16("abcd"), "defg",
372 content::PAGE_TRANSITION_AUTO_BOOKMARK);
373 352
374 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 353 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
375 UpdateNavigation(window_id, tab_id, nav1, 0, true); 354 UpdateNavigation(window_id, tab_id, nav1, true);
376 355
377 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); 356 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false);
378 UpdateNavigation(window_id, tab2_id, nav2, 0, true); 357 UpdateNavigation(window_id, tab2_id, nav2, true);
379 358
380 service()->WindowClosing(window_id); 359 service()->WindowClosing(window_id);
381 360
382 ScopedVector<SessionWindow> windows; 361 ScopedVector<SessionWindow> windows;
383 ReadWindows(&(windows.get())); 362 ReadWindows(&(windows.get()));
384 363
385 ASSERT_EQ(1U, windows.size()); 364 ASSERT_EQ(1U, windows.size());
386 ASSERT_EQ(0, windows[0]->selected_tab_index); 365 ASSERT_EQ(0, windows[0]->selected_tab_index);
387 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 366 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
388 ASSERT_EQ(2U, windows[0]->tabs.size()); 367 ASSERT_EQ(2U, windows[0]->tabs.size());
(...skipping 12 matching lines...) Expand all
401 SessionID tab_id; 380 SessionID tab_id;
402 SessionID tab2_id; 381 SessionID tab2_id;
403 ASSERT_NE(window2_id.id(), window_id.id()); 382 ASSERT_NE(window2_id.id(), window_id.id());
404 383
405 service()->SetWindowType( 384 service()->SetWindowType(
406 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 385 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
407 service()->SetWindowBounds(window2_id, 386 service()->SetWindowBounds(window2_id,
408 window_bounds, 387 window_bounds,
409 ui::SHOW_STATE_NORMAL); 388 ui::SHOW_STATE_NORMAL);
410 389
411 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 390 TabNavigation nav1 =
412 ASCIIToUTF16("abc"), "def", 391 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
413 content::PAGE_TRANSITION_QUALIFIER_MASK); 392 TabNavigation nav2 =
414 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 393 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
415 ASCIIToUTF16("abcd"), "defg",
416 content::PAGE_TRANSITION_AUTO_BOOKMARK);
417 394
418 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 395 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
419 UpdateNavigation(window_id, tab_id, nav1, 0, true); 396 UpdateNavigation(window_id, tab_id, nav1, true);
420 397
421 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); 398 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
422 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 399 UpdateNavigation(window2_id, tab2_id, nav2, true);
423 400
424 service()->WindowClosing(window2_id); 401 service()->WindowClosing(window2_id);
425 service()->TabClosed(window2_id, tab2_id, false); 402 service()->TabClosed(window2_id, tab2_id, false);
426 service()->WindowClosed(window2_id); 403 service()->WindowClosed(window2_id);
427 404
428 ScopedVector<SessionWindow> windows; 405 ScopedVector<SessionWindow> windows;
429 ReadWindows(&(windows.get())); 406 ReadWindows(&(windows.get()));
430 407
431 ASSERT_EQ(1U, windows.size()); 408 ASSERT_EQ(1U, windows.size());
432 ASSERT_EQ(0, windows[0]->selected_tab_index); 409 ASSERT_EQ(0, windows[0]->selected_tab_index);
(...skipping 14 matching lines...) Expand all
447 SessionID tab_id; 424 SessionID tab_id;
448 SessionID tab2_id; 425 SessionID tab2_id;
449 ASSERT_NE(window2_id.id(), window_id.id()); 426 ASSERT_NE(window2_id.id(), window_id.id());
450 427
451 service()->SetWindowType( 428 service()->SetWindowType(
452 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); 429 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL);
453 service()->SetWindowBounds(window2_id, 430 service()->SetWindowBounds(window2_id,
454 window_bounds, 431 window_bounds,
455 ui::SHOW_STATE_NORMAL); 432 ui::SHOW_STATE_NORMAL);
456 433
457 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 434 TabNavigation nav1 =
458 ASCIIToUTF16("abc"), "def", 435 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
459 content::PAGE_TRANSITION_QUALIFIER_MASK); 436 TabNavigation nav2 =
460 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 437 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
461 ASCIIToUTF16("abcd"), "defg",
462 content::PAGE_TRANSITION_AUTO_BOOKMARK);
463 438
464 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 439 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
465 UpdateNavigation(window_id, tab_id, nav1, 0, true); 440 UpdateNavigation(window_id, tab_id, nav1, true);
466 441
467 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); 442 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
468 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 443 UpdateNavigation(window2_id, tab2_id, nav2, true);
469 444
470 ScopedVector<SessionWindow> windows; 445 ScopedVector<SessionWindow> windows;
471 ReadWindows(&(windows.get())); 446 ReadWindows(&(windows.get()));
472 447
473 ASSERT_EQ(1U, windows.size()); 448 ASSERT_EQ(1U, windows.size());
474 ASSERT_EQ(0, windows[0]->selected_tab_index); 449 ASSERT_EQ(0, windows[0]->selected_tab_index);
475 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 450 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
476 ASSERT_EQ(1U, windows[0]->tabs.size()); 451 ASSERT_EQ(1U, windows[0]->tabs.size());
477 452
478 SessionTab* tab = windows[0]->tabs[0]; 453 SessionTab* tab = windows[0]->tabs[0];
(...skipping 10 matching lines...) Expand all
489 SessionID tab_id; 464 SessionID tab_id;
490 SessionID tab2_id; 465 SessionID tab2_id;
491 ASSERT_NE(window2_id.id(), window_id.id()); 466 ASSERT_NE(window2_id.id(), window_id.id());
492 467
493 service()->SetWindowType( 468 service()->SetWindowType(
494 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); 469 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL);
495 service()->SetWindowBounds(window2_id, 470 service()->SetWindowBounds(window2_id,
496 window_bounds, 471 window_bounds,
497 ui::SHOW_STATE_NORMAL); 472 ui::SHOW_STATE_NORMAL);
498 473
499 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 474 TabNavigation nav1 =
500 ASCIIToUTF16("abc"), "def", 475 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
501 content::PAGE_TRANSITION_QUALIFIER_MASK); 476 TabNavigation nav2 =
502 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 477 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
503 ASCIIToUTF16("abcd"), "defg",
504 content::PAGE_TRANSITION_AUTO_BOOKMARK);
505 478
506 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 479 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
507 UpdateNavigation(window_id, tab_id, nav1, 0, true); 480 UpdateNavigation(window_id, tab_id, nav1, true);
508 481
509 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); 482 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
510 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 483 UpdateNavigation(window2_id, tab2_id, nav2, true);
511 484
512 ScopedVector<SessionWindow> windows; 485 ScopedVector<SessionWindow> windows;
513 ReadWindows(&(windows.get())); 486 ReadWindows(&(windows.get()));
514 487
515 ASSERT_EQ(2U, windows.size()); 488 ASSERT_EQ(2U, windows.size());
516 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? 489 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ?
517 0 : 1; 490 0 : 1;
518 int popup_index = tabbed_index == 0 ? 1 : 0; 491 int popup_index = tabbed_index == 0 ? 1 : 0;
519 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); 492 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
520 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); 493 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id());
(...skipping 20 matching lines...) Expand all
541 SessionID tab2_id; 514 SessionID tab2_id;
542 ASSERT_NE(window2_id.id(), window_id.id()); 515 ASSERT_NE(window2_id.id(), window_id.id());
543 516
544 service()->SetWindowType( 517 service()->SetWindowType(
545 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP); 518 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP);
546 service()->SetWindowBounds(window2_id, 519 service()->SetWindowBounds(window2_id,
547 window_bounds, 520 window_bounds,
548 ui::SHOW_STATE_NORMAL); 521 ui::SHOW_STATE_NORMAL);
549 service()->SetWindowAppName(window2_id, "TestApp"); 522 service()->SetWindowAppName(window2_id, "TestApp");
550 523
551 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 524 TabNavigation nav1 =
552 ASCIIToUTF16("abc"), "def", 525 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
553 content::PAGE_TRANSITION_QUALIFIER_MASK); 526 TabNavigation nav2 =
554 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 527 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd");
555 ASCIIToUTF16("abcd"), "defg",
556 content::PAGE_TRANSITION_AUTO_BOOKMARK);
557 528
558 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 529 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
559 UpdateNavigation(window_id, tab_id, nav1, 0, true); 530 UpdateNavigation(window_id, tab_id, nav1, true);
560 531
561 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); 532 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
562 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 533 UpdateNavigation(window2_id, tab2_id, nav2, true);
563 534
564 ScopedVector<SessionWindow> windows; 535 ScopedVector<SessionWindow> windows;
565 ReadWindows(&(windows.get())); 536 ReadWindows(&(windows.get()));
566 537
567 ASSERT_EQ(2U, windows.size()); 538 ASSERT_EQ(2U, windows.size());
568 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? 539 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ?
569 0 : 1; 540 0 : 1;
570 int app_index = tabbed_index == 0 ? 1 : 0; 541 int app_index = tabbed_index == 0 ? 1 : 0;
571 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); 542 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
572 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); 543 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id());
(...skipping 17 matching lines...) Expand all
590 561
591 // Tests pruning from the front. 562 // Tests pruning from the front.
592 TEST_F(SessionServiceTest, PruneFromFront) { 563 TEST_F(SessionServiceTest, PruneFromFront) {
593 const std::string base_url("http://google.com/"); 564 const std::string base_url("http://google.com/");
594 SessionID tab_id; 565 SessionID tab_id;
595 566
596 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 567 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
597 568
598 // Add 5 navigations, with the 4th selected. 569 // Add 5 navigations, with the 4th selected.
599 for (int i = 0; i < 5; ++i) { 570 for (int i = 0; i < 5; ++i) {
600 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), 571 TabNavigation nav =
601 content::Referrer(), 572 SessionTypesTestHelper::CreateNavigation(
602 ASCIIToUTF16("a"), "b", 573 base_url + base::IntToString(i), "a");
603 content::PAGE_TRANSITION_QUALIFIER_MASK); 574 nav.set_index(i);
604 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); 575 UpdateNavigation(window_id, tab_id, nav, (i == 3));
605 } 576 }
606 577
607 // Prune the first two navigations from the front. 578 // Prune the first two navigations from the front.
608 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); 579 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2);
609 580
610 // Read back in. 581 // Read back in.
611 ScopedVector<SessionWindow> windows; 582 ScopedVector<SessionWindow> windows;
612 ReadWindows(&(windows.get())); 583 ReadWindows(&(windows.get()));
613 584
614 ASSERT_EQ(1U, windows.size()); 585 ASSERT_EQ(1U, windows.size());
(...skipping 18 matching lines...) Expand all
633 604
634 // Prunes from front so that we have no entries. 605 // Prunes from front so that we have no entries.
635 TEST_F(SessionServiceTest, PruneToEmpty) { 606 TEST_F(SessionServiceTest, PruneToEmpty) {
636 const std::string base_url("http://google.com/"); 607 const std::string base_url("http://google.com/");
637 SessionID tab_id; 608 SessionID tab_id;
638 609
639 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 610 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
640 611
641 // Add 5 navigations, with the 4th selected. 612 // Add 5 navigations, with the 4th selected.
642 for (int i = 0; i < 5; ++i) { 613 for (int i = 0; i < 5; ++i) {
643 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), 614 TabNavigation nav =
644 content::Referrer(), 615 SessionTypesTestHelper::CreateNavigation(
645 ASCIIToUTF16("a"), "b", 616 base_url + base::IntToString(i), "a");
646 content::PAGE_TRANSITION_QUALIFIER_MASK); 617 nav.set_index(i);
647 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); 618 UpdateNavigation(window_id, tab_id, nav, (i == 3));
648 } 619 }
649 620
650 // Prune the first two navigations from the front. 621 // Prune the first two navigations from the front.
651 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); 622 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5);
652 623
653 // Read back in. 624 // Read back in.
654 ScopedVector<SessionWindow> windows; 625 ScopedVector<SessionWindow> windows;
655 ReadWindows(&(windows.get())); 626 ReadWindows(&(windows.get()));
656 627
657 ASSERT_EQ(0U, windows.size()); 628 ASSERT_EQ(0U, windows.size());
(...skipping 13 matching lines...) Expand all
671 TEST_F(SessionServiceTest, PinnedTrue) { 642 TEST_F(SessionServiceTest, PinnedTrue) {
672 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); 643 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true));
673 } 644 }
674 645
675 // Make sure application extension ids are persisted. 646 // Make sure application extension ids are persisted.
676 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { 647 TEST_F(SessionServiceTest, PersistApplicationExtensionID) {
677 SessionID tab_id; 648 SessionID tab_id;
678 ASSERT_NE(window_id.id(), tab_id.id()); 649 ASSERT_NE(window_id.id(), tab_id.id());
679 std::string app_id("foo"); 650 std::string app_id("foo");
680 651
681 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 652 TabNavigation nav1 =
682 ASCIIToUTF16("abc"), std::string(), 653 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
683 content::PAGE_TRANSITION_QUALIFIER_MASK);
684 654
685 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 655 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
686 UpdateNavigation(window_id, tab_id, nav1, 0, true); 656 UpdateNavigation(window_id, tab_id, nav1, true);
687 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); 657 helper_.SetTabExtensionAppID(window_id, tab_id, app_id);
688 658
689 ScopedVector<SessionWindow> windows; 659 ScopedVector<SessionWindow> windows;
690 ReadWindows(&(windows.get())); 660 ReadWindows(&(windows.get()));
691 661
692 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); 662 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1);
693 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); 663 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id);
694 } 664 }
695 665
696 // Check that user agent overrides are persisted. 666 // Check that user agent overrides are persisted.
697 TEST_F(SessionServiceTest, PersistUserAgentOverrides) { 667 TEST_F(SessionServiceTest, PersistUserAgentOverrides) {
698 SessionID tab_id; 668 SessionID tab_id;
699 ASSERT_NE(window_id.id(), tab_id.id()); 669 ASSERT_NE(window_id.id(), tab_id.id());
700 std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) " 670 std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) "
701 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 " 671 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 "
702 "Safari/535.19"; 672 "Safari/535.19";
703 673
704 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 674 TabNavigation nav1 =
705 ASCIIToUTF16("abc"), std::string(), 675 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
706 content::PAGE_TRANSITION_QUALIFIER_MASK); 676 SessionTypesTestHelper::SetIsOverridingUserAgent(&nav1, true);
707 nav1.set_is_overriding_user_agent(true);
708 677
709 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 678 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
710 UpdateNavigation(window_id, tab_id, nav1, 0, true); 679 UpdateNavigation(window_id, tab_id, nav1, true);
711 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override); 680 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override);
712 681
713 ScopedVector<SessionWindow> windows; 682 ScopedVector<SessionWindow> windows;
714 ReadWindows(&(windows.get())); 683 ReadWindows(&(windows.get()));
715 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); 684 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1);
716 685
717 SessionTab* tab = windows[0]->tabs[0]; 686 SessionTab* tab = windows[0]->tabs[0];
718 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 687 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
719 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 688 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
720 EXPECT_TRUE(user_agent_override == tab->user_agent_override); 689 EXPECT_TRUE(user_agent_override == tab->user_agent_override);
721 } 690 }
722 691
723 // Test that the notification for SESSION_SERVICE_SAVED is working properly. 692 // Test that the notification for SESSION_SERVICE_SAVED is working properly.
724 TEST_F(SessionServiceTest, SavedSessionNotification) { 693 TEST_F(SessionServiceTest, SavedSessionNotification) {
725 content::NotificationRegistrar registrar_; 694 content::NotificationRegistrar registrar_;
726 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 695 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
727 content::NotificationService::AllSources()); 696 content::NotificationService::AllSources());
728 service()->Save(); 697 service()->Save();
729 EXPECT_EQ(sync_save_count_, 1); 698 EXPECT_EQ(sync_save_count_, 1);
730 } 699 }
731 700
732 // Makes sure a tab closed by a user gesture is not restored. 701 // Makes sure a tab closed by a user gesture is not restored.
733 TEST_F(SessionServiceTest, CloseTabUserGesture) { 702 TEST_F(SessionServiceTest, CloseTabUserGesture) {
734 SessionID tab_id; 703 SessionID tab_id;
735 ASSERT_NE(window_id.id(), tab_id.id()); 704 ASSERT_NE(window_id.id(), tab_id.id());
736 705
737 TabNavigation nav1(0, GURL("http://google.com"), 706 TabNavigation nav1 =
738 content::Referrer(GURL("http://www.referrer.com"), 707 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
739 WebKit::WebReferrerPolicyDefault),
740 ASCIIToUTF16("abc"), "def",
741 content::PAGE_TRANSITION_QUALIFIER_MASK);
742 708
743 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 709 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
744 UpdateNavigation(window_id, tab_id, nav1, 0, true); 710 UpdateNavigation(window_id, tab_id, nav1, true);
745 service()->TabClosed(window_id, tab_id, true); 711 service()->TabClosed(window_id, tab_id, true);
746 712
747 ScopedVector<SessionWindow> windows; 713 ScopedVector<SessionWindow> windows;
748 ReadWindows(&(windows.get())); 714 ReadWindows(&(windows.get()));
749 715
750 ASSERT_TRUE(windows.empty()); 716 ASSERT_TRUE(windows.empty());
751 } 717 }
752 718
753 // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL. 719 // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL.
754 TEST_F(SessionServiceTest, DontPersistDefault) { 720 TEST_F(SessionServiceTest, DontPersistDefault) {
755 SessionID tab_id; 721 SessionID tab_id;
756 ASSERT_NE(window_id.id(), tab_id.id()); 722 ASSERT_NE(window_id.id(), tab_id.id());
757 TabNavigation nav1(0, GURL("http://google.com"), 723 TabNavigation nav1 =
758 content::Referrer(GURL("http://www.referrer.com"), 724 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc");
759 WebKit::WebReferrerPolicyDefault),
760 ASCIIToUTF16("abc"), "def",
761 content::PAGE_TRANSITION_QUALIFIER_MASK);
762 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 725 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
763 UpdateNavigation(window_id, tab_id, nav1, 0, true); 726 UpdateNavigation(window_id, tab_id, nav1, true);
764 service()->SetWindowBounds(window_id, 727 service()->SetWindowBounds(window_id,
765 window_bounds, 728 window_bounds,
766 ui::SHOW_STATE_DEFAULT); 729 ui::SHOW_STATE_DEFAULT);
767 730
768 ScopedVector<SessionWindow> windows; 731 ScopedVector<SessionWindow> windows;
769 ReadWindows(&(windows.get())); 732 ReadWindows(&(windows.get()));
770 ASSERT_EQ(1U, windows.size()); 733 ASSERT_EQ(1U, windows.size());
771 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state); 734 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state);
772 } 735 }
773 736
774 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { 737 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) {
775 SessionID tab_id; 738 SessionID tab_id;
776 ASSERT_NE(window_id.id(), tab_id.id()); 739 ASSERT_NE(window_id.id(), tab_id.id());
777 740
778 // Create a content state representing a HTTP body without posted passwords. 741 // Create a content state representing a HTTP body without posted passwords.
779 WebKit::WebHTTPBody http_body; 742 WebKit::WebHTTPBody http_body;
780 http_body.initialize(); 743 http_body.initialize();
781 const char char_data[] = "data"; 744 const char char_data[] = "data";
782 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); 745 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1));
783 WebKit::WebHistoryItem history_item; 746 WebKit::WebHistoryItem history_item;
784 history_item.initialize(); 747 history_item.initialize();
785 history_item.setHTTPBody(http_body); 748 history_item.setHTTPBody(http_body);
786 std::string content_state = webkit_glue::HistoryItemToString(history_item); 749 std::string content_state = webkit_glue::HistoryItemToString(history_item);
787 750
788 // Create a TabNavigation containing content_state and representing a POST 751 // Create a TabNavigation containing content_state and representing a POST
789 // request. 752 // request.
790 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 753 TabNavigation nav1 =
791 ASCIIToUTF16("title"), content_state, 754 SessionTypesTestHelper::CreateNavigation("http://google.com", "title");
792 content::PAGE_TRANSITION_QUALIFIER_MASK); 755 SessionTypesTestHelper::SetContentState(&nav1, content_state);
793 nav1.set_type_mask(TabNavigation::HAS_POST_DATA); 756 SessionTypesTestHelper::SetHasPostData(&nav1, true);
794 757
795 // Create a TabNavigation containing content_state and representing a normal 758 // Create a TabNavigation containing content_state and representing a normal
796 // request. 759 // request.
797 TabNavigation nav2(0, GURL("http://google.com/nopost"), content::Referrer(), 760 TabNavigation nav2 =
798 ASCIIToUTF16("title"), content_state, 761 SessionTypesTestHelper::CreateNavigation(
799 content::PAGE_TRANSITION_QUALIFIER_MASK); 762 "http://google.com/nopost", "title");
763 SessionTypesTestHelper::SetContentState(&nav2, content_state);
764 nav2.set_index(1);
800 765
801 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 766 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
802 UpdateNavigation(window_id, tab_id, nav1, 0, true); 767 UpdateNavigation(window_id, tab_id, nav1, true);
803 UpdateNavigation(window_id, tab_id, nav2, 1, true); 768 UpdateNavigation(window_id, tab_id, nav2, true);
804 769
805 ScopedVector<SessionWindow> windows; 770 ScopedVector<SessionWindow> windows;
806 ReadWindows(&(windows.get())); 771 ReadWindows(&(windows.get()));
807 772
808 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); 773 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2);
809 774
810 // Expected: the content state of both navigations was saved and restored. 775 // Expected: the content state of both navigations was saved and restored.
776 ASSERT_EQ(2u, windows[0]->tabs[0]->navigations.size());
811 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]); 777 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]);
812 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]); 778 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]);
813 } 779 }
814 780
815 TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { 781 TEST_F(SessionServiceTest, RemovePostDataWithPasswords) {
816 SessionID tab_id; 782 SessionID tab_id;
817 ASSERT_NE(window_id.id(), tab_id.id()); 783 ASSERT_NE(window_id.id(), tab_id.id());
818 784
819 // Create a content state representing a HTTP body with posted passwords. 785 // Create a content state representing a HTTP body with posted passwords.
820 WebKit::WebHTTPBody http_body; 786 WebKit::WebHTTPBody http_body;
821 http_body.initialize(); 787 http_body.initialize();
822 const char char_data[] = "data"; 788 const char char_data[] = "data";
823 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); 789 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1));
824 http_body.setContainsPasswordData(true); 790 http_body.setContainsPasswordData(true);
825 WebKit::WebHistoryItem history_item; 791 WebKit::WebHistoryItem history_item;
826 history_item.initialize(); 792 history_item.initialize();
827 history_item.setHTTPBody(http_body); 793 history_item.setHTTPBody(http_body);
828 std::string content_state = webkit_glue::HistoryItemToString(history_item); 794 std::string content_state = webkit_glue::HistoryItemToString(history_item);
829 795
830 // Create a TabNavigation containing content_state and representing a POST 796 // Create a TabNavigation containing content_state and representing a POST
831 // request with passwords. 797 // request with passwords.
832 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 798 TabNavigation nav1 =
833 ASCIIToUTF16("title"), content_state, 799 SessionTypesTestHelper::CreateNavigation("http://google.com", "title");
834 content::PAGE_TRANSITION_QUALIFIER_MASK); 800 SessionTypesTestHelper::SetContentState(&nav1, content_state);
835 nav1.set_type_mask(TabNavigation::HAS_POST_DATA); 801 SessionTypesTestHelper::SetHasPostData(&nav1, true);
836 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 802 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
837 UpdateNavigation(window_id, tab_id, nav1, 0, true); 803 UpdateNavigation(window_id, tab_id, nav1, true);
838 804
839 ScopedVector<SessionWindow> windows; 805 ScopedVector<SessionWindow> windows;
840 ReadWindows(&(windows.get())); 806 ReadWindows(&(windows.get()));
841 807
842 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); 808 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1);
843 809
844 // Expected: the HTTP body was removed from the content state of the POST 810 // Expected: the HTTP body was removed from the content state of the POST
845 // navigation with passwords. 811 // navigation with passwords.
846 EXPECT_NE(content_state, windows[0]->tabs[0]->navigations[0].state()); 812 EXPECT_NE(content_state, windows[0]->tabs[0]->navigations[0].content_state());
847 } 813 }
848 814
849 // This test is only applicable to chromeos. 815 // This test is only applicable to chromeos.
850 #if defined(OS_CHROMEOS) 816 #if defined(OS_CHROMEOS)
851 // Verifies migration of tab/window closed works. 817 // Verifies migration of tab/window closed works.
852 TEST_F(SessionServiceTest, CanOpenV1TabClosed) { 818 TEST_F(SessionServiceTest, CanOpenV1TabClosed) {
853 FilePath v1_file_path; 819 FilePath v1_file_path;
854 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path)); 820 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path));
855 // v1_session_file contains a tab closed command with the original id. The 821 // v1_session_file contains a tab closed command with the original id. The
856 // file was generated from ClosingTabStaysClosed. If we successfully processed 822 // file was generated from ClosingTabStaysClosed. If we successfully processed
857 // the file we'll have one tab. 823 // the file we'll have one tab.
858 v1_file_path = 824 v1_file_path =
859 v1_file_path.AppendASCII("sessions").AppendASCII("v1_session_file"); 825 v1_file_path.AppendASCII("sessions").AppendASCII("v1_session_file");
860 FilePath dest_file_path(path_); 826 FilePath dest_file_path(path_);
861 dest_file_path = dest_file_path.AppendASCII("Current Session"); 827 dest_file_path = dest_file_path.AppendASCII("Current Session");
862 828
863 // Forces closing the file. 829 // Forces closing the file.
864 helper_.set_service(NULL); 830 helper_.set_service(NULL);
865 831
866 ASSERT_TRUE(file_util::CopyFile(v1_file_path, dest_file_path)); 832 ASSERT_TRUE(file_util::CopyFile(v1_file_path, dest_file_path));
867 833
868 SessionService* session_service = new SessionService(path_); 834 SessionService* session_service = new SessionService(path_);
869 helper_.set_service(session_service); 835 helper_.set_service(session_service);
870 ScopedVector<SessionWindow> windows; 836 ScopedVector<SessionWindow> windows;
871 helper_.ReadWindows(&(windows.get())); 837 helper_.ReadWindows(&(windows.get()));
872 ASSERT_EQ(1u, windows.size()); 838 ASSERT_EQ(1u, windows.size());
873 EXPECT_EQ(1u, windows[0]->tabs.size()); 839 EXPECT_EQ(1u, windows[0]->tabs.size());
874 } 840 }
875 #endif 841 #endif
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service_test_helper.cc ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698