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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura_browsertest.cc

Issue 11635059: navigation: Retain a screenshot of the page before it unloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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
« no previous file with comments | « content/browser/web_contents/navigation_entry_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/test_timeouts.h" 9 #include "base/test/test_timeouts.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h" 11 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/web_contents/navigation_controller_impl.h"
13 #include "content/browser/web_contents/navigation_entry_impl.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 14 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
14 #include "content/public/test/browser_test_utils.h" 16 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
16 #include "content/shell/shell.h" 18 #include "content/shell/shell.h"
17 #include "content/test/content_browser_test.h" 19 #include "content/test/content_browser_test.h"
18 #include "content/test/content_browser_test_utils.h" 20 #include "content/test/content_browser_test_utils.h"
19 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/event_generator.h" 22 #include "ui/aura/test/event_generator.h"
21 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 256 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
255 gfx::Point(x, bounds.y() + 5), 257 gfx::Point(x, bounds.y() + 5),
256 0, timestamp); 258 0, timestamp);
257 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 259 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc);
258 EXPECT_EQ(1, GetCurrentIndex()); 260 EXPECT_EQ(1, GetCurrentIndex());
259 } 261 }
260 262
261 // Do not end the overscroll sequence. 263 // Do not end the overscroll sequence.
262 } 264 }
263 265
266 // The test is disabled on windows since the gesture support in win-aura isn't
267 // complete yet. See http://crbug.com/157268
268 #if defined(OS_WIN)
269 #define MAYBE_OverscrollScreenshot \
270 DISABLED_OverscrollScreenshot
271 #else
272 #define MAYBE_OverscrollScreenshot \
273 OverscrollScreenshot
274 #endif
275 // Tests that the page has has a screenshot when navigation happens:
276 // - from within the page (from a JS function)
277 // - interactively, when user does an overscroll gesture
278 // - interactively, when user navigates in history without the overscroll
279 // gesture.
280 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
281 OverscrollScreenshot) {
282 ASSERT_NO_FATAL_FAILURE(
283 StartTestWithPage("files/overscroll_navigation.html"));
284 WebContentsImpl* web_contents =
285 static_cast<WebContentsImpl*>(shell()->web_contents());
286 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(
287 web_contents->GetRenderViewHost());
288
289 // Do a few navigations initiated by the page.
290 ExecuteSyncJSFunction(view_host, "navigate_next()");
291 EXPECT_EQ(1, GetCurrentIndex());
292 ExecuteSyncJSFunction(view_host, "navigate_next()");
293 EXPECT_EQ(2, GetCurrentIndex());
294
295 // The current entry won't have any screenshots. But the entries in the
296 // history should now have screenshots.
297 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
298 web_contents->GetController().GetEntryAtIndex(2));
299 EXPECT_FALSE(entry->screenshot().get());
300
301 entry = NavigationEntryImpl::FromNavigationEntry(
302 web_contents->GetController().GetEntryAtIndex(1));
303 EXPECT_TRUE(entry->screenshot().get());
304
305 entry = NavigationEntryImpl::FromNavigationEntry(
306 web_contents->GetController().GetEntryAtIndex(0));
307 EXPECT_TRUE(entry->screenshot().get());
308
309 // Navigate again. Index 2 should now have a screenshot.
310 ExecuteSyncJSFunction(view_host, "navigate_next()");
311 EXPECT_EQ(3, GetCurrentIndex());
312
313 entry = NavigationEntryImpl::FromNavigationEntry(
314 web_contents->GetController().GetEntryAtIndex(2));
315 EXPECT_TRUE(entry->screenshot().get());
316
317 entry = NavigationEntryImpl::FromNavigationEntry(
318 web_contents->GetController().GetEntryAtIndex(3));
319 EXPECT_FALSE(entry->screenshot().get());
320
321 {
322 // Now, swipe right to navigate backwards. This should navigate away from
323 // index 3 to index 2, and index 3 should have a screenshot.
324 string16 expected_title = ASCIIToUTF16("Title: #2");
325 content::TitleWatcher title_watcher(web_contents, expected_title);
326 aura::Window* content = web_contents->GetContentNativeView();
327 gfx::Rect bounds = content->GetBoundsInRootWindow();
328 aura::test::EventGenerator generator(content->GetRootWindow(), content);
329 generator.GestureScrollSequence(
330 gfx::Point(bounds.x() + 2, bounds.y() + 10),
331 gfx::Point(bounds.right() - 10, bounds.y() + 10),
332 base::TimeDelta::FromMilliseconds(20),
333 1);
334 string16 actual_title = title_watcher.WaitAndGetTitle();
335 EXPECT_EQ(expected_title, actual_title);
336 EXPECT_EQ(2, GetCurrentIndex());
337 entry = NavigationEntryImpl::FromNavigationEntry(
338 web_contents->GetController().GetEntryAtIndex(3));
339 EXPECT_TRUE(entry->screenshot().get());
340 }
341
342 // Navigate a couple more times.
343 ExecuteSyncJSFunction(view_host, "navigate_next()");
344 EXPECT_EQ(3, GetCurrentIndex());
345 ExecuteSyncJSFunction(view_host, "navigate_next()");
346 EXPECT_EQ(4, GetCurrentIndex());
347 entry = NavigationEntryImpl::FromNavigationEntry(
348 web_contents->GetController().GetEntryAtIndex(4));
349 EXPECT_FALSE(entry->screenshot().get());
350
351 {
352 // Navigate back in history.
353 string16 expected_title = ASCIIToUTF16("Title: #3");
354 content::TitleWatcher title_watcher(web_contents, expected_title);
355 web_contents->GetController().GoBack();
356 string16 actual_title = title_watcher.WaitAndGetTitle();
357 EXPECT_EQ(expected_title, actual_title);
358 EXPECT_EQ(3, GetCurrentIndex());
359 entry = NavigationEntryImpl::FromNavigationEntry(
360 web_contents->GetController().GetEntryAtIndex(4));
361 EXPECT_TRUE(entry->screenshot().get());
362 }
363 }
364
264 } // namespace content 365 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/navigation_entry_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698