| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/html/parser/HTMLPreloadScanner.h" |
| 7 |
| 8 #include "core/MediaTypeNames.h" |
| 9 #include "core/css/MediaValuesCached.h" |
| 10 #include "core/html/parser/HTMLParserOptions.h" |
| 11 #include "core/html/parser/HTMLResourcePreloader.h" |
| 12 #include "core/testing/DummyPageHolder.h" |
| 13 #include <gtest/gtest.h> |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 typedef struct { |
| 18 const char* baseURL; |
| 19 const char* inputHTML; |
| 20 const char* preloadedURL; |
| 21 const char* outputBaseURL; |
| 22 Resource::Type type; |
| 23 int resourceWidth; |
| 24 } TestCase; |
| 25 |
| 26 class MockHTMLResourcePreloader : public ResourcePreloader { |
| 27 public: |
| 28 void preloadRequestVerification(Resource::Type type, const String& url, cons
t String& baseURL, int width) |
| 29 { |
| 30 EXPECT_EQ(m_preloadRequest->resourceType(), type); |
| 31 EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), url.ascii(
).data()); |
| 32 EXPECT_STREQ(m_preloadRequest->baseURL().ascii().data(), baseURL.ascii()
.data()); |
| 33 EXPECT_EQ(m_preloadRequest->resourceWidth(), width); |
| 34 } |
| 35 |
| 36 protected: |
| 37 virtual void preload(PassOwnPtr<PreloadRequest> preloadRequest) |
| 38 { |
| 39 m_preloadRequest = preloadRequest; |
| 40 } |
| 41 |
| 42 private: |
| 43 |
| 44 OwnPtr<PreloadRequest> m_preloadRequest; |
| 45 }; |
| 46 |
| 47 class HTMLPreloadScannerTest : public testing::Test { |
| 48 protected: |
| 49 HTMLPreloadScannerTest() |
| 50 : m_dummyPageHolder(DummyPageHolder::create()) |
| 51 { |
| 52 } |
| 53 |
| 54 PassRefPtr<MediaValues> createMediaValues() |
| 55 { |
| 56 MediaValuesCached::MediaValuesCachedData data; |
| 57 data.viewportWidth = 500; |
| 58 data.viewportHeight = 600; |
| 59 data.deviceWidth = 500; |
| 60 data.deviceHeight = 500; |
| 61 data.devicePixelRatio = 2.0; |
| 62 data.colorBitsPerComponent = 24; |
| 63 data.monochromeBitsPerComponent = 0; |
| 64 data.primaryPointerType = PointerTypeFine; |
| 65 data.defaultFontSize = 16; |
| 66 data.threeDEnabled = true; |
| 67 data.mediaType = MediaTypeNames::screen; |
| 68 data.strictMode = true; |
| 69 data.displayMode = WebDisplayModeBrowser; |
| 70 return MediaValuesCached::create(data); |
| 71 } |
| 72 |
| 73 virtual void SetUp() |
| 74 { |
| 75 HTMLParserOptions options(&m_dummyPageHolder->document()); |
| 76 KURL documentURL(ParsedURLString, "http://whatever.test/"); |
| 77 m_scanner = HTMLPreloadScanner::create(options, documentURL, createMedia
Values()); |
| 78 |
| 79 } |
| 80 |
| 81 void test(TestCase testCase) |
| 82 { |
| 83 MockHTMLResourcePreloader preloader; |
| 84 KURL baseURL(ParsedURLString, testCase.baseURL); |
| 85 m_scanner->appendToEnd(String(testCase.inputHTML)); |
| 86 m_scanner->scan(&preloader, baseURL); |
| 87 |
| 88 preloader.preloadRequestVerification(testCase.type, testCase.preloadedUR
L, testCase.outputBaseURL, testCase.resourceWidth); |
| 89 } |
| 90 |
| 91 private: |
| 92 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 93 OwnPtr<HTMLPreloadScanner> m_scanner; |
| 94 }; |
| 95 |
| 96 TEST_F(HTMLPreloadScannerTest, testImages) |
| 97 { |
| 98 TestCase testCases[] = { |
| 99 {"http://example.test", "<img src='bla.gif'>", "bla.gif", "http://exampl
e.test/", Resource::Image, 0}, |
| 100 {0, 0, 0, 0, Resource::Raw, 0} // Do not remove the terminator line. |
| 101 }; |
| 102 |
| 103 for (unsigned i = 0; testCases[i].inputHTML; ++i) { |
| 104 TestCase testCase = testCases[i]; |
| 105 test(testCase); |
| 106 } |
| 107 } |
| 108 |
| 109 } |
| OLD | NEW |