web_contents_view_aura_browsertest.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// Use of this source code is governed by a BSD-style license that can be 3b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// found in the LICENSE file. 4b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 5b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/browser/web_contents/web_contents_view_aura.h" 6b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 7b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "base/command_line.h" 8b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "base/run_loop.h" 92a835f947a114142071456d7586118a0949499a0Misha Brukman#include "base/strings/utf_string_conversions.h" 10b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "base/test/test_timeouts.h" 11b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "base/values.h" 12b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#if defined(OS_WIN) 13b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "base/win/windows_version.h" 14b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#endif 152a835f947a114142071456d7586118a0949499a0Misha Brukman#include "content/browser/frame_host/navigation_controller_impl.h" 16b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/browser/frame_host/navigation_entry_impl.h" 17b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 18b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/browser/web_contents/web_contents_impl.h" 19ce07e99dd6fafc51805c21d53286ae5765d1cffcMisha Brukman#include "content/browser/web_contents/web_contents_view.h" 20b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/browser/render_frame_host.h" 21b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/browser/web_contents_observer.h" 22b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/common/content_switches.h" 23b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/test/browser_test_utils.h" 24b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/test/content_browser_test.h" 25b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/test/content_browser_test_utils.h" 26b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/public/test/test_utils.h" 27b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "content/shell/browser/shell.h" 28b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "ui/aura/test/event_generator.h" 292a835f947a114142071456d7586118a0949499a0Misha Brukman#include "ui/aura/window.h" 30b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "ui/aura/window_tree_host.h" 31b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#include "ui/compositor/scoped_animation_duration_scale_mode.h" 32d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "ui/events/event_processor.h" 33fdf16ca44f130afe80c57481d0c08130aa08cc09Rafael Espindola 34d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruthnamespace content { 359ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames 36a937f220e14826266a8f05b58a541aad669c8912Lang Hames// This class keeps track of the RenderViewHost whose screenshot was captured. 37b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Chengclass ScreenshotTracker : public NavigationEntryScreenshotManager { 38789d5d85ba6e9259a8e0f0bcfbd06a59ad164512Pete Cooper public: 3927601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames explicit ScreenshotTracker(NavigationControllerImpl* controller) 404eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer : NavigationEntryScreenshotManager(controller), 419ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames screenshot_taken_for_(NULL), 422a835f947a114142071456d7586118a0949499a0Misha Brukman waiting_for_screenshots_(0) { 43781f5b3953a6ffcf878cebecf1f121a237eff5baLang Hames } 442a835f947a114142071456d7586118a0949499a0Misha Brukman 452a835f947a114142071456d7586118a0949499a0Misha Brukman virtual ~ScreenshotTracker() { 461ead68d769f27f6d68d4aaeffe4199fa2cacbc95Jakob Stoklund Olesen } 470b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth 48b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; } 49dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 50ce63ffb52f249b62cdf2d250c128007b13f27e71Daniel Dunbar void Reset() { 512a835f947a114142071456d7586118a0949499a0Misha Brukman screenshot_taken_for_ = NULL; 522a835f947a114142071456d7586118a0949499a0Misha Brukman screenshot_set_.clear(); 532a835f947a114142071456d7586118a0949499a0Misha Brukman } 542a835f947a114142071456d7586118a0949499a0Misha Brukman 55b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng void SetScreenshotInterval(int interval_ms) { 5620df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames SetMinScreenshotIntervalMS(interval_ms); 57b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng } 58b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 59f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames void WaitUntilScreenshotIsReady() { 60eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames if (!waiting_for_screenshots_) 61dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return; 62dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines message_loop_runner_ = new content::MessageLoopRunner; 63b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng message_loop_runner_->Run(); 641aecd15bd1b54f33bfd928e082a3798f0edf33aaDuncan Sands } 65f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 66b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng bool ScreenshotSetForEntry(NavigationEntryImpl* entry) const { 678481e3b368444386d5be5b74cd1e0ba6f858d983Lang Hames return screenshot_set_.count(entry) > 0; 688481e3b368444386d5be5b74cd1e0ba6f858d983Lang Hames } 69030c4bfbc9885444b8a5ad0b5f1e50045a351d17Lang Hames 70030c4bfbc9885444b8a5ad0b5f1e50045a351d17Lang Hames private: 718481e3b368444386d5be5b74cd1e0ba6f858d983Lang Hames // Overridden from NavigationEntryScreenshotManager: 7220df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames virtual void TakeScreenshotImpl(RenderViewHost* host, 7320df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames NavigationEntryImpl* entry) OVERRIDE { 7420df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames ++waiting_for_screenshots_; 7520df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames screenshot_taken_for_ = host; 7620df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry); 7720df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames } 7820df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames 79f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE { 80f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames --waiting_for_screenshots_; 81f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames screenshot_set_[entry] = true; 82f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames NavigationEntryScreenshotManager::OnScreenshotSet(entry); 83f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames if (waiting_for_screenshots_ == 0 && message_loop_runner_.get()) 84f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames message_loop_runner_->Quit(); 85f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames } 86f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 87f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames RenderViewHost* screenshot_taken_for_; 88f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 89f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames int waiting_for_screenshots_; 90f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames std::map<NavigationEntryImpl*, bool> screenshot_set_; 91dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 9236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker); 93081c34b725980f995be9080eaec24cd3dfaaf065Owen Anderson}; 94081c34b725980f995be9080eaec24cd3dfaaf065Owen Anderson 95081c34b725980f995be9080eaec24cd3dfaaf065Owen Andersonclass NavigationWatcher : public WebContentsObserver { 96081c34b725980f995be9080eaec24cd3dfaaf065Owen Anderson public: 97081c34b725980f995be9080eaec24cd3dfaaf065Owen Anderson explicit NavigationWatcher(WebContents* contents) 98f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames : WebContentsObserver(contents), 99f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames navigated_(false), 10036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines should_quit_loop_(false) { 101f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames } 102f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 103f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames virtual ~NavigationWatcher() {} 104f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 10536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void WaitUntilNavigationStarts() { 106f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames if (navigated_) 107f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames return; 10836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines should_quit_loop_ = true; 109f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames base::MessageLoop::current()->Run(); 110f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames } 111f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 112f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames private: 113f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // Overridden from WebContentsObserver: 114f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames virtual void AboutToNavigateRenderView(RenderViewHost* host) OVERRIDE { 115f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames navigated_ = true; 116f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames if (should_quit_loop_) 117f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames base::MessageLoop::current()->Quit(); 118f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames } 119f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 12036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool navigated_; 121f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames bool should_quit_loop_; 1228d857660ce194f05eca3e21d149e8cf3101da9e4Lang Hames 1238d857660ce194f05eca3e21d149e8cf3101da9e4Lang Hames DISALLOW_COPY_AND_ASSIGN(NavigationWatcher); 124f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames}; 125f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 126f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hamesclass WebContentsViewAuraTest : public ContentBrowserTest { 127f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames public: 128f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames WebContentsViewAuraTest() 1294eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer : screenshot_manager_(NULL) { 130f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames } 13136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 132f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // Executes the javascript synchronously and makes sure the returned value is 133f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // freed properly. 134f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { 135f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames scoped_ptr<base::Value> value = 136f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames content::ExecuteScriptAndGetValue(rfh, jscript); 137f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames } 138f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 139f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // Starts the test server and navigates to the given url. Sets a large enough 140f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // size to the root window. Returns after the navigation to the url is 141f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // complete. 142f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames void StartTestWithPage(const std::string& url) { 143f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames ASSERT_TRUE(test_server()->Start()); 144f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames GURL test_url(test_server()->GetURL(url)); 145f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames NavigateToURL(shell(), test_url); 146f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 147f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames WebContentsImpl* web_contents = 148f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 149f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames NavigationControllerImpl* controller = &web_contents->GetController(); 150f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 151f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames screenshot_manager_ = new ScreenshotTracker(controller); 152eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames controller->SetScreenshotManager(screenshot_manager_); 153eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames } 154f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 155f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames void TestOverscrollNavigation(bool touch_handler) { 15636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ASSERT_NO_FATAL_FAILURE( 157eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames StartTestWithPage("files/overscroll_navigation.html")); 158eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames WebContentsImpl* web_contents = 159eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 160eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames NavigationController& controller = web_contents->GetController(); 161eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames RenderFrameHost* main_frame = web_contents->GetMainFrame(); 16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 163eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames web_contents->GetView()); 164eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames view_aura->SetupOverlayWindowForTesting(); 165eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 16616f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick EXPECT_FALSE(controller.CanGoBack()); 167eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_FALSE(controller.CanGoForward()); 168eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames int index = -1; 169eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames scoped_ptr<base::Value> value = 170eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 171eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ASSERT_TRUE(value->GetAsInteger(&index)); 172eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_EQ(0, index); 173eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 174eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames if (touch_handler) 175eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); 176eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 177eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 178eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 179eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 180eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ASSERT_TRUE(value->GetAsInteger(&index)); 181eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_EQ(2, index); 182eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_TRUE(controller.CanGoBack()); 183eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_FALSE(controller.CanGoForward()); 184eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 185604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs aura::Window* content = web_contents->GetContentNativeView(); 1864eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer gfx::Rect bounds = content->GetBoundsInRootWindow(); 187604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs aura::test::EventGenerator generator(content->GetRootWindow(), content); 188eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames const int kScrollDurationMs = 20; 1893b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen const int kScrollSteps = 10; 190eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 19116f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick { 192eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames // Do a swipe-right now. That should navigate backwards. 19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines base::string16 expected_title = base::ASCIIToUTF16("Title: #1"); 19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines content::TitleWatcher title_watcher(web_contents, expected_title); 195eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames generator.GestureScrollSequence( 196eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames gfx::Point(bounds.x() + 2, bounds.y() + 10), 197eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames gfx::Point(bounds.right() - 10, bounds.y() + 10), 198d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen base::TimeDelta::FromMilliseconds(kScrollDurationMs), 1993b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen kScrollSteps); 200d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen base::string16 actual_title = title_watcher.WaitAndGetTitle(); 201d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen EXPECT_EQ(expected_title, actual_title); 202d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 203eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ASSERT_TRUE(value->GetAsInteger(&index)); 204eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_EQ(1, index); 20516f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick EXPECT_TRUE(controller.CanGoBack()); 206eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_TRUE(controller.CanGoForward()); 207eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames } 208eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 209eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames { 2103b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen // Do a fling-right now. That should navigate backwards. 2113b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen base::string16 expected_title = base::ASCIIToUTF16("Title:"); 2123b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen content::TitleWatcher title_watcher(web_contents, expected_title); 2138a8cf9617cdc735f0425e828bb7a6f401c0cf0f6Lang Hames generator.GestureScrollSequence( 2143b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen gfx::Point(bounds.x() + 2, bounds.y() + 10), 215eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames gfx::Point(bounds.right() - 10, bounds.y() + 10), 216eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames base::TimeDelta::FromMilliseconds(kScrollDurationMs), 217eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames kScrollSteps); 218eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames base::string16 actual_title = title_watcher.WaitAndGetTitle(); 219dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines EXPECT_EQ(expected_title, actual_title); 220714c0eb811340a41a602509b70ca83cd4b2f2868Jakob Stoklund Olesen value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 221714c0eb811340a41a602509b70ca83cd4b2f2868Jakob Stoklund Olesen ASSERT_TRUE(value->GetAsInteger(&index)); 222fb9ebbf236974beac31705eaeb9f50ab585af6abJakob Stoklund Olesen EXPECT_EQ(0, index); 2233b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen EXPECT_FALSE(controller.CanGoBack()); 2243b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen EXPECT_TRUE(controller.CanGoForward()); 2253b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen } 2268a8cf9617cdc735f0425e828bb7a6f401c0cf0f6Lang Hames 2273b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen { 2283b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen // Do a swipe-left now. That should navigate forward. 2293b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen base::string16 expected_title = base::ASCIIToUTF16("Title: #1"); 230241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen content::TitleWatcher title_watcher(web_contents, expected_title); 231241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen generator.GestureScrollSequence( 232241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen gfx::Point(bounds.right() - 10, bounds.y() + 10), 233241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen gfx::Point(bounds.x() + 2, bounds.y() + 10), 234241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen base::TimeDelta::FromMilliseconds(kScrollDurationMs), 2353b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen kScrollSteps); 236eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames base::string16 actual_title = title_watcher.WaitAndGetTitle(); 237241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen EXPECT_EQ(expected_title, actual_title); 238241d0209a765c97c684b120527e185f17723f650Jakob Stoklund Olesen value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 2393b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen ASSERT_TRUE(value->GetAsInteger(&index)); 2403b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen EXPECT_EQ(1, index); 2413b30bca16f7ab002bcd5058b3f3a044a267541e0Jakob Stoklund Olesen EXPECT_TRUE(controller.CanGoBack()); 242eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_TRUE(controller.CanGoForward()); 243eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames } 24436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 245eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 246eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames int GetCurrentIndex() { 247eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames WebContentsImpl* web_contents = 248eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 24936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RenderFrameHost* main_frame = web_contents->GetMainFrame(); 25036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int index = -1; 25136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines scoped_ptr<base::Value> value; 25236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 25336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (!value->GetAsInteger(&index)) 25436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines index = -1; 25536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return index; 25636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 257eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 258eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames protected: 259481630dee5f221c04bb26fe12f0887b4f25f8455Lang Hames ScreenshotTracker* screenshot_manager() { return screenshot_manager_; } 260eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames void set_min_screenshot_interval(int interval_ms) { 261eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames screenshot_manager_->SetScreenshotInterval(interval_ms); 262eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames } 263eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 264eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames private: 26536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ScreenshotTracker* screenshot_manager_; 26636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 267eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest); 268eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames}; 269eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 270eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames// Flaky on Windows and ChromeOS: http://crbug.com/305722 271eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang HamesIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 272eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames DISABLED_OverscrollNavigation) { 27336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines TestOverscrollNavigation(false); 27436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 275eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 27636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// Flaky on Windows (might be related to the above test): 27736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// http://crbug.com/305722 278eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#if defined(OS_WIN) 279b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#define MAYBE_OverscrollNavigationWithTouchHandler \ 280eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames DISABLED_OverscrollNavigationWithTouchHandler 281eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#else 28236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#define MAYBE_OverscrollNavigationWithTouchHandler \ 283eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames OverscrollNavigationWithTouchHandler 284eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#endif 285eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang HamesIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 286eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames MAYBE_OverscrollNavigationWithTouchHandler) { 287eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames TestOverscrollNavigation(true); 288eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames} 289eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 290e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames// Disabled because the test always fails the first time it runs on the Win Aura 291e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames// bots, and usually but not always passes second-try (See crbug.com/179532). 292e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames#if defined(OS_WIN) 293e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames#define MAYBE_QuickOverscrollDirectionChange \ 294e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames DISABLED_QuickOverscrollDirectionChange 295eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#else 296eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange 297b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng#endif 2985e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang HamesIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 299eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames MAYBE_QuickOverscrollDirectionChange) { 300b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng ASSERT_NO_FATAL_FAILURE( 3015e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames StartTestWithPage("files/overscroll_navigation.html")); 302eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames WebContentsImpl* web_contents = 303d0f6f017319bbc32b57c2e574d774ac91fe20f18Lang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 304eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames RenderFrameHost* main_frame = web_contents->GetMainFrame(); 305eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 306d0f6f017319bbc32b57c2e574d774ac91fe20f18Lang Hames // This test triggers a large number of animations. Speed them up to ensure 307eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames // the test completes within its time limit. 308eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ui::ScopedAnimationDurationScaleMode fast_duration_mode( 309b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng ui::ScopedAnimationDurationScaleMode::FAST_DURATION); 310b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 311604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs // Make sure the page has both back/forward history. 312e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 3134eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer EXPECT_EQ(1, GetCurrentIndex()); 314e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 315e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames EXPECT_EQ(2, GetCurrentIndex()); 31636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines web_contents->GetController().GoBack(); 31736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EXPECT_EQ(1, GetCurrentIndex()); 318e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames 319e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames aura::Window* content = web_contents->GetContentNativeView(); 320a7542d5f870c5d98960d1676e23ac1d1d975d7e5Benjamin Kramer ui::EventProcessor* dispatcher = content->GetHost()->event_processor(); 321e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames gfx::Rect bounds = content->GetBoundsInRootWindow(); 322e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames 323e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames base::TimeDelta timestamp; 324dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 325dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines gfx::Point(bounds.x() + bounds.width() / 2, bounds.y() + 5), 326dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 0, timestamp); 327e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 3285e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames ASSERT_FALSE(details.dispatcher_destroyed); 329e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames EXPECT_EQ(1, GetCurrentIndex()); 3305e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames 331e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames timestamp += base::TimeDelta::FromMilliseconds(10); 3325e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames ui::TouchEvent move1(ui::ET_TOUCH_MOVED, 333e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames gfx::Point(bounds.right() - 10, bounds.y() + 5), 334f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 0, timestamp); 335f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames details = dispatcher->OnEventFromSource(&move1); 336e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ASSERT_FALSE(details.dispatcher_destroyed); 337f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames EXPECT_EQ(1, GetCurrentIndex()); 338f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 33916f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick // Swipe back from the right edge, back to the left edge, back to the right 340f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames // edge. 341dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 342e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames for (int x = bounds.right() - 10; x >= bounds.x() + 10; x-= 10) { 343f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames timestamp += base::TimeDelta::FromMilliseconds(10); 344790047620a8f31cee1841c06c9e5e7688166ad93Jakob Stoklund Olesen ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 345f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames gfx::Point(x, bounds.y() + 5), 3465e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames 0, timestamp); 347e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames details = dispatcher->OnEventFromSource(&inc); 348f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames ASSERT_FALSE(details.dispatcher_destroyed); 34916f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick EXPECT_EQ(1, GetCurrentIndex()); 3505e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames } 351f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 3525e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames for (int x = bounds.x() + 10; x <= bounds.width() - 10; x+= 10) { 353f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames timestamp += base::TimeDelta::FromMilliseconds(10); 354f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines gfx::Point(x, bounds.y() + 5), 35636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 0, timestamp); 35736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines details = dispatcher->OnEventFromSource(&inc); 35836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ASSERT_FALSE(details.dispatcher_destroyed); 35936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EXPECT_EQ(1, GetCurrentIndex()); 36036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 361f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 362f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames for (int x = bounds.width() - 10; x >= bounds.x() + 10; x-= 10) { 363f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames timestamp += base::TimeDelta::FromMilliseconds(10); 364f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 36536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines gfx::Point(x, bounds.y() + 5), 36636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 0, timestamp); 36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines details = dispatcher->OnEventFromSource(&inc); 368a91d7b170b57e3ccb715e331575ef198e51cd304Lang Hames ASSERT_FALSE(details.dispatcher_destroyed); 36936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EXPECT_EQ(1, GetCurrentIndex()); 37036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 37136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 372e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames // Do not end the overscroll sequence. 37336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 374f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames 375f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames// Tests that the page has has a screenshot when navigation happens: 376e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames// - from within the page (from a JS function) 37736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// - interactively, when user does an overscroll gesture 37836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// - interactively, when user navigates in history without the overscroll 37936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// gesture. 380e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames// Flaky on Windows and ChromeOS (http://crbug.com/357311). Might be related to 381e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames// OverscrollNavigation test. 382e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang HamesIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, DISABLED_OverscrollScreenshot) { 383e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames // Disable the test for WinXP. See http://crbug/294116. 384e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames#if defined(OS_WIN) 38536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (base::win::GetVersion() < base::win::VERSION_VISTA) { 386e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames LOG(WARNING) << "Test disabled due to unknown bug on WinXP."; 387e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames return; 388e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames } 389e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames#endif 390e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames 391e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ASSERT_NO_FATAL_FAILURE( 392e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames StartTestWithPage("files/overscroll_navigation.html")); 393e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames WebContentsImpl* web_contents = 394e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 395e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames RenderFrameHost* main_frame = web_contents->GetMainFrame(); 396e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames 397e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames set_min_screenshot_interval(0); 398e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames 399e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames // Do a few navigations initiated by the page. 400e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 401e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames EXPECT_EQ(1, GetCurrentIndex()); 402e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 4035e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames EXPECT_EQ(2, GetCurrentIndex()); 404e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames screenshot_manager()->WaitUntilScreenshotIsReady(); 4055e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames 406e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames // The current entry won't have any screenshots. But the entries in the 407e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames // history should now have screenshots. 408e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 409e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames web_contents->GetController().GetEntryAtIndex(2)); 41016f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick EXPECT_FALSE(entry->screenshot().get()); 411e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames 412e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames entry = NavigationEntryImpl::FromNavigationEntry( 413e9c935662d77b8c5a3a26f5622dc2a3ed22d75c8Lang Hames web_contents->GetController().GetEntryAtIndex(1)); 414b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 415eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 416eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames entry = NavigationEntryImpl::FromNavigationEntry( 4179ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames web_contents->GetController().GetEntryAtIndex(0)); 4189ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 4199ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames 420eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames // Navigate again. Index 2 should now have a screenshot. 421eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 422eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_EQ(3, GetCurrentIndex()); 423442c59f0a2fc3e596d0ce1f13b4a6849b2f46cc4Lang Hames screenshot_manager()->WaitUntilScreenshotIsReady(); 424eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 4258d857660ce194f05eca3e21d149e8cf3101da9e4Lang Hames entry = NavigationEntryImpl::FromNavigationEntry( 4268d857660ce194f05eca3e21d149e8cf3101da9e4Lang Hames web_contents->GetController().GetEntryAtIndex(2)); 427eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 428eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 4294eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer entry = NavigationEntryImpl::FromNavigationEntry( 4304eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer web_contents->GetController().GetEntryAtIndex(3)); 431781f5b3953a6ffcf878cebecf1f121a237eff5baLang Hames EXPECT_FALSE(entry->screenshot().get()); 432781f5b3953a6ffcf878cebecf1f121a237eff5baLang Hames 4339ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames { 4349ad7e07a0fb565a8935ceaa2d266bd6e505203afLang Hames // Now, swipe right to navigate backwards. This should navigate away from 435eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames // index 3 to index 2, and index 3 should have a screenshot. 436442c59f0a2fc3e596d0ce1f13b4a6849b2f46cc4Lang Hames base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); 437eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames content::TitleWatcher title_watcher(web_contents, expected_title); 438eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames aura::Window* content = web_contents->GetContentNativeView(); 439eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames gfx::Rect bounds = content->GetBoundsInRootWindow(); 440eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames aura::test::EventGenerator generator(content->GetRootWindow(), content); 44127601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames generator.GestureScrollSequence( 44227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames gfx::Point(bounds.x() + 2, bounds.y() + 10), 443d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen gfx::Point(bounds.right() - 10, bounds.y() + 10), 444d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen base::TimeDelta::FromMilliseconds(20), 445d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen 1); 44627601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames base::string16 actual_title = title_watcher.WaitAndGetTitle(); 447d67582e2767df96610ba8dc1835ad4bf99fc77e8Jakob Stoklund Olesen EXPECT_EQ(expected_title, actual_title); 44827601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_EQ(2, GetCurrentIndex()); 44927601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames screenshot_manager()->WaitUntilScreenshotIsReady(); 45027601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames entry = NavigationEntryImpl::FromNavigationEntry( 45127601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames web_contents->GetController().GetEntryAtIndex(3)); 45227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 453eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames } 4545e77f4b1d239a61dbdb37026bfc92d83d82ceb70Lang Hames 455eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames // Navigate a couple more times. 45627601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames ExecuteSyncJSFunction(main_frame, "navigate_next()"); 45727601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_EQ(3, GetCurrentIndex()); 458b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng ExecuteSyncJSFunction(main_frame, "navigate_next()"); 459b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng EXPECT_EQ(4, GetCurrentIndex()); 460f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames screenshot_manager()->WaitUntilScreenshotIsReady(); 461f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames entry = NavigationEntryImpl::FromNavigationEntry( 462eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames web_contents->GetController().GetEntryAtIndex(4)); 463eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_FALSE(entry->screenshot().get()); 464eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 465eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames { 466eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames // Navigate back in history. 467eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames base::string16 expected_title = base::ASCIIToUTF16("Title: #3"); 46836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines content::TitleWatcher title_watcher(web_contents, expected_title); 469eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames web_contents->GetController().GoBack(); 470eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames base::string16 actual_title = title_watcher.WaitAndGetTitle(); 47136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EXPECT_EQ(expected_title, actual_title); 47236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EXPECT_EQ(3, GetCurrentIndex()); 47336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines screenshot_manager()->WaitUntilScreenshotIsReady(); 474eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames entry = NavigationEntryImpl::FromNavigationEntry( 475eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames web_contents->GetController().GetEntryAtIndex(4)); 47616f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 477d76938788b4b682043a74befbb6320ce0077ddc9Patrik Hägglund } 478d76938788b4b682043a74befbb6320ce0077ddc9Patrik Hägglund} 479eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 48016f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick// Crashes under ThreadSanitizer, http://crbug.com/356758. 481eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#if defined(THREAD_SANITIZER) 482eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames#define MAYBE_ScreenshotForSwappedOutRenderViews \ 4831feb5854aeeda897e9318c8193d187673c8576b8Mark Lacey DISABLED_ScreenshotForSwappedOutRenderViews 48420942dcd8634ad75091fe89669868cfebf74e869Jakob Stoklund Olesen#else 485cfa81014099254bd42f246a4d434dc2ca1463c6cJakob Stoklund Olesen#define MAYBE_ScreenshotForSwappedOutRenderViews \ 486cfa81014099254bd42f246a4d434dc2ca1463c6cJakob Stoklund Olesen ScreenshotForSwappedOutRenderViews 487d76938788b4b682043a74befbb6320ce0077ddc9Patrik Hägglund#endif 488cfa81014099254bd42f246a4d434dc2ca1463c6cJakob Stoklund Olesen// Tests that screenshot is taken correctly when navigation causes a 489eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames// RenderViewHost to be swapped out. 490eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang HamesIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 491eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames MAYBE_ScreenshotForSwappedOutRenderViews) { 492cfa81014099254bd42f246a4d434dc2ca1463c6cJakob Stoklund Olesen ASSERT_NO_FATAL_FAILURE( 493eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames StartTestWithPage("files/overscroll_navigation.html")); 4941feb5854aeeda897e9318c8193d187673c8576b8Mark Lacey // Create a new server with a different site. 4951feb5854aeeda897e9318c8193d187673c8576b8Mark Lacey net::SpawnedTestServer https_server( 4961feb5854aeeda897e9318c8193d187673c8576b8Mark Lacey net::SpawnedTestServer::TYPE_HTTPS, 4971feb5854aeeda897e9318c8193d187673c8576b8Mark Lacey net::SpawnedTestServer::kLocalhost, 49827601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 49927601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames ASSERT_TRUE(https_server.Start()); 500309315420669ff5bde9b0ae1213171a88216fad7David Greene 501b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng WebContentsImpl* web_contents = 502b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng static_cast<WebContentsImpl*>(shell()->web_contents()); 503cfa81014099254bd42f246a4d434dc2ca1463c6cJakob Stoklund Olesen set_min_screenshot_interval(0); 504eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames 5055e25ee8a1fcf8288d00d731b0f7ab7976f33b123Craig Topper struct { 506b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng GURL url; 507b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng int transition; 508b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng } navigations[] = { 509b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng { https_server.GetURL("files/title1.html"), 510b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, 511b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng { test_server()->GetURL("files/title2.html"), 512eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames PAGE_TRANSITION_AUTO_BOOKMARK }, 513eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames { https_server.GetURL("files/title3.html"), 51427601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, 515eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames { GURL(), 0 } 516eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames }; 51727601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 518eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames screenshot_manager()->Reset(); 51927601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames for (int i = 0; !navigations[i].url.is_empty(); ++i) { 520980bddfb1c26e2e9374d1645f9ae26c44742606fJakob Stoklund Olesen // Navigate via the user initiating a navigation from the UI. 5216699fb27091927528f9f6059c3034d566dbed623Lang Hames NavigationController::LoadURLParams params(navigations[i].url); 52227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames params.transition_type = PageTransitionFromInt(navigations[i].transition); 52327601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 524714c0eb811340a41a602509b70ca83cd4b2f2868Jakob Stoklund Olesen RenderViewHost* old_host = web_contents->GetRenderViewHost(); 52527601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames web_contents->GetController().LoadURLWithParams(params); 5262a835f947a114142071456d7586118a0949499a0Misha Brukman WaitForLoadStop(web_contents); 5272a835f947a114142071456d7586118a0949499a0Misha Brukman screenshot_manager()->WaitUntilScreenshotIsReady(); 52827601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 52927601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_NE(old_host, web_contents->GetRenderViewHost()) 53027601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames << navigations[i].url.spec(); 531eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for()); 53227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 533b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 534b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng web_contents->GetController().GetEntryAtOffset(-1)); 535b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 53627601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 53716f72dd68653bd4984363483cfc15ce91fa613d4Andrew Trick entry = NavigationEntryImpl::FromNavigationEntry( 538b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng web_contents->GetController().GetLastCommittedEntry()); 53927601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 54027601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_FALSE(entry->screenshot().get()); 5414eed756153b84c211114a3e9186bf0cb55d4b394Benjamin Kramer screenshot_manager()->Reset(); 542b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng } 543095f994ba63994e8eb4b77127f9b872429496dbaArnaud A. de Grandmaison 544095f994ba63994e8eb4b77127f9b872429496dbaArnaud A. de Grandmaison // Increase the minimum interval between taking screenshots. 545a77da0579bc141eba62760e21a216e5d3eafd792Arnaud A. de Grandmaison set_min_screenshot_interval(60000); 54649c8aa0d8b2824c70d178c5d55cda64d6613c0d8Owen Anderson 547cfa81014099254bd42f246a4d434dc2ca1463c6cJakob Stoklund Olesen // Navigate again. This should not take any screenshot because of the 548b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng // increased screenshot interval. 54918bb0545ff79b85ef424e95e2170e3a06f11b735Chad Rosier NavigationController::LoadURLParams params(navigations[0].url); 55018bb0545ff79b85ef424e95e2170e3a06f11b735Chad Rosier params.transition_type = PageTransitionFromInt(navigations[0].transition); 55196601ca332ab388754ca4673be8973396fea2dddCraig Topper web_contents->GetController().LoadURLWithParams(params); 55227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames WaitForLoadStop(web_contents); 553b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng screenshot_manager()->WaitUntilScreenshotIsReady(); 5542a835f947a114142071456d7586118a0949499a0Misha Brukman 555b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); 556b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng} 557b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 558b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// TODO(sadrul): This test is disabled because it reparents in a way the 5592a835f947a114142071456d7586118a0949499a0Misha Brukman// FocusController does not support. This code would crash in 560b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// a production build. It only passed prior to this revision 561b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// because testing used the old FocusManager which did some 56227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames// different (osbolete) processing. TODO(sadrul) to figure out 56327601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames// how this test should work that mimics production code a bit 5642a835f947a114142071456d7586118a0949499a0Misha Brukman// better. 56596601ca332ab388754ca4673be8973396fea2dddCraig TopperIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 56620df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames DISABLED_ContentWindowReparent) { 56720df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames ASSERT_NO_FATAL_FAILURE( 56820df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames StartTestWithPage("files/overscroll_navigation.html")); 56920df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames 57096601ca332ab388754ca4673be8973396fea2dddCraig Topper scoped_ptr<aura::Window> window(new aura::Window(NULL)); 57120df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames window->Init(aura::WINDOW_LAYER_NOT_DRAWN); 57227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 573eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames WebContentsImpl* web_contents = 57427601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 57527601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 57627601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames EXPECT_EQ(1, GetCurrentIndex()); 57727601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 578ab62b7e8618bda8063b49afab181bc7ed5546104Lang Hames aura::Window* content = web_contents->GetContentNativeView(); 579ab62b7e8618bda8063b49afab181bc7ed5546104Lang Hames gfx::Rect bounds = content->GetBoundsInRootWindow(); 5806699fb27091927528f9f6059c3034d566dbed623Lang Hames aura::test::EventGenerator generator(content->GetRootWindow(), content); 58136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines generator.GestureScrollSequence( 58236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines gfx::Point(bounds.x() + 2, bounds.y() + 10), 58320df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames gfx::Point(bounds.right() - 10, bounds.y() + 10), 58420df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames base::TimeDelta::FromMilliseconds(20), 58520df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames 1); 58620df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames 58720df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames window->AddChild(shell()->web_contents()->GetContentNativeView()); 58820df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames} 58920df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames 59036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) { 59120df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames ASSERT_NO_FATAL_FAILURE( 59220df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames StartTestWithPage("files/overscroll_navigation.html")); 59320df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames 59420df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames WebContentsImpl* web_contents = 59520df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames static_cast<WebContentsImpl*>(shell()->web_contents()); 59620df03ccd572aefadc3d68e4abc2e58c0bef9ff7Lang Hames ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 597ab62b7e8618bda8063b49afab181bc7ed5546104Lang Hames EXPECT_EQ(1, GetCurrentIndex()); 59836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 599233fd9cea04468d71ae44031df3f2c8d1c3299a7Lang Hames aura::Window* content = web_contents->GetContentNativeView(); 600ab62b7e8618bda8063b49afab181bc7ed5546104Lang Hames gfx::Rect bounds = content->GetBoundsInRootWindow(); 601b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng aura::test::EventGenerator generator(content->GetRootWindow(), content); 602ab62b7e8618bda8063b49afab181bc7ed5546104Lang Hames generator.GestureScrollSequence( 60327601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames gfx::Point(bounds.x() + 2, bounds.y() + 10), 604b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng gfx::Point(bounds.right() - 10, bounds.y() + 10), 605b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng base::TimeDelta::FromMilliseconds(20), 60627601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 1); 60727601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames 608eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames delete web_contents->GetContentNativeView(); 609eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames} 610b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 611309315420669ff5bde9b0ae1213171a88216fad7David Greene 61227601ef8325f85b9677b55e3e2ca1a1368d8eee5Lang Hames#if defined(OS_WIN) 6132a835f947a114142071456d7586118a0949499a0Misha Brukman// This appears to be flaky in the same was as the other overscroll 614b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// tests. Enabling for non-Windows platforms. 615b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng// See http://crbug.com/369871. 61636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#define MAYBE_RepeatedQuickOverscrollGestures DISABLED_RepeatedQuickOverscrollGestures 61736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#else 61836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#define MAYBE_RepeatedQuickOverscrollGestures RepeatedQuickOverscrollGestures 6193389e10d675f7723d3ab24deda60dfba568b42c0Benjamin Kramer#endif 620b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng 621b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan ChengIN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 622f70e7cc7a2871d498dbecbec2d1c3beb3da2af33Lang Hames MAYBE_RepeatedQuickOverscrollGestures) { 62336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ASSERT_NO_FATAL_FAILURE( 624604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs StartTestWithPage("files/overscroll_navigation.html")); 625604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs 626604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs WebContentsImpl* web_contents = 627604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs static_cast<WebContentsImpl*>(shell()->web_contents()); 628604b3573f955d61ba87215c25ba2f52477c71eccAndy Gibbs NavigationController& controller = web_contents->GetController(); 629eb6c8f53b4df1488f3d07c11af8f754cc4620f3aLang Hames RenderFrameHost* main_frame = web_contents->GetMainFrame(); 630b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 631b1290a6cc40f7caa0351450ce7021a0d48b5f2c0Evan Cheng web_contents->GetView()); 632 view_aura->SetupOverlayWindowForTesting(); 633 ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); 634 635 // Navigate twice, then navigate back in history once. 636 ExecuteSyncJSFunction(main_frame, "navigate_next()"); 637 ExecuteSyncJSFunction(main_frame, "navigate_next()"); 638 EXPECT_EQ(2, GetCurrentIndex()); 639 EXPECT_TRUE(controller.CanGoBack()); 640 EXPECT_FALSE(controller.CanGoForward()); 641 642 web_contents->GetController().GoBack(); 643 WaitForLoadStop(web_contents); 644 EXPECT_EQ(1, GetCurrentIndex()); 645 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); 646 EXPECT_TRUE(controller.CanGoBack()); 647 EXPECT_TRUE(controller.CanGoForward()); 648 649 aura::Window* content = web_contents->GetContentNativeView(); 650 gfx::Rect bounds = content->GetBoundsInRootWindow(); 651 aura::test::EventGenerator generator(content->GetRootWindow(), content); 652 653 // Do a swipe left to start a forward navigation. Then quickly do a swipe 654 // right. 655 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); 656 content::TitleWatcher title_watcher(web_contents, expected_title); 657 NavigationWatcher nav_watcher(web_contents); 658 659 generator.GestureScrollSequence( 660 gfx::Point(bounds.right() - 10, bounds.y() + 10), 661 gfx::Point(bounds.x() + 2, bounds.y() + 10), 662 base::TimeDelta::FromMilliseconds(2000), 663 10); 664 nav_watcher.WaitUntilNavigationStarts(); 665 666 generator.GestureScrollSequence( 667 gfx::Point(bounds.x() + 2, bounds.y() + 10), 668 gfx::Point(bounds.right() - 10, bounds.y() + 10), 669 base::TimeDelta::FromMilliseconds(2000), 670 10); 671 base::string16 actual_title = title_watcher.WaitAndGetTitle(); 672 EXPECT_EQ(expected_title, actual_title); 673 674 EXPECT_EQ(2, GetCurrentIndex()); 675 EXPECT_TRUE(controller.CanGoBack()); 676 EXPECT_FALSE(controller.CanGoForward()); 677} 678 679// Verify that hiding a parent of the renderer will hide the content too. 680IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, HideContentOnParenHide) { 681 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/title1.html")); 682 WebContentsImpl* web_contents = 683 static_cast<WebContentsImpl*>(shell()->web_contents()); 684 aura::Window* content = web_contents->GetNativeView()->parent(); 685 EXPECT_TRUE(web_contents->should_normally_be_visible()); 686 content->Hide(); 687 EXPECT_FALSE(web_contents->should_normally_be_visible()); 688 content->Show(); 689 EXPECT_TRUE(web_contents->should_normally_be_visible()); 690} 691 692} // namespace content 693