| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #import <EarlGrey/EarlGrey.h> | 8 #import <EarlGrey/EarlGrey.h> |
| 9 | 9 |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/sys_string_conversions.h" |
| 11 #import "base/test/ios/wait_util.h" | 12 #import "base/test/ios/wait_util.h" |
| 12 #import "ios/web/public/test/http_server.h" | 13 #import "ios/web/public/test/http_server.h" |
| 13 #include "ios/web/public/test/http_server_util.h" | 14 #include "ios/web/public/test/http_server_util.h" |
| 14 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" | 15 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
| 15 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 16 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| 16 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" | 17 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." | 21 #error "This file requires ARC support." |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 using web::WebViewContainingText; | 24 using base::SysUTF8ToNSString; |
| 24 using web::WebViewCssSelector; | 25 using web::WebViewCssSelector; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Loads a web page with given content. | 29 // Loads a web page with given content. |
| 29 void LoadPage(const std::string& page_content) { | 30 void LoadPage(const std::string& page_content) { |
| 30 const GURL url = web::test::HttpServer::MakeUrl("http://plugin"); | 31 const GURL url = web::test::HttpServer::MakeUrl("http://plugin"); |
| 31 std::map<GURL, std::string> responses{{url, page_content}}; | 32 std::map<GURL, std::string> responses{{url, page_content}}; |
| 32 web::test::SetUpSimpleHttpServer(responses); | 33 web::test::SetUpSimpleHttpServer(responses); |
| 33 [ShellEarlGrey loadURL:url]; | 34 [ShellEarlGrey loadURL:url]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 "<html><body width='800' height='600'>" | 51 "<html><body width='800' height='600'>" |
| 51 "<p>%s</p>" | 52 "<p>%s</p>" |
| 52 "<applet code='Some.class' width='550' height='550'>" | 53 "<applet code='Some.class' width='550' height='550'>" |
| 53 " <p>%s</p>" | 54 " <p>%s</p>" |
| 54 "</applet>" | 55 "</applet>" |
| 55 "</body></html>", | 56 "</body></html>", |
| 56 kPageDescription, kFallbackText); | 57 kPageDescription, kFallbackText); |
| 57 LoadPage(page); | 58 LoadPage(page); |
| 58 | 59 |
| 59 // Verify that placeholder image is not displayed. | 60 // Verify that placeholder image is not displayed. |
| 60 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 61 [ShellEarlGrey |
| 61 assertWithMatcher:grey_notNil()]; | 62 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 62 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFallbackText)] | 63 [ShellEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kFallbackText)]; |
| 63 assertWithMatcher:grey_notNil()]; | |
| 64 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 64 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 65 assertWithMatcher:grey_nil()]; | 65 assertWithMatcher:grey_nil()]; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Tests placeholder for a large <applet> with no fallback. | 68 // Tests placeholder for a large <applet> with no fallback. |
| 69 - (void)testPluginPlaceholderAppletOnly { | 69 - (void)testPluginPlaceholderAppletOnly { |
| 70 const char kPageDescription[] = "Applet, no fallback"; | 70 const char kPageDescription[] = "Applet, no fallback"; |
| 71 const std::string page = base::StringPrintf( | 71 const std::string page = base::StringPrintf( |
| 72 "<html><body width='800' height='600'>" | 72 "<html><body width='800' height='600'>" |
| 73 "<p>%s</p>" | 73 "<p>%s</p>" |
| 74 "<applet code='Some.class' width='550' height='550'>" | 74 "<applet code='Some.class' width='550' height='550'>" |
| 75 "</applet>" | 75 "</applet>" |
| 76 "</body></html>", | 76 "</body></html>", |
| 77 kPageDescription); | 77 kPageDescription); |
| 78 LoadPage(page); | 78 LoadPage(page); |
| 79 | 79 |
| 80 // Verify that plugin object is replaced with placeholder image. | 80 // Verify that plugin object is replaced with placeholder image. |
| 81 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 81 [ShellEarlGrey |
| 82 assertWithMatcher:grey_notNil()]; | 82 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 83 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] | 83 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] |
| 84 assertWithMatcher:grey_notNil()]; | 84 assertWithMatcher:grey_notNil()]; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Tests placeholder for a large <object> with an embed fallback. | 87 // Tests placeholder for a large <object> with an embed fallback. |
| 88 - (void)testPluginPlaceholderObjectEmbed { | 88 - (void)testPluginPlaceholderObjectEmbed { |
| 89 const char kPageDescription[] = "Object, embed fallback"; | 89 const char kPageDescription[] = "Object, embed fallback"; |
| 90 const std::string page = base::StringPrintf( | 90 const std::string page = base::StringPrintf( |
| 91 "<html><body width='800' height='600'>" | 91 "<html><body width='800' height='600'>" |
| 92 "<p>%s</p>" | 92 "<p>%s</p>" |
| 93 "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'" | 93 "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'" |
| 94 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" | 94 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" |
| 95 "flash/swflash.cab#version=6,0,0,0' width='550' height='550'>" | 95 "flash/swflash.cab#version=6,0,0,0' width='550' height='550'>" |
| 96 " <param name='movie' value='some.swf'>" | 96 " <param name='movie' value='some.swf'>" |
| 97 " <embed src='some.swf' width='550' height='550'>" | 97 " <embed src='some.swf' width='550' height='550'>" |
| 98 "</object>" | 98 "</object>" |
| 99 "</body></html>", | 99 "</body></html>", |
| 100 kPageDescription); | 100 kPageDescription); |
| 101 LoadPage(page); | 101 LoadPage(page); |
| 102 | 102 |
| 103 // Verify that plugin object is replaced with placeholder image. | 103 // Verify that plugin object is replaced with placeholder image. |
| 104 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 104 [ShellEarlGrey |
| 105 assertWithMatcher:grey_notNil()]; | 105 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 106 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] | 106 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] |
| 107 assertWithMatcher:grey_notNil()]; | 107 assertWithMatcher:grey_notNil()]; |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Tests that a large <object> with text fallback is untouched. | 110 // Tests that a large <object> with text fallback is untouched. |
| 111 - (void)testPluginPlaceholderObjectFallback { | 111 - (void)testPluginPlaceholderObjectFallback { |
| 112 const char kPageDescription[] = "Object, text fallback"; | 112 const char kPageDescription[] = "Object, text fallback"; |
| 113 const char kFallbackText[] = "You don't have Flash. Tough luck!"; | 113 const char kFallbackText[] = "You don't have Flash. Tough luck!"; |
| 114 const std::string page = base::StringPrintf( | 114 const std::string page = base::StringPrintf( |
| 115 "<html><body width='800' height='600'>" | 115 "<html><body width='800' height='600'>" |
| 116 "<p>%s</p>" | 116 "<p>%s</p>" |
| 117 "<object type='application/x-shockwave-flash' data='some.sfw'" | 117 "<object type='application/x-shockwave-flash' data='some.sfw'" |
| 118 " width='550' height='550'>" | 118 " width='550' height='550'>" |
| 119 " <param name='movie' value='some.swf'>" | 119 " <param name='movie' value='some.swf'>" |
| 120 " <p>%s</p>" | 120 " <p>%s</p>" |
| 121 "</object>" | 121 "</object>" |
| 122 "</body></html>", | 122 "</body></html>", |
| 123 kPageDescription, kFallbackText); | 123 kPageDescription, kFallbackText); |
| 124 LoadPage(page); | 124 LoadPage(page); |
| 125 | 125 |
| 126 // Verify that placeholder image is not displayed. | 126 // Verify that placeholder image is not displayed. |
| 127 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 127 [ShellEarlGrey |
| 128 assertWithMatcher:grey_notNil()]; | 128 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 129 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFallbackText)] | 129 [ShellEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kFallbackText)]; |
| 130 assertWithMatcher:grey_notNil()]; | |
| 131 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 130 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 132 assertWithMatcher:grey_nil()]; | 131 assertWithMatcher:grey_nil()]; |
| 133 } | 132 } |
| 134 | 133 |
| 135 // Tests placeholder for a large <object> with no fallback. | 134 // Tests placeholder for a large <object> with no fallback. |
| 136 - (void)testPluginPlaceholderObjectOnly { | 135 - (void)testPluginPlaceholderObjectOnly { |
| 137 const char kPageDescription[] = "Object, no fallback"; | 136 const char kPageDescription[] = "Object, no fallback"; |
| 138 const std::string page = base::StringPrintf( | 137 const std::string page = base::StringPrintf( |
| 139 "<html><body width='800' height='600'>" | 138 "<html><body width='800' height='600'>" |
| 140 "<p>%s</p>" | 139 "<p>%s</p>" |
| 141 "<object type='application/x-shockwave-flash' data='some.swf'" | 140 "<object type='application/x-shockwave-flash' data='some.swf'" |
| 142 " width='550' height='550'>" | 141 " width='550' height='550'>" |
| 143 "</object>" | 142 "</object>" |
| 144 "</body></html>", | 143 "</body></html>", |
| 145 kPageDescription); | 144 kPageDescription); |
| 146 LoadPage(page); | 145 LoadPage(page); |
| 147 | 146 |
| 148 // Verify that plugin object is replaced with placeholder image. | 147 // Verify that plugin object is replaced with placeholder image. |
| 149 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 148 [ShellEarlGrey |
| 150 assertWithMatcher:grey_notNil()]; | 149 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 151 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] | 150 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img[src*='data']")] |
| 152 assertWithMatcher:grey_notNil()]; | 151 assertWithMatcher:grey_notNil()]; |
| 153 } | 152 } |
| 154 | 153 |
| 155 // Tests that a large png <object> is untouched. | 154 // Tests that a large png <object> is untouched. |
| 156 - (void)testPluginPlaceholderPNGObject { | 155 - (void)testPluginPlaceholderPNGObject { |
| 157 const char kPageDescription[] = "PNG object"; | 156 const char kPageDescription[] = "PNG object"; |
| 158 const std::string page = base::StringPrintf( | 157 const std::string page = base::StringPrintf( |
| 159 "<html><body width='800' height='600'>" | 158 "<html><body width='800' height='600'>" |
| 160 "<p>%s</p>" | 159 "<p>%s</p>" |
| 161 "<object data='foo.png' type='image/png' width='550' height='550'>" | 160 "<object data='foo.png' type='image/png' width='550' height='550'>" |
| 162 "</object>" | 161 "</object>" |
| 163 "</body></html>", | 162 "</body></html>", |
| 164 kPageDescription); | 163 kPageDescription); |
| 165 LoadPage(page); | 164 LoadPage(page); |
| 166 | 165 |
| 167 // Verify that placeholder image is not displayed. | 166 // Verify that placeholder image is not displayed. |
| 168 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 167 [ShellEarlGrey |
| 169 assertWithMatcher:grey_notNil()]; | 168 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 170 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 169 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 171 assertWithMatcher:grey_nil()]; | 170 assertWithMatcher:grey_nil()]; |
| 172 } | 171 } |
| 173 | 172 |
| 174 // Test that non-major plugins (e.g., top/side ads) don't get placeholders. | 173 // Test that non-major plugins (e.g., top/side ads) don't get placeholders. |
| 175 - (void)testPluginPlaceholderSmallFlash { | 174 - (void)testPluginPlaceholderSmallFlash { |
| 176 const char kPageDescription[] = "Flash ads"; | 175 const char kPageDescription[] = "Flash ads"; |
| 177 const std::string page = base::StringPrintf( | 176 const std::string page = base::StringPrintf( |
| 178 "<html><body width='800' height='600'>" | 177 "<html><body width='800' height='600'>" |
| 179 "<p>%s</p>" | 178 "<p>%s</p>" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 196 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" | 195 " codebase='http://download.macromedia.com/pub/shockwave/cabs/'" |
| 197 "flash/swflash.cab#version=6,0,0,0' width='728' height='90'>" | 196 "flash/swflash.cab#version=6,0,0,0' width='728' height='90'>" |
| 198 " <param name='movie' value='some.swf'>" | 197 " <param name='movie' value='some.swf'>" |
| 199 " <embed src='some.swf' width='728' height='90'>" | 198 " <embed src='some.swf' width='728' height='90'>" |
| 200 "</object>" | 199 "</object>" |
| 201 "</body></html>", | 200 "</body></html>", |
| 202 kPageDescription); | 201 kPageDescription); |
| 203 LoadPage(page); | 202 LoadPage(page); |
| 204 | 203 |
| 205 // Verify that placeholder image is not displayed. | 204 // Verify that placeholder image is not displayed. |
| 206 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageDescription)] | 205 [ShellEarlGrey |
| 207 assertWithMatcher:grey_notNil()]; | 206 waitForWebViewContainingText:SysUTF8ToNSString(kPageDescription)]; |
| 208 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] | 207 [[EarlGrey selectElementWithMatcher:WebViewCssSelector("img")] |
| 209 assertWithMatcher:grey_nil()]; | 208 assertWithMatcher:grey_nil()]; |
| 210 } | 209 } |
| 211 | 210 |
| 212 @end | 211 @end |
| OLD | NEW |