OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 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 <functional> |
| 32 #include <list> |
| 33 #include <memory> |
31 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
32 #include "platform/testing/URLTestHelpers.h" | 35 #include "platform/testing/URLTestHelpers.h" |
| 36 #include "platform/testing/UnitTestHelpers.h" |
33 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
34 #include "public/platform/WebPrerender.h" | 38 #include "public/platform/WebPrerender.h" |
35 #include "public/platform/WebPrerenderingSupport.h" | 39 #include "public/platform/WebPrerenderingSupport.h" |
36 #include "public/platform/WebString.h" | 40 #include "public/platform/WebString.h" |
37 #include "public/platform/WebURLLoaderMockFactory.h" | 41 #include "public/platform/WebURLLoaderMockFactory.h" |
38 #include "public/web/WebCache.h" | 42 #include "public/web/WebCache.h" |
39 #include "public/web/WebFrame.h" | 43 #include "public/web/WebFrame.h" |
40 #include "public/web/WebPrerendererClient.h" | 44 #include "public/web/WebPrerendererClient.h" |
41 #include "public/web/WebScriptSource.h" | 45 #include "public/web/WebScriptSource.h" |
42 #include "public/web/WebView.h" | 46 #include "public/web/WebView.h" |
43 #include "public/web/WebViewClient.h" | 47 #include "public/web/WebViewClient.h" |
44 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
45 #include "web/WebLocalFrameImpl.h" | 49 #include "web/WebLocalFrameImpl.h" |
46 #include "web/tests/FrameTestHelpers.h" | 50 #include "web/tests/FrameTestHelpers.h" |
47 #include "wtf/PtrUtil.h" | 51 #include "wtf/PtrUtil.h" |
48 #include <functional> | |
49 #include <list> | |
50 #include <memory> | |
51 | 52 |
52 namespace blink { | 53 namespace blink { |
53 | 54 |
54 namespace { | 55 namespace { |
55 | 56 |
56 WebURL toWebURL(const char* url) { | 57 WebURL toWebURL(const char* url) { |
57 return WebURL(blink::URLTestHelpers::toKURL(url)); | 58 return WebURL(blink::URLTestHelpers::toKURL(url)); |
58 } | 59 } |
59 | 60 |
60 class TestPrerendererClient : public WebPrerendererClient { | 61 class TestPrerendererClient : public WebPrerendererClient { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 m_abandonedPrerenders.push_back(prerender); | 149 m_abandonedPrerenders.push_back(prerender); |
149 } | 150 } |
150 | 151 |
151 void prefetchFinished() override {} | 152 void prefetchFinished() override {} |
152 | 153 |
153 Vector<WebPrerender> m_addedPrerenders; | 154 Vector<WebPrerender> m_addedPrerenders; |
154 Vector<WebPrerender> m_canceledPrerenders; | 155 Vector<WebPrerender> m_canceledPrerenders; |
155 Vector<WebPrerender> m_abandonedPrerenders; | 156 Vector<WebPrerender> m_abandonedPrerenders; |
156 }; | 157 }; |
157 | 158 |
158 class PrerenderingTest : public testing::Test { | 159 class PrerenderingTest : public ::testing::Test { |
159 public: | 160 public: |
160 ~PrerenderingTest() override { | 161 ~PrerenderingTest() override { |
161 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 162 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
162 WebCache::clear(); | 163 WebCache::clear(); |
163 } | 164 } |
164 | 165 |
165 void initialize(const char* baseURL, const char* fileName) { | 166 void initialize(const char* baseURL, const char* fileName) { |
166 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL), | 167 URLTestHelpers::registerMockedURLLoadFromBase( |
167 WebString::fromUTF8(fileName)); | 168 WebString::fromUTF8(baseURL), blink::testing::webTestDataPath(), |
| 169 WebString::fromUTF8(fileName)); |
168 const bool RunJavascript = true; | 170 const bool RunJavascript = true; |
169 m_webViewHelper.initialize(RunJavascript); | 171 m_webViewHelper.initialize(RunJavascript); |
170 m_webViewHelper.webView()->setPrerendererClient(&m_prerendererClient); | 172 m_webViewHelper.webView()->setPrerendererClient(&m_prerendererClient); |
171 | 173 |
172 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), | 174 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), |
173 std::string(baseURL) + fileName); | 175 std::string(baseURL) + fileName); |
174 } | 176 } |
175 | 177 |
176 void navigateAway() { | 178 void navigateAway() { |
177 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), | 179 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 467 |
466 WebPrerender relNextAndPrerender = prerendererClient()->releaseWebPrerender(); | 468 WebPrerender relNextAndPrerender = prerendererClient()->releaseWebPrerender(); |
467 EXPECT_EQ(toWebURL("http://rel-next-and-prerender.com/"), | 469 EXPECT_EQ(toWebURL("http://rel-next-and-prerender.com/"), |
468 relNextAndPrerender.url()); | 470 relNextAndPrerender.url()); |
469 EXPECT_EQ( | 471 EXPECT_EQ( |
470 static_cast<unsigned>(PrerenderRelTypeNext | PrerenderRelTypePrerender), | 472 static_cast<unsigned>(PrerenderRelTypeNext | PrerenderRelTypePrerender), |
471 relNextAndPrerender.relTypes()); | 473 relNextAndPrerender.relTypes()); |
472 } | 474 } |
473 | 475 |
474 } // namespace blink | 476 } // namespace blink |
OLD | NEW |