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

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

Issue 2900593002: Move many more classes to use WebLocalFrameBase over WebLocalFrameImpl. (Closed)
Patch Set: Rebase Created 3 years, 6 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 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/LocalFrameClientImpl.h" 31 #include "web/LocalFrameClientImpl.h"
32 32
33 #include "core/frame/WebLocalFrameBase.h"
33 #include "core/loader/FrameLoader.h" 34 #include "core/loader/FrameLoader.h"
34 #include "platform/weborigin/KURL.h" 35 #include "platform/weborigin/KURL.h"
35 #include "platform/wtf/text/CString.h" 36 #include "platform/wtf/text/CString.h"
36 #include "platform/wtf/text/WTFString.h" 37 #include "platform/wtf/text/WTFString.h"
37 #include "public/web/WebFrameClient.h" 38 #include "public/web/WebFrameClient.h"
38 #include "public/web/WebSettings.h" 39 #include "public/web/WebSettings.h"
39 #include "public/web/WebView.h" 40 #include "public/web/WebView.h"
40 #include "testing/gmock/include/gmock/gmock.h" 41 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
42 #include "web/WebLocalFrameImpl.h"
43 #include "web/tests/FrameTestHelpers.h" 43 #include "web/tests/FrameTestHelpers.h"
44 44
45 using testing::_; 45 using testing::_;
46 using testing::Mock; 46 using testing::Mock;
47 using testing::Return; 47 using testing::Return;
48 48
49 namespace blink { 49 namespace blink {
50 namespace { 50 namespace {
51 51
52 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient { 52 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
(...skipping 21 matching lines...) Expand all
74 } 74 }
75 75
76 void TearDown() override { web_view_->Close(); } 76 void TearDown() override { web_view_->Close(); }
77 77
78 WebString UserAgent() { 78 WebString UserAgent() {
79 // The test always returns the same user agent . 79 // The test always returns the same user agent .
80 WTF::CString user_agent = GetLocalFrameClient().UserAgent().Utf8(); 80 WTF::CString user_agent = GetLocalFrameClient().UserAgent().Utf8();
81 return WebString::FromUTF8(user_agent.data(), user_agent.length()); 81 return WebString::FromUTF8(user_agent.data(), user_agent.length());
82 } 82 }
83 83
84 WebLocalFrameImpl* MainFrame() { 84 WebLocalFrameBase* MainFrame() {
85 return ToWebLocalFrameImpl(web_view_->MainFrame()); 85 return ToWebLocalFrameBase(web_view_->MainFrame());
86 } 86 }
87 Document& GetDocument() { 87 Document& GetDocument() {
88 return *ToWebLocalFrameImpl(main_frame_)->GetFrame()->GetDocument(); 88 return *ToWebLocalFrameBase(main_frame_)->GetFrame()->GetDocument();
89 } 89 }
90 MockWebFrameClient& WebFrameClient() { return web_frame_client_; } 90 MockWebFrameClient& WebFrameClient() { return web_frame_client_; }
91 LocalFrameClient& GetLocalFrameClient() { 91 LocalFrameClient& GetLocalFrameClient() {
92 return *ToLocalFrameClientImpl(ToWebLocalFrameImpl(web_view_->MainFrame()) 92 return *ToLocalFrameClientImpl(ToWebLocalFrameBase(web_view_->MainFrame())
93 ->GetFrame() 93 ->GetFrame()
94 ->Loader() 94 ->Loader()
95 .Client()); 95 .Client());
96 } 96 }
97 97
98 private: 98 private:
99 MockWebFrameClient web_frame_client_; 99 MockWebFrameClient web_frame_client_;
100 WebView* web_view_; 100 WebView* web_view_;
101 WebLocalFrame* main_frame_; 101 WebLocalFrame* main_frame_;
102 }; 102 };
103 103
104 TEST_F(LocalFrameClientImplTest, UserAgentOverride) { 104 TEST_F(LocalFrameClientImplTest, UserAgentOverride) {
105 const WebString default_user_agent = UserAgent(); 105 const WebString default_user_agent = UserAgent();
106 const WebString override_user_agent = WebString::FromUTF8("dummy override"); 106 const WebString override_user_agent = WebString::FromUTF8("dummy override");
107 107
108 // Override the user agent and make sure we get it back. 108 // Override the user agent and make sure we get it back.
109 EXPECT_CALL(WebFrameClient(), UserAgentOverride()) 109 EXPECT_CALL(WebFrameClient(), UserAgentOverride())
110 .WillOnce(Return(override_user_agent)); 110 .WillOnce(Return(override_user_agent));
111 EXPECT_TRUE(override_user_agent.Equals(UserAgent())); 111 EXPECT_TRUE(override_user_agent.Equals(UserAgent()));
112 Mock::VerifyAndClearExpectations(&WebFrameClient()); 112 Mock::VerifyAndClearExpectations(&WebFrameClient());
113 113
114 // Remove the override and make sure we get the original back. 114 // Remove the override and make sure we get the original back.
115 EXPECT_CALL(WebFrameClient(), UserAgentOverride()) 115 EXPECT_CALL(WebFrameClient(), UserAgentOverride())
116 .WillOnce(Return(WebString())); 116 .WillOnce(Return(WebString()));
117 EXPECT_TRUE(default_user_agent.Equals(UserAgent())); 117 EXPECT_TRUE(default_user_agent.Equals(UserAgent()));
118 } 118 }
119 119
120 } // namespace 120 } // namespace
121 } // namespace blink 121 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698