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

Side by Side Diff: third_party/WebKit/Source/web/tests/ProgrammaticScrollTest.cpp

Issue 2860673002: Change all test cases to use WebViewBase instead of WebViewImpl. (Closed)
Patch Set: Address code review comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "core/exported/WebViewBase.h" 1 #include "core/exported/WebViewBase.h"
2 #include "core/frame/FrameView.h" 2 #include "core/frame/FrameView.h"
3 #include "core/loader/DocumentLoader.h" 3 #include "core/loader/DocumentLoader.h"
4 #include "core/loader/FrameLoader.h" 4 #include "core/loader/FrameLoader.h"
5 #include "platform/testing/URLTestHelpers.h" 5 #include "platform/testing/URLTestHelpers.h"
6 #include "platform/testing/UnitTestHelpers.h" 6 #include "platform/testing/UnitTestHelpers.h"
7 #include "public/platform/Platform.h" 7 #include "public/platform/Platform.h"
8 #include "public/platform/WebInputEvent.h" 8 #include "public/platform/WebInputEvent.h"
9 #include "public/platform/WebURLLoaderMockFactory.h" 9 #include "public/platform/WebURLLoaderMockFactory.h"
10 #include "public/web/WebFrame.h" 10 #include "public/web/WebFrame.h"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 std::string base_url_; 39 std::string base_url_;
40 FrameTestHelpers::TestWebFrameClient mock_web_frame_client_; 40 FrameTestHelpers::TestWebFrameClient mock_web_frame_client_;
41 }; 41 };
42 42
43 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale) { 43 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale) {
44 RegisterMockedHttpURLLoad("long_scroll.html"); 44 RegisterMockedHttpURLLoad("long_scroll.html");
45 45
46 FrameTestHelpers::WebViewHelper web_view_helper; 46 FrameTestHelpers::WebViewHelper web_view_helper;
47 WebView* web_view = web_view_helper.InitializeAndLoad( 47 WebViewBase* web_view = web_view_helper.InitializeAndLoad(
48 base_url_ + "long_scroll.html", true, 0, 0); 48 base_url_ + "long_scroll.html", true, 0, 0);
49 web_view->Resize(WebSize(1000, 1000)); 49 web_view->Resize(WebSize(1000, 1000));
50 web_view->UpdateAllLifecyclePhases(); 50 web_view->UpdateAllLifecyclePhases();
51 51
52 WebViewImpl* web_view_impl = ToWebViewImpl(web_view); 52 FrameLoader& loader = web_view->MainFrameImpl()->GetFrame()->Loader();
53 FrameLoader& loader = web_view_impl->MainFrameImpl()->GetFrame()->Loader();
54 loader.GetDocumentLoader()->SetLoadType(kFrameLoadTypeBackForward); 53 loader.GetDocumentLoader()->SetLoadType(kFrameLoadTypeBackForward);
55 54
56 web_view_impl->SetPageScaleFactor(3.0f); 55 web_view->SetPageScaleFactor(3.0f);
57 web_view_impl->MainFrame()->SetScrollOffset(WebSize(0, 500)); 56 web_view->MainFrame()->SetScrollOffset(WebSize(0, 500));
58 loader.GetDocumentLoader()->GetInitialScrollState().was_scrolled_by_user = 57 loader.GetDocumentLoader()->GetInitialScrollState().was_scrolled_by_user =
59 false; 58 false;
60 loader.GetDocumentLoader()->GetHistoryItem()->SetPageScaleFactor(2); 59 loader.GetDocumentLoader()->GetHistoryItem()->SetPageScaleFactor(2);
61 loader.GetDocumentLoader()->GetHistoryItem()->SetScrollOffset( 60 loader.GetDocumentLoader()->GetHistoryItem()->SetScrollOffset(
62 ScrollOffset(0, 200)); 61 ScrollOffset(0, 200));
63 62
64 // Flip back the wasScrolledByUser flag which was set to true by 63 // Flip back the wasScrolledByUser flag which was set to true by
65 // setPageScaleFactor because otherwise 64 // setPageScaleFactor because otherwise
66 // FrameLoader::restoreScrollPositionAndViewState does nothing. 65 // FrameLoader::restoreScrollPositionAndViewState does nothing.
67 loader.GetDocumentLoader()->GetInitialScrollState().was_scrolled_by_user = 66 loader.GetDocumentLoader()->GetInitialScrollState().was_scrolled_by_user =
68 false; 67 false;
69 loader.RestoreScrollPositionAndViewState(); 68 loader.RestoreScrollPositionAndViewState();
70 69
71 // Expect that both scroll and scale were restored. 70 // Expect that both scroll and scale were restored.
72 EXPECT_EQ(2.0f, web_view_impl->PageScaleFactor()); 71 EXPECT_EQ(2.0f, web_view->PageScaleFactor());
73 EXPECT_EQ(200, web_view_impl->MainFrameImpl()->GetScrollOffset().height); 72 EXPECT_EQ(200, web_view->MainFrameImpl()->GetScrollOffset().height);
74 } 73 }
75 74
76 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) { 75 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) {
77 RegisterMockedHttpURLLoad("long_scroll.html"); 76 RegisterMockedHttpURLLoad("long_scroll.html");
78 77
79 FrameTestHelpers::WebViewHelper web_view_helper; 78 FrameTestHelpers::WebViewHelper web_view_helper;
80 WebView* web_view = web_view_helper.InitializeAndLoad( 79 WebViewBase* web_view = web_view_helper.InitializeAndLoad(
81 base_url_ + "long_scroll.html", true, 0, 0); 80 base_url_ + "long_scroll.html", true, 0, 0);
82 web_view->Resize(WebSize(1000, 1000)); 81 web_view->Resize(WebSize(1000, 1000));
83 web_view->UpdateAllLifecyclePhases(); 82 web_view->UpdateAllLifecyclePhases();
84 83
85 WebViewImpl* web_view_impl = ToWebViewImpl(web_view); 84 FrameLoader& loader = web_view->MainFrameImpl()->GetFrame()->Loader();
86 FrameLoader& loader = web_view_impl->MainFrameImpl()->GetFrame()->Loader();
87 loader.GetDocumentLoader()->SetLoadType(kFrameLoadTypeBackForward); 85 loader.GetDocumentLoader()->SetLoadType(kFrameLoadTypeBackForward);
88 86
89 web_view_impl->SetPageScaleFactor(3.0f); 87 web_view->SetPageScaleFactor(3.0f);
90 web_view_impl->MainFrame()->SetScrollOffset(WebSize(0, 500)); 88 web_view->MainFrame()->SetScrollOffset(WebSize(0, 500));
91 loader.GetDocumentLoader()->GetInitialScrollState().was_scrolled_by_user = 89 loader.GetDocumentLoader()->GetInitialScrollState().was_scrolled_by_user =
92 false; 90 false;
93 loader.GetDocumentLoader()->GetHistoryItem()->SetPageScaleFactor(0); 91 loader.GetDocumentLoader()->GetHistoryItem()->SetPageScaleFactor(0);
94 loader.GetDocumentLoader()->GetHistoryItem()->SetScrollOffset( 92 loader.GetDocumentLoader()->GetHistoryItem()->SetScrollOffset(
95 ScrollOffset(0, 400)); 93 ScrollOffset(0, 400));
96 94
97 // FrameLoader::restoreScrollPositionAndViewState flows differently if scale 95 // FrameLoader::restoreScrollPositionAndViewState flows differently if scale
98 // is zero. 96 // is zero.
99 loader.RestoreScrollPositionAndViewState(); 97 loader.RestoreScrollPositionAndViewState();
100 98
101 // Expect that only the scroll position was restored. 99 // Expect that only the scroll position was restored.
102 EXPECT_EQ(3.0f, web_view_impl->PageScaleFactor()); 100 EXPECT_EQ(3.0f, web_view->PageScaleFactor());
103 EXPECT_EQ(400, web_view_impl->MainFrameImpl()->GetScrollOffset().height); 101 EXPECT_EQ(400, web_view->MainFrameImpl()->GetScrollOffset().height);
104 } 102 }
105 103
106 } // namespace blink 104 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698