12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/web_contents/web_contents_view_aura.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/run_loop.h" 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/test/test_timeouts.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h" 12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(OS_WIN) 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/win/windows_version.h" 14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/navigation_controller_impl.h" 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/navigation_entry_impl.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_view_aura.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/web_contents/web_contents_impl.h" 20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/browser/web_contents/web_contents_view.h" 2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/common/input/synthetic_web_input_event_builders.h" 2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/common/input_messages.h" 2346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "content/common/view_messages.h" 2403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/browser/browser_message_filter.h" 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/render_frame_host.h" 261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/web_contents_delegate.h" 27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/content_switches.h" 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/browser_test_utils.h" 30effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/public/test/content_browser_test.h" 31effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/public/test/content_browser_test_utils.h" 3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "content/public/test/test_renderer_host.h" 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/test_utils.h" 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window.h" 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_tree_host.h" 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/scoped_animation_duration_scale_mode.h" 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/event_processor.h" 3903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "ui/events/event_switches.h" 4046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/events/event_utils.h" 415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/events/test/event_generator.h" 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace { 4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// TODO(tdresser): Find a way to avoid sleeping like this. See crbug.com/405282 4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// for details. 4703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void GiveItSomeTime() { 4803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::RunLoop run_loop; 4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::MessageLoop::current()->PostDelayedTask( 5003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) FROM_HERE, 5103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) run_loop.QuitClosure(), 5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::TimeDelta::FromMillisecondsD(10)); 5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) run_loop.Run(); 5403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// WebContentsDelegate which tracks vertical overscroll updates. 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass VerticalOverscrollTracker : public content::WebContentsDelegate { 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public: 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci VerticalOverscrollTracker() : count_(0), completed_(false) {} 601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual ~VerticalOverscrollTracker() {} 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int num_overscroll_updates() const { 631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return count_; 641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool overscroll_completed() const { 671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return completed_; 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void Reset() { 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci count_ = 0; 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci completed_ = false; 731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private: 761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool CanOverscrollContent() const OVERRIDE { 771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return true; 781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OverscrollUpdate(int delta_y) OVERRIDE { 811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ++count_; 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OverscrollComplete() OVERRIDE { 851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci completed_ = true; 861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int count_; 891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool completed_; 901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DISALLOW_COPY_AND_ASSIGN(VerticalOverscrollTracker); 921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}; 931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 9403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} //namespace 9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 9603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content { 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This class keeps track of the RenderViewHost whose screenshot was captured. 100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ScreenshotTracker : public NavigationEntryScreenshotManager { 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit ScreenshotTracker(NavigationControllerImpl* controller) 103f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) : NavigationEntryScreenshotManager(controller), 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_taken_for_(NULL), 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) waiting_for_screenshots_(0) { 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~ScreenshotTracker() { 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; } 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Reset() { 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) screenshot_taken_for_ = NULL; 115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) screenshot_set_.clear(); 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void SetScreenshotInterval(int interval_ms) { 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetMinScreenshotIntervalMS(interval_ms); 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void WaitUntilScreenshotIsReady() { 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!waiting_for_screenshots_) 124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) message_loop_runner_ = new content::MessageLoopRunner; 126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) message_loop_runner_->Run(); 127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 129d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool ScreenshotSetForEntry(NavigationEntryImpl* entry) const { 130d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return screenshot_set_.count(entry) > 0; 131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Overridden from NavigationEntryScreenshotManager: 135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void TakeScreenshotImpl(RenderViewHost* host, 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NavigationEntryImpl* entry) OVERRIDE { 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ++waiting_for_screenshots_; 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) screenshot_taken_for_ = host; 139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry); 140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE { 143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) --waiting_for_screenshots_; 144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) screenshot_set_[entry] = true; 145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) NavigationEntryScreenshotManager::OnScreenshotSet(entry); 1467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (waiting_for_screenshots_ == 0 && message_loop_runner_.get()) 147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) message_loop_runner_->Quit(); 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* screenshot_taken_for_; 151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int waiting_for_screenshots_; 153d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) std::map<NavigationEntryImpl*, bool> screenshot_set_; 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker); 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 158d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class NavigationWatcher : public WebContentsObserver { 159d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public: 160d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) explicit NavigationWatcher(WebContents* contents) 161d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) : WebContentsObserver(contents), 162d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) navigated_(false), 163d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) should_quit_loop_(false) { 164d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 165d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 166d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual ~NavigationWatcher() {} 167d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 168d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void WaitUntilNavigationStarts() { 169d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (navigated_) 170d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return; 171d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) should_quit_loop_ = true; 172d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::MessageLoop::current()->Run(); 173d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 174d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 175d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private: 176d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Overridden from WebContentsObserver: 177d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void AboutToNavigateRenderView(RenderViewHost* host) OVERRIDE { 178d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) navigated_ = true; 179d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (should_quit_loop_) 180d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::MessageLoop::current()->Quit(); 181d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 182d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 183d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool navigated_; 184d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool should_quit_loop_; 185d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 186d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NavigationWatcher); 187d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}; 188d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 18903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class InputEventMessageFilterWaitsForAcks : public BrowserMessageFilter { 19003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) public: 19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputEventMessageFilterWaitsForAcks() 19203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) : BrowserMessageFilter(InputMsgStart), 19303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) type_(blink::WebInputEvent::Undefined), 19403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {} 19503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 19603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void WaitForAck(blink::WebInputEvent::Type type) { 19703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::RunLoop run_loop; 19803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); 19903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::AutoReset<blink::WebInputEvent::Type> reset_type(&type_, type); 20003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) run_loop.Run(); 20103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 20203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 20303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputEventAckState last_ack_state() const { return state_; } 20403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 20503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) protected: 20603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual ~InputEventMessageFilterWaitsForAcks() {} 20703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 20803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) private: 20903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void ReceivedEventAck(blink::WebInputEvent::Type type, 21003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputEventAckState state) { 21103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (type_ == type) { 21203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) state_ = state; 21303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) quit_.Run(); 21403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 21503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 21603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 21703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // BrowserMessageFilter: 21803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { 21903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (message.type() == InputHostMsg_HandleInputEvent_ACK::ID) { 22003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputHostMsg_HandleInputEvent_ACK::Param params; 22103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputHostMsg_HandleInputEvent_ACK::Read(&message, ¶ms); 22203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) blink::WebInputEvent::Type type = params.a.type; 22303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputEventAckState ack = params.a.state; 22403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 22503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::Bind(&InputEventMessageFilterWaitsForAcks::ReceivedEventAck, 22603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) this, type, ack)); 22703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 22803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return false; 22903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 23003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 23103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::Closure quit_; 23203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) blink::WebInputEvent::Type type_; 23303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputEventAckState state_; 23403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 23503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(InputEventMessageFilterWaitsForAcks); 23603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}; 23703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebContentsViewAuraTest : public ContentBrowserTest { 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 240c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WebContentsViewAuraTest() 241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : screenshot_manager_(NULL) { 242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Executes the javascript synchronously and makes sure the returned value is 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // freed properly. 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<base::Value> value = 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::ExecuteScriptAndGetValue(rfh, jscript); 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Starts the test server and navigates to the given url. Sets a large enough 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // size to the root window. Returns after the navigation to the url is 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // complete. 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StartTestWithPage(const std::string& url) { 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL test_url(test_server()->GetURL(url)); 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateToURL(shell(), test_url); 258c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WebContentsImpl* web_contents = 260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NavigationControllerImpl* controller = &web_contents->GetController(); 262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager_ = new ScreenshotTracker(controller); 264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller->SetScreenshotManager(screenshot_manager_); 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 26703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void SetUpCommandLine(CommandLine* cmd) OVERRIDE { 26803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) cmd->AppendSwitchASCII(switches::kTouchEvents, 26903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) switches::kTouchEventsEnabled); 27003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 27103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void TestOverscrollNavigation(bool touch_handler) { 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents = 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationController& controller = web_contents->GetController(); 278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderFrameHost* main_frame = web_contents->GetMainFrame(); 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(controller.CanGoBack()); 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(controller.CanGoForward()); 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int index = -1; 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<base::Value> value = 284a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(value->GetAsInteger(&index)); 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0, index); 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (touch_handler) 289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(value->GetAsInteger(&index)); 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, index); 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(controller.CanGoBack()); 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(controller.CanGoForward()); 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 299010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 3015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::EventGenerator generator(content->GetRootWindow(), content); 302d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const int kScrollDurationMs = 20; 303d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const int kScrollSteps = 10; 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do a swipe-right now. That should navigate backwards. 3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 expected_title = base::ASCIIToUTF16("Title: #1"); 3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) generator.GestureScrollSequence( 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 312d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::TimeDelta::FromMilliseconds(kScrollDurationMs), 313d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) kScrollSteps); 314a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 actual_title = title_watcher.WaitAndGetTitle(); 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_title, actual_title); 316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(value->GetAsInteger(&index)); 3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, index); 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(controller.CanGoBack()); 3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(controller.CanGoForward()); 3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do a fling-right now. That should navigate backwards. 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 expected_title = base::ASCIIToUTF16("Title:"); 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) generator.GestureScrollSequence( 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 330d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::TimeDelta::FromMilliseconds(kScrollDurationMs), 331d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) kScrollSteps); 332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 actual_title = title_watcher.WaitAndGetTitle(); 3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_title, actual_title); 334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(value->GetAsInteger(&index)); 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0, index); 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(controller.CanGoBack()); 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(controller.CanGoForward()); 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do a swipe-left now. That should navigate forward. 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 expected_title = base::ASCIIToUTF16("Title: #1"); 3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) generator.GestureScrollSequence( 3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 348d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::TimeDelta::FromMilliseconds(kScrollDurationMs), 349d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) kScrollSteps); 350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 actual_title = title_watcher.WaitAndGetTitle(); 3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_title, actual_title); 352a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(value->GetAsInteger(&index)); 3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, index); 3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(controller.CanGoBack()); 3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(controller.CanGoForward()); 3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int GetCurrentIndex() { 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents = 3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderFrameHost* main_frame = web_contents->GetMainFrame(); 3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int index = -1; 3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<base::Value> value; 366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!value->GetAsInteger(&index)) 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) index = -1; 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return index; 3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 37203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int ExecuteScriptAndExtractInt(const std::string& script) { 37303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int value = 0; 37403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) EXPECT_TRUE(content::ExecuteScriptAndExtractInt( 37503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) shell()->web_contents(), 37603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) "domAutomationController.send(" + script + ")", 37703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) &value)); 37803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return value; 37903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 38003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 38103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderViewHost* GetRenderViewHost() const { 38203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderViewHost* const rvh = shell()->web_contents()->GetRenderViewHost(); 38303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) CHECK(rvh); 38403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return rvh; 38503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 38603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 38703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderWidgetHostImpl* GetRenderWidgetHost() const { 38803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderWidgetHostImpl* const rwh = 38903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderWidgetHostImpl::From(shell() 39003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ->web_contents() 39103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ->GetRenderWidgetHostView() 39203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ->GetRenderWidgetHost()); 39303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) CHECK(rwh); 39403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return rwh; 39503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 39603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 39703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderWidgetHostViewBase* GetRenderWidgetHostView() const { 39803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return static_cast<RenderWidgetHostViewBase*>( 39903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderViewHost()->GetView()); 40003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 40103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 40203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) InputEventMessageFilterWaitsForAcks* filter() { 40303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return filter_.get(); 40403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 40503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 40603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void WaitAFrame() { 40703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) uint32 frame = GetRenderWidgetHostView()->RendererFrameNumber(); 40803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) while (!GetRenderWidgetHost()->ScheduleComposite()) 40903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GiveItSomeTime(); 41003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) while (GetRenderWidgetHostView()->RendererFrameNumber() == frame) 41103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GiveItSomeTime(); 41203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 41303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 414c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected: 415c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScreenshotTracker* screenshot_manager() { return screenshot_manager_; } 416c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void set_min_screenshot_interval(int interval_ms) { 417c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager_->SetScreenshotInterval(interval_ms); 418c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 419c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 42003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void AddInputEventMessageFilter() { 42103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) filter_ = new InputEventMessageFilterWaitsForAcks(); 4221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetRenderWidgetHost()->GetProcess()->AddFilter(filter_.get()); 42303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 42403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 426c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScreenshotTracker* screenshot_manager_; 42703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_refptr<InputEventMessageFilterWaitsForAcks> filter_; 428c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest); 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 432116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Flaky on Windows: http://crbug.com/305722 433116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(OS_WIN) 434116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation 435116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#else 436116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define MAYBE_OverscrollNavigation OverscrollNavigation 437116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif 438116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 439116680a4aac90f2aa7413d9095a592090648e557Ben MurdochIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollNavigation) { 4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestOverscrollNavigation(false); 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 443cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Flaky on Windows (might be related to the above test): 444cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// http://crbug.com/305722 4454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_WIN) 4464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define MAYBE_OverscrollNavigationWithTouchHandler \ 4474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DISABLED_OverscrollNavigationWithTouchHandler 4484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#else 4494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define MAYBE_OverscrollNavigationWithTouchHandler \ 4504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) OverscrollNavigationWithTouchHandler 4514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 4534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) MAYBE_OverscrollNavigationWithTouchHandler) { 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestOverscrollNavigation(true); 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Disabled because the test always fails the first time it runs on the Win Aura 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// bots, and usually but not always passes second-try (See crbug.com/179532). 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_QuickOverscrollDirectionChange \ 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISABLED_QuickOverscrollDirectionChange 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MAYBE_QuickOverscrollDirectionChange) { 4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents = 4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 471a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderFrameHost* main_frame = web_contents->GetMainFrame(); 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This test triggers a large number of animations. Speed them up to ensure 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the test completes within its time limit. 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode fast_duration_mode( 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::FAST_DURATION); 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure the page has both back/forward history. 479a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 481a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, GetCurrentIndex()); 4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GoBack(); 4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 486010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 487a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventProcessor* dispatcher = content->GetHost()->event_processor(); 4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 49046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) base::TimeDelta timestamp = ui::EventTimeForNow(); 4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.x() + bounds.width() / 2, bounds.y() + 5), 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 0, timestamp); 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_FALSE(details.dispatcher_destroyed); 4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) timestamp += base::TimeDelta::FromMilliseconds(10); 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TouchEvent move1(ui::ET_TOUCH_MOVED, 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 5), 5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 0, timestamp); 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) details = dispatcher->OnEventFromSource(&move1); 5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_FALSE(details.dispatcher_destroyed); 5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Swipe back from the right edge, back to the left edge, back to the right 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // edge. 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int x = bounds.right() - 10; x >= bounds.x() + 10; x-= 10) { 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) timestamp += base::TimeDelta::FromMilliseconds(10); 5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(x, bounds.y() + 5), 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 0, timestamp); 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) details = dispatcher->OnEventFromSource(&inc); 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_FALSE(details.dispatcher_destroyed); 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int x = bounds.x() + 10; x <= bounds.width() - 10; x+= 10) { 5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) timestamp += base::TimeDelta::FromMilliseconds(10); 5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(x, bounds.y() + 5), 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 0, timestamp); 5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) details = dispatcher->OnEventFromSource(&inc); 5255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_FALSE(details.dispatcher_destroyed); 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int x = bounds.width() - 10; x >= bounds.x() + 10; x-= 10) { 5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) timestamp += base::TimeDelta::FromMilliseconds(10); 5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(x, bounds.y() + 5), 5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 0, timestamp); 5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) details = dispatcher->OnEventFromSource(&inc); 5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_FALSE(details.dispatcher_destroyed); 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do not end the overscroll sequence. 5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tests that the page has has a screenshot when navigation happens: 5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// - from within the page (from a JS function) 5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// - interactively, when user does an overscroll gesture 5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// - interactively, when user navigates in history without the overscroll 5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// gesture. 547116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Flaky on Windows (http://crbug.com/357311). Might be related to 548cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// OverscrollNavigation test. 5495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Flaky on Ozone (http://crbug.com/399676). 55003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Flaky on ChromeOS (http://crbug.com/405945). 55103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if defined(OS_WIN) || defined(USE_OZONE) || defined(OS_CHROMEOS) 552116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define MAYBE_OverscrollScreenshot DISABLED_OverscrollScreenshot 553116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#else 554116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define MAYBE_OverscrollScreenshot OverscrollScreenshot 555116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif 556116680a4aac90f2aa7413d9095a592090648e557Ben MurdochIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollScreenshot) { 557d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Disable the test for WinXP. See http://crbug/294116. 558d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(OS_WIN) 559d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (base::win::GetVersion() < base::win::VERSION_VISTA) { 560d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) LOG(WARNING) << "Test disabled due to unknown bug on WinXP."; 561d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return; 562d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 563d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif 564d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents = 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 569a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderFrameHost* main_frame = web_contents->GetMainFrame(); 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) set_min_screenshot_interval(0); 572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do a few navigations initiated by the page. 5745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Screenshots should never be captured since these are all in-page 5755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // navigations. 576a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 578a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, GetCurrentIndex()); 580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(2)); 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(entry->screenshot().get()); 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(1)); 5885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(0)); 5925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 594a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(2)); 5995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(3)); 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(entry->screenshot().get()); 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Now, swipe right to navigate backwards. This should navigate away from 6065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // index 3 to index 2. 6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 609010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 6115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::EventGenerator generator(content->GetRootWindow(), content); 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) generator.GestureScrollSequence( 6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta::FromMilliseconds(20), 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1); 617a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 actual_title = title_watcher.WaitAndGetTitle(); 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_title, actual_title); 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, GetCurrentIndex()); 620c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(3)); 6235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Navigate a couple more times. 627a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, GetCurrentIndex()); 629a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(4, GetCurrentIndex()); 631c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(4)); 6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(entry->screenshot().get()); 6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Navigate back in history. 6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 expected_title = base::ASCIIToUTF16("Title: #3"); 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GoBack(); 641a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 actual_title = title_watcher.WaitAndGetTitle(); 6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_title, actual_title); 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, GetCurrentIndex()); 644c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtIndex(4)); 6475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 651effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Crashes under ThreadSanitizer, http://crbug.com/356758. 652effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(THREAD_SANITIZER) 653effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#define MAYBE_ScreenshotForSwappedOutRenderViews \ 654effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DISABLED_ScreenshotForSwappedOutRenderViews 655effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#else 656effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#define MAYBE_ScreenshotForSwappedOutRenderViews \ 657effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ScreenshotForSwappedOutRenderViews 658effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tests that screenshot is taken correctly when navigation causes a 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// RenderViewHost to be swapped out. 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 662effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch MAYBE_ScreenshotForSwappedOutRenderViews) { 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Create a new server with a different site. 666c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) net::SpawnedTestServer https_server( 667c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) net::SpawnedTestServer::TYPE_HTTPS, 668c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) net::SpawnedTestServer::kLocalhost, 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(https_server.Start()); 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents = 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 674c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) set_min_screenshot_interval(0); 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct { 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL url; 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int transition; 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } navigations[] = { 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { https_server.GetURL("files/title1.html"), 6811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR }, 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { test_server()->GetURL("files/title2.html"), 6831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::PAGE_TRANSITION_AUTO_BOOKMARK }, 6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { https_server.GetURL("files/title3.html"), 6851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR }, 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { GURL(), 0 } 6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 689c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->Reset(); 6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int i = 0; !navigations[i].url.is_empty(); ++i) { 6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Navigate via the user initiating a navigation from the UI. 6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationController::LoadURLParams params(navigations[i].url); 6931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci params.transition_type = 6941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::PageTransitionFromInt(navigations[i].transition); 6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* old_host = web_contents->GetRenderViewHost(); 6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().LoadURLWithParams(params); 6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WaitForLoadStop(web_contents); 699c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE(old_host, web_contents->GetRenderViewHost()) 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) << navigations[i].url.spec(); 703c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for()); 7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents->GetController().GetEntryAtOffset(-1)); 707d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 7104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) web_contents->GetController().GetLastCommittedEntry()); 711d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(entry->screenshot().get()); 713d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) screenshot_manager()->Reset(); 7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 715c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 716c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Increase the minimum interval between taking screenshots. 717c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) set_min_screenshot_interval(60000); 718c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 719c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Navigate again. This should not take any screenshot because of the 720c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // increased screenshot interval. 721c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NavigationController::LoadURLParams params(navigations[0].url); 7221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci params.transition_type = ui::PageTransitionFromInt(navigations[0].transition); 723c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) web_contents->GetController().LoadURLWithParams(params); 724c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WaitForLoadStop(web_contents); 725c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 726c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 727c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); 728c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 729c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Tests that navigations resulting from reloads, history.replaceState, 7315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// and history.pushState do not capture screenshots. 732f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ReplaceStateReloadPushState) { 733f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 734f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 735f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) WebContentsImpl* web_contents = 736f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 737f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) RenderFrameHost* main_frame = web_contents->GetMainFrame(); 738f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 739f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) set_min_screenshot_interval(0); 740f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) screenshot_manager()->Reset(); 741f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "use_replace_state()"); 742f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 743f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // history.replaceState shouldn't capture a screenshot 744f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); 745f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) screenshot_manager()->Reset(); 746f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) web_contents->GetController().Reload(true); 747f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) WaitForLoadStop(web_contents); 748f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // reloading the page shouldn't capture a screenshot 7495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // TODO (mfomitchev): currently broken. Uncomment when 7505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // FrameHostMsg_DidCommitProvisionalLoad_Params.was_within_same_page 7515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // is populated properly when reloading the page. 7525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) //EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); 753f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) screenshot_manager()->Reset(); 754f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "use_push_state()"); 755f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) screenshot_manager()->WaitUntilScreenshotIsReady(); 7565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // pushing a state shouldn't capture a screenshot 7575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // TODO (mfomitchev): currently broken. Uncomment when 7585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // FrameHostMsg_DidCommitProvisionalLoad_Params.was_within_same_page 7595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // is populated properly when pushState is used. 7605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) //EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); 761f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 762f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 7638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// TODO(sadrul): This test is disabled because it reparents in a way the 7648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// FocusController does not support. This code would crash in 7658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// a production build. It only passed prior to this revision 7668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// because testing used the old FocusManager which did some 7678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// different (osbolete) processing. TODO(sadrul) to figure out 7688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// how this test should work that mimics production code a bit 7698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// better. 770c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 7718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DISABLED_ContentWindowReparent) { 772c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 773c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 774c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 775c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<aura::Window> window(new aura::Window(NULL)); 7765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Init(aura::WINDOW_LAYER_NOT_DRAWN); 777c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 778c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WebContentsImpl* web_contents = 779c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 780a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 781c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 782c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 783010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 784c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 7855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::EventGenerator generator(content->GetRootWindow(), content); 786c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) generator.GestureScrollSequence( 787c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 788c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 789c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::TimeDelta::FromMilliseconds(20), 790c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1); 791c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 792010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) window->AddChild(shell()->web_contents()->GetContentNativeView()); 793c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 794c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 795cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) { 796c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 797c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 798c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 799c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WebContentsImpl* web_contents = 800c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 801a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 802c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 803c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 804010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 805c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 8065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::EventGenerator generator(content->GetRootWindow(), content); 807c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) generator.GestureScrollSequence( 808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 809c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 810c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::TimeDelta::FromMilliseconds(20), 811c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1); 812c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 813010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) delete web_contents->GetContentNativeView(); 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8160de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) 81746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 8180de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)// This appears to be flaky in the same was as the other overscroll 8190de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)// tests. Enabling for non-Windows platforms. 8200de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)// See http://crbug.com/369871. 82146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// For linux, see http://crbug.com/381294 8220de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#define MAYBE_RepeatedQuickOverscrollGestures DISABLED_RepeatedQuickOverscrollGestures 8230de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#else 8240de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#define MAYBE_RepeatedQuickOverscrollGestures RepeatedQuickOverscrollGestures 8250de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#endif 8260de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) 827b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 8280de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) MAYBE_RepeatedQuickOverscrollGestures) { 829b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 830b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 831b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 832b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) WebContentsImpl* web_contents = 833b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 834b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) NavigationController& controller = web_contents->GetController(); 835a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderFrameHost* main_frame = web_contents->GetMainFrame(); 836a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); 837b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 838b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Navigate twice, then navigate back in history once. 839a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 840a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteSyncJSFunction(main_frame, "navigate_next()"); 841b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_EQ(2, GetCurrentIndex()); 842b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_TRUE(controller.CanGoBack()); 843b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_FALSE(controller.CanGoForward()); 844b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 845b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) web_contents->GetController().GoBack(); 846b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) WaitForLoadStop(web_contents); 847b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_EQ(1, GetCurrentIndex()); 848d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); 849b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_TRUE(controller.CanGoBack()); 850b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_TRUE(controller.CanGoForward()); 851b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 852010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 853b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 8545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::EventGenerator generator(content->GetRootWindow(), content); 855b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 856b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Do a swipe left to start a forward navigation. Then quickly do a swipe 857b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // right. 8585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); 859b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 860d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) NavigationWatcher nav_watcher(web_contents); 861b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 862b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) generator.GestureScrollSequence( 863b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 864b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 865b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::TimeDelta::FromMilliseconds(2000), 866b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 10); 867d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) nav_watcher.WaitUntilNavigationStarts(); 868d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 869b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) generator.GestureScrollSequence( 870b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) gfx::Point(bounds.x() + 2, bounds.y() + 10), 871b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) gfx::Point(bounds.right() - 10, bounds.y() + 10), 872b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::TimeDelta::FromMilliseconds(2000), 873b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 10); 874a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 actual_title = title_watcher.WaitAndGetTitle(); 875b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_EQ(expected_title, actual_title); 876b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 877b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_EQ(2, GetCurrentIndex()); 878b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_TRUE(controller.CanGoBack()); 879b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) EXPECT_FALSE(controller.CanGoForward()); 880b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 881b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 882cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Verify that hiding a parent of the renderer will hide the content too. 883cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, HideContentOnParenHide) { 884cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/title1.html")); 885cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) WebContentsImpl* web_contents = 886cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 887cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) aura::Window* content = web_contents->GetNativeView()->parent(); 888cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_TRUE(web_contents->should_normally_be_visible()); 889cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) content->Hide(); 890cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(web_contents->should_normally_be_visible()); 891cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) content->Show(); 892cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_TRUE(web_contents->should_normally_be_visible()); 893cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 894cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 8955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Ensure that SnapToPhysicalPixelBoundary() is called on WebContentsView parent 8965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// change. This is a regression test for http://crbug.com/388908. 8975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, WebContentsViewReparent) { 8985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 8995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 9005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 9015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) scoped_ptr<aura::Window> window(new aura::Window(NULL)); 9025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) window->Init(aura::WINDOW_LAYER_NOT_DRAWN); 9035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 9045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) RenderWidgetHostViewAura* rwhva = 9055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) static_cast<RenderWidgetHostViewAura*>( 9065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) shell()->web_contents()->GetRenderWidgetHostView()); 9075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) rwhva->ResetHasSnappedToBoundary(); 9085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_FALSE(rwhva->has_snapped_to_boundary()); 9095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) window->AddChild(shell()->web_contents()->GetNativeView()); 9105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(rwhva->has_snapped_to_boundary()); 9115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 9125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 91303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Flaky on some platforms, likely for the same reason as other flaky overscroll 91403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// tests. http://crbug.com/305722 9151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(tdresser): Re-enable this once eager GR is back on. See 9161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// crbug.com/410280. 91703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 91803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define MAYBE_OverscrollNavigationTouchThrottling \ 91903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DISABLED_OverscrollNavigationTouchThrottling 92003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#else 92103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define MAYBE_OverscrollNavigationTouchThrottling \ 9221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DISABLED_OverscrollNavigationTouchThrottling 92303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif 92403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 92503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Tests that touch moves are not throttled when performing a scroll gesture on 92603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// a non-scrollable area, except during gesture-nav. 92703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 92803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) MAYBE_OverscrollNavigationTouchThrottling) { 92903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 93003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) StartTestWithPage("files/overscroll_navigation.html")); 93103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 93203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) AddInputEventMessageFilter(); 93303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 93403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WebContentsImpl* web_contents = 93503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) static_cast<WebContentsImpl*>(shell()->web_contents()); 93603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) aura::Window* content = web_contents->GetContentNativeView(); 93703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) gfx::Rect bounds = content->GetBoundsInRootWindow(); 93803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const int dx = 20; 93903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 94003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ExecuteSyncJSFunction(web_contents->GetMainFrame(), 94103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) "install_touchmove_handler()"); 94203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 94303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 94403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 94503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) for (int navigated = 0; navigated <= 1; ++navigated) { 94603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (navigated) { 94703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 94803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ExecuteSyncJSFunction(web_contents->GetMainFrame(), 94903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) "reset_touchmove_count()"); 95003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 95103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Send touch press. 95203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SyntheticWebTouchEvent touch; 95303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) touch.PressPoint(bounds.x() + 2, bounds.y() + 10); 95403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, 95503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ui::LatencyInfo()); 95603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) filter()->WaitForAck(blink::WebInputEvent::TouchStart); 95703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 95803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 95903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Assert on the ack, because we'll end up waiting for acks that will never 96003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // come if this is not true. 96103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state()); 96203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 96303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Send first touch move, and then a scroll begin. 96403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) touch.MovePoint(0, bounds.x() + 20 + 1 * dx, bounds.y() + 100); 96503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, 96603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ui::LatencyInfo()); 96703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) filter()->WaitForAck(blink::WebInputEvent::TouchMove); 96803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state()); 96903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 97003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) blink::WebGestureEvent scroll_begin = 97103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SyntheticWebGestureEventBuilder::BuildScrollBegin(1, 1); 97203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo( 97303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scroll_begin, ui::LatencyInfo()); 97403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Scroll begin ignores ack disposition, so don't wait for the ack. 97503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 97603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 97703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // First touchmove already sent, start at 2. 97803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) for (int i = 2; i <= 10; ++i) { 97903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Send a touch move, followed by a scroll update 98003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) touch.MovePoint(0, bounds.x() + 20 + i * dx, bounds.y() + 100); 98103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo( 98203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) touch, ui::LatencyInfo()); 98303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 98403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 98503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) blink::WebGestureEvent scroll_update = 98603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, 5, 0); 98703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 98803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo( 98903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scroll_update, ui::LatencyInfo()); 99003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 99103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 99203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 99303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 99403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) touch.ReleasePoint(0); 99503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, 99603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ui::LatencyInfo()); 99703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 99803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 99903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) blink::WebGestureEvent scroll_end; 100003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scroll_end.type = blink::WebInputEvent::GestureScrollEnd; 100103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo( 100203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scroll_end, ui::LatencyInfo()); 100303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WaitAFrame(); 100403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 100503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (!navigated) 100603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount")); 100703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) else 100803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount")); 100903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 101003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 101103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 10121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Test that vertical overscroll updates are sent only when a user overscrolls 10131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// vertically. 10141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_WIN) 10151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define MAYBE_VerticalOverscroll DISABLED_VerticalOverscroll 10161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#else 10171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define MAYBE_VerticalOverscroll VerticalOverscroll 10181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif 10191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_VerticalOverscroll) { 10211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 10221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci switches::kScrollEndEffect, "1"); 10231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_NO_FATAL_FAILURE(StartTestWithPage("about:blank")); 10251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WebContentsImpl* web_contents = 10261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static_cast<WebContentsImpl*>(shell()->web_contents()); 10271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci VerticalOverscrollTracker tracker; 10281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci web_contents->SetDelegate(&tracker); 10291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // This test triggers a large number of animations. Speed them up to ensure 10311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // the test completes within its time limit. 10321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ScopedAnimationDurationScaleMode fast_duration_mode( 10331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ScopedAnimationDurationScaleMode::FAST_DURATION); 10341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci aura::Window* content = web_contents->GetContentNativeView(); 10361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::EventProcessor* dispatcher = content->GetHost()->event_processor(); 10371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::Rect bounds = content->GetBoundsInRootWindow(); 10381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Overscroll horizontally. 10401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci { 10411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int kXStep = bounds.width() / 10; 10421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::Point location(bounds.right() - kXStep, bounds.y() + 5); 10431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::TimeDelta timestamp = ui::EventTimeForNow(); 10441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent press( 10451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ET_TOUCH_PRESSED, 10461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location, 10471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 0, 10481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp); 10491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 10501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 10511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 10521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location -= gfx::Vector2d(kXStep, 0); 10531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 10541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci while (location.x() > bounds.x() + kXStep) { 10561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); 10571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&inc); 10581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 10591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 10601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location -= gfx::Vector2d(10, 0); 10611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 10621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 10631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); 10651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&press); 10661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 10671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 10681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_EQ(0, tracker.num_overscroll_updates()); 10701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_FALSE(tracker.overscroll_completed()); 10711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 10721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Overscroll vertically. 10741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci { 10751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci tracker.Reset(); 10761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int kYStep = bounds.height() / 10; 10781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::Point location(bounds.x() + 10, bounds.y() + kYStep); 10791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::TimeDelta timestamp = ui::EventTimeForNow(); 10801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent press( 10811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ET_TOUCH_PRESSED, 10821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location, 10831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 0, 10841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp); 10851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 10861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 10871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 10881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location += gfx::Vector2d(0, kYStep); 10891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 10901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 10911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci while (location.y() < bounds.bottom() - kYStep) { 10921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); 10931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&inc); 10941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 10951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 10961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location += gfx::Vector2d(0, kYStep); 10971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 10981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 10991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); 11011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&release); 11021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 11031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 11041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_LT(0, tracker.num_overscroll_updates()); 11061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_TRUE(tracker.overscroll_completed()); 11071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 11081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Start out overscrolling vertically, then switch directions and finish 11101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // overscrolling horizontally. 11111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci { 11121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci tracker.Reset(); 11131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int kXStep = bounds.width() / 10; 11151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int kYStep = bounds.height() / 10; 11161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::Point location = bounds.origin() + gfx::Vector2d(0, kYStep); 11171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::TimeDelta timestamp = ui::EventTimeForNow(); 11181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent press( 11191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ET_TOUCH_PRESSED, 11201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location, 11211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 0, 11221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp); 11231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 11241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 11251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 11261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location += gfx::Vector2d(0, kYStep); 11271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 11281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci for (size_t i = 0; i < 3; ++i) { 11301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); 11311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&inc); 11321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 11331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 11341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location += gfx::Vector2d(0, kYStep); 11351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 11361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 11371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci while (location.x() < bounds.right() - kXStep) { 11391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); 11401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&inc); 11411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 11421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 11431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci location += gfx::Vector2d(kXStep, 0); 11441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci timestamp += base::TimeDelta::FromMilliseconds(10); 11451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 11461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); 11481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci details = dispatcher->OnEventFromSource(&release); 11491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_FALSE(details.dispatcher_destroyed); 11501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WaitAFrame(); 11511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_LT(0, tracker.num_overscroll_updates()); 11531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_FALSE(tracker.overscroll_completed()); 11541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 11551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 11561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace content 1158