Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * All original work by Opera Softare ASA contained in this source | |
| 3 * code distribution is licensed as follows: | |
| 4 * | |
| 5 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | |
| 6 * | |
| 7 * Redistribution and use in source and binary forms, with or without | |
| 8 * modification, are permitted provided that the following conditions | |
| 9 * are met: | |
| 10 * | |
| 11 * 1. Redistributions of source code must retain the above copyright | |
| 12 * notice, this list of conditions and the following disclaimer. | |
| 13 * 2. Redistributions in binary form must reproduce the above copyright | |
| 14 * notice, this list of conditions and the following disclaimer in the | |
| 15 * documentation and/or other materials provided with the distribution. | |
| 16 * 3. Neither the name of Opera Software ASA nor the names of its | |
| 17 * contributors may be used to endorse or promote products derived | |
| 18 * from this software without specific prior written permission. | |
| 19 * | |
| 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 31 * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 32 */ | |
| 33 | |
| 34 #include "config.h" | |
| 35 | |
| 36 #include "core/page/PageSerializer.h" | |
| 37 | |
| 38 #include "FrameTestHelpers.h" | |
| 39 #include "URLTestHelpers.h" | |
| 40 #include "WebFrameClient.h" | |
| 41 #include "WebFrameImpl.h" | |
| 42 #include "WebSettings.h" | |
| 43 #include "WebViewImpl.h" | |
| 44 | |
| 
 
abarth-chromium
2013/06/18 09:42:20
There's no need for all these blank lines.  You ca
 
 | |
| 45 #include "core/page/Page.h" | |
| 46 #include "core/platform/SerializedResource.h" | |
| 47 | |
| 48 #include "public/platform/Platform.h" | |
| 49 #include "public/platform/WebString.h" | |
| 50 #include "public/platform/WebThread.h" | |
| 51 #include "public/platform/WebURL.h" | |
| 52 #include "public/platform/WebURLRequest.h" | |
| 53 #include "public/platform/WebURLResponse.h" | |
| 54 #include "public/platform/WebUnitTestSupport.h" | |
| 55 | |
| 56 #include "wtf/Vector.h" | |
| 57 | |
| 58 #include <gtest/gtest.h> | |
| 59 | |
| 60 using namespace WebCore; | |
| 61 using namespace WebKit; | |
| 62 using WebKit::FrameTestHelpers::runPendingTasks; | |
| 63 using WebKit::URLTestHelpers::toKURL; | |
| 64 using WebKit::URLTestHelpers::registerMockedURLLoad; | |
| 65 | |
| 66 namespace { | |
| 67 | |
| 68 class TestWebFrameClient : public WebFrameClient { | |
| 69 public: | |
| 70 virtual ~TestWebFrameClient() { } | |
| 71 }; | |
| 72 | |
| 73 class PageSerializeTest : public testing::Test { | |
| 
 
abarth-chromium
2013/06/18 09:42:20
PageSerializeTest -> PageSerializerTest
 
 | |
| 74 public: | |
| 75 PageSerializeTest() : m_folder(WebString::fromUTF8("pageserializer/")), | |
| 
 
abarth-chromium
2013/06/18 09:42:20
Please add a line break between the () and the :
 
 | |
| 76 m_baseUrl(toKURL("http://www.test.com")) | |
| 77 { | |
| 78 } | |
| 79 | |
| 80 protected: | |
| 81 virtual void SetUp() | |
| 82 { | |
| 83 // Create and initialize the WebView. | |
| 84 m_webViewImpl = static_cast<WebViewImpl*>(WebView::create(0)); | |
| 85 | |
| 86 // We want the images to load and JavaScript to be on. | |
| 87 WebSettings* settings = m_webViewImpl->settings(); | |
| 88 settings->setImagesEnabled(true); | |
| 89 settings->setLoadsImagesAutomatically(true); | |
| 90 settings->setJavaScriptEnabled(true); | |
| 91 | |
| 92 m_webViewImpl->initializeMainFrame(&m_webFrameClient); | |
| 93 } | |
| 94 | |
| 95 virtual void TearDown() | |
| 96 { | |
| 97 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | |
| 98 m_webViewImpl->close(); | |
| 
 
abarth-chromium
2013/06/18 09:42:20
Please set m_webViewImpl to 0 after closing it.
 
 | |
| 99 } | |
| 100 | |
| 101 void setBaseUrl(const char* url) | |
| 102 { | |
| 103 m_baseUrl = toKURL(url); | |
| 104 } | |
| 105 | |
| 106 void setBaseFolder(const char* folder) | |
| 107 { | |
| 108 m_folder = WebString::fromUTF8(folder); | |
| 109 } | |
| 110 | |
| 111 void registerURL(const char* file, const char* mimeType) | |
| 112 { | |
| 113 registerMockedURLLoad(KURL(m_baseUrl, file), WebString::fromUTF8(file), m_folder, WebString::fromUTF8(mimeType)); | |
| 114 } | |
| 115 | |
| 116 void serialize(const char* url) | |
| 117 { | |
| 118 WebURLRequest urlRequest; | |
| 119 urlRequest.initialize(); | |
| 120 urlRequest.setURL(KURL(m_baseUrl, url)); | |
| 121 m_webViewImpl->mainFrame()->loadRequest(urlRequest); | |
| 122 // Make sure any pending request get served. | |
| 123 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); | |
| 124 // Some requests get delayed, run the timer. | |
| 125 runPendingTasks(); | |
| 126 // Server the delayed resources. | |
| 127 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); | |
| 128 | |
| 129 PageSerializer serializer(&m_resources); | |
| 130 serializer.serialize(m_webViewImpl->mainFrameImpl()->frame()->page()); | |
| 131 } | |
| 132 | |
| 133 Vector<SerializedResource>& getResources() | |
| 134 { | |
| 135 return m_resources; | |
| 136 } | |
| 137 | |
| 138 bool isSerialized(const char* url, const char* mimeType) | |
| 139 { | |
| 140 KURL kURL = KURL(m_baseUrl, url); | |
| 141 WTF::String mime(mimeType); | |
| 142 for (size_t i = 0; i < m_resources.size(); ++i) { | |
| 143 const SerializedResource& resource = m_resources[i]; | |
| 144 if (resource.url == kURL && !resource.data->isEmpty() && equalIgnori ngCase(resource.mimeType, mime)) | |
| 145 return true; | |
| 146 } | |
| 147 return false; | |
| 148 } | |
| 149 | |
| 150 WebViewImpl* m_webViewImpl; | |
| 151 | |
| 152 private: | |
| 153 TestWebFrameClient m_webFrameClient; | |
| 154 WebString m_folder; | |
| 155 KURL m_baseUrl; | |
| 156 Vector<SerializedResource> m_resources; | |
| 157 }; | |
| 158 | |
| 159 | |
| 160 TEST_F(PageSerializeTest, InputImage) | |
| 161 { | |
| 162 setBaseFolder("pageserializer/input-image/"); | |
| 163 | |
| 164 registerURL("input-image.html", "text/html"); | |
| 165 registerURL("button.png", "image/png"); | |
| 166 | |
| 167 serialize("input-image.html"); | |
| 168 | |
| 169 EXPECT_TRUE(isSerialized("button.png", "image/png")); | |
| 170 EXPECT_FALSE(isSerialized("non-existing-button.png", "image/png")); | |
| 171 } | |
| 172 | |
| 173 } | |
| OLD | NEW |