OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
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/FrameLoaderClientImpl.h" | 31 #include "web/LocalFrameClientImpl.h" |
32 | 32 |
33 #include "core/loader/FrameLoader.h" | 33 #include "core/loader/FrameLoader.h" |
34 #include "platform/weborigin/KURL.h" | 34 #include "platform/weborigin/KURL.h" |
35 #include "public/web/WebFrameClient.h" | 35 #include "public/web/WebFrameClient.h" |
36 #include "public/web/WebSettings.h" | 36 #include "public/web/WebSettings.h" |
37 #include "public/web/WebView.h" | 37 #include "public/web/WebView.h" |
38 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
40 #include "web/WebLocalFrameImpl.h" | 40 #include "web/WebLocalFrameImpl.h" |
41 #include "web/tests/FrameTestHelpers.h" | 41 #include "web/tests/FrameTestHelpers.h" |
42 #include "wtf/text/CString.h" | 42 #include "wtf/text/CString.h" |
43 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.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 { |
53 public: | 53 public: |
54 ~MockWebFrameClient() override {} | 54 ~MockWebFrameClient() override {} |
55 | 55 |
56 MOCK_METHOD0(userAgentOverride, WebString()); | 56 MOCK_METHOD0(userAgentOverride, WebString()); |
57 }; | 57 }; |
58 | 58 |
59 class FrameLoaderClientImplTest : public ::testing::Test { | 59 class LocalFrameClientImplTest : public ::testing::Test { |
60 protected: | 60 protected: |
61 void SetUp() override { | 61 void SetUp() override { |
62 ON_CALL(m_webFrameClient, userAgentOverride()) | 62 ON_CALL(m_webFrameClient, userAgentOverride()) |
63 .WillByDefault(Return(WebString())); | 63 .WillByDefault(Return(WebString())); |
64 | 64 |
65 FrameTestHelpers::TestWebViewClient webViewClient; | 65 FrameTestHelpers::TestWebViewClient webViewClient; |
66 m_webView = WebView::create(&webViewClient, WebPageVisibilityStateVisible); | 66 m_webView = WebView::create(&webViewClient, WebPageVisibilityStateVisible); |
67 // FIXME: http://crbug.com/363843. This needs to find a better way to | 67 // FIXME: http://crbug.com/363843. This needs to find a better way to |
68 // not create graphics layers. | 68 // not create graphics layers. |
69 m_webView->settings()->setAcceleratedCompositingEnabled(false); | 69 m_webView->settings()->setAcceleratedCompositingEnabled(false); |
70 m_mainFrame = WebLocalFrame::create(WebTreeScopeType::Document, | 70 m_mainFrame = WebLocalFrame::create(WebTreeScopeType::Document, |
71 &m_webFrameClient, nullptr, nullptr); | 71 &m_webFrameClient, nullptr, nullptr); |
72 m_webView->setMainFrame(m_mainFrame); | 72 m_webView->setMainFrame(m_mainFrame); |
73 } | 73 } |
74 | 74 |
75 void TearDown() override { m_webView->close(); } | 75 void TearDown() override { m_webView->close(); } |
76 | 76 |
77 WebString userAgent() { | 77 WebString userAgent() { |
78 // The test always returns the same user agent . | 78 // The test always returns the same user agent . |
79 WTF::CString userAgent = frameLoaderClient().userAgent().utf8(); | 79 WTF::CString userAgent = localFrameClient().userAgent().utf8(); |
80 return WebString::fromUTF8(userAgent.data(), userAgent.length()); | 80 return WebString::fromUTF8(userAgent.data(), userAgent.length()); |
81 } | 81 } |
82 | 82 |
83 WebLocalFrameImpl* mainFrame() { | 83 WebLocalFrameImpl* mainFrame() { |
84 return toWebLocalFrameImpl(m_webView->mainFrame()); | 84 return toWebLocalFrameImpl(m_webView->mainFrame()); |
85 } | 85 } |
86 Document& document() { | 86 Document& document() { |
87 return *toWebLocalFrameImpl(m_mainFrame)->frame()->document(); | 87 return *toWebLocalFrameImpl(m_mainFrame)->frame()->document(); |
88 } | 88 } |
89 MockWebFrameClient& webFrameClient() { return m_webFrameClient; } | 89 MockWebFrameClient& webFrameClient() { return m_webFrameClient; } |
90 FrameLoaderClient& frameLoaderClient() { | 90 LocalFrameClient& localFrameClient() { |
91 return *toFrameLoaderClientImpl(toWebLocalFrameImpl(m_webView->mainFrame()) | 91 return *toLocalFrameClientImpl(toWebLocalFrameImpl(m_webView->mainFrame()) |
92 ->frame() | 92 ->frame() |
93 ->loader() | 93 ->loader() |
94 .client()); | 94 .client()); |
95 } | 95 } |
96 | 96 |
97 private: | 97 private: |
98 MockWebFrameClient m_webFrameClient; | 98 MockWebFrameClient m_webFrameClient; |
99 WebView* m_webView; | 99 WebView* m_webView; |
100 WebLocalFrame* m_mainFrame; | 100 WebLocalFrame* m_mainFrame; |
101 }; | 101 }; |
102 | 102 |
103 TEST_F(FrameLoaderClientImplTest, UserAgentOverride) { | 103 TEST_F(LocalFrameClientImplTest, UserAgentOverride) { |
104 const WebString defaultUserAgent = userAgent(); | 104 const WebString defaultUserAgent = userAgent(); |
105 const WebString overrideUserAgent = WebString::fromUTF8("dummy override"); | 105 const WebString overrideUserAgent = WebString::fromUTF8("dummy override"); |
106 | 106 |
107 // Override the user agent and make sure we get it back. | 107 // Override the user agent and make sure we get it back. |
108 EXPECT_CALL(webFrameClient(), userAgentOverride()) | 108 EXPECT_CALL(webFrameClient(), userAgentOverride()) |
109 .WillOnce(Return(overrideUserAgent)); | 109 .WillOnce(Return(overrideUserAgent)); |
110 EXPECT_TRUE(overrideUserAgent.equals(userAgent())); | 110 EXPECT_TRUE(overrideUserAgent.equals(userAgent())); |
111 Mock::VerifyAndClearExpectations(&webFrameClient()); | 111 Mock::VerifyAndClearExpectations(&webFrameClient()); |
112 | 112 |
113 // Remove the override and make sure we get the original back. | 113 // Remove the override and make sure we get the original back. |
114 EXPECT_CALL(webFrameClient(), userAgentOverride()) | 114 EXPECT_CALL(webFrameClient(), userAgentOverride()) |
115 .WillOnce(Return(WebString())); | 115 .WillOnce(Return(WebString())); |
116 EXPECT_TRUE(defaultUserAgent.equals(userAgent())); | 116 EXPECT_TRUE(defaultUserAgent.equals(userAgent())); |
117 } | 117 } |
118 | 118 |
119 } // namespace | 119 } // namespace |
120 } // namespace blink | 120 } // namespace blink |
OLD | NEW |