OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #include "web/FrameLoaderClientImpl.h" | |
32 | |
33 #include "core/loader/FrameLoader.h" | |
34 #include "platform/weborigin/KURL.h" | |
35 #include "public/web/WebFrameClient.h" | |
36 #include "public/web/WebSettings.h" | |
37 #include "public/web/WebView.h" | |
38 #include "testing/gmock/include/gmock/gmock.h" | |
39 #include "testing/gtest/include/gtest/gtest.h" | |
40 #include "web/WebLocalFrameImpl.h" | |
41 #include "web/tests/FrameTestHelpers.h" | |
42 #include "wtf/text/CString.h" | |
43 #include "wtf/text/WTFString.h" | |
44 | |
45 using testing::_; | |
46 using testing::Mock; | |
47 using testing::Return; | |
48 | |
49 namespace blink { | |
50 namespace { | |
51 | |
52 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | |
53 public: | |
54 ~MockWebFrameClient() override {} | |
55 | |
56 MOCK_METHOD0(userAgentOverride, WebString()); | |
57 }; | |
58 | |
59 class FrameLoaderClientImplTest : public ::testing::Test { | |
60 protected: | |
61 void SetUp() override { | |
62 ON_CALL(m_webFrameClient, userAgentOverride()) | |
63 .WillByDefault(Return(WebString())); | |
64 | |
65 FrameTestHelpers::TestWebViewClient webViewClient; | |
66 m_webView = WebView::create(&webViewClient, WebPageVisibilityStateVisible); | |
67 // FIXME: http://crbug.com/363843. This needs to find a better way to | |
68 // not create graphics layers. | |
69 m_webView->settings()->setAcceleratedCompositingEnabled(false); | |
70 m_mainFrame = WebLocalFrame::create(WebTreeScopeType::Document, | |
71 &m_webFrameClient, nullptr, nullptr); | |
72 m_webView->setMainFrame(m_mainFrame); | |
73 } | |
74 | |
75 void TearDown() override { m_webView->close(); } | |
76 | |
77 WebString userAgent() { | |
78 // The test always returns the same user agent . | |
79 WTF::CString userAgent = frameLoaderClient().userAgent().utf8(); | |
80 return WebString::fromUTF8(userAgent.data(), userAgent.length()); | |
81 } | |
82 | |
83 WebLocalFrameImpl* mainFrame() { | |
84 return toWebLocalFrameImpl(m_webView->mainFrame()); | |
85 } | |
86 Document& document() { | |
87 return *toWebLocalFrameImpl(m_mainFrame)->frame()->document(); | |
88 } | |
89 MockWebFrameClient& webFrameClient() { return m_webFrameClient; } | |
90 FrameLoaderClient& frameLoaderClient() { | |
91 return *toFrameLoaderClientImpl(toWebLocalFrameImpl(m_webView->mainFrame()) | |
92 ->frame() | |
93 ->loader() | |
94 .client()); | |
95 } | |
96 | |
97 private: | |
98 MockWebFrameClient m_webFrameClient; | |
99 WebView* m_webView; | |
100 WebLocalFrame* m_mainFrame; | |
101 }; | |
102 | |
103 TEST_F(FrameLoaderClientImplTest, UserAgentOverride) { | |
104 const WebString defaultUserAgent = userAgent(); | |
105 const WebString overrideUserAgent = WebString::fromUTF8("dummy override"); | |
106 | |
107 // Override the user agent and make sure we get it back. | |
108 EXPECT_CALL(webFrameClient(), userAgentOverride()) | |
109 .WillOnce(Return(overrideUserAgent)); | |
110 EXPECT_TRUE(overrideUserAgent.equals(userAgent())); | |
111 Mock::VerifyAndClearExpectations(&webFrameClient()); | |
112 | |
113 // Remove the override and make sure we get the original back. | |
114 EXPECT_CALL(webFrameClient(), userAgentOverride()) | |
115 .WillOnce(Return(WebString())); | |
116 EXPECT_TRUE(defaultUserAgent.equals(userAgent())); | |
117 } | |
118 | |
119 } // namespace | |
120 } // namespace blink | |
OLD | NEW |