This source file includes following definitions.
- GoBack
- GetWebContents
- GetScriptIntValue
- GetScrollTop
- GetScrollLeft
- SendWheelEvent
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/base/net_util.h"
#include "url/gurl.h"
class ChromeRenderWidgetHostViewMacDelegateTest : public InProcessBrowserTest {
public:
ChromeRenderWidgetHostViewMacDelegateTest() {
const base::FilePath base_path(FILE_PATH_LITERAL("scroll"));
url1_ = ui_test_utils::GetTestUrl(
base_path, base::FilePath(FILE_PATH_LITERAL("text.html")));
url2_ = ui_test_utils::GetTestUrl(
base_path, base::FilePath(FILE_PATH_LITERAL("blank.html")));
}
protected:
void GoBack() {
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::GoBack(browser(), CURRENT_TAB);
observer.Wait();
}
content::WebContents* GetWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
int GetScriptIntValue(const std::string& query) {
int value = 0;
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
GetWebContents(),
"domAutomationController.send(" + query + ")",
&value));
return value;
}
int GetScrollTop() {
return GetScriptIntValue("document.body.scrollTop");
}
int GetScrollLeft() {
return GetScriptIntValue("document.body.scrollLeft");
}
void SendWheelEvent(int dx, int dy, blink::WebMouseWheelEvent::Phase phase) {
blink::WebMouseWheelEvent event;
event.type = blink::WebInputEvent::MouseWheel;
event.phase = phase;
event.deltaX = dx;
event.deltaY = dy;
event.wheelTicksY = -2;
event.hasPreciseScrollingDeltas = 1;
GetWebContents()->GetRenderViewHost()->ForwardWheelEvent(event);
}
GURL url1_;
GURL url2_;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeRenderWidgetHostViewMacDelegateTest);
};
IN_PROC_BROWSER_TEST_F(ChromeRenderWidgetHostViewMacDelegateTest,
GoBackScrollOffset) {
ui_test_utils::NavigateToURL(browser(), url1_);
ASSERT_EQ(url1_, GetWebContents()->GetURL());
SendWheelEvent(0, -200, blink::WebMouseWheelEvent::PhaseNone);
const int scroll_offset = GetScrollTop();
ASSERT_NE(0, scroll_offset);
ui_test_utils::NavigateToURL(browser(), url2_);
ASSERT_EQ(url2_, GetWebContents()->GetURL());
ASSERT_EQ(0, GetScrollTop());
GoBack();
ASSERT_EQ(url1_, GetWebContents()->GetURL());
ASSERT_EQ(scroll_offset, GetScrollTop());
}
IN_PROC_BROWSER_TEST_F(ChromeRenderWidgetHostViewMacDelegateTest,
GoBackUsingGestureScrollOffset) {
ui_test_utils::NavigateToURL(browser(), url1_);
ASSERT_EQ(url1_, GetWebContents()->GetURL());
SendWheelEvent(0, -200, blink::WebMouseWheelEvent::PhaseNone);
const int scroll_offset = GetScrollTop();
ASSERT_NE(0, scroll_offset);
ui_test_utils::NavigateToURL(browser(), url2_);
ASSERT_EQ(url2_, GetWebContents()->GetURL());
ASSERT_EQ(0, GetScrollTop());
SendWheelEvent(500, 0, blink::WebMouseWheelEvent::PhaseBegan);
SendWheelEvent(500, 0, blink::WebMouseWheelEvent::PhaseEnded);
ASSERT_EQ(0, GetScrollLeft());
GoBack();
ASSERT_EQ(url1_, GetWebContents()->GetURL());
ASSERT_EQ(scroll_offset, GetScrollTop());
}