Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 13 matching lines...) Expand all Loading... | |
| 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 "public/web/WebSearchableFormData.h" | 31 #include "public/web/WebSearchableFormData.h" |
| 32 | 32 |
| 33 #include "platform/testing/URLTestHelpers.h" | 33 #include "platform/testing/URLTestHelpers.h" |
| 34 #include "platform/testing/UnitTestHelpers.h" | |
| 34 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 35 #include "public/platform/WebURLLoaderMockFactory.h" | 36 #include "public/platform/WebURLLoaderMockFactory.h" |
| 36 #include "public/web/WebCache.h" | 37 #include "public/web/WebCache.h" |
| 37 #include "public/web/WebDocument.h" | 38 #include "public/web/WebDocument.h" |
| 38 #include "public/web/WebFrame.h" | 39 #include "public/web/WebFrame.h" |
| 39 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 41 #include "web/tests/FrameTestHelpers.h" | 42 #include "web/tests/FrameTestHelpers.h" |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 class WebSearchableFormDataTest : public testing::Test { | 46 namespace { |
| 47 | |
| 48 void registerMockedURLLoadFromBaseURL(const std::string& baseURL, | |
| 49 const std::string& fileName) { | |
| 50 URLTestHelpers::registerMockedURLLoadFromBase( | |
| 51 WebString::fromUTF8(baseURL.c_str()), testing::webTestDataPath(), | |
|
Takashi Toyoshima
2017/01/26 10:57:58
removing c_str
| |
| 52 WebString::fromUTF8(fileName.c_str())); | |
| 53 } | |
| 54 | |
| 55 class WebSearchableFormDataTest : public ::testing::Test { | |
| 46 protected: | 56 protected: |
| 47 WebSearchableFormDataTest() {} | 57 WebSearchableFormDataTest() {} |
| 48 | 58 |
| 49 ~WebSearchableFormDataTest() override { | 59 ~WebSearchableFormDataTest() override { |
| 50 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 60 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
| 51 WebCache::clear(); | 61 WebCache::clear(); |
| 52 } | 62 } |
| 53 | 63 |
| 54 FrameTestHelpers::WebViewHelper m_webViewHelper; | 64 FrameTestHelpers::WebViewHelper m_webViewHelper; |
| 55 }; | 65 }; |
| 56 | 66 |
| 67 } // namespace | |
| 57 TEST_F(WebSearchableFormDataTest, HttpSearchString) { | 68 TEST_F(WebSearchableFormDataTest, HttpSearchString) { |
| 58 std::string baseURL("http://www.test.com/"); | 69 std::string baseURL("http://www.test.com/"); |
| 59 URLTestHelpers::registerMockedURLFromBaseURL( | 70 registerMockedURLLoadFromBaseURL(baseURL, "search_form_http.html"); |
| 60 WebString::fromUTF8(baseURL.c_str()), "search_form_http.html"); | |
| 61 WebView* webView = | 71 WebView* webView = |
| 62 m_webViewHelper.initializeAndLoad(baseURL + "search_form_http.html"); | 72 m_webViewHelper.initializeAndLoad(baseURL + "search_form_http.html"); |
| 63 | 73 |
| 64 WebVector<WebFormElement> forms; | 74 WebVector<WebFormElement> forms; |
| 65 webView->mainFrame()->document().forms(forms); | 75 webView->mainFrame()->document().forms(forms); |
| 66 | 76 |
| 67 EXPECT_EQ(forms.size(), 1U); | 77 EXPECT_EQ(forms.size(), 1U); |
| 68 | 78 |
| 69 WebSearchableFormData searchableFormData(forms[0]); | 79 WebSearchableFormData searchableFormData(forms[0]); |
| 70 EXPECT_EQ("http://www.mock.url/search?hl=en&q={searchTerms}&btnM=Mock+Search", | 80 EXPECT_EQ("http://www.mock.url/search?hl=en&q={searchTerms}&btnM=Mock+Search", |
| 71 searchableFormData.url().string()); | 81 searchableFormData.url().string()); |
| 72 } | 82 } |
| 73 | 83 |
| 74 TEST_F(WebSearchableFormDataTest, HttpsSearchString) { | 84 TEST_F(WebSearchableFormDataTest, HttpsSearchString) { |
| 75 std::string baseURL("https://www.test.com/"); | 85 std::string baseURL("https://www.test.com/"); |
| 76 URLTestHelpers::registerMockedURLFromBaseURL( | 86 registerMockedURLLoadFromBaseURL(baseURL, "search_form_https.html"); |
| 77 WebString::fromUTF8(baseURL.c_str()), "search_form_https.html"); | |
| 78 WebView* webView = | 87 WebView* webView = |
| 79 m_webViewHelper.initializeAndLoad(baseURL + "search_form_https.html"); | 88 m_webViewHelper.initializeAndLoad(baseURL + "search_form_https.html"); |
| 80 | 89 |
| 81 WebVector<WebFormElement> forms; | 90 WebVector<WebFormElement> forms; |
| 82 webView->mainFrame()->document().forms(forms); | 91 webView->mainFrame()->document().forms(forms); |
| 83 | 92 |
| 84 EXPECT_EQ(forms.size(), 1U); | 93 EXPECT_EQ(forms.size(), 1U); |
| 85 | 94 |
| 86 WebSearchableFormData searchableFormData(forms[0]); | 95 WebSearchableFormData searchableFormData(forms[0]); |
| 87 EXPECT_EQ( | 96 EXPECT_EQ( |
| 88 "https://www.mock.url/search?hl=en&q={searchTerms}&btnM=Mock+Search", | 97 "https://www.mock.url/search?hl=en&q={searchTerms}&btnM=Mock+Search", |
| 89 searchableFormData.url().string()); | 98 searchableFormData.url().string()); |
| 90 } | 99 } |
| 91 | 100 |
| 92 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |