OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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 #include "chrome/browser/back_forward_menu_model.h" | |
6 | |
7 #include "base/path_service.h" | |
8 #include "base/string_util.h" | |
9 #include "base/utf_string_conversions.h" | |
10 #include "chrome/browser/profile_manager.h" | |
11 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | |
12 #include "chrome/browser/tab_contents/navigation_controller.h" | |
13 #include "chrome/browser/tab_contents/navigation_entry.h" | |
14 #include "chrome/browser/tab_contents/tab_contents.h" | |
15 #include "chrome/browser/tab_contents/test_tab_contents.h" | |
16 #include "chrome/common/url_constants.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
19 class BackFwdMenuModelTest : public RenderViewHostTestHarness { | |
20 public: | |
21 void ValidateModel(BackForwardMenuModel* model, int history_items, | |
22 int chapter_stops) { | |
23 int h = std::min(BackForwardMenuModel::kMaxHistoryItems, history_items); | |
24 int c = std::min(BackForwardMenuModel::kMaxChapterStops, chapter_stops); | |
25 EXPECT_EQ(h, model->GetHistoryItemCount()); | |
26 EXPECT_EQ(c, model->GetChapterStopCount(h)); | |
27 if (h > 0) | |
28 h += 2; // Separator and View History link. | |
29 if (c > 0) | |
30 ++c; | |
31 EXPECT_EQ(h + c, model->GetItemCount()); | |
32 } | |
33 | |
34 void LoadURLAndUpdateState(const char* url, const char* title) { | |
35 NavigateAndCommit(GURL(url)); | |
36 controller().GetLastCommittedEntry()->set_title(UTF8ToUTF16(title)); | |
37 } | |
38 | |
39 // Navigate back or forward the given amount and commits the entry (which | |
40 // will be pending after we ask to navigate there). | |
41 void NavigateToOffset(int offset) { | |
42 controller().GoToOffset(offset); | |
43 contents()->CommitPendingNavigation(); | |
44 } | |
45 | |
46 // Same as NavigateToOffset but goes to an absolute index. | |
47 void NavigateToIndex(int index) { | |
48 controller().GoToIndex(index); | |
49 contents()->CommitPendingNavigation(); | |
50 } | |
51 | |
52 // Goes back/forward and commits the load. | |
53 void GoBack() { | |
54 controller().GoBack(); | |
55 contents()->CommitPendingNavigation(); | |
56 } | |
57 void GoForward() { | |
58 controller().GoForward(); | |
59 contents()->CommitPendingNavigation(); | |
60 } | |
61 }; | |
62 | |
63 TEST_F(BackFwdMenuModelTest, BasicCase) { | |
64 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( | |
65 NULL, BackForwardMenuModel::BACKWARD_MENU)); | |
66 back_model->set_test_tab_contents(contents()); | |
67 | |
68 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel( | |
69 NULL, BackForwardMenuModel::FORWARD_MENU)); | |
70 forward_model->set_test_tab_contents(contents()); | |
71 | |
72 EXPECT_EQ(0, back_model->GetItemCount()); | |
73 EXPECT_EQ(0, forward_model->GetItemCount()); | |
74 EXPECT_FALSE(back_model->ItemHasCommand(1)); | |
75 | |
76 // Seed the controller with a few URLs | |
77 LoadURLAndUpdateState("http://www.a.com/1", "A1"); | |
78 LoadURLAndUpdateState("http://www.a.com/2", "A2"); | |
79 LoadURLAndUpdateState("http://www.a.com/3", "A3"); | |
80 LoadURLAndUpdateState("http://www.b.com/1", "B1"); | |
81 LoadURLAndUpdateState("http://www.b.com/2", "B2"); | |
82 LoadURLAndUpdateState("http://www.c.com/1", "C1"); | |
83 LoadURLAndUpdateState("http://www.c.com/2", "C2"); | |
84 LoadURLAndUpdateState("http://www.c.com/3", "C3"); | |
85 | |
86 // There're two more items here: a separator and a "Show Full History". | |
87 EXPECT_EQ(9, back_model->GetItemCount()); | |
88 EXPECT_EQ(0, forward_model->GetItemCount()); | |
89 EXPECT_EQ(ASCIIToUTF16("C2"), back_model->GetLabelAt(0)); | |
90 EXPECT_EQ(ASCIIToUTF16("A1"), back_model->GetLabelAt(6)); | |
91 EXPECT_EQ(back_model->GetShowFullHistoryLabel(), | |
92 back_model->GetLabelAt(8)); | |
93 | |
94 EXPECT_TRUE(back_model->ItemHasCommand(0)); | |
95 EXPECT_TRUE(back_model->ItemHasCommand(6)); | |
96 EXPECT_TRUE(back_model->IsSeparator(7)); | |
97 EXPECT_TRUE(back_model->ItemHasCommand(8)); | |
98 EXPECT_FALSE(back_model->ItemHasCommand(9)); | |
99 EXPECT_FALSE(back_model->ItemHasCommand(9)); | |
100 | |
101 NavigateToOffset(-7); | |
102 | |
103 EXPECT_EQ(0, back_model->GetItemCount()); | |
104 EXPECT_EQ(9, forward_model->GetItemCount()); | |
105 EXPECT_EQ(ASCIIToUTF16("A2"), forward_model->GetLabelAt(0)); | |
106 EXPECT_EQ(ASCIIToUTF16("C3"), forward_model->GetLabelAt(6)); | |
107 EXPECT_EQ(forward_model->GetShowFullHistoryLabel(), | |
108 forward_model->GetLabelAt(8)); | |
109 | |
110 EXPECT_TRUE(forward_model->ItemHasCommand(0)); | |
111 EXPECT_TRUE(forward_model->ItemHasCommand(6)); | |
112 EXPECT_TRUE(forward_model->IsSeparator(7)); | |
113 EXPECT_TRUE(forward_model->ItemHasCommand(8)); | |
114 EXPECT_FALSE(forward_model->ItemHasCommand(7)); | |
115 EXPECT_FALSE(forward_model->ItemHasCommand(9)); | |
116 | |
117 NavigateToOffset(4); | |
118 | |
119 EXPECT_EQ(6, back_model->GetItemCount()); | |
120 EXPECT_EQ(5, forward_model->GetItemCount()); | |
121 EXPECT_EQ(ASCIIToUTF16("B1"), back_model->GetLabelAt(0)); | |
122 EXPECT_EQ(ASCIIToUTF16("A1"), back_model->GetLabelAt(3)); | |
123 EXPECT_EQ(back_model->GetShowFullHistoryLabel(), | |
124 back_model->GetLabelAt(5)); | |
125 EXPECT_EQ(ASCIIToUTF16("C1"), forward_model->GetLabelAt(0)); | |
126 EXPECT_EQ(ASCIIToUTF16("C3"), forward_model->GetLabelAt(2)); | |
127 EXPECT_EQ(forward_model->GetShowFullHistoryLabel(), | |
128 forward_model->GetLabelAt(4)); | |
129 } | |
130 | |
131 TEST_F(BackFwdMenuModelTest, MaxItemsTest) { | |
132 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( | |
133 NULL, BackForwardMenuModel::BACKWARD_MENU)); | |
134 back_model->set_test_tab_contents(contents()); | |
135 | |
136 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel( | |
137 NULL, BackForwardMenuModel::FORWARD_MENU)); | |
138 forward_model->set_test_tab_contents(contents()); | |
139 | |
140 // Seed the controller with 32 URLs | |
141 LoadURLAndUpdateState("http://www.a.com/1", "A1"); | |
142 LoadURLAndUpdateState("http://www.a.com/2", "A2"); | |
143 LoadURLAndUpdateState("http://www.a.com/3", "A3"); | |
144 LoadURLAndUpdateState("http://www.b.com/1", "B1"); | |
145 LoadURLAndUpdateState("http://www.b.com/2", "B2"); | |
146 LoadURLAndUpdateState("http://www.b.com/3", "B3"); | |
147 LoadURLAndUpdateState("http://www.c.com/1", "C1"); | |
148 LoadURLAndUpdateState("http://www.c.com/2", "C2"); | |
149 LoadURLAndUpdateState("http://www.c.com/3", "C3"); | |
150 LoadURLAndUpdateState("http://www.d.com/1", "D1"); | |
151 LoadURLAndUpdateState("http://www.d.com/2", "D2"); | |
152 LoadURLAndUpdateState("http://www.d.com/3", "D3"); | |
153 LoadURLAndUpdateState("http://www.e.com/1", "E1"); | |
154 LoadURLAndUpdateState("http://www.e.com/2", "E2"); | |
155 LoadURLAndUpdateState("http://www.e.com/3", "E3"); | |
156 LoadURLAndUpdateState("http://www.f.com/1", "F1"); | |
157 LoadURLAndUpdateState("http://www.f.com/2", "F2"); | |
158 LoadURLAndUpdateState("http://www.f.com/3", "F3"); | |
159 LoadURLAndUpdateState("http://www.g.com/1", "G1"); | |
160 LoadURLAndUpdateState("http://www.g.com/2", "G2"); | |
161 LoadURLAndUpdateState("http://www.g.com/3", "G3"); | |
162 LoadURLAndUpdateState("http://www.h.com/1", "H1"); | |
163 LoadURLAndUpdateState("http://www.h.com/2", "H2"); | |
164 LoadURLAndUpdateState("http://www.h.com/3", "H3"); | |
165 LoadURLAndUpdateState("http://www.i.com/1", "I1"); | |
166 LoadURLAndUpdateState("http://www.i.com/2", "I2"); | |
167 LoadURLAndUpdateState("http://www.i.com/3", "I3"); | |
168 LoadURLAndUpdateState("http://www.j.com/1", "J1"); | |
169 LoadURLAndUpdateState("http://www.j.com/2", "J2"); | |
170 LoadURLAndUpdateState("http://www.j.com/3", "J3"); | |
171 LoadURLAndUpdateState("http://www.k.com/1", "K1"); | |
172 LoadURLAndUpdateState("http://www.k.com/2", "K2"); | |
173 | |
174 // Also there're two more for a separator and a "Show Full History". | |
175 int chapter_stop_offset = 6; | |
176 EXPECT_EQ(BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset, | |
177 back_model->GetItemCount()); | |
178 EXPECT_EQ(0, forward_model->GetItemCount()); | |
179 EXPECT_EQ(ASCIIToUTF16("K1"), back_model->GetLabelAt(0)); | |
180 EXPECT_EQ(back_model->GetShowFullHistoryLabel(), | |
181 back_model->GetLabelAt(BackForwardMenuModel::kMaxHistoryItems + 1 + | |
182 chapter_stop_offset)); | |
183 | |
184 // Test for out of bounds (beyond Show Full History). | |
185 EXPECT_FALSE(back_model->ItemHasCommand( | |
186 BackForwardMenuModel::kMaxHistoryItems + chapter_stop_offset + 2)); | |
187 | |
188 EXPECT_TRUE(back_model->ItemHasCommand( | |
189 BackForwardMenuModel::kMaxHistoryItems - 1)); | |
190 EXPECT_TRUE(back_model->IsSeparator( | |
191 BackForwardMenuModel::kMaxHistoryItems)); | |
192 | |
193 NavigateToIndex(0); | |
194 | |
195 EXPECT_EQ(BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset, | |
196 forward_model->GetItemCount()); | |
197 EXPECT_EQ(0, back_model->GetItemCount()); | |
198 EXPECT_EQ(ASCIIToUTF16("A2"), forward_model->GetLabelAt(0)); | |
199 EXPECT_EQ(forward_model->GetShowFullHistoryLabel(), | |
200 forward_model->GetLabelAt(BackForwardMenuModel::kMaxHistoryItems + 1 + | |
201 chapter_stop_offset)); | |
202 | |
203 // Out of bounds | |
204 EXPECT_FALSE(forward_model->ItemHasCommand( | |
205 BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset)); | |
206 | |
207 EXPECT_TRUE(forward_model->ItemHasCommand( | |
208 BackForwardMenuModel::kMaxHistoryItems - 1)); | |
209 EXPECT_TRUE(forward_model->IsSeparator( | |
210 BackForwardMenuModel::kMaxHistoryItems)); | |
211 } | |
212 | |
213 TEST_F(BackFwdMenuModelTest, ChapterStops) { | |
214 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( | |
215 NULL, BackForwardMenuModel::BACKWARD_MENU)); | |
216 back_model->set_test_tab_contents(contents()); | |
217 | |
218 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel( | |
219 NULL, BackForwardMenuModel::FORWARD_MENU)); | |
220 forward_model->set_test_tab_contents(contents()); | |
221 | |
222 // Seed the controller with 32 URLs. | |
223 int i = 0; | |
224 LoadURLAndUpdateState("http://www.a.com/1", "A1"); | |
225 ValidateModel(back_model.get(), i++, 0); | |
226 LoadURLAndUpdateState("http://www.a.com/2", "A2"); | |
227 ValidateModel(back_model.get(), i++, 0); | |
228 LoadURLAndUpdateState("http://www.a.com/3", "A3"); | |
229 ValidateModel(back_model.get(), i++, 0); | |
230 LoadURLAndUpdateState("http://www.b.com/1", "B1"); | |
231 ValidateModel(back_model.get(), i++, 0); | |
232 LoadURLAndUpdateState("http://www.b.com/2", "B2"); | |
233 ValidateModel(back_model.get(), i++, 0); | |
234 // i = 5 | |
235 LoadURLAndUpdateState("http://www.b.com/3", "B3"); | |
236 ValidateModel(back_model.get(), i++, 0); | |
237 LoadURLAndUpdateState("http://www.c.com/1", "C1"); | |
238 ValidateModel(back_model.get(), i++, 0); | |
239 LoadURLAndUpdateState("http://www.c.com/2", "C2"); | |
240 ValidateModel(back_model.get(), i++, 0); | |
241 LoadURLAndUpdateState("http://www.c.com/3", "C3"); | |
242 ValidateModel(back_model.get(), i++, 0); | |
243 LoadURLAndUpdateState("http://www.d.com/1", "D1"); | |
244 ValidateModel(back_model.get(), i++, 0); | |
245 // i = 10 | |
246 LoadURLAndUpdateState("http://www.d.com/2", "D2"); | |
247 ValidateModel(back_model.get(), i++, 0); | |
248 LoadURLAndUpdateState("http://www.d.com/3", "D3"); | |
249 ValidateModel(back_model.get(), i++, 0); | |
250 LoadURLAndUpdateState("http://www.e.com/1", "E1"); | |
251 ValidateModel(back_model.get(), i++, 0); | |
252 LoadURLAndUpdateState("http://www.e.com/2", "E2"); | |
253 ValidateModel(back_model.get(), i++, 0); | |
254 LoadURLAndUpdateState("http://www.e.com/3", "E3"); | |
255 ValidateModel(back_model.get(), i++, 0); | |
256 // i = 15 | |
257 LoadURLAndUpdateState("http://www.f.com/1", "F1"); | |
258 ValidateModel(back_model.get(), i++, 1); | |
259 LoadURLAndUpdateState("http://www.f.com/2", "F2"); | |
260 ValidateModel(back_model.get(), i++, 1); | |
261 LoadURLAndUpdateState("http://www.f.com/3", "F3"); | |
262 ValidateModel(back_model.get(), i++, 1); | |
263 LoadURLAndUpdateState("http://www.g.com/1", "G1"); | |
264 ValidateModel(back_model.get(), i++, 2); | |
265 LoadURLAndUpdateState("http://www.g.com/2", "G2"); | |
266 ValidateModel(back_model.get(), i++, 2); | |
267 // i = 20 | |
268 LoadURLAndUpdateState("http://www.g.com/3", "G3"); | |
269 ValidateModel(back_model.get(), i++, 2); | |
270 LoadURLAndUpdateState("http://www.h.com/1", "H1"); | |
271 ValidateModel(back_model.get(), i++, 3); | |
272 LoadURLAndUpdateState("http://www.h.com/2", "H2"); | |
273 ValidateModel(back_model.get(), i++, 3); | |
274 LoadURLAndUpdateState("http://www.h.com/3", "H3"); | |
275 ValidateModel(back_model.get(), i++, 3); | |
276 LoadURLAndUpdateState("http://www.i.com/1", "I1"); | |
277 ValidateModel(back_model.get(), i++, 4); | |
278 // i = 25 | |
279 LoadURLAndUpdateState("http://www.i.com/2", "I2"); | |
280 ValidateModel(back_model.get(), i++, 4); | |
281 LoadURLAndUpdateState("http://www.i.com/3", "I3"); | |
282 ValidateModel(back_model.get(), i++, 4); | |
283 LoadURLAndUpdateState("http://www.j.com/1", "J1"); | |
284 ValidateModel(back_model.get(), i++, 5); | |
285 LoadURLAndUpdateState("http://www.j.com/2", "J2"); | |
286 ValidateModel(back_model.get(), i++, 5); | |
287 LoadURLAndUpdateState("http://www.j.com/3", "J3"); | |
288 ValidateModel(back_model.get(), i++, 5); | |
289 // i = 30 | |
290 LoadURLAndUpdateState("http://www.k.com/1", "K1"); | |
291 ValidateModel(back_model.get(), i++, 6); | |
292 LoadURLAndUpdateState("http://www.k.com/2", "K2"); | |
293 ValidateModel(back_model.get(), i++, 6); | |
294 // i = 32 | |
295 LoadURLAndUpdateState("http://www.k.com/3", "K3"); | |
296 ValidateModel(back_model.get(), i++, 6); | |
297 | |
298 // A chapter stop is defined as the last page the user | |
299 // browsed to within the same domain. | |
300 | |
301 // Check to see if the chapter stops have the right labels. | |
302 int index = BackForwardMenuModel::kMaxHistoryItems; | |
303 // Empty string indicates item is a separator. | |
304 EXPECT_EQ(ASCIIToUTF16(""), back_model->GetLabelAt(index++)); | |
305 EXPECT_EQ(ASCIIToUTF16("F3"), back_model->GetLabelAt(index++)); | |
306 EXPECT_EQ(ASCIIToUTF16("E3"), back_model->GetLabelAt(index++)); | |
307 EXPECT_EQ(ASCIIToUTF16("D3"), back_model->GetLabelAt(index++)); | |
308 EXPECT_EQ(ASCIIToUTF16("C3"), back_model->GetLabelAt(index++)); | |
309 // The menu should only show a maximum of 5 chapter stops. | |
310 EXPECT_EQ(ASCIIToUTF16("B3"), back_model->GetLabelAt(index)); | |
311 // Empty string indicates item is a separator. | |
312 EXPECT_EQ(ASCIIToUTF16(""), back_model->GetLabelAt(index + 1)); | |
313 EXPECT_EQ(back_model->GetShowFullHistoryLabel(), | |
314 back_model->GetLabelAt(index + 2)); | |
315 | |
316 // If we go back two we should still see the same chapter stop at the end. | |
317 GoBack(); | |
318 EXPECT_EQ(ASCIIToUTF16("B3"), back_model->GetLabelAt(index)); | |
319 GoBack(); | |
320 EXPECT_EQ(ASCIIToUTF16("B3"), back_model->GetLabelAt(index)); | |
321 // But if we go back again, it should change. | |
322 GoBack(); | |
323 EXPECT_EQ(ASCIIToUTF16("A3"), back_model->GetLabelAt(index)); | |
324 GoBack(); | |
325 EXPECT_EQ(ASCIIToUTF16("A3"), back_model->GetLabelAt(index)); | |
326 GoBack(); | |
327 EXPECT_EQ(ASCIIToUTF16("A3"), back_model->GetLabelAt(index)); | |
328 GoBack(); | |
329 // It is now a separator. | |
330 EXPECT_EQ(ASCIIToUTF16(""), back_model->GetLabelAt(index)); | |
331 // Undo our position change. | |
332 NavigateToOffset(6); | |
333 | |
334 // Go back enough to make sure no chapter stops should appear. | |
335 NavigateToOffset(-BackForwardMenuModel::kMaxHistoryItems); | |
336 ValidateModel(forward_model.get(), BackForwardMenuModel::kMaxHistoryItems, 0); | |
337 // Go forward (still no chapter stop) | |
338 GoForward(); | |
339 ValidateModel(forward_model.get(), | |
340 BackForwardMenuModel::kMaxHistoryItems - 1, 0); | |
341 // Go back two (one chapter stop should show up) | |
342 GoBack(); | |
343 GoBack(); | |
344 ValidateModel(forward_model.get(), | |
345 BackForwardMenuModel::kMaxHistoryItems, 1); | |
346 | |
347 // Go to beginning. | |
348 NavigateToIndex(0); | |
349 | |
350 // Check to see if the chapter stops have the right labels. | |
351 index = BackForwardMenuModel::kMaxHistoryItems; | |
352 // Empty string indicates item is a separator. | |
353 EXPECT_EQ(ASCIIToUTF16(""), forward_model->GetLabelAt(index++)); | |
354 EXPECT_EQ(ASCIIToUTF16("E3"), forward_model->GetLabelAt(index++)); | |
355 EXPECT_EQ(ASCIIToUTF16("F3"), forward_model->GetLabelAt(index++)); | |
356 EXPECT_EQ(ASCIIToUTF16("G3"), forward_model->GetLabelAt(index++)); | |
357 EXPECT_EQ(ASCIIToUTF16("H3"), forward_model->GetLabelAt(index++)); | |
358 // The menu should only show a maximum of 5 chapter stops. | |
359 EXPECT_EQ(ASCIIToUTF16("I3"), forward_model->GetLabelAt(index)); | |
360 // Empty string indicates item is a separator. | |
361 EXPECT_EQ(ASCIIToUTF16(""), forward_model->GetLabelAt(index + 1)); | |
362 EXPECT_EQ(forward_model->GetShowFullHistoryLabel(), | |
363 forward_model->GetLabelAt(index + 2)); | |
364 | |
365 // If we advance one we should still see the same chapter stop at the end. | |
366 GoForward(); | |
367 EXPECT_EQ(ASCIIToUTF16("I3"), forward_model->GetLabelAt(index)); | |
368 // But if we advance one again, it should change. | |
369 GoForward(); | |
370 EXPECT_EQ(ASCIIToUTF16("J3"), forward_model->GetLabelAt(index)); | |
371 GoForward(); | |
372 EXPECT_EQ(ASCIIToUTF16("J3"), forward_model->GetLabelAt(index)); | |
373 GoForward(); | |
374 EXPECT_EQ(ASCIIToUTF16("J3"), forward_model->GetLabelAt(index)); | |
375 GoForward(); | |
376 EXPECT_EQ(ASCIIToUTF16("K3"), forward_model->GetLabelAt(index)); | |
377 | |
378 // Now test the boundary cases by using the chapter stop function directly. | |
379 // Out of bounds, first too far right (incrementing), then too far left. | |
380 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(33, false)); | |
381 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(-1, true)); | |
382 // Test being at end and going right, then at beginning going left. | |
383 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(32, true)); | |
384 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(0, false)); | |
385 // Test success: beginning going right and end going left. | |
386 EXPECT_EQ(2, back_model->GetIndexOfNextChapterStop(0, true)); | |
387 EXPECT_EQ(29, back_model->GetIndexOfNextChapterStop(32, false)); | |
388 // Now see when the chapter stops begin to show up. | |
389 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false)); | |
390 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(2, false)); | |
391 EXPECT_EQ(2, back_model->GetIndexOfNextChapterStop(3, false)); | |
392 // Now see when the chapter stops end. | |
393 EXPECT_EQ(32, back_model->GetIndexOfNextChapterStop(30, true)); | |
394 EXPECT_EQ(32, back_model->GetIndexOfNextChapterStop(31, true)); | |
395 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(32, true)); | |
396 | |
397 // Bug found during review (two different sites, but first wasn't considered | |
398 // a chapter-stop). | |
399 // Go to A1; | |
400 NavigateToIndex(0); | |
401 LoadURLAndUpdateState("http://www.b.com/1", "B1"); | |
402 EXPECT_EQ(0, back_model->GetIndexOfNextChapterStop(1, false)); | |
403 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true)); | |
404 | |
405 // Now see if it counts 'www.x.com' and 'mail.x.com' as same domain, which | |
406 // it should. | |
407 // Go to A1. | |
408 NavigateToIndex(0); | |
409 LoadURLAndUpdateState("http://mail.a.com/2", "A2-mai"); | |
410 LoadURLAndUpdateState("http://www.b.com/1", "B1"); | |
411 LoadURLAndUpdateState("http://mail.b.com/2", "B2-mai"); | |
412 LoadURLAndUpdateState("http://new.site.com", "new"); | |
413 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true)); | |
414 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(1, true)); | |
415 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(2, true)); | |
416 EXPECT_EQ(4, back_model->GetIndexOfNextChapterStop(3, true)); | |
417 // And try backwards as well. | |
418 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(4, false)); | |
419 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(3, false)); | |
420 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(2, false)); | |
421 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false)); | |
422 } | |
OLD | NEW |