Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2667283007: Refactor Samsung SmartClip implementation. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 3136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3147 "border: 2px solid skyblue; float: left; width: 190px; height: 30px; " 3147 "border: 2px solid skyblue; float: left; width: 190px; height: 30px; "
3148 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: " 3148 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: "
3149 "normal; font-variant-ligatures: normal; font-variant-caps: normal; " 3149 "normal; font-variant-ligatures: normal; font-variant-caps: normal; "
3150 "font-weight: normal; letter-spacing: normal; orphans: 2; text-align: " 3150 "font-weight: normal; letter-spacing: normal; orphans: 2; text-align: "
3151 "start; text-indent: 0px; text-transform: none; white-space: normal; " 3151 "start; text-indent: 0px; text-transform: none; white-space: normal; "
3152 "widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; " 3152 "widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; "
3153 "text-decoration-style: initial; text-decoration-color: initial;\">Price " 3153 "text-decoration-style: initial; text-decoration-color: initial;\">Price "
3154 "10,000,000won</div>"; 3154 "10,000,000won</div>";
3155 WebString clipText; 3155 WebString clipText;
3156 WebString clipHtml; 3156 WebString clipHtml;
3157 WebRect clipRect;
3158 URLTestHelpers::registerMockedURLFromBaseURL( 3157 URLTestHelpers::registerMockedURLFromBaseURL(
3159 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf")); 3158 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf"));
3160 URLTestHelpers::registerMockedURLFromBaseURL( 3159 URLTestHelpers::registerMockedURLFromBaseURL(
3161 WebString::fromUTF8(m_baseURL.c_str()), 3160 WebString::fromUTF8(m_baseURL.c_str()),
3162 WebString::fromUTF8("smartclip.html")); 3161 WebString::fromUTF8("smartclip.html"));
3163 WebView* webView = 3162 WebViewImpl* webView =
3164 m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.html"); 3163 m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.html");
3165 webView->resize(WebSize(500, 500)); 3164 webView->resize(WebSize(500, 500));
3166 webView->updateAllLifecyclePhases(); 3165 webView->updateAllLifecyclePhases();
3167 WebRect cropRect(300, 125, 152, 50); 3166 WebRect cropRect(300, 125, 152, 50);
3168 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); 3167 webView->mainFrameImpl()->extractSmartClipData(cropRect, clipText, clipHtml);
3169 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str()); 3168 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str());
3170 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str()); 3169 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str());
3171 } 3170 }
3172 3171
3173 TEST_P(WebViewTest, SmartClipDataWithPinchZoom) { 3172 TEST_P(WebViewTest, SmartClipDataWithPinchZoom) {
3174 static const char kExpectedClipText[] = "\nPrice 10,000,000won"; 3173 static const char kExpectedClipText[] = "\nPrice 10,000,000won";
3175 static const char kExpectedClipHtml[] = 3174 static const char kExpectedClipHtml[] =
3176 "<div id=\"div4\" style=\"padding: 10px; margin: 10px; border: 2px " 3175 "<div id=\"div4\" style=\"padding: 10px; margin: 10px; border: 2px "
3177 "solid skyblue; float: left; width: 190px; height: 30px; " 3176 "solid skyblue; float: left; width: 190px; height: 30px; "
3178 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: " 3177 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: "
3179 "normal; font-variant-ligatures: normal; font-variant-caps: normal; " 3178 "normal; font-variant-ligatures: normal; font-variant-caps: normal; "
3180 "font-weight: normal; letter-spacing: " 3179 "font-weight: normal; letter-spacing: "
3181 "normal; orphans: 2; text-align: start; " 3180 "normal; orphans: 2; text-align: start; "
3182 "text-indent: 0px; text-transform: none; white-space: normal; widows: " 3181 "text-indent: 0px; text-transform: none; white-space: normal; widows: "
3183 "2; word-spacing: 0px; -webkit-text-stroke-width: 0px; " 3182 "2; word-spacing: 0px; -webkit-text-stroke-width: 0px; "
3184 "text-decoration-style: initial; text-decoration-color: initial;\">Air " 3183 "text-decoration-style: initial; text-decoration-color: initial;\">Air "
3185 "conditioner</div><div id=\"div5\" style=\"padding: 10px; margin: 10px; " 3184 "conditioner</div><div id=\"div5\" style=\"padding: 10px; margin: 10px; "
3186 "border: 2px solid skyblue; float: left; width: 190px; height: 30px; " 3185 "border: 2px solid skyblue; float: left; width: 190px; height: 30px; "
3187 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: " 3186 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: "
3188 "normal; font-variant-ligatures: normal; font-variant-caps: normal; " 3187 "normal; font-variant-ligatures: normal; font-variant-caps: normal; "
3189 "font-weight: normal; letter-spacing: normal; orphans: 2; text-align: " 3188 "font-weight: normal; letter-spacing: normal; orphans: 2; text-align: "
3190 "start; text-indent: 0px; text-transform: none; white-space: normal; " 3189 "start; text-indent: 0px; text-transform: none; white-space: normal; "
3191 "widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; " 3190 "widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; "
3192 "text-decoration-style: initial; text-decoration-color: initial;\">Price " 3191 "text-decoration-style: initial; text-decoration-color: initial;\">Price "
3193 "10,000,000won</div>"; 3192 "10,000,000won</div>";
3194 WebString clipText; 3193 WebString clipText;
3195 WebString clipHtml; 3194 WebString clipHtml;
3196 WebRect clipRect;
3197 URLTestHelpers::registerMockedURLFromBaseURL( 3195 URLTestHelpers::registerMockedURLFromBaseURL(
3198 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf")); 3196 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf"));
3199 URLTestHelpers::registerMockedURLFromBaseURL( 3197 URLTestHelpers::registerMockedURLFromBaseURL(
3200 WebString::fromUTF8(m_baseURL.c_str()), 3198 WebString::fromUTF8(m_baseURL.c_str()),
3201 WebString::fromUTF8("smartclip.html")); 3199 WebString::fromUTF8("smartclip.html"));
3202 WebView* webView = 3200 WebViewImpl* webView =
3203 m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.html"); 3201 m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.html");
3204 webView->resize(WebSize(500, 500)); 3202 webView->resize(WebSize(500, 500));
3205 webView->updateAllLifecyclePhases(); 3203 webView->updateAllLifecyclePhases();
3206 webView->setPageScaleFactor(1.5); 3204 webView->setPageScaleFactor(1.5);
3207 webView->setVisualViewportOffset(WebFloatPoint(167, 100)); 3205 webView->setVisualViewportOffset(WebFloatPoint(167, 100));
3208 WebRect cropRect(200, 38, 228, 75); 3206 WebRect cropRect(200, 38, 228, 75);
3209 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); 3207 webView->mainFrameImpl()->extractSmartClipData(cropRect, clipText, clipHtml);
3210 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str()); 3208 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str());
3211 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str()); 3209 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str());
3212 } 3210 }
3213 3211
3214 TEST_P(WebViewTest, SmartClipReturnsEmptyStringsWhenUserSelectIsNone) { 3212 TEST_P(WebViewTest, SmartClipReturnsEmptyStringsWhenUserSelectIsNone) {
3215 WebString clipText; 3213 WebString clipText;
3216 WebString clipHtml; 3214 WebString clipHtml;
3217 WebRect clipRect;
3218 URLTestHelpers::registerMockedURLFromBaseURL( 3215 URLTestHelpers::registerMockedURLFromBaseURL(
3219 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf")); 3216 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf"));
3220 URLTestHelpers::registerMockedURLFromBaseURL( 3217 URLTestHelpers::registerMockedURLFromBaseURL(
3221 WebString::fromUTF8(m_baseURL.c_str()), 3218 WebString::fromUTF8(m_baseURL.c_str()),
3222 WebString::fromUTF8("smartclip_user_select_none.html")); 3219 WebString::fromUTF8("smartclip_user_select_none.html"));
3223 WebView* webView = m_webViewHelper.initializeAndLoad( 3220 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
3224 m_baseURL + "smartclip_user_select_none.html"); 3221 m_baseURL + "smartclip_user_select_none.html");
3225 webView->resize(WebSize(500, 500)); 3222 webView->resize(WebSize(500, 500));
3226 webView->updateAllLifecyclePhases(); 3223 webView->updateAllLifecyclePhases();
3227 WebRect cropRect(0, 0, 100, 100); 3224 WebRect cropRect(0, 0, 100, 100);
3228 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); 3225 webView->mainFrameImpl()->extractSmartClipData(cropRect, clipText, clipHtml);
3229 EXPECT_STREQ("", clipText.utf8().c_str()); 3226 EXPECT_STREQ("", clipText.utf8().c_str());
3230 EXPECT_STREQ("", clipHtml.utf8().c_str()); 3227 EXPECT_STREQ("", clipHtml.utf8().c_str());
3231 } 3228 }
3232 3229
3233 TEST_P(WebViewTest, SmartClipDoesNotCrashPositionReversed) { 3230 TEST_P(WebViewTest, SmartClipDoesNotCrashPositionReversed) {
3234 WebString clipText; 3231 WebString clipText;
3235 WebString clipHtml; 3232 WebString clipHtml;
3236 WebRect clipRect;
3237 URLTestHelpers::registerMockedURLFromBaseURL( 3233 URLTestHelpers::registerMockedURLFromBaseURL(
3238 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf")); 3234 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf"));
3239 URLTestHelpers::registerMockedURLFromBaseURL( 3235 URLTestHelpers::registerMockedURLFromBaseURL(
3240 WebString::fromUTF8(m_baseURL.c_str()), 3236 WebString::fromUTF8(m_baseURL.c_str()),
3241 WebString::fromUTF8("smartclip_reversed_positions.html")); 3237 WebString::fromUTF8("smartclip_reversed_positions.html"));
3242 WebView* webView = m_webViewHelper.initializeAndLoad( 3238 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
3243 m_baseURL + "smartclip_reversed_positions.html"); 3239 m_baseURL + "smartclip_reversed_positions.html");
3244 webView->resize(WebSize(500, 500)); 3240 webView->resize(WebSize(500, 500));
3245 webView->updateAllLifecyclePhases(); 3241 webView->updateAllLifecyclePhases();
3246 // Left upper corner of the rect will be end position in the DOM hierarchy. 3242 // Left upper corner of the rect will be end position in the DOM hierarchy.
3247 WebRect cropRect(30, 110, 400, 250); 3243 WebRect cropRect(30, 110, 400, 250);
3248 // This should not still crash. See crbug.com/589082 for more details. 3244 // This should not still crash. See crbug.com/589082 for more details.
3249 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); 3245 webView->mainFrameImpl()->extractSmartClipData(cropRect, clipText, clipHtml);
3250 } 3246 }
3251 3247
3252 class CreateChildCounterFrameClient 3248 class CreateChildCounterFrameClient
3253 : public FrameTestHelpers::TestWebFrameClient { 3249 : public FrameTestHelpers::TestWebFrameClient {
3254 public: 3250 public:
3255 CreateChildCounterFrameClient() : m_count(0) {} 3251 CreateChildCounterFrameClient() : m_count(0) {}
3256 WebLocalFrame* createChildFrame(WebLocalFrame* parent, 3252 WebLocalFrame* createChildFrame(WebLocalFrame* parent,
3257 WebTreeScopeType, 3253 WebTreeScopeType,
3258 const WebString& name, 3254 const WebString& name,
3259 const WebString& uniqueName, 3255 const WebString& uniqueName,
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4373 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); 4369 EXPECT_EQ(expectedWidth, vwElement->offsetWidth());
4374 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); 4370 EXPECT_EQ(expectedHeight, vwElement->offsetHeight());
4375 4371
4376 webView->resize(WebSize(800, 600)); 4372 webView->resize(WebSize(800, 600));
4377 frame->printEnd(); 4373 frame->printEnd();
4378 4374
4379 EXPECT_EQ(800, vwElement->offsetWidth()); 4375 EXPECT_EQ(800, vwElement->offsetWidth());
4380 } 4376 }
4381 4377
4382 } // namespace blink 4378 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698